2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
4 c48c4a9c 2018-03-11 stsp * Permission to use, copy, modify, and distribute this software for any
5 c48c4a9c 2018-03-11 stsp * purpose with or without fee is hereby granted, provided that the above
6 c48c4a9c 2018-03-11 stsp * copyright notice and this permission notice appear in all copies.
8 c48c4a9c 2018-03-11 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 c48c4a9c 2018-03-11 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 c48c4a9c 2018-03-11 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 c48c4a9c 2018-03-11 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 c48c4a9c 2018-03-11 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 c48c4a9c 2018-03-11 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 c48c4a9c 2018-03-11 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c48c4a9c 2018-03-11 stsp #include <sys/queue.h>
18 133d2798 2019-01-08 stsp #include <sys/tree.h>
19 c48c4a9c 2018-03-11 stsp #include <sys/stat.h>
21 d1f6d47b 2019-02-04 stsp #include <dirent.h>
22 c48c4a9c 2018-03-11 stsp #include <stdio.h>
23 c48c4a9c 2018-03-11 stsp #include <stdlib.h>
24 c48c4a9c 2018-03-11 stsp #include <string.h>
25 c48c4a9c 2018-03-11 stsp #include <sha1.h>
26 c34b20a2 2018-03-12 stsp #include <endian.h>
27 133d2798 2019-01-08 stsp #include <limits.h>
29 c48c4a9c 2018-03-11 stsp #include "got_error.h"
30 8da9e5f4 2019-01-12 stsp #include "got_object.h"
32 133d2798 2019-01-08 stsp #include "got_lib_path.h"
33 718b3ab0 2018-03-17 stsp #include "got_lib_fileindex.h"
34 b25ae4fa 2019-02-04 stsp #include "got_lib_worktree.h"
36 133d2798 2019-01-08 stsp struct got_fileindex {
37 133d2798 2019-01-08 stsp struct got_fileindex_tree entries;
38 133d2798 2019-01-08 stsp int nentries;
39 133d2798 2019-01-08 stsp #define GOT_FILEIDX_MAX_ENTRIES INT_MAX
42 c48c4a9c 2018-03-11 stsp const struct got_error *
43 51514078 2018-12-25 stsp got_fileindex_entry_update(struct got_fileindex_entry *entry,
44 51514078 2018-12-25 stsp const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1)
46 c48c4a9c 2018-03-11 stsp struct stat sb;
48 c34b20a2 2018-03-12 stsp if (lstat(ondisk_path, &sb) != 0)
49 c48c4a9c 2018-03-11 stsp return got_error_from_errno();
51 51514078 2018-12-25 stsp entry->ctime_sec = sb.st_ctime;
52 51514078 2018-12-25 stsp entry->ctime_nsec = sb.st_ctimensec;
53 51514078 2018-12-25 stsp entry->mtime_sec = sb.st_mtime;
54 51514078 2018-12-25 stsp entry->mtime_nsec = sb.st_mtimensec;
55 51514078 2018-12-25 stsp entry->uid = sb.st_uid;
56 51514078 2018-12-25 stsp entry->gid = sb.st_gid;
57 51514078 2018-12-25 stsp entry->size = (sb.st_size & 0xffffffff);
58 51514078 2018-12-25 stsp if (sb.st_mode & S_IFLNK)
59 a7f9d64d 2019-01-13 stsp entry->mode = GOT_FILEIDX_MODE_SYMLINK;
61 a7f9d64d 2019-01-13 stsp entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
62 51514078 2018-12-25 stsp entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
63 a7f9d64d 2019-01-13 stsp GOT_FILEIDX_MODE_PERMS_SHIFT);
64 51514078 2018-12-25 stsp memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
65 51514078 2018-12-25 stsp memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
67 51514078 2018-12-25 stsp return NULL;
70 51514078 2018-12-25 stsp const struct got_error *
71 51514078 2018-12-25 stsp got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
72 51514078 2018-12-25 stsp const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
73 51514078 2018-12-25 stsp uint8_t *commit_sha1)
77 c48c4a9c 2018-03-11 stsp *entry = calloc(1, sizeof(**entry));
78 c48c4a9c 2018-03-11 stsp if (*entry == NULL)
79 0a585a0d 2018-03-17 stsp return got_error_from_errno();
81 c34b20a2 2018-03-12 stsp (*entry)->path = strdup(relpath);
82 c48c4a9c 2018-03-11 stsp if ((*entry)->path == NULL) {
83 0a585a0d 2018-03-17 stsp const struct got_error *err = got_error_from_errno();
84 c48c4a9c 2018-03-11 stsp free(*entry);
85 c48c4a9c 2018-03-11 stsp *entry = NULL;
89 c34b20a2 2018-03-12 stsp len = strlen(relpath);
90 a7f9d64d 2019-01-13 stsp if (len > GOT_FILEIDX_F_PATH_LEN)
91 a7f9d64d 2019-01-13 stsp len = GOT_FILEIDX_F_PATH_LEN;
92 c48c4a9c 2018-03-11 stsp (*entry)->flags |= len;
94 51514078 2018-12-25 stsp return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
95 51514078 2018-12-25 stsp commit_sha1);
99 7426bbfd 2018-12-24 stsp got_fileindex_entry_free(struct got_fileindex_entry *entry)
101 c48c4a9c 2018-03-11 stsp free(entry->path);
102 c48c4a9c 2018-03-11 stsp free(entry);
105 50952927 2019-01-12 stsp static const struct got_error *
106 50952927 2019-01-12 stsp add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
108 133d2798 2019-01-08 stsp if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
109 133d2798 2019-01-08 stsp return got_error(GOT_ERR_NO_SPACE);
111 133d2798 2019-01-08 stsp RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
112 133d2798 2019-01-08 stsp fileindex->nentries++;
113 133d2798 2019-01-08 stsp return NULL;
116 50952927 2019-01-12 stsp const struct got_error *
117 50952927 2019-01-12 stsp got_fileindex_entry_add(struct got_fileindex *fileindex,
118 50952927 2019-01-12 stsp struct got_fileindex_entry *entry)
120 50952927 2019-01-12 stsp /* Flag this entry until it gets written out to disk. */
121 a7f9d64d 2019-01-13 stsp entry->flags |= GOT_FILEIDX_F_INTENT_TO_ADD;
123 50952927 2019-01-12 stsp return add_entry(fileindex, entry);
127 512f0d0e 2019-01-02 stsp got_fileindex_entry_remove(struct got_fileindex *fileindex,
128 512f0d0e 2019-01-02 stsp struct got_fileindex_entry *entry)
130 133d2798 2019-01-08 stsp RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
131 133d2798 2019-01-08 stsp fileindex->nentries--;
134 51514078 2018-12-25 stsp struct got_fileindex_entry *
135 51514078 2018-12-25 stsp got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
137 133d2798 2019-01-08 stsp struct got_fileindex_entry key;
138 133d2798 2019-01-08 stsp memset(&key, 0, sizeof(key));
139 133d2798 2019-01-08 stsp key.path = (char *)path;
140 133d2798 2019-01-08 stsp return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
143 512f0d0e 2019-01-02 stsp const struct got_error *
144 e1ed7f77 2019-01-06 stsp got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
145 b504a804 2019-01-08 stsp got_fileindex_cb cb, void *cb_arg)
147 133d2798 2019-01-08 stsp const struct got_error *err;
148 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry, *tmp;
150 133d2798 2019-01-08 stsp RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
151 133d2798 2019-01-08 stsp err = (*cb)(cb_arg, entry);
153 133d2798 2019-01-08 stsp return err;
155 b504a804 2019-01-08 stsp return NULL;
158 133d2798 2019-01-08 stsp struct got_fileindex *
159 133d2798 2019-01-08 stsp got_fileindex_alloc(void)
161 133d2798 2019-01-08 stsp struct got_fileindex *fileindex;
163 133d2798 2019-01-08 stsp fileindex = calloc(1, sizeof(*fileindex));
164 133d2798 2019-01-08 stsp if (fileindex == NULL)
165 133d2798 2019-01-08 stsp return NULL;
167 133d2798 2019-01-08 stsp RB_INIT(&fileindex->entries);
168 133d2798 2019-01-08 stsp return fileindex;
172 7426bbfd 2018-12-24 stsp got_fileindex_free(struct got_fileindex *fileindex)
174 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry;
176 133d2798 2019-01-08 stsp while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
177 133d2798 2019-01-08 stsp RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
178 133d2798 2019-01-08 stsp got_fileindex_entry_free(entry);
180 9d31a1d8 2018-03-11 stsp free(fileindex);
183 c34b20a2 2018-03-12 stsp static const struct got_error *
184 c34b20a2 2018-03-12 stsp write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
188 c34b20a2 2018-03-12 stsp val = htobe64(val);
189 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
190 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
191 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
192 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
193 c34b20a2 2018-03-12 stsp return NULL;
196 c34b20a2 2018-03-12 stsp static const struct got_error *
197 c34b20a2 2018-03-12 stsp write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
201 c34b20a2 2018-03-12 stsp val = htobe32(val);
202 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
203 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
204 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
205 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
206 c34b20a2 2018-03-12 stsp return NULL;
209 c34b20a2 2018-03-12 stsp static const struct got_error *
210 c34b20a2 2018-03-12 stsp write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
214 c34b20a2 2018-03-12 stsp val = htobe16(val);
215 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
216 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
217 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
218 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
219 c34b20a2 2018-03-12 stsp return NULL;
222 c34b20a2 2018-03-12 stsp static const struct got_error *
223 c34b20a2 2018-03-12 stsp write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
225 3c5b70f2 2018-12-27 stsp size_t n, len, pad = 0;
226 c34b20a2 2018-03-12 stsp static const uint8_t zero[8] = { 0 };
228 c34b20a2 2018-03-12 stsp len = strlen(path);
229 3c5b70f2 2018-12-27 stsp while ((len + pad) % 8 != 0)
231 3c5b70f2 2018-12-27 stsp if (pad == 0)
232 3c5b70f2 2018-12-27 stsp pad = 8; /* NUL-terminate */
234 c34b20a2 2018-03-12 stsp SHA1Update(ctx, path, len);
235 c34b20a2 2018-03-12 stsp n = fwrite(path, 1, len, outfile);
236 c34b20a2 2018-03-12 stsp if (n != len)
237 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
238 c34b20a2 2018-03-12 stsp SHA1Update(ctx, zero, pad);
239 c34b20a2 2018-03-12 stsp n = fwrite(zero, 1, pad, outfile);
240 c34b20a2 2018-03-12 stsp if (n != pad)
241 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
242 c34b20a2 2018-03-12 stsp return NULL;
245 c34b20a2 2018-03-12 stsp static const struct got_error *
246 c34b20a2 2018-03-12 stsp write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
247 c34b20a2 2018-03-12 stsp FILE *outfile)
249 c34b20a2 2018-03-12 stsp const struct got_error *err;
252 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
254 c34b20a2 2018-03-12 stsp return err;
255 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
257 c34b20a2 2018-03-12 stsp return err;
258 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
260 c34b20a2 2018-03-12 stsp return err;
261 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
263 c34b20a2 2018-03-12 stsp return err;
265 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->uid, outfile);
267 c34b20a2 2018-03-12 stsp return err;
268 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->gid, outfile);
270 c34b20a2 2018-03-12 stsp return err;
271 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->size, outfile);
273 c34b20a2 2018-03-12 stsp return err;
275 c34b20a2 2018-03-12 stsp err = write_fileindex_val16(ctx, entry->mode, outfile);
277 c34b20a2 2018-03-12 stsp return err;
279 c34b20a2 2018-03-12 stsp SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
280 c34b20a2 2018-03-12 stsp n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
281 fc76cabb 2018-12-25 stsp if (n != SHA1_DIGEST_LENGTH)
282 fc76cabb 2018-12-25 stsp return got_ferror(outfile, GOT_ERR_IO);
284 fc76cabb 2018-12-25 stsp SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
285 fc76cabb 2018-12-25 stsp n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
286 c34b20a2 2018-03-12 stsp if (n != SHA1_DIGEST_LENGTH)
287 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
289 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->flags, outfile);
291 c34b20a2 2018-03-12 stsp return err;
293 c34b20a2 2018-03-12 stsp err = write_fileindex_path(ctx, entry->path, outfile);
294 c34b20a2 2018-03-12 stsp return err;
297 9d31a1d8 2018-03-11 stsp const struct got_error *
298 9d31a1d8 2018-03-11 stsp got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
300 b504a804 2019-01-08 stsp const struct got_error *err = NULL;
301 c34b20a2 2018-03-12 stsp struct got_fileindex_hdr hdr;
302 c34b20a2 2018-03-12 stsp SHA1_CTX ctx;
303 c34b20a2 2018-03-12 stsp uint8_t sha1[SHA1_DIGEST_LENGTH];
305 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry;
307 c34b20a2 2018-03-12 stsp SHA1Init(&ctx);
309 c34b20a2 2018-03-12 stsp hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
310 c34b20a2 2018-03-12 stsp hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
311 133d2798 2019-01-08 stsp hdr.nentries = htobe32(fileindex->nentries);
313 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
314 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
315 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
316 a5744d71 2019-01-12 stsp n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
317 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.signature))
318 a5744d71 2019-01-12 stsp return got_ferror(outfile, GOT_ERR_IO);
319 a5744d71 2019-01-12 stsp n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
320 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.version))
321 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
322 a5744d71 2019-01-12 stsp n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
323 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.nentries))
324 a5744d71 2019-01-12 stsp return got_ferror(outfile, GOT_ERR_IO);
326 133d2798 2019-01-08 stsp RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
327 a7f9d64d 2019-01-13 stsp entry->flags &= ~GOT_FILEIDX_F_INTENT_TO_ADD;
328 133d2798 2019-01-08 stsp err = write_fileindex_entry(&ctx, entry, outfile);
330 133d2798 2019-01-08 stsp return err;
333 c34b20a2 2018-03-12 stsp SHA1Final(sha1, &ctx);
334 c34b20a2 2018-03-12 stsp n = fwrite(sha1, 1, sizeof(sha1), outfile);
335 c34b20a2 2018-03-12 stsp if (n != sizeof(sha1))
336 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
338 27d0e5bd 2019-01-12 stsp if (fflush(outfile) != 0)
339 27d0e5bd 2019-01-12 stsp return got_error_from_errno();
341 52a74475 2018-12-24 stsp return NULL;
344 52a74475 2018-12-24 stsp static const struct got_error *
345 52a74475 2018-12-24 stsp read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
349 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
350 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
351 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
352 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
353 9eb6a6b2 2018-12-24 stsp *val = be64toh(*val);
354 52a74475 2018-12-24 stsp return NULL;
357 52a74475 2018-12-24 stsp static const struct got_error *
358 52a74475 2018-12-24 stsp read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
362 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
363 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
364 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
365 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
366 9eb6a6b2 2018-12-24 stsp *val = be32toh(*val);
367 52a74475 2018-12-24 stsp return NULL;
370 52a74475 2018-12-24 stsp static const struct got_error *
371 52a74475 2018-12-24 stsp read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
375 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
376 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
377 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
378 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
379 9eb6a6b2 2018-12-24 stsp *val = be16toh(*val);
380 52a74475 2018-12-24 stsp return NULL;
383 52a74475 2018-12-24 stsp static const struct got_error *
384 52a74475 2018-12-24 stsp read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
386 52a74475 2018-12-24 stsp const struct got_error *err = NULL;
387 52a74475 2018-12-24 stsp uint8_t buf[8];
388 52a74475 2018-12-24 stsp size_t n, len = 0, totlen = sizeof(buf);
390 52a74475 2018-12-24 stsp *path = malloc(totlen);
391 52a74475 2018-12-24 stsp if (*path == NULL)
392 52a74475 2018-12-24 stsp return got_error_from_errno();
395 52a74475 2018-12-24 stsp n = fread(buf, 1, sizeof(buf), infile);
396 52a74475 2018-12-24 stsp if (n != sizeof(buf))
397 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
398 52a74475 2018-12-24 stsp if (len + sizeof(buf) > totlen) {
399 52a74475 2018-12-24 stsp char *p = reallocarray(*path, totlen + sizeof(buf), 1);
400 52a74475 2018-12-24 stsp if (p == NULL) {
401 52a74475 2018-12-24 stsp err = got_error_from_errno();
404 52a74475 2018-12-24 stsp totlen += sizeof(buf);
407 52a74475 2018-12-24 stsp SHA1Update(ctx, buf, sizeof(buf));
408 52a74475 2018-12-24 stsp memcpy(*path + len, buf, sizeof(buf));
409 52a74475 2018-12-24 stsp len += sizeof(buf);
410 60619907 2018-12-27 stsp } while (memchr(buf, '\0', sizeof(buf)) == NULL);
413 52a74475 2018-12-24 stsp free(*path);
414 52a74475 2018-12-24 stsp *path = NULL;
416 52a74475 2018-12-24 stsp return err;
419 52a74475 2018-12-24 stsp static const struct got_error *
420 52a74475 2018-12-24 stsp read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
421 52a74475 2018-12-24 stsp FILE *infile)
423 52a74475 2018-12-24 stsp const struct got_error *err;
424 52a74475 2018-12-24 stsp struct got_fileindex_entry *entry;
427 52a74475 2018-12-24 stsp *entryp = NULL;
429 52a74475 2018-12-24 stsp entry = calloc(1, sizeof(*entry));
430 52a74475 2018-12-24 stsp if (entry == NULL)
431 52a74475 2018-12-24 stsp return got_error_from_errno();
433 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
436 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
439 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
442 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
446 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->uid, ctx, infile);
449 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->gid, ctx, infile);
452 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->size, ctx, infile);
456 52a74475 2018-12-24 stsp err = read_fileindex_val16(&entry->mode, ctx, infile);
460 52a74475 2018-12-24 stsp n = fread(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, infile);
461 52a74475 2018-12-24 stsp if (n != SHA1_DIGEST_LENGTH) {
462 27793341 2019-01-12 stsp err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
465 52a74475 2018-12-24 stsp SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
467 fc76cabb 2018-12-25 stsp n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
468 fc76cabb 2018-12-25 stsp if (n != SHA1_DIGEST_LENGTH) {
469 27793341 2019-01-12 stsp err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
472 fc76cabb 2018-12-25 stsp SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
474 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->flags, ctx, infile);
478 52a74475 2018-12-24 stsp err = read_fileindex_path(&entry->path, ctx, infile);
481 52a74475 2018-12-24 stsp free(entry);
483 52a74475 2018-12-24 stsp *entryp = entry;
484 52a74475 2018-12-24 stsp return err;
487 52a74475 2018-12-24 stsp const struct got_error *
488 52a74475 2018-12-24 stsp got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
490 52a74475 2018-12-24 stsp const struct got_error *err = NULL;
491 52a74475 2018-12-24 stsp struct got_fileindex_hdr hdr;
492 52a74475 2018-12-24 stsp SHA1_CTX ctx;
493 52a74475 2018-12-24 stsp struct got_fileindex_entry *entry;
494 52a74475 2018-12-24 stsp uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
495 52a74475 2018-12-24 stsp uint8_t sha1[SHA1_DIGEST_LENGTH];
499 52a74475 2018-12-24 stsp SHA1Init(&ctx);
501 b6d05318 2019-01-13 stsp n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
502 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.signature)) {
503 b6d05318 2019-01-13 stsp if (n == 0) /* EOF */
504 b6d05318 2019-01-13 stsp return NULL;
505 b6d05318 2019-01-13 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
507 b6d05318 2019-01-13 stsp n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
508 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.version)) {
509 51514078 2018-12-25 stsp if (n == 0) /* EOF */
510 51514078 2018-12-25 stsp return NULL;
511 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
513 b6d05318 2019-01-13 stsp n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
514 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.nentries)) {
515 b6d05318 2019-01-13 stsp if (n == 0) /* EOF */
516 b6d05318 2019-01-13 stsp return NULL;
517 b6d05318 2019-01-13 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
520 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
521 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
522 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
524 9eb6a6b2 2018-12-24 stsp hdr.signature = be32toh(hdr.signature);
525 9eb6a6b2 2018-12-24 stsp hdr.version = be32toh(hdr.version);
526 9eb6a6b2 2018-12-24 stsp hdr.nentries = be32toh(hdr.nentries);
528 52a74475 2018-12-24 stsp if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
529 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_SIG);
530 52a74475 2018-12-24 stsp if (hdr.version != GOT_FILE_INDEX_VERSION)
531 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_VER);
533 52a74475 2018-12-24 stsp for (i = 0; i < hdr.nentries; i++) {
534 52a74475 2018-12-24 stsp err = read_fileindex_entry(&entry, &ctx, infile);
536 52a74475 2018-12-24 stsp return err;
537 50952927 2019-01-12 stsp err = add_entry(fileindex, entry);
539 52a74475 2018-12-24 stsp return err;
542 52a74475 2018-12-24 stsp n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
543 52a74475 2018-12-24 stsp if (n != sizeof(sha1_expected))
544 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
545 52a74475 2018-12-24 stsp SHA1Final(sha1, &ctx);
546 52a74475 2018-12-24 stsp if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
547 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_CSUM);
549 9d31a1d8 2018-03-11 stsp return NULL;
552 50952927 2019-01-12 stsp struct got_fileindex_entry *
553 50952927 2019-01-12 stsp walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
555 50952927 2019-01-12 stsp struct got_fileindex_entry *next;
557 50952927 2019-01-12 stsp next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
559 50952927 2019-01-12 stsp /* Skip entries which were newly added by diff callbacks. */
560 a7f9d64d 2019-01-13 stsp while (next && (next->flags & GOT_FILEIDX_F_INTENT_TO_ADD))
561 50952927 2019-01-12 stsp next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
563 50952927 2019-01-12 stsp return next;
566 8da9e5f4 2019-01-12 stsp static const struct got_error *
567 9d2a8e53 2019-01-28 stsp diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
568 9d2a8e53 2019-01-28 stsp struct got_tree_object *, const char *, struct got_repository *,
569 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *, void *);
571 9d2a8e53 2019-01-28 stsp static const struct got_error *
572 8da9e5f4 2019-01-12 stsp walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
573 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry **ie, struct got_tree_entry *te,
574 8da9e5f4 2019-01-12 stsp const char *path, struct got_repository *repo,
575 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
577 8da9e5f4 2019-01-12 stsp const struct got_error *err = NULL;
579 bd4792ec 2019-01-13 stsp if (S_ISDIR(te->mode)) {
580 8da9e5f4 2019-01-12 stsp char *subpath;
581 8da9e5f4 2019-01-12 stsp struct got_tree_object *subtree;
583 8da9e5f4 2019-01-12 stsp if (asprintf(&subpath, "%s%s%s", path,
584 8da9e5f4 2019-01-12 stsp path[0] == '\0' ? "" : "/", te->name) == -1)
585 8da9e5f4 2019-01-12 stsp return got_error_from_errno();
587 8da9e5f4 2019-01-12 stsp err = got_object_open_as_tree(&subtree, repo, te->id);
589 8da9e5f4 2019-01-12 stsp free(subpath);
590 8da9e5f4 2019-01-12 stsp return err;
593 8da9e5f4 2019-01-12 stsp err = diff_fileindex_tree(fileindex, ie, subtree,
594 8da9e5f4 2019-01-12 stsp subpath, repo, cb, cb_arg);
595 8da9e5f4 2019-01-12 stsp free(subpath);
596 8da9e5f4 2019-01-12 stsp got_object_tree_close(subtree);
598 8da9e5f4 2019-01-12 stsp return err;
601 bd4792ec 2019-01-13 stsp *next = SIMPLEQ_NEXT(te, entry);
602 8da9e5f4 2019-01-12 stsp return NULL;
606 bad322f2 2019-01-28 stsp * Decide whether a fileindex entry path is equivalent to a tree entry path,
607 bad322f2 2019-01-28 stsp * and if it is not, then decide which of the two should be processed first.
610 bad322f2 2019-01-28 stsp cmp_entries(const char *ie_path, const char *parent_path,
611 bad322f2 2019-01-28 stsp size_t parent_len, const char *te_name)
613 bad322f2 2019-01-28 stsp int cmp = strncmp(ie_path, parent_path, parent_len);
614 62d20534 2019-01-28 stsp if (cmp == 0) {
615 bad322f2 2019-01-28 stsp const char *ie_name = ie_path + parent_len;
616 70e2377c 2019-01-28 stsp while (ie_name[0] == '/')
618 bad322f2 2019-01-28 stsp cmp = strcmp(ie_name, te_name);
620 70e2377c 2019-01-28 stsp return cmp;
624 8da9e5f4 2019-01-12 stsp static const struct got_error *
625 8da9e5f4 2019-01-12 stsp diff_fileindex_tree(struct got_fileindex *fileindex,
626 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry **ie, struct got_tree_object *tree,
627 8da9e5f4 2019-01-12 stsp const char *path, struct got_repository *repo,
628 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
630 8da9e5f4 2019-01-12 stsp const struct got_error *err = NULL;
631 8da9e5f4 2019-01-12 stsp struct got_tree_entry *te = NULL;
632 8da9e5f4 2019-01-12 stsp size_t path_len = strlen(path);
633 8da9e5f4 2019-01-12 stsp const struct got_tree_entries *entries;
634 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry *next;
636 8da9e5f4 2019-01-12 stsp entries = got_object_tree_get_entries(tree);
637 8da9e5f4 2019-01-12 stsp te = SIMPLEQ_FIRST(&entries->head);
638 500cd40f 2019-02-04 stsp while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
639 8da9e5f4 2019-01-12 stsp if (te && *ie) {
640 bad322f2 2019-01-28 stsp int cmp = cmp_entries((*ie)->path, path, path_len,
642 8da9e5f4 2019-01-12 stsp if (cmp == 0) {
643 8da9e5f4 2019-01-12 stsp err = cb->diff_old_new(cb_arg, *ie, te,
647 50952927 2019-01-12 stsp *ie = walk_fileindex(fileindex, *ie);
648 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te,
649 8da9e5f4 2019-01-12 stsp path, repo, cb, cb_arg);
650 50952927 2019-01-12 stsp } else if (cmp < 0 ) {
651 50952927 2019-01-12 stsp next = walk_fileindex(fileindex, *ie);
652 8da9e5f4 2019-01-12 stsp err = cb->diff_old(cb_arg, *ie, path);
655 8da9e5f4 2019-01-12 stsp *ie = next;
657 8da9e5f4 2019-01-12 stsp err = cb->diff_new(cb_arg, te, path);
660 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te,
661 8da9e5f4 2019-01-12 stsp path, repo, cb, cb_arg);
665 8da9e5f4 2019-01-12 stsp } else if (*ie) {
666 50952927 2019-01-12 stsp next = walk_fileindex(fileindex, *ie);
667 8da9e5f4 2019-01-12 stsp err = cb->diff_old(cb_arg, *ie, path);
670 8da9e5f4 2019-01-12 stsp *ie = next;
671 8da9e5f4 2019-01-12 stsp } else if (te) {
672 8da9e5f4 2019-01-12 stsp err = cb->diff_new(cb_arg, te, path);
675 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
682 8da9e5f4 2019-01-12 stsp return err;
685 8da9e5f4 2019-01-12 stsp const struct got_error *
686 8da9e5f4 2019-01-12 stsp got_fileindex_diff_tree(struct got_fileindex *fileindex,
687 8da9e5f4 2019-01-12 stsp struct got_tree_object *tree, struct got_repository *repo,
688 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
690 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry *min;
691 8da9e5f4 2019-01-12 stsp min = RB_MIN(got_fileindex_tree, &fileindex->entries);
692 8da9e5f4 2019-01-12 stsp return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
695 d1f6d47b 2019-02-04 stsp static const struct got_error *
696 d1f6d47b 2019-02-04 stsp diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
697 c7f4312f 2019-02-05 stsp const char *, const char *, struct got_repository *,
698 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *, void *);
700 d1f6d47b 2019-02-04 stsp static const struct got_error *
701 f5d3d7af 2019-02-05 stsp walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
702 f5d3d7af 2019-02-05 stsp struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
703 c7f4312f 2019-02-05 stsp const char *path, DIR *dir, const char *rootpath,
704 c7f4312f 2019-02-05 stsp struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
705 c7f4312f 2019-02-05 stsp void *cb_arg)
707 d1f6d47b 2019-02-04 stsp const struct got_error *err = NULL;
708 f5d3d7af 2019-02-05 stsp struct dirent *de = dle->data;
710 f5d3d7af 2019-02-05 stsp if (de->d_type == DT_DIR) {
711 d1f6d47b 2019-02-04 stsp char *subpath;
712 c7f4312f 2019-02-05 stsp char *subdirpath;
713 d1f6d47b 2019-02-04 stsp DIR *subdir;
715 d1f6d47b 2019-02-04 stsp if (asprintf(&subpath, "%s%s%s", path,
716 f5d3d7af 2019-02-05 stsp path[0] == '\0' ? "" : "/", de->d_name) == -1)
717 d1f6d47b 2019-02-04 stsp return got_error_from_errno();
719 c7f4312f 2019-02-05 stsp if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
720 c7f4312f 2019-02-05 stsp free(subpath);
721 c7f4312f 2019-02-05 stsp return got_error_from_errno();
724 c7f4312f 2019-02-05 stsp subdir = opendir(subdirpath);
725 d1f6d47b 2019-02-04 stsp if (subdir == NULL) {
726 d1f6d47b 2019-02-04 stsp free(subpath);
727 c7f4312f 2019-02-05 stsp free(subdirpath);
728 d1f6d47b 2019-02-04 stsp return got_error_from_errno();
731 c7f4312f 2019-02-05 stsp err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
732 c7f4312f 2019-02-05 stsp subpath, repo, cb, cb_arg);
733 d1f6d47b 2019-02-04 stsp free(subpath);
734 c7f4312f 2019-02-05 stsp free(subdirpath);
735 d1f6d47b 2019-02-04 stsp closedir(subdir);
737 d1f6d47b 2019-02-04 stsp return err;
740 f5d3d7af 2019-02-05 stsp *next = TAILQ_NEXT(dle, entry);
741 d1f6d47b 2019-02-04 stsp return NULL;
744 d1f6d47b 2019-02-04 stsp static const struct got_error *
745 d1f6d47b 2019-02-04 stsp diff_fileindex_dir(struct got_fileindex *fileindex,
746 c7f4312f 2019-02-05 stsp struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
747 c7f4312f 2019-02-05 stsp const char *path, struct got_repository *repo,
748 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
750 d1f6d47b 2019-02-04 stsp const struct got_error *err = NULL;
751 d1f6d47b 2019-02-04 stsp struct dirent *de = NULL;
752 d1f6d47b 2019-02-04 stsp size_t path_len = strlen(path);
753 d1f6d47b 2019-02-04 stsp struct got_fileindex_entry *next;
754 f5d3d7af 2019-02-05 stsp struct got_pathlist_head dirlist;
755 f5d3d7af 2019-02-05 stsp struct got_pathlist_entry *dle;
757 f5d3d7af 2019-02-05 stsp TAILQ_INIT(&dirlist);
759 500cd40f 2019-02-04 stsp while (1) {
760 f5d3d7af 2019-02-05 stsp struct got_pathlist_entry *new = NULL;
761 ed83bff7 2019-02-05 stsp struct dirent *dep = NULL;
763 ed83bff7 2019-02-05 stsp de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
764 ed83bff7 2019-02-05 stsp if (de == NULL) {
765 ed83bff7 2019-02-05 stsp err = got_error_from_errno();
769 ed83bff7 2019-02-05 stsp if (readdir_r(dir, de, &dep) != 0) {
770 ed83bff7 2019-02-05 stsp err = got_error_from_errno();
774 ed83bff7 2019-02-05 stsp if (dep == NULL) {
779 b1ec3986 2019-02-04 stsp if (strcmp(de->d_name, ".") == 0 ||
780 b25ae4fa 2019-02-04 stsp strcmp(de->d_name, "..") == 0 ||
781 b25ae4fa 2019-02-04 stsp (path[0] == '\0' &&
782 ed83bff7 2019-02-05 stsp strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
787 f5d3d7af 2019-02-05 stsp err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
790 f5d3d7af 2019-02-05 stsp if (new == NULL) {
791 f5d3d7af 2019-02-05 stsp err = got_error(GOT_ERR_DIR_DUP_ENTRY);
796 f5d3d7af 2019-02-05 stsp dle = TAILQ_FIRST(&dirlist);
797 500cd40f 2019-02-04 stsp while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
798 500cd40f 2019-02-04 stsp if (dle && *ie) {
800 f5d3d7af 2019-02-05 stsp de = dle->data;
801 e7a2f030 2019-02-05 stsp cmp = cmp_entries((*ie)->path, path, path_len,
802 f5d3d7af 2019-02-05 stsp de->d_name);
803 d1f6d47b 2019-02-04 stsp if (cmp == 0) {
804 f5d3d7af 2019-02-05 stsp err = cb->diff_old_new(cb_arg, *ie, de, path);
807 d1f6d47b 2019-02-04 stsp *ie = walk_fileindex(fileindex, *ie);
808 500cd40f 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path,
809 c7f4312f 2019-02-05 stsp dir, rootpath, repo, cb, cb_arg);
810 d1f6d47b 2019-02-04 stsp } else if (cmp < 0 ) {
811 d1f6d47b 2019-02-04 stsp next = walk_fileindex(fileindex, *ie);
812 d1f6d47b 2019-02-04 stsp err = cb->diff_old(cb_arg, *ie, path);
815 d1f6d47b 2019-02-04 stsp *ie = next;
817 f5d3d7af 2019-02-05 stsp err = cb->diff_new(cb_arg, de, path);
820 500cd40f 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path,
821 c7f4312f 2019-02-05 stsp dir, rootpath, repo, cb, cb_arg);
825 554b91b1 2019-02-04 stsp } else if (*ie) {
826 554b91b1 2019-02-04 stsp next = walk_fileindex(fileindex, *ie);
827 554b91b1 2019-02-04 stsp err = cb->diff_old(cb_arg, *ie, path);
830 554b91b1 2019-02-04 stsp *ie = next;
831 554b91b1 2019-02-04 stsp } else if (dle) {
832 763e1377 2019-02-05 stsp de = dle->data;
833 f5d3d7af 2019-02-05 stsp err = cb->diff_new(cb_arg, de, path);
836 554b91b1 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path, dir,
837 c7f4312f 2019-02-05 stsp rootpath, repo, cb, cb_arg);
843 ed83bff7 2019-02-05 stsp TAILQ_FOREACH(dle, &dirlist, entry)
844 ed83bff7 2019-02-05 stsp free(dle->data);
845 f5d3d7af 2019-02-05 stsp got_pathlist_free(&dirlist);
846 d1f6d47b 2019-02-04 stsp return err;
849 d1f6d47b 2019-02-04 stsp const struct got_error *
850 c7f4312f 2019-02-05 stsp got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
851 c7f4312f 2019-02-05 stsp const char *rootpath, struct got_repository *repo,
852 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
854 d1f6d47b 2019-02-04 stsp struct got_fileindex_entry *min;
855 d1f6d47b 2019-02-04 stsp min = RB_MIN(got_fileindex_tree, &fileindex->entries);
856 c7f4312f 2019-02-05 stsp return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, "",
857 c7f4312f 2019-02-05 stsp repo, cb, cb_arg);
860 7a9df742 2019-01-08 stsp RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);