Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 /*
18 * State information for a tracked file in a work tree.
19 * When written to disk, multi-byte fields are written in big-endian.
20 * Some fields are based on results from stat(2). These are only used in
21 * order to detect modifications made to on-disk files, they are never
22 * applied back to the filesystem.
23 */
24 struct got_fileindex_entry {
25 TAILQ_ENTRY(got_fileindex_entry) entry;
26 uint64_t ctime_sec;
27 uint64_t ctime_nsec;
28 uint64_t mtime_sec;
29 uint64_t mtime_nsec;
30 uint32_t uid;
31 uint32_t gid;
32 /*
33 * On-disk size is truncated to the lower 32 bits.
34 * The value is only used to check for modifications anyway.
35 */
36 uint32_t size;
38 uint16_t mode;
39 #define GOT_INDEX_ENTRY_MODE_FILE_TYPE 0x000f
40 #define GOT_INDEX_ENTRY_MODE_REGULAR_FILE 1
41 #define GOT_INDEX_ENTRY_MODE_SYMLINK 2
42 #define GOT_INDEX_ENTRY_MODE_PERMS 0xff10
43 #define GOT_INDEX_ENTRY_MODE_PERMS_SHIFT 4
45 /* SHA1 of corresponding blob in repository. */
46 uint8_t blob_sha1[SHA1_DIGEST_LENGTH];
48 uint32_t flags;
49 #define GOT_INDEX_ENTRY_F_PATH_LEN 0x00000fff
50 #define GOT_INDEX_ENTRY_F_STAGE 0x00003000
51 #define GOT_INDEX_ENTRY_F_EXTENDED 0x00004000
52 #define GOT_INDEX_ENTRY_F_ASSUME_VALID 0x00008000
54 /*
55 * UNIX-style path, relative to work tree root.
56 * Variable length, and NUL-padded to a multiple of 8 on disk.
57 */
58 char *path;
60 /* More data could be here if F_EXTENDED is set; To be determined... */
61 };
63 /* "Stages" of a file afflicted by a 3-way merge conflict. */
64 #define GOT_INDEX_ENTRY_STAGE_MERGED 0
65 #define GOT_INDEX_ENTRY_STAGE_ANCESTOR 1
66 #define GOT_INDEX_ENTRY_STAGE_OURS 2
67 #define GOT_INDEX_ENTRY_STAGE_THEIRS 3
69 struct got_fileindex {
70 uint32_t nentries;
71 TAILQ_HEAD(, got_fileindex_entry) entries;
72 };
74 /* On-disk file index header structure. */
75 struct got_fileindex_hdr {
76 uint32_t signature; /* big-endian */
77 #define GOT_FILE_INDEX_SIGNATURE 0x676f7449 /* 'g', 'o', 't', 'I' */
78 uint32_t version; /* big-endian */
79 #define GOT_FILE_INDEX_VERSION 1
80 uint32_t nentries; /* big-endian */
81 /* list of concatenated fileindex entries */
82 uint8_t sha1[SHA1_DIGEST_LENGTH]; /* checksum of above on-disk data */
83 };
85 const struct got_error *got_fileindex_entry_open(struct got_fileindex_entry **,
86 const char *, const char *, uint8_t *);
87 void got_fileindex_entry_close(struct got_fileindex_entry *);
88 struct got_fileindex *got_fileindex_open(void);
89 void got_fileindex_close(struct got_fileindex *);
90 const struct got_error *got_fileindex_write(struct got_fileindex *, FILE *);
91 const struct got_error *got_fileindex_entry_add(struct got_fileindex *,
92 struct got_fileindex_entry *);