commit - 5677e194b16f497f2450d3468248f557068e7f05
commit + c48c4a9c3b2477fbcd1461a40f7bfe2e6fcab5a1
blob - /dev/null
blob + 653a6b140ea86094279af36022357ed7865fe0c4 (mode 644)
--- /dev/null
+++ lib/fileindex.c
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/queue.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sha1.h>
+
+#include "got_error.h"
+
+#include "got_fileindex_priv.h"
+
+const struct got_error *
+got_fileindex_entry_open(struct got_fileindex_entry **entry, const char *path,
+ uint8_t *blob_sha1)
+{
+ struct stat sb;
+ size_t len;
+
+ if (lstat(path, &sb) != 0)
+ return got_error_from_errno();
+
+ *entry = calloc(1, sizeof(**entry));
+ if (*entry == NULL)
+ return got_error(GOT_ERR_NO_MEM);
+
+ (*entry)->path = strdup(path);
+ if ((*entry)->path == NULL) {
+ free(*entry);
+ *entry = NULL;
+ return got_error(GOT_ERR_NO_MEM);
+ }
+
+ (*entry)->ctime_sec = sb.st_ctime;
+ (*entry)->ctime_nsec = sb.st_ctimensec;
+ (*entry)->mtime_sec = sb.st_mtime;
+ (*entry)->mtime_nsec = sb.st_mtimensec;
+ (*entry)->uid = sb.st_uid;
+ (*entry)->gid = sb.st_gid;
+ (*entry)->size = (sb.st_size & 0xffffffff);
+ if (sb.st_mode & S_IFLNK)
+ (*entry)->mode = GOT_INDEX_ENTRY_MODE_SYMLINK;
+ else
+ (*entry)->mode = GOT_INDEX_ENTRY_MODE_REGULAR_FILE;
+ (*entry)->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
+ GOT_INDEX_ENTRY_MODE_PERMS_SHIFT);
+ memcpy((*entry)->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
+ len = strlen(path);
+ if (len > GOT_INDEX_ENTRY_F_PATH_LEN)
+ len = GOT_INDEX_ENTRY_F_PATH_LEN;
+ (*entry)->flags |= len;
+
+ return NULL;
+}
+
+void
+got_fileindex_entry_close(struct got_fileindex_entry *entry)
+{
+ free(entry->path);
+ free(entry);
+}
blob - 67b91d863861d1f4719ff8b4ad689e8b489e74ca
blob + 732e8afe5960c979a1f37d0d499d86f01200b73e
--- lib/got_fileindex_priv.h
+++ lib/got_fileindex_priv.h
* applied back to the filesystem.
*/
struct got_fileindex_entry {
- TAILQ_ENTRY(, got_fileindex_entry) entry;
+ TAILQ_ENTRY(got_fileindex_entry) entry;
uint64_t ctime_sec;
uint64_t ctime_nsec;
uint64_t mtime_sec;
* The value is only used to check for modifications anyway.
*/
uint32_t size;
+
uint16_t mode;
-#define GOT_INDEX_ENTRY_MODE_OBJ_TYPE 0x000f
-#define GOT_INDEX_ENTRY_MODE_PERMS 0xff10
+#define GOT_INDEX_ENTRY_MODE_FILE_TYPE 0x000f
+#define GOT_INDEX_ENTRY_MODE_REGULAR_FILE 1
+#define GOT_INDEX_ENTRY_MODE_SYMLINK 2
+#define GOT_INDEX_ENTRY_MODE_PERMS 0xff10
+#define GOT_INDEX_ENTRY_MODE_PERMS_SHIFT 4
/* SHA1 of corresponding blob in repository. */
uint8_t blob_sha1[SHA1_DIGEST_LENGTH];
* UNIX-style path, relative to work tree root.
* Variable length, and NUL-padded to a multiple of 8 on disk.
*/
- const char *path;
+ char *path;
};
/* "Stages" of a file afflicted by a 3-way merge conflict. */
struct got_fileindex_hdr {
uint32_t signature; /* big-endian on disk */
uint32_t version; /* big-endian on disk */
+#define GOT_FILE_INDEX_VERSION 1
uint32_t nentries; /* big-endian on disk */
TAILQ_HEAD(, got_fileindex_entry) entries;
uint8_t sha1[SHA1_DIGEST_LENGTH]; /* checksum of above on-disk data */
blob - 5d751acef4a4112fea37f987e888afca0651f9bd
blob + cb4b123622c451543c9a1a62b6027745ccc179d7
--- regress/worktree/Makefile
+++ regress/worktree/Makefile
PROG = worktree_test
SRCS = worktree.c repository.c object.c path.c error.c refs.c sha1.c pack.c \
- delta.c zbuf.c worktree_test.c
+ delta.c zbuf.c fileindex.c worktree_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz