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 /* got_fileindex_entry flags */
38 #define GOT_FILEIDX_F_PATH_LEN 0x00000fff
39 #define GOT_FILEIDX_F_STAGE 0x00003000
40 #define GOT_FILEIDX_F_EXTENDED 0x00004000
41 #define GOT_FILEIDX_F_ASSUME_VALID 0x00008000
42 #define GOT_FILEIDX_F_NOT_FLUSHED 0x20000000
44 struct got_fileindex {
45 struct got_fileindex_tree entries;
47 #define GOT_FILEIDX_MAX_ENTRIES INT_MAX
50 const struct got_error *
51 got_fileindex_entry_update(struct got_fileindex_entry *entry,
52 const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1,
53 int update_timestamps)
57 if (lstat(ondisk_path, &sb) != 0)
58 return got_error_from_errno();
60 if (update_timestamps) {
61 entry->ctime_sec = sb.st_ctime;
62 entry->ctime_nsec = sb.st_ctimensec;
63 entry->mtime_sec = sb.st_mtime;
64 entry->mtime_nsec = sb.st_mtimensec;
66 entry->uid = sb.st_uid;
67 entry->gid = sb.st_gid;
68 entry->size = (sb.st_size & 0xffffffff);
69 if (sb.st_mode & S_IFLNK)
70 entry->mode = GOT_FILEIDX_MODE_SYMLINK;
72 entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
73 entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
74 GOT_FILEIDX_MODE_PERMS_SHIFT);
75 memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
76 memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
81 const struct got_error *
82 got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
83 const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
88 *entry = calloc(1, sizeof(**entry));
90 return got_error_from_errno();
92 (*entry)->path = strdup(relpath);
93 if ((*entry)->path == NULL) {
94 const struct got_error *err = got_error_from_errno();
100 len = strlen(relpath);
101 if (len > GOT_FILEIDX_F_PATH_LEN)
102 len = GOT_FILEIDX_F_PATH_LEN;
103 (*entry)->flags |= len;
105 return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
110 got_fileindex_entry_free(struct got_fileindex_entry *entry)
116 static const struct got_error *
117 add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
119 if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
120 return got_error(GOT_ERR_NO_SPACE);
122 RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
123 fileindex->nentries++;
127 const struct got_error *
128 got_fileindex_entry_add(struct got_fileindex *fileindex,
129 struct got_fileindex_entry *entry)
131 /* Flag this entry until it gets written out to disk. */
132 entry->flags |= GOT_FILEIDX_F_NOT_FLUSHED;
134 return add_entry(fileindex, entry);
138 got_fileindex_entry_remove(struct got_fileindex *fileindex,
139 struct got_fileindex_entry *entry)
141 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
142 fileindex->nentries--;
145 struct got_fileindex_entry *
146 got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
148 struct got_fileindex_entry key;
149 memset(&key, 0, sizeof(key));
150 key.path = (char *)path;
151 return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
154 const struct got_error *
155 got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
156 got_fileindex_cb cb, void *cb_arg)
158 const struct got_error *err;
159 struct got_fileindex_entry *entry, *tmp;
161 RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
162 err = (*cb)(cb_arg, entry);
169 struct got_fileindex *
170 got_fileindex_alloc(void)
172 struct got_fileindex *fileindex;
174 fileindex = calloc(1, sizeof(*fileindex));
175 if (fileindex == NULL)
178 RB_INIT(&fileindex->entries);
183 got_fileindex_free(struct got_fileindex *fileindex)
185 struct got_fileindex_entry *entry;
187 while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
188 RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
189 got_fileindex_entry_free(entry);
194 static const struct got_error *
195 write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
200 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
201 n = fwrite(&val, 1, sizeof(val), outfile);
202 if (n != sizeof(val))
203 return got_ferror(outfile, GOT_ERR_IO);
207 static const struct got_error *
208 write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
213 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
214 n = fwrite(&val, 1, sizeof(val), outfile);
215 if (n != sizeof(val))
216 return got_ferror(outfile, GOT_ERR_IO);
220 static const struct got_error *
221 write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
226 SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
227 n = fwrite(&val, 1, sizeof(val), outfile);
228 if (n != sizeof(val))
229 return got_ferror(outfile, GOT_ERR_IO);
233 static const struct got_error *
234 write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
236 size_t n, len, pad = 0;
237 static const uint8_t zero[8] = { 0 };
240 while ((len + pad) % 8 != 0)
243 pad = 8; /* NUL-terminate */
245 SHA1Update(ctx, path, len);
246 n = fwrite(path, 1, len, outfile);
248 return got_ferror(outfile, GOT_ERR_IO);
249 SHA1Update(ctx, zero, pad);
250 n = fwrite(zero, 1, pad, outfile);
252 return got_ferror(outfile, GOT_ERR_IO);
256 static const struct got_error *
257 write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
260 const struct got_error *err;
263 err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
266 err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
269 err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
272 err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
276 err = write_fileindex_val32(ctx, entry->uid, outfile);
279 err = write_fileindex_val32(ctx, entry->gid, outfile);
282 err = write_fileindex_val32(ctx, entry->size, outfile);
286 err = write_fileindex_val16(ctx, entry->mode, outfile);
290 SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
291 n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
292 if (n != SHA1_DIGEST_LENGTH)
293 return got_ferror(outfile, GOT_ERR_IO);
295 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
296 n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
297 if (n != SHA1_DIGEST_LENGTH)
298 return got_ferror(outfile, GOT_ERR_IO);
300 err = write_fileindex_val32(ctx, entry->flags, outfile);
304 err = write_fileindex_path(ctx, entry->path, outfile);
308 const struct got_error *
309 got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
311 const struct got_error *err = NULL;
312 struct got_fileindex_hdr hdr;
314 uint8_t sha1[SHA1_DIGEST_LENGTH];
316 struct got_fileindex_entry *entry;
320 hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
321 hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
322 hdr.nentries = htobe32(fileindex->nentries);
324 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
325 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
326 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
327 n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
328 if (n != sizeof(hdr.signature))
329 return got_ferror(outfile, GOT_ERR_IO);
330 n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
331 if (n != sizeof(hdr.version))
332 return got_ferror(outfile, GOT_ERR_IO);
333 n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
334 if (n != sizeof(hdr.nentries))
335 return got_ferror(outfile, GOT_ERR_IO);
337 RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
338 entry->flags &= ~GOT_FILEIDX_F_NOT_FLUSHED;
339 err = write_fileindex_entry(&ctx, entry, outfile);
344 SHA1Final(sha1, &ctx);
345 n = fwrite(sha1, 1, sizeof(sha1), outfile);
346 if (n != sizeof(sha1))
347 return got_ferror(outfile, GOT_ERR_IO);
349 if (fflush(outfile) != 0)
350 return got_error_from_errno();
355 static const struct got_error *
356 read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
360 n = fread(val, 1, sizeof(*val), infile);
361 if (n != sizeof(*val))
362 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
363 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
364 *val = be64toh(*val);
368 static const struct got_error *
369 read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
373 n = fread(val, 1, sizeof(*val), infile);
374 if (n != sizeof(*val))
375 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
376 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
377 *val = be32toh(*val);
381 static const struct got_error *
382 read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
386 n = fread(val, 1, sizeof(*val), infile);
387 if (n != sizeof(*val))
388 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
389 SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
390 *val = be16toh(*val);
394 static const struct got_error *
395 read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
397 const struct got_error *err = NULL;
399 size_t n, len = 0, totlen = sizeof(buf);
401 *path = malloc(totlen);
403 return got_error_from_errno();
406 n = fread(buf, 1, sizeof(buf), infile);
407 if (n != sizeof(buf))
408 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
409 if (len + sizeof(buf) > totlen) {
410 char *p = reallocarray(*path, totlen + sizeof(buf), 1);
412 err = got_error_from_errno();
415 totlen += sizeof(buf);
418 SHA1Update(ctx, buf, sizeof(buf));
419 memcpy(*path + len, buf, sizeof(buf));
421 } while (memchr(buf, '\0', sizeof(buf)) == NULL);
430 static const struct got_error *
431 read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
434 const struct got_error *err;
435 struct got_fileindex_entry *entry;
440 entry = calloc(1, sizeof(*entry));
442 return got_error_from_errno();
444 err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
447 err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
450 err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
453 err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
457 err = read_fileindex_val32(&entry->uid, ctx, infile);
460 err = read_fileindex_val32(&entry->gid, ctx, infile);
463 err = read_fileindex_val32(&entry->size, ctx, infile);
467 err = read_fileindex_val16(&entry->mode, ctx, infile);
471 n = fread(entry->blob_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->blob_sha1, SHA1_DIGEST_LENGTH);
478 n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
479 if (n != SHA1_DIGEST_LENGTH) {
480 err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
483 SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
485 err = read_fileindex_val32(&entry->flags, ctx, infile);
489 err = read_fileindex_path(&entry->path, ctx, infile);
498 const struct got_error *
499 got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
501 const struct got_error *err = NULL;
502 struct got_fileindex_hdr hdr;
504 struct got_fileindex_entry *entry;
505 uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
506 uint8_t sha1[SHA1_DIGEST_LENGTH];
512 n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
513 if (n != sizeof(hdr.signature)) {
514 if (n == 0) /* EOF */
516 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
518 n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
519 if (n != sizeof(hdr.version)) {
520 if (n == 0) /* EOF */
522 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
524 n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
525 if (n != sizeof(hdr.nentries)) {
526 if (n == 0) /* EOF */
528 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
531 SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
532 SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
533 SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
535 hdr.signature = be32toh(hdr.signature);
536 hdr.version = be32toh(hdr.version);
537 hdr.nentries = be32toh(hdr.nentries);
539 if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
540 return got_error(GOT_ERR_FILEIDX_SIG);
541 if (hdr.version != GOT_FILE_INDEX_VERSION)
542 return got_error(GOT_ERR_FILEIDX_VER);
544 for (i = 0; i < hdr.nentries; i++) {
545 err = read_fileindex_entry(&entry, &ctx, infile);
548 err = add_entry(fileindex, entry);
553 n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
554 if (n != sizeof(sha1_expected))
555 return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
556 SHA1Final(sha1, &ctx);
557 if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
558 return got_error(GOT_ERR_FILEIDX_CSUM);
563 static struct got_fileindex_entry *
564 walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
566 struct got_fileindex_entry *next;
568 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
570 /* Skip entries which were newly added by diff callbacks. */
571 while (next && (next->flags & GOT_FILEIDX_F_NOT_FLUSHED))
572 next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
577 static const struct got_error *
578 diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
579 struct got_tree_object *, const char *, struct got_repository *,
580 struct got_fileindex_diff_tree_cb *, void *);
582 static const struct got_error *
583 walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
584 struct got_fileindex_entry **ie, struct got_tree_entry *te,
585 const char *path, struct got_repository *repo,
586 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
588 const struct got_error *err = NULL;
590 if (S_ISDIR(te->mode)) {
592 struct got_tree_object *subtree;
594 if (asprintf(&subpath, "%s%s%s", path,
595 path[0] == '\0' ? "" : "/", te->name) == -1)
596 return got_error_from_errno();
598 err = got_object_open_as_tree(&subtree, repo, te->id);
604 err = diff_fileindex_tree(fileindex, ie, subtree,
605 subpath, repo, cb, cb_arg);
607 got_object_tree_close(subtree);
612 *next = SIMPLEQ_NEXT(te, entry);
616 static const struct got_error *
617 diff_fileindex_tree(struct got_fileindex *fileindex,
618 struct got_fileindex_entry **ie, struct got_tree_object *tree,
619 const char *path, struct got_repository *repo,
620 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
622 const struct got_error *err = NULL;
623 struct got_tree_entry *te = NULL;
624 size_t path_len = strlen(path);
625 const struct got_tree_entries *entries;
626 struct got_fileindex_entry *next;
628 entries = got_object_tree_get_entries(tree);
629 te = SIMPLEQ_FIRST(&entries->head);
630 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
634 if (asprintf(&te_path, "%s/%s", path, te->name) == -1) {
635 err = got_error_from_errno();
638 cmp = got_path_cmp((*ie)->path, te_path);
641 err = cb->diff_old_new(cb_arg, *ie, te,
645 *ie = walk_fileindex(fileindex, *ie);
646 err = walk_tree(&te, fileindex, ie, te,
647 path, repo, cb, cb_arg);
648 } else if (cmp < 0 ) {
649 next = walk_fileindex(fileindex, *ie);
650 err = cb->diff_old(cb_arg, *ie, path);
655 err = cb->diff_new(cb_arg, te, path);
658 err = walk_tree(&te, fileindex, ie, te,
659 path, repo, cb, cb_arg);
664 next = walk_fileindex(fileindex, *ie);
665 err = cb->diff_old(cb_arg, *ie, path);
670 err = cb->diff_new(cb_arg, te, path);
673 err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
683 const struct got_error *
684 got_fileindex_diff_tree(struct got_fileindex *fileindex,
685 struct got_tree_object *tree, struct got_repository *repo,
686 struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
688 struct got_fileindex_entry *min;
689 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
690 return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
693 static const struct got_error *
694 diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
695 const char *, const char *, struct got_repository *,
696 struct got_fileindex_diff_dir_cb *, void *);
698 static const struct got_error *
699 walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
700 struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
701 const char *path, DIR *dir, const char *rootpath,
702 struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
705 const struct got_error *err = NULL;
706 struct dirent *de = dle->data;
708 if (de->d_type == DT_DIR) {
713 if (asprintf(&subpath, "%s%s%s", path,
714 path[0] == '\0' ? "" : "/", de->d_name) == -1)
715 return got_error_from_errno();
717 if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
719 return got_error_from_errno();
722 subdir = opendir(subdirpath);
723 if (subdir == NULL) {
726 return got_error_from_errno();
729 err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
730 subpath, repo, cb, cb_arg);
738 *next = TAILQ_NEXT(dle, entry);
742 static const struct got_error *
743 diff_fileindex_dir(struct got_fileindex *fileindex,
744 struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
745 const char *path, struct got_repository *repo,
746 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
748 const struct got_error *err = NULL;
749 struct dirent *de = NULL;
750 size_t path_len = strlen(path);
751 struct got_fileindex_entry *next;
752 struct got_pathlist_head dirlist;
753 struct got_pathlist_entry *dle;
755 TAILQ_INIT(&dirlist);
758 struct got_pathlist_entry *new = NULL;
759 struct dirent *dep = NULL;
761 de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
763 err = got_error_from_errno();
767 if (readdir_r(dir, de, &dep) != 0) {
768 err = got_error_from_errno();
777 if (strcmp(de->d_name, ".") == 0 ||
778 strcmp(de->d_name, "..") == 0 ||
780 strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
785 err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
789 err = got_error(GOT_ERR_DIR_DUP_ENTRY);
794 dle = TAILQ_FIRST(&dirlist);
795 while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
800 if (asprintf(&de_path, "%s/%s", path,
802 err = got_error_from_errno();
805 cmp = got_path_cmp((*ie)->path, de_path);
808 err = cb->diff_old_new(cb_arg, *ie, de, path);
811 *ie = walk_fileindex(fileindex, *ie);
812 err = walk_dir(&dle, fileindex, ie, dle, path,
813 dir, rootpath, repo, cb, cb_arg);
814 } else if (cmp < 0 ) {
815 next = walk_fileindex(fileindex, *ie);
816 err = cb->diff_old(cb_arg, *ie, path);
821 err = cb->diff_new(cb_arg, de, path);
824 err = walk_dir(&dle, fileindex, ie, dle, path,
825 dir, rootpath, repo, cb, cb_arg);
830 next = walk_fileindex(fileindex, *ie);
831 err = cb->diff_old(cb_arg, *ie, path);
837 err = cb->diff_new(cb_arg, de, path);
840 err = walk_dir(&dle, fileindex, ie, dle, path, dir,
841 rootpath, repo, cb, cb_arg);
847 TAILQ_FOREACH(dle, &dirlist, entry)
849 got_pathlist_free(&dirlist);
853 const struct got_error *
854 got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
855 const char *rootpath, const char *path, struct got_repository *repo,
856 struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
858 struct got_fileindex_entry *min;
859 min = RB_MIN(got_fileindex_tree, &fileindex->entries);
860 return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, path,
864 RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);