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_file_index_entry {
25 uint64_t ctime_sec;
26 uint64_t ctime_nsec;
27 uint64_t mtime_sec;
28 uint64_t mtime_nsec;
29 uint32_t uid;
30 uint32_t gid;
31 /*
32 * On-disk size is truncated to the lower 32 bits.
33 * The value is only used to check for modifications anyway.
34 */
35 uint32_t size;
36 uint16_t mode;
37 #define GOT_INDEX_ENTRY_MODE_OBJ_TYPE 0x000f
38 #define GOT_INDEX_ENTRY_MODE_PERMS 0xff10
40 /* SHA1 of corresponding blob in repository. */
41 uint8_t blob_sha1[SHA1_DIGEST_LENGTH];
43 uint32_t flags;
44 #define GOT_INDEX_ENTRY_F_PATH_LEN 0x00000fff
45 #define GOT_INDEX_ENTRY_F_STAGE 0x00003000
46 #define GOT_INDEX_ENTRY_F_EXTENDED 0x00004000
47 #define GOT_INDEX_ENTRY_F_ASSUME_VALID 0x00008000
49 /*
50 * UNIX-style path, relative to work tree root.
51 * Variable length and NUL-padded to a multiple of 8.
52 */
53 const char *path;
54 };
56 /* "Stages" of a file which is afflicted by a 3-way merge conflict. */
57 #define GOT_INDEX_ENTRY_STAGE_MERGED 0
58 #define GOT_INDEX_ENTRY_STAGE_ANCESTOR 1
59 #define GOT_INDEX_ENTRY_STAGE_OURS 2
60 #define GOT_INDEX_ENTRY_STAGE_THEIRS 3
62 /* On-disk file index header structure. */
63 struct got_file_index_hdr {
64 uint32_t signature; /* big-endian on disk */
65 uint32_t version; /* big-endian on disk */
66 uint32_t nentries; /* big-endian on disk */
67 struct got_index_entry *entries; /* big-endian on disk */
68 uint8_t sha1[SHA1_DIGEST_LENGTH]; /* checksum of above data */
69 };