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