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>
30 #include "got_error.h"
31 #include "got_object.h"
33 #include "got_lib_path.h"
34 #include "got_lib_fileindex.h"
35 #include "got_lib_worktree.h"
37 struct got_fileindex {
38 struct got_fileindex_tree entries;
40 #define GOT_FILEIDX_MAX_ENTRIES INT_MAX
43 const struct got_error *
44 got_fileindex_entry_update(struct got_fileindex_entry *entry,
45 const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1,
46 int update_timestamps)
50 if (lstat(ondisk_path, &sb) != 0)
51 return got_error_from_errno();
53 if (update_timestamps) {
54 entry->ctime_sec = sb.st_ctime;
55 entry->ctime_nsec = sb.st_ctimensec;
56 entry->mtime_sec = sb.st_mtime;
57 entry->mtime_nsec = sb.st_mtimensec;
59 entry->uid = sb.st_uid;
60 entry->gid = sb.st_gid;
61 entry->size = (sb.st_size & 0xffffffff);
62 if (sb.st_mode & S_IFLNK)
63 entry->mode = GOT_FILEIDX_MODE_SYMLINK;
65 entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
66 entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
67 GOT_FILEIDX_MODE_PERMS_SHIFT);
68 memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
69 memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
74 const struct got_error *
75 got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
76 const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
81 *entry = calloc(1, sizeof(**entry));
83 return got_error_from_errno();
85 (*entry)->path = strdup(relpath);
86 if ((*entry)->path == NULL) {
87 const struct got_error *err = got_error_from_errno();
93 len = strlen(relpath);
94 if (len > GOT_FILEIDX_F_PATH_LEN)
95 len = GOT_FILEIDX_F_PATH_LEN;
96 (*entry)->flags |= len;
98 return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
103 got_fileindex_entry_free(struct got_fileindex_entry *entry)
109 static const struct got_error *
110 add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
112 if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
113 return got_error(GOT_ERR_NO_SPACE);
115 RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
116 fileindex->nentries++;
120 const struct got_error *
121 got_fileindex_entry_add(struct got_fileindex *fileindex,
122 struct got_fileindex_entry *entry)
124 /* Flag this entry until it gets written out to disk. */
125 entry->flags |= GOT_FILEIDX_F_INTENT_TO_ADD;
127 return add_entry(fileindex, entry);
131 got_fileindex_entry_remove(struct got_fileindex *fileindex,
132 struct got_fileindex_entry *entry)
134 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
135 fileindex->nentries--;
138 struct got_fileindex_entry *
139 got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
141 struct got_fileindex_entry key;
142 memset(&key, 0, sizeof(key));
143 key.path = (char *)path;
144 return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
147 const struct got_error *
148 got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
149 got_fileindex_cb cb, void *cb_arg)
151 const struct got_error *err;
152 struct got_fileindex_entry *entry, *tmp;
154 RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
155 err = (*cb)(cb_arg, entry);
162 struct got_fileindex *
163 got_fileindex_alloc(void)
165 struct got_fileindex *fileindex;
167 fileindex = calloc(1, sizeof(*fileindex));
168 if (fileindex == NULL)
171 RB_INIT(&fileindex->entries);
176 got_fileindex_free(struct got_fileindex *fileindex)
178 struct got_fileindex_entry *entry;
180 while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
181 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
182 got_fileindex_entry_free(entry);
187 static const struct got_error *
188 write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
193 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
194 n = fwrite(&val, 1, sizeof(val), outfile);
195 if (n != sizeof(val))
196 return got_ferror(outfile, GOT_ERR_IO);
200 static const struct got_error *
201 write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
206 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
207 n = fwrite(&val, 1, sizeof(val), outfile);
208 if (n != sizeof(val))
209 return got_ferror(outfile, GOT_ERR_IO);
213 static const struct got_error *
214 write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
219 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
220 n = fwrite(&val, 1, sizeof(val), outfile);
221 if (n != sizeof(val))
222 return got_ferror(outfile, GOT_ERR_IO);
226 static const struct got_error *
227 write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
229 size_t n, len, pad = 0;
230 static const uint8_t zero[8] = { 0 };
233 while ((len + pad) % 8 != 0)
236 pad = 8; /* NUL-terminate */
238 SHA1Update(ctx, path, len);
239 n = fwrite(path, 1, len, outfile);
241 return got_ferror(outfile, GOT_ERR_IO);
242 SHA1Update(ctx, zero, pad);
243 n = fwrite(zero, 1, pad, outfile);
245 return got_ferror(outfile, GOT_ERR_IO);
249 static const struct got_error *
250 write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
253 const struct got_error *err;
256 err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
259 err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
262 err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
265 err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
269 err = write_fileindex_val32(ctx, entry->uid, outfile);
272 err = write_fileindex_val32(ctx, entry->gid, outfile);
275 err = write_fileindex_val32(ctx, entry->size, outfile);
279 err = write_fileindex_val16(ctx, entry->mode, outfile);
283 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
284 n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
285 if (n != SHA1_DIGEST_LENGTH)
286 return got_ferror(outfile, GOT_ERR_IO);
288 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
289 n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
290 if (n != SHA1_DIGEST_LENGTH)
291 return got_ferror(outfile, GOT_ERR_IO);
293 err = write_fileindex_val32(ctx, entry->flags, outfile);
297 err = write_fileindex_path(ctx, entry->path, outfile);
301 const struct got_error *
302 got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
304 const struct got_error *err = NULL;
305 struct got_fileindex_hdr hdr;
307 uint8_t sha1[SHA1_DIGEST_LENGTH];
309 struct got_fileindex_entry *entry;
313 hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
314 hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
315 hdr.nentries = htobe32(fileindex->nentries);
317 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
318 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
319 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
320 n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
321 if (n != sizeof(hdr.signature))
322 return got_ferror(outfile, GOT_ERR_IO);
323 n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
324 if (n != sizeof(hdr.version))
325 return got_ferror(outfile, GOT_ERR_IO);
326 n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
327 if (n != sizeof(hdr.nentries))
328 return got_ferror(outfile, GOT_ERR_IO);
330 RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
331 entry->flags &= ~GOT_FILEIDX_F_INTENT_TO_ADD;
332 err = write_fileindex_entry(&ctx, entry, outfile);
337 SHA1Final(sha1, &ctx);
338 n = fwrite(sha1, 1, sizeof(sha1), outfile);
339 if (n != sizeof(sha1))
340 return got_ferror(outfile, GOT_ERR_IO);
342 if (fflush(outfile) != 0)
343 return got_error_from_errno();
348 static const struct got_error *
349 read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
353 n = fread(val, 1, sizeof(*val), infile);
354 if (n != sizeof(*val))
355 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
356 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
357 *val = be64toh(*val);
361 static const struct got_error *
362 read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
366 n = fread(val, 1, sizeof(*val), infile);
367 if (n != sizeof(*val))
368 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
369 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
370 *val = be32toh(*val);
374 static const struct got_error *
375 read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
379 n = fread(val, 1, sizeof(*val), infile);
380 if (n != sizeof(*val))
381 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
382 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
383 *val = be16toh(*val);
387 static const struct got_error *
388 read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
390 const struct got_error *err = NULL;
392 size_t n, len = 0, totlen = sizeof(buf);
394 *path = malloc(totlen);
396 return got_error_from_errno();
399 n = fread(buf, 1, sizeof(buf), infile);
400 if (n != sizeof(buf))
401 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
402 if (len + sizeof(buf) > totlen) {
403 char *p = reallocarray(*path, totlen + sizeof(buf), 1);
405 err = got_error_from_errno();
408 totlen += sizeof(buf);
411 SHA1Update(ctx, buf, sizeof(buf));
412 memcpy(*path + len, buf, sizeof(buf));
414 } while (memchr(buf, '\0', sizeof(buf)) == NULL);
423 static const struct got_error *
424 read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
427 const struct got_error *err;
428 struct got_fileindex_entry *entry;
433 entry = calloc(1, sizeof(*entry));
435 return got_error_from_errno();
437 err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
440 err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
443 err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
446 err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
450 err = read_fileindex_val32(&entry->uid, ctx, infile);
453 err = read_fileindex_val32(&entry->gid, ctx, infile);
456 err = read_fileindex_val32(&entry->size, ctx, infile);
460 err = read_fileindex_val16(&entry->mode, ctx, infile);
464 n = fread(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, infile);
465 if (n != SHA1_DIGEST_LENGTH) {
466 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
469 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
471 n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
472 if (n != SHA1_DIGEST_LENGTH) {
473 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
476 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
478 err = read_fileindex_val32(&entry->flags, ctx, infile);
482 err = read_fileindex_path(&entry->path, ctx, infile);
491 const struct got_error *
492 got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
494 const struct got_error *err = NULL;
495 struct got_fileindex_hdr hdr;
497 struct got_fileindex_entry *entry;
498 uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
499 uint8_t sha1[SHA1_DIGEST_LENGTH];
505 n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
506 if (n != sizeof(hdr.signature)) {
507 if (n == 0) /* EOF */
509 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
511 n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
512 if (n != sizeof(hdr.version)) {
513 if (n == 0) /* EOF */
515 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
517 n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
518 if (n != sizeof(hdr.nentries)) {
519 if (n == 0) /* EOF */
521 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
524 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
525 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
526 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
528 hdr.signature = be32toh(hdr.signature);
529 hdr.version = be32toh(hdr.version);
530 hdr.nentries = be32toh(hdr.nentries);
532 if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
533 return got_error(GOT_ERR_FILEIDX_SIG);
534 if (hdr.version != GOT_FILE_INDEX_VERSION)
535 return got_error(GOT_ERR_FILEIDX_VER);
537 for (i = 0; i < hdr.nentries; i++) {
538 err = read_fileindex_entry(&entry, &ctx, infile);
541 err = add_entry(fileindex, entry);
546 n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
547 if (n != sizeof(sha1_expected))
548 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
549 SHA1Final(sha1, &ctx);
550 if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
551 return got_error(GOT_ERR_FILEIDX_CSUM);
556 struct got_fileindex_entry *
557 walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
559 struct got_fileindex_entry *next;
561 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
563 /* Skip entries which were newly added by diff callbacks. */
564 while (next && (next->flags & GOT_FILEIDX_F_INTENT_TO_ADD))
565 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
570 static const struct got_error *
571 diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
572 struct got_tree_object *, const char *, struct got_repository *,
573 struct got_fileindex_diff_tree_cb *, void *);
575 static const struct got_error *
576 walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
577 struct got_fileindex_entry **ie, struct got_tree_entry *te,
578 const char *path, struct got_repository *repo,
579 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
581 const struct got_error *err = NULL;
583 if (S_ISDIR(te->mode)) {
585 struct got_tree_object *subtree;
587 if (asprintf(&subpath, "%s%s%s", path,
588 path[0] == '\0' ? "" : "/", te->name) == -1)
589 return got_error_from_errno();
591 err = got_object_open_as_tree(&subtree, repo, te->id);
597 err = diff_fileindex_tree(fileindex, ie, subtree,
598 subpath, repo, cb, cb_arg);
600 got_object_tree_close(subtree);
605 *next = SIMPLEQ_NEXT(te, entry);
609 static const struct got_error *
610 diff_fileindex_tree(struct got_fileindex *fileindex,
611 struct got_fileindex_entry **ie, struct got_tree_object *tree,
612 const char *path, struct got_repository *repo,
613 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
615 const struct got_error *err = NULL;
616 struct got_tree_entry *te = NULL;
617 size_t path_len = strlen(path);
618 const struct got_tree_entries *entries;
619 struct got_fileindex_entry *next;
621 entries = got_object_tree_get_entries(tree);
622 te = SIMPLEQ_FIRST(&entries->head);
623 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
627 if (asprintf(&te_path, "%s/%s", path, te->name) == -1) {
628 err = got_error_from_errno();
631 cmp = got_path_cmp((*ie)->path, te_path);
634 err = cb->diff_old_new(cb_arg, *ie, te,
638 *ie = walk_fileindex(fileindex, *ie);
639 err = walk_tree(&te, fileindex, ie, te,
640 path, repo, cb, cb_arg);
641 } else if (cmp < 0 ) {
642 next = walk_fileindex(fileindex, *ie);
643 err = cb->diff_old(cb_arg, *ie, path);
648 err = cb->diff_new(cb_arg, te, path);
651 err = walk_tree(&te, fileindex, ie, te,
652 path, repo, cb, cb_arg);
657 next = walk_fileindex(fileindex, *ie);
658 err = cb->diff_old(cb_arg, *ie, path);
663 err = cb->diff_new(cb_arg, te, path);
666 err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
676 const struct got_error *
677 got_fileindex_diff_tree(struct got_fileindex *fileindex,
678 struct got_tree_object *tree, struct got_repository *repo,
679 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
681 struct got_fileindex_entry *min;
682 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
683 return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
686 static const struct got_error *
687 diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
688 const char *, const char *, struct got_repository *,
689 struct got_fileindex_diff_dir_cb *, void *);
691 static const struct got_error *
692 walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
693 struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
694 const char *path, DIR *dir, const char *rootpath,
695 struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
698 const struct got_error *err = NULL;
699 struct dirent *de = dle->data;
701 if (de->d_type == DT_DIR) {
706 if (asprintf(&subpath, "%s%s%s", path,
707 path[0] == '\0' ? "" : "/", de->d_name) == -1)
708 return got_error_from_errno();
710 if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
712 return got_error_from_errno();
715 subdir = opendir(subdirpath);
716 if (subdir == NULL) {
719 return got_error_from_errno();
722 err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
723 subpath, repo, cb, cb_arg);
731 *next = TAILQ_NEXT(dle, entry);
735 static const struct got_error *
736 diff_fileindex_dir(struct got_fileindex *fileindex,
737 struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
738 const char *path, struct got_repository *repo,
739 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
741 const struct got_error *err = NULL;
742 struct dirent *de = NULL;
743 size_t path_len = strlen(path);
744 struct got_fileindex_entry *next;
745 struct got_pathlist_head dirlist;
746 struct got_pathlist_entry *dle;
748 TAILQ_INIT(&dirlist);
751 struct got_pathlist_entry *new = NULL;
752 struct dirent *dep = NULL;
754 de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
756 err = got_error_from_errno();
760 if (readdir_r(dir, de, &dep) != 0) {
761 err = got_error_from_errno();
770 if (strcmp(de->d_name, ".") == 0 ||
771 strcmp(de->d_name, "..") == 0 ||
773 strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
778 err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
782 err = got_error(GOT_ERR_DIR_DUP_ENTRY);
787 dle = TAILQ_FIRST(&dirlist);
788 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
793 if (asprintf(&de_path, "%s/%s", path,
795 err = got_error_from_errno();
798 cmp = got_path_cmp((*ie)->path, de_path);
801 err = cb->diff_old_new(cb_arg, *ie, de, path);
804 *ie = walk_fileindex(fileindex, *ie);
805 err = walk_dir(&dle, fileindex, ie, dle, path,
806 dir, rootpath, repo, cb, cb_arg);
807 } else if (cmp < 0 ) {
808 next = walk_fileindex(fileindex, *ie);
809 err = cb->diff_old(cb_arg, *ie, path);
814 err = cb->diff_new(cb_arg, de, path);
817 err = walk_dir(&dle, fileindex, ie, dle, path,
818 dir, rootpath, repo, cb, cb_arg);
823 next = walk_fileindex(fileindex, *ie);
824 err = cb->diff_old(cb_arg, *ie, path);
830 err = cb->diff_new(cb_arg, de, path);
833 err = walk_dir(&dle, fileindex, ie, dle, path, dir,
834 rootpath, repo, cb, cb_arg);
840 TAILQ_FOREACH(dle, &dirlist, entry)
842 got_pathlist_free(&dirlist);
846 const struct got_error *
847 got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
848 const char *rootpath, const char *path, struct got_repository *repo,
849 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
851 struct got_fileindex_entry *min;
852 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
853 return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, path,
857 RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);