Blame


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