2 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 #include <sys/queue.h>
29 #include "got_error.h"
30 #include "got_object.h"
32 #include "got_lib_path.h"
33 #include "got_lib_fileindex.h"
34 #include "got_lib_worktree.h"
36 struct got_fileindex {
37 struct got_fileindex_tree entries;
39 #define GOT_FILEIDX_MAX_ENTRIES INT_MAX
42 const struct got_error *
43 got_fileindex_entry_update(struct got_fileindex_entry *entry,
44 const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1)
48 if (lstat(ondisk_path, &sb) != 0)
49 return got_error_from_errno();
51 entry->ctime_sec = sb.st_ctime;
52 entry->ctime_nsec = sb.st_ctimensec;
53 entry->mtime_sec = sb.st_mtime;
54 entry->mtime_nsec = sb.st_mtimensec;
55 entry->uid = sb.st_uid;
56 entry->gid = sb.st_gid;
57 entry->size = (sb.st_size & 0xffffffff);
58 if (sb.st_mode & S_IFLNK)
59 entry->mode = GOT_FILEIDX_MODE_SYMLINK;
61 entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
62 entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
63 GOT_FILEIDX_MODE_PERMS_SHIFT);
64 memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
65 memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
70 const struct got_error *
71 got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
72 const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
77 *entry = calloc(1, sizeof(**entry));
79 return got_error_from_errno();
81 (*entry)->path = strdup(relpath);
82 if ((*entry)->path == NULL) {
83 const struct got_error *err = got_error_from_errno();
89 len = strlen(relpath);
90 if (len > GOT_FILEIDX_F_PATH_LEN)
91 len = GOT_FILEIDX_F_PATH_LEN;
92 (*entry)->flags |= len;
94 return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
99 got_fileindex_entry_free(struct got_fileindex_entry *entry)
105 static const struct got_error *
106 add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
108 if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
109 return got_error(GOT_ERR_NO_SPACE);
111 RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
112 fileindex->nentries++;
116 const struct got_error *
117 got_fileindex_entry_add(struct got_fileindex *fileindex,
118 struct got_fileindex_entry *entry)
120 /* Flag this entry until it gets written out to disk. */
121 entry->flags |= GOT_FILEIDX_F_INTENT_TO_ADD;
123 return add_entry(fileindex, entry);
127 got_fileindex_entry_remove(struct got_fileindex *fileindex,
128 struct got_fileindex_entry *entry)
130 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
131 fileindex->nentries--;
134 struct got_fileindex_entry *
135 got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
137 struct got_fileindex_entry key;
138 memset(&key, 0, sizeof(key));
139 key.path = (char *)path;
140 return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
143 const struct got_error *
144 got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
145 got_fileindex_cb cb, void *cb_arg)
147 const struct got_error *err;
148 struct got_fileindex_entry *entry, *tmp;
150 RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
151 err = (*cb)(cb_arg, entry);
158 struct got_fileindex *
159 got_fileindex_alloc(void)
161 struct got_fileindex *fileindex;
163 fileindex = calloc(1, sizeof(*fileindex));
164 if (fileindex == NULL)
167 RB_INIT(&fileindex->entries);
172 got_fileindex_free(struct got_fileindex *fileindex)
174 struct got_fileindex_entry *entry;
176 while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
177 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
178 got_fileindex_entry_free(entry);
183 static const struct got_error *
184 write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
189 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
190 n = fwrite(&val, 1, sizeof(val), outfile);
191 if (n != sizeof(val))
192 return got_ferror(outfile, GOT_ERR_IO);
196 static const struct got_error *
197 write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
202 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
203 n = fwrite(&val, 1, sizeof(val), outfile);
204 if (n != sizeof(val))
205 return got_ferror(outfile, GOT_ERR_IO);
209 static const struct got_error *
210 write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
215 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
216 n = fwrite(&val, 1, sizeof(val), outfile);
217 if (n != sizeof(val))
218 return got_ferror(outfile, GOT_ERR_IO);
222 static const struct got_error *
223 write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
225 size_t n, len, pad = 0;
226 static const uint8_t zero[8] = { 0 };
229 while ((len + pad) % 8 != 0)
232 pad = 8; /* NUL-terminate */
234 SHA1Update(ctx, path, len);
235 n = fwrite(path, 1, len, outfile);
237 return got_ferror(outfile, GOT_ERR_IO);
238 SHA1Update(ctx, zero, pad);
239 n = fwrite(zero, 1, pad, outfile);
241 return got_ferror(outfile, GOT_ERR_IO);
245 static const struct got_error *
246 write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
249 const struct got_error *err;
252 err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
255 err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
258 err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
261 err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
265 err = write_fileindex_val32(ctx, entry->uid, outfile);
268 err = write_fileindex_val32(ctx, entry->gid, outfile);
271 err = write_fileindex_val32(ctx, entry->size, outfile);
275 err = write_fileindex_val16(ctx, entry->mode, outfile);
279 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
280 n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
281 if (n != SHA1_DIGEST_LENGTH)
282 return got_ferror(outfile, GOT_ERR_IO);
284 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
285 n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
286 if (n != SHA1_DIGEST_LENGTH)
287 return got_ferror(outfile, GOT_ERR_IO);
289 err = write_fileindex_val32(ctx, entry->flags, outfile);
293 err = write_fileindex_path(ctx, entry->path, outfile);
297 const struct got_error *
298 got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
300 const struct got_error *err = NULL;
301 struct got_fileindex_hdr hdr;
303 uint8_t sha1[SHA1_DIGEST_LENGTH];
305 struct got_fileindex_entry *entry;
309 hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
310 hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
311 hdr.nentries = htobe32(fileindex->nentries);
313 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
314 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
315 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
316 n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
317 if (n != sizeof(hdr.signature))
318 return got_ferror(outfile, GOT_ERR_IO);
319 n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
320 if (n != sizeof(hdr.version))
321 return got_ferror(outfile, GOT_ERR_IO);
322 n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
323 if (n != sizeof(hdr.nentries))
324 return got_ferror(outfile, GOT_ERR_IO);
326 RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
327 entry->flags &= ~GOT_FILEIDX_F_INTENT_TO_ADD;
328 err = write_fileindex_entry(&ctx, entry, outfile);
333 SHA1Final(sha1, &ctx);
334 n = fwrite(sha1, 1, sizeof(sha1), outfile);
335 if (n != sizeof(sha1))
336 return got_ferror(outfile, GOT_ERR_IO);
338 if (fflush(outfile) != 0)
339 return got_error_from_errno();
344 static const struct got_error *
345 read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
349 n = fread(val, 1, sizeof(*val), infile);
350 if (n != sizeof(*val))
351 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
352 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
353 *val = be64toh(*val);
357 static const struct got_error *
358 read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
362 n = fread(val, 1, sizeof(*val), infile);
363 if (n != sizeof(*val))
364 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
365 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
366 *val = be32toh(*val);
370 static const struct got_error *
371 read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
375 n = fread(val, 1, sizeof(*val), infile);
376 if (n != sizeof(*val))
377 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
378 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
379 *val = be16toh(*val);
383 static const struct got_error *
384 read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
386 const struct got_error *err = NULL;
388 size_t n, len = 0, totlen = sizeof(buf);
390 *path = malloc(totlen);
392 return got_error_from_errno();
395 n = fread(buf, 1, sizeof(buf), infile);
396 if (n != sizeof(buf))
397 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
398 if (len + sizeof(buf) > totlen) {
399 char *p = reallocarray(*path, totlen + sizeof(buf), 1);
401 err = got_error_from_errno();
404 totlen += sizeof(buf);
407 SHA1Update(ctx, buf, sizeof(buf));
408 memcpy(*path + len, buf, sizeof(buf));
410 } while (memchr(buf, '\0', sizeof(buf)) == NULL);
419 static const struct got_error *
420 read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
423 const struct got_error *err;
424 struct got_fileindex_entry *entry;
429 entry = calloc(1, sizeof(*entry));
431 return got_error_from_errno();
433 err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
436 err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
439 err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
442 err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
446 err = read_fileindex_val32(&entry->uid, ctx, infile);
449 err = read_fileindex_val32(&entry->gid, ctx, infile);
452 err = read_fileindex_val32(&entry->size, ctx, infile);
456 err = read_fileindex_val16(&entry->mode, ctx, infile);
460 n = fread(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, infile);
461 if (n != SHA1_DIGEST_LENGTH) {
462 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
465 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
467 n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
468 if (n != SHA1_DIGEST_LENGTH) {
469 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
472 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
474 err = read_fileindex_val32(&entry->flags, ctx, infile);
478 err = read_fileindex_path(&entry->path, ctx, infile);
487 const struct got_error *
488 got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
490 const struct got_error *err = NULL;
491 struct got_fileindex_hdr hdr;
493 struct got_fileindex_entry *entry;
494 uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
495 uint8_t sha1[SHA1_DIGEST_LENGTH];
501 n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
502 if (n != sizeof(hdr.signature)) {
503 if (n == 0) /* EOF */
505 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
507 n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
508 if (n != sizeof(hdr.version)) {
509 if (n == 0) /* EOF */
511 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
513 n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
514 if (n != sizeof(hdr.nentries)) {
515 if (n == 0) /* EOF */
517 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
520 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
521 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
522 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
524 hdr.signature = be32toh(hdr.signature);
525 hdr.version = be32toh(hdr.version);
526 hdr.nentries = be32toh(hdr.nentries);
528 if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
529 return got_error(GOT_ERR_FILEIDX_SIG);
530 if (hdr.version != GOT_FILE_INDEX_VERSION)
531 return got_error(GOT_ERR_FILEIDX_VER);
533 for (i = 0; i < hdr.nentries; i++) {
534 err = read_fileindex_entry(&entry, &ctx, infile);
537 err = add_entry(fileindex, entry);
542 n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
543 if (n != sizeof(sha1_expected))
544 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
545 SHA1Final(sha1, &ctx);
546 if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
547 return got_error(GOT_ERR_FILEIDX_CSUM);
552 struct got_fileindex_entry *
553 walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
555 struct got_fileindex_entry *next;
557 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
559 /* Skip entries which were newly added by diff callbacks. */
560 while (next && (next->flags & GOT_FILEIDX_F_INTENT_TO_ADD))
561 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
566 static const struct got_error *
567 diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
568 struct got_tree_object *, const char *, struct got_repository *,
569 struct got_fileindex_diff_tree_cb *, void *);
571 static const struct got_error *
572 walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
573 struct got_fileindex_entry **ie, struct got_tree_entry *te,
574 const char *path, struct got_repository *repo,
575 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
577 const struct got_error *err = NULL;
579 if (S_ISDIR(te->mode)) {
581 struct got_tree_object *subtree;
583 if (asprintf(&subpath, "%s%s%s", path,
584 path[0] == '\0' ? "" : "/", te->name) == -1)
585 return got_error_from_errno();
587 err = got_object_open_as_tree(&subtree, repo, te->id);
593 err = diff_fileindex_tree(fileindex, ie, subtree,
594 subpath, repo, cb, cb_arg);
596 got_object_tree_close(subtree);
601 *next = SIMPLEQ_NEXT(te, entry);
606 * Decide whether a fileindex entry path is equivalent to a tree entry path,
607 * and if it is not, then decide which of the two should be processed first.
610 cmp_entries(const char *ie_path, const char *parent_path,
611 size_t parent_len, const char *te_name)
613 int cmp = strncmp(ie_path, parent_path, parent_len);
615 const char *ie_name = ie_path + parent_len;
616 while (ie_name[0] == '/')
618 cmp = strcmp(ie_name, te_name);
624 static const struct got_error *
625 diff_fileindex_tree(struct got_fileindex *fileindex,
626 struct got_fileindex_entry **ie, struct got_tree_object *tree,
627 const char *path, struct got_repository *repo,
628 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
630 const struct got_error *err = NULL;
631 struct got_tree_entry *te = NULL;
632 size_t path_len = strlen(path);
633 const struct got_tree_entries *entries;
634 struct got_fileindex_entry *next;
636 entries = got_object_tree_get_entries(tree);
637 te = SIMPLEQ_FIRST(&entries->head);
638 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
640 int cmp = cmp_entries((*ie)->path, path, path_len,
643 err = cb->diff_old_new(cb_arg, *ie, te,
647 *ie = walk_fileindex(fileindex, *ie);
648 err = walk_tree(&te, fileindex, ie, te,
649 path, repo, cb, cb_arg);
650 } else if (cmp < 0 ) {
651 next = walk_fileindex(fileindex, *ie);
652 err = cb->diff_old(cb_arg, *ie, path);
657 err = cb->diff_new(cb_arg, te, path);
660 err = walk_tree(&te, fileindex, ie, te,
661 path, repo, cb, cb_arg);
666 next = walk_fileindex(fileindex, *ie);
667 err = cb->diff_old(cb_arg, *ie, path);
672 err = cb->diff_new(cb_arg, te, path);
675 err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
685 const struct got_error *
686 got_fileindex_diff_tree(struct got_fileindex *fileindex,
687 struct got_tree_object *tree, struct got_repository *repo,
688 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
690 struct got_fileindex_entry *min;
691 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
692 return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
695 static const struct got_error *
696 diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
697 const char *, const char *, struct got_repository *,
698 struct got_fileindex_diff_dir_cb *, void *);
700 static const struct got_error *
701 walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
702 struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
703 const char *path, DIR *dir, const char *rootpath,
704 struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
707 const struct got_error *err = NULL;
708 struct dirent *de = dle->data;
710 if (de->d_type == DT_DIR) {
715 if (asprintf(&subpath, "%s%s%s", path,
716 path[0] == '\0' ? "" : "/", de->d_name) == -1)
717 return got_error_from_errno();
719 if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
721 return got_error_from_errno();
724 subdir = opendir(subdirpath);
725 if (subdir == NULL) {
730 return got_error_from_errno();
733 err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
734 subpath, repo, cb, cb_arg);
742 *next = TAILQ_NEXT(dle, entry);
746 static const struct got_error *
747 diff_fileindex_dir(struct got_fileindex *fileindex,
748 struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
749 const char *path, struct got_repository *repo,
750 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
752 const struct got_error *err = NULL;
753 struct dirent *de = NULL;
754 size_t path_len = strlen(path);
755 struct got_fileindex_entry *next;
756 struct got_pathlist_head dirlist;
757 struct got_pathlist_entry *dle;
759 TAILQ_INIT(&dirlist);
762 struct got_pathlist_entry *new = NULL;
763 struct dirent *dep = NULL;
765 de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
767 err = got_error_from_errno();
771 if (readdir_r(dir, de, &dep) != 0) {
772 err = got_error_from_errno();
781 if (strcmp(de->d_name, ".") == 0 ||
782 strcmp(de->d_name, "..") == 0 ||
784 strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
789 err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
793 err = got_error(GOT_ERR_DIR_DUP_ENTRY);
798 dle = TAILQ_FIRST(&dirlist);
799 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
803 cmp = cmp_entries((*ie)->path, path, path_len,
806 err = cb->diff_old_new(cb_arg, *ie, de, path);
809 *ie = walk_fileindex(fileindex, *ie);
810 err = walk_dir(&dle, fileindex, ie, dle, path,
811 dir, rootpath, repo, cb, cb_arg);
812 } else if (cmp < 0 ) {
813 next = walk_fileindex(fileindex, *ie);
814 err = cb->diff_old(cb_arg, *ie, path);
819 err = cb->diff_new(cb_arg, de, path);
822 err = walk_dir(&dle, fileindex, ie, dle, path,
823 dir, rootpath, repo, cb, cb_arg);
828 next = walk_fileindex(fileindex, *ie);
829 err = cb->diff_old(cb_arg, *ie, path);
835 err = cb->diff_new(cb_arg, de, path);
838 err = walk_dir(&dle, fileindex, ie, dle, path, dir,
839 rootpath, repo, cb, cb_arg);
845 TAILQ_FOREACH(dle, &dirlist, entry)
847 got_pathlist_free(&dirlist);
851 const struct got_error *
852 got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
853 const char *rootpath, struct got_repository *repo,
854 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
856 struct got_fileindex_entry *min;
857 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
858 return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, "",
862 RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);