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,
45 int update_timestamps)
49 if (lstat(ondisk_path, &sb) != 0)
50 return got_error_from_errno();
52 if (update_timestamps) {
53 entry->ctime_sec = sb.st_ctime;
54 entry->ctime_nsec = sb.st_ctimensec;
55 entry->mtime_sec = sb.st_mtime;
56 entry->mtime_nsec = sb.st_mtimensec;
58 entry->uid = sb.st_uid;
59 entry->gid = sb.st_gid;
60 entry->size = (sb.st_size & 0xffffffff);
61 if (sb.st_mode & S_IFLNK)
62 entry->mode = GOT_FILEIDX_MODE_SYMLINK;
64 entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
65 entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
66 GOT_FILEIDX_MODE_PERMS_SHIFT);
67 memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
68 memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
73 const struct got_error *
74 got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
75 const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
80 *entry = calloc(1, sizeof(**entry));
82 return got_error_from_errno();
84 (*entry)->path = strdup(relpath);
85 if ((*entry)->path == NULL) {
86 const struct got_error *err = got_error_from_errno();
92 len = strlen(relpath);
93 if (len > GOT_FILEIDX_F_PATH_LEN)
94 len = GOT_FILEIDX_F_PATH_LEN;
95 (*entry)->flags |= len;
97 return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
102 got_fileindex_entry_free(struct got_fileindex_entry *entry)
108 static const struct got_error *
109 add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
111 if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
112 return got_error(GOT_ERR_NO_SPACE);
114 RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
115 fileindex->nentries++;
119 const struct got_error *
120 got_fileindex_entry_add(struct got_fileindex *fileindex,
121 struct got_fileindex_entry *entry)
123 /* Flag this entry until it gets written out to disk. */
124 entry->flags |= GOT_FILEIDX_F_INTENT_TO_ADD;
126 return add_entry(fileindex, entry);
130 got_fileindex_entry_remove(struct got_fileindex *fileindex,
131 struct got_fileindex_entry *entry)
133 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
134 fileindex->nentries--;
137 struct got_fileindex_entry *
138 got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
140 struct got_fileindex_entry key;
141 memset(&key, 0, sizeof(key));
142 key.path = (char *)path;
143 return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
146 const struct got_error *
147 got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
148 got_fileindex_cb cb, void *cb_arg)
150 const struct got_error *err;
151 struct got_fileindex_entry *entry, *tmp;
153 RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
154 err = (*cb)(cb_arg, entry);
161 struct got_fileindex *
162 got_fileindex_alloc(void)
164 struct got_fileindex *fileindex;
166 fileindex = calloc(1, sizeof(*fileindex));
167 if (fileindex == NULL)
170 RB_INIT(&fileindex->entries);
175 got_fileindex_free(struct got_fileindex *fileindex)
177 struct got_fileindex_entry *entry;
179 while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
180 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
181 got_fileindex_entry_free(entry);
186 static const struct got_error *
187 write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
192 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
193 n = fwrite(&val, 1, sizeof(val), outfile);
194 if (n != sizeof(val))
195 return got_ferror(outfile, GOT_ERR_IO);
199 static const struct got_error *
200 write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
205 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
206 n = fwrite(&val, 1, sizeof(val), outfile);
207 if (n != sizeof(val))
208 return got_ferror(outfile, GOT_ERR_IO);
212 static const struct got_error *
213 write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
218 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
219 n = fwrite(&val, 1, sizeof(val), outfile);
220 if (n != sizeof(val))
221 return got_ferror(outfile, GOT_ERR_IO);
225 static const struct got_error *
226 write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
228 size_t n, len, pad = 0;
229 static const uint8_t zero[8] = { 0 };
232 while ((len + pad) % 8 != 0)
235 pad = 8; /* NUL-terminate */
237 SHA1Update(ctx, path, len);
238 n = fwrite(path, 1, len, outfile);
240 return got_ferror(outfile, GOT_ERR_IO);
241 SHA1Update(ctx, zero, pad);
242 n = fwrite(zero, 1, pad, outfile);
244 return got_ferror(outfile, GOT_ERR_IO);
248 static const struct got_error *
249 write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
252 const struct got_error *err;
255 err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
258 err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
261 err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
264 err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
268 err = write_fileindex_val32(ctx, entry->uid, outfile);
271 err = write_fileindex_val32(ctx, entry->gid, outfile);
274 err = write_fileindex_val32(ctx, entry->size, outfile);
278 err = write_fileindex_val16(ctx, entry->mode, outfile);
282 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
283 n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
284 if (n != SHA1_DIGEST_LENGTH)
285 return got_ferror(outfile, GOT_ERR_IO);
287 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
288 n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
289 if (n != SHA1_DIGEST_LENGTH)
290 return got_ferror(outfile, GOT_ERR_IO);
292 err = write_fileindex_val32(ctx, entry->flags, outfile);
296 err = write_fileindex_path(ctx, entry->path, outfile);
300 const struct got_error *
301 got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
303 const struct got_error *err = NULL;
304 struct got_fileindex_hdr hdr;
306 uint8_t sha1[SHA1_DIGEST_LENGTH];
308 struct got_fileindex_entry *entry;
312 hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
313 hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
314 hdr.nentries = htobe32(fileindex->nentries);
316 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
317 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
318 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
319 n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
320 if (n != sizeof(hdr.signature))
321 return got_ferror(outfile, GOT_ERR_IO);
322 n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
323 if (n != sizeof(hdr.version))
324 return got_ferror(outfile, GOT_ERR_IO);
325 n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
326 if (n != sizeof(hdr.nentries))
327 return got_ferror(outfile, GOT_ERR_IO);
329 RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
330 entry->flags &= ~GOT_FILEIDX_F_INTENT_TO_ADD;
331 err = write_fileindex_entry(&ctx, entry, outfile);
336 SHA1Final(sha1, &ctx);
337 n = fwrite(sha1, 1, sizeof(sha1), outfile);
338 if (n != sizeof(sha1))
339 return got_ferror(outfile, GOT_ERR_IO);
341 if (fflush(outfile) != 0)
342 return got_error_from_errno();
347 static const struct got_error *
348 read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
352 n = fread(val, 1, sizeof(*val), infile);
353 if (n != sizeof(*val))
354 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
355 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
356 *val = be64toh(*val);
360 static const struct got_error *
361 read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
365 n = fread(val, 1, sizeof(*val), infile);
366 if (n != sizeof(*val))
367 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
368 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
369 *val = be32toh(*val);
373 static const struct got_error *
374 read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
378 n = fread(val, 1, sizeof(*val), infile);
379 if (n != sizeof(*val))
380 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
381 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
382 *val = be16toh(*val);
386 static const struct got_error *
387 read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
389 const struct got_error *err = NULL;
391 size_t n, len = 0, totlen = sizeof(buf);
393 *path = malloc(totlen);
395 return got_error_from_errno();
398 n = fread(buf, 1, sizeof(buf), infile);
399 if (n != sizeof(buf))
400 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
401 if (len + sizeof(buf) > totlen) {
402 char *p = reallocarray(*path, totlen + sizeof(buf), 1);
404 err = got_error_from_errno();
407 totlen += sizeof(buf);
410 SHA1Update(ctx, buf, sizeof(buf));
411 memcpy(*path + len, buf, sizeof(buf));
413 } while (memchr(buf, '\0', sizeof(buf)) == NULL);
422 static const struct got_error *
423 read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
426 const struct got_error *err;
427 struct got_fileindex_entry *entry;
432 entry = calloc(1, sizeof(*entry));
434 return got_error_from_errno();
436 err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
439 err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
442 err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
445 err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
449 err = read_fileindex_val32(&entry->uid, ctx, infile);
452 err = read_fileindex_val32(&entry->gid, ctx, infile);
455 err = read_fileindex_val32(&entry->size, ctx, infile);
459 err = read_fileindex_val16(&entry->mode, ctx, infile);
463 n = fread(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, infile);
464 if (n != SHA1_DIGEST_LENGTH) {
465 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
468 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
470 n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
471 if (n != SHA1_DIGEST_LENGTH) {
472 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
475 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
477 err = read_fileindex_val32(&entry->flags, ctx, infile);
481 err = read_fileindex_path(&entry->path, ctx, infile);
490 const struct got_error *
491 got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
493 const struct got_error *err = NULL;
494 struct got_fileindex_hdr hdr;
496 struct got_fileindex_entry *entry;
497 uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
498 uint8_t sha1[SHA1_DIGEST_LENGTH];
504 n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
505 if (n != sizeof(hdr.signature)) {
506 if (n == 0) /* EOF */
508 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
510 n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
511 if (n != sizeof(hdr.version)) {
512 if (n == 0) /* EOF */
514 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
516 n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
517 if (n != sizeof(hdr.nentries)) {
518 if (n == 0) /* EOF */
520 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
523 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
524 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
525 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
527 hdr.signature = be32toh(hdr.signature);
528 hdr.version = be32toh(hdr.version);
529 hdr.nentries = be32toh(hdr.nentries);
531 if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
532 return got_error(GOT_ERR_FILEIDX_SIG);
533 if (hdr.version != GOT_FILE_INDEX_VERSION)
534 return got_error(GOT_ERR_FILEIDX_VER);
536 for (i = 0; i < hdr.nentries; i++) {
537 err = read_fileindex_entry(&entry, &ctx, infile);
540 err = add_entry(fileindex, entry);
545 n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
546 if (n != sizeof(sha1_expected))
547 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
548 SHA1Final(sha1, &ctx);
549 if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
550 return got_error(GOT_ERR_FILEIDX_CSUM);
555 struct got_fileindex_entry *
556 walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
558 struct got_fileindex_entry *next;
560 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
562 /* Skip entries which were newly added by diff callbacks. */
563 while (next && (next->flags & GOT_FILEIDX_F_INTENT_TO_ADD))
564 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
569 static const struct got_error *
570 diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
571 struct got_tree_object *, const char *, struct got_repository *,
572 struct got_fileindex_diff_tree_cb *, void *);
574 static const struct got_error *
575 walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
576 struct got_fileindex_entry **ie, struct got_tree_entry *te,
577 const char *path, struct got_repository *repo,
578 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
580 const struct got_error *err = NULL;
582 if (S_ISDIR(te->mode)) {
584 struct got_tree_object *subtree;
586 if (asprintf(&subpath, "%s%s%s", path,
587 path[0] == '\0' ? "" : "/", te->name) == -1)
588 return got_error_from_errno();
590 err = got_object_open_as_tree(&subtree, repo, te->id);
596 err = diff_fileindex_tree(fileindex, ie, subtree,
597 subpath, repo, cb, cb_arg);
599 got_object_tree_close(subtree);
604 *next = SIMPLEQ_NEXT(te, entry);
608 static const struct got_error *
609 diff_fileindex_tree(struct got_fileindex *fileindex,
610 struct got_fileindex_entry **ie, struct got_tree_object *tree,
611 const char *path, struct got_repository *repo,
612 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
614 const struct got_error *err = NULL;
615 struct got_tree_entry *te = NULL;
616 size_t path_len = strlen(path);
617 const struct got_tree_entries *entries;
618 struct got_fileindex_entry *next;
620 entries = got_object_tree_get_entries(tree);
621 te = SIMPLEQ_FIRST(&entries->head);
622 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
626 if (asprintf(&te_path, "%s/%s", path, te->name) == -1) {
627 err = got_error_from_errno();
630 cmp = got_path_cmp((*ie)->path, te_path);
633 err = cb->diff_old_new(cb_arg, *ie, te,
637 *ie = walk_fileindex(fileindex, *ie);
638 err = walk_tree(&te, fileindex, ie, te,
639 path, repo, cb, cb_arg);
640 } else if (cmp < 0 ) {
641 next = walk_fileindex(fileindex, *ie);
642 err = cb->diff_old(cb_arg, *ie, path);
647 err = cb->diff_new(cb_arg, te, path);
650 err = walk_tree(&te, fileindex, ie, te,
651 path, repo, cb, cb_arg);
656 next = walk_fileindex(fileindex, *ie);
657 err = cb->diff_old(cb_arg, *ie, path);
662 err = cb->diff_new(cb_arg, te, path);
665 err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
675 const struct got_error *
676 got_fileindex_diff_tree(struct got_fileindex *fileindex,
677 struct got_tree_object *tree, struct got_repository *repo,
678 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
680 struct got_fileindex_entry *min;
681 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
682 return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
685 static const struct got_error *
686 diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
687 const char *, const char *, struct got_repository *,
688 struct got_fileindex_diff_dir_cb *, void *);
690 static const struct got_error *
691 walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
692 struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
693 const char *path, DIR *dir, const char *rootpath,
694 struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
697 const struct got_error *err = NULL;
698 struct dirent *de = dle->data;
700 if (de->d_type == DT_DIR) {
705 if (asprintf(&subpath, "%s%s%s", path,
706 path[0] == '\0' ? "" : "/", de->d_name) == -1)
707 return got_error_from_errno();
709 if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
711 return got_error_from_errno();
714 subdir = opendir(subdirpath);
715 if (subdir == NULL) {
718 return got_error_from_errno();
721 err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
722 subpath, repo, cb, cb_arg);
730 *next = TAILQ_NEXT(dle, entry);
734 static const struct got_error *
735 diff_fileindex_dir(struct got_fileindex *fileindex,
736 struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
737 const char *path, struct got_repository *repo,
738 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
740 const struct got_error *err = NULL;
741 struct dirent *de = NULL;
742 size_t path_len = strlen(path);
743 struct got_fileindex_entry *next;
744 struct got_pathlist_head dirlist;
745 struct got_pathlist_entry *dle;
747 TAILQ_INIT(&dirlist);
750 struct got_pathlist_entry *new = NULL;
751 struct dirent *dep = NULL;
753 de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
755 err = got_error_from_errno();
759 if (readdir_r(dir, de, &dep) != 0) {
760 err = got_error_from_errno();
769 if (strcmp(de->d_name, ".") == 0 ||
770 strcmp(de->d_name, "..") == 0 ||
772 strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
777 err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
781 err = got_error(GOT_ERR_DIR_DUP_ENTRY);
786 dle = TAILQ_FIRST(&dirlist);
787 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
792 if (asprintf(&de_path, "%s/%s", path,
794 err = got_error_from_errno();
797 cmp = got_path_cmp((*ie)->path, de_path);
800 err = cb->diff_old_new(cb_arg, *ie, de, path);
803 *ie = walk_fileindex(fileindex, *ie);
804 err = walk_dir(&dle, fileindex, ie, dle, path,
805 dir, rootpath, repo, cb, cb_arg);
806 } else if (cmp < 0 ) {
807 next = walk_fileindex(fileindex, *ie);
808 err = cb->diff_old(cb_arg, *ie, path);
813 err = cb->diff_new(cb_arg, de, path);
816 err = walk_dir(&dle, fileindex, ie, dle, path,
817 dir, rootpath, repo, cb, cb_arg);
822 next = walk_fileindex(fileindex, *ie);
823 err = cb->diff_old(cb_arg, *ie, path);
829 err = cb->diff_new(cb_arg, de, path);
832 err = walk_dir(&dle, fileindex, ie, dle, path, dir,
833 rootpath, repo, cb, cb_arg);
839 TAILQ_FOREACH(dle, &dirlist, entry)
841 got_pathlist_free(&dirlist);
845 const struct got_error *
846 got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
847 const char *rootpath, struct got_repository *repo,
848 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
850 struct got_fileindex_entry *min;
851 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
852 return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, "",
856 RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);