tree.h API: simplify read_tree_recursive() signature

Simplify the signature of read_tree_recursive() to omit the "base", "baselen" and "stage" arguments. No callers of it use these parameters for anything anymore. The last function to call read_tree_recursive() with a non-"" path was read_tree_recursive() itself, but that was changed in ffd31f661d5 (Reimplement read_tree_recursive() using tree_entry_interesting(), 2011-03-25). The last user of the "stage" parameter went away in the last commit, and even that use was mere boilerplate. So let's remove those and rename the read_tree_recursive() function to just read_tree(). We had another read_tree() function that I've refactored away in preceding commits, since all in-tree users read trees recursively with a callback we can change the name to signify that this is the norm. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 20, 2021 at 23:37 UTC 47957485b3b731a7860e0554d2bd12c0dce1c75a
8 files changed +39 -45
archive.c
+9 -9
@@ -229,7 +229,7 @@ static int write_directory(struct archiver_context *c)
229
230 static int queue_or_write_archive_entry(const struct object_id *oid,
231 struct strbuf *base, const char *filename,
232 - unsigned mode, int stage, void *context)
232 + unsigned mode, void *context)
233 {
234 struct archiver_context *c = context;
235
@@ -314,10 +314,10 @@ int write_archive_entries(struct archiver_args *args,
314 git_attr_set_direction(GIT_ATTR_INDEX);
315 }
316
317 - err = read_tree_recursive(args->repo, args->tree, "",
318 - 0, 0, &args->pathspec,
319 - queue_or_write_archive_entry,
320 - &context);
317 + err = read_tree(args->repo, args->tree,
318 + &args->pathspec,
319 + queue_or_write_archive_entry,
320 + &context);
321 if (err == READ_TREE_RECURSIVE)
322 err = 0;
323 while (context.bottom) {
@@ -375,7 +375,7 @@ struct path_exists_context {
375 };
376
377 static int reject_entry(const struct object_id *oid, struct strbuf *base,
378 - const char *filename, unsigned mode, int stage,
378 + const char *filename, unsigned mode,
379 void *context)
380 {
381 int ret = -1;
@@ -403,9 +403,9 @@ static int path_exists(struct archiver_args *args, const char *path)
403 ctx.args = args;
404 parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
405 ctx.pathspec.recursive = 1;
406 - ret = read_tree_recursive(args->repo, args->tree, "",
407 - 0, 0, &ctx.pathspec,
408 - reject_entry, &ctx);
406 + ret = read_tree(args->repo, args->tree,
407 + &ctx.pathspec,
408 + reject_entry, &ctx);
409 clear_pathspec(&ctx.pathspec);
410 return ret != 0;
411 }
builtin/checkout.c
+4 -4
@@ -114,7 +114,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
114 }
115
116 static int update_some(const struct object_id *oid, struct strbuf *base,
117 - const char *pathname, unsigned mode, int stage, void *context)
117 + const char *pathname, unsigned mode, void *context)
118 {
119 int len;
120 struct cache_entry *ce;
@@ -155,8 +155,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
155
156 static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
157 {
158 - read_tree_recursive(the_repository, tree, "", 0, 0,
159 - pathspec, update_some, NULL);
158 + read_tree(the_repository, tree,
159 + pathspec, update_some, NULL);
160
161 /* update the index with the given tree's info
162 * for all args, expanding wildcards, and exit
@@ -322,7 +322,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce,
322 * If it comes from the tree-ish, we already know it
323 * matches the pathspec and could just stamp
324 * CE_MATCHED to it from update_some(). But we still
325 - * need ps_matched and read_tree_recursive (and
325 + * need ps_matched and read_tree (and
326 * eventually tree_entry_interesting) cannot fill
327 * ps_matched yet. Once it can, we can avoid calling
328 * match_pathspec() for _all_ entries when
builtin/log.c
+4 -4
@@ -599,7 +599,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
599
600 static int show_tree_object(const struct object_id *oid,
601 struct strbuf *base,
602 - const char *pathname, unsigned mode, int stage, void *context)
602 + const char *pathname, unsigned mode, void *context)
603 {
604 FILE *file = context;
605 fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
@@ -681,9 +681,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
681 diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
682 name,
683 diff_get_color_opt(&rev.diffopt, DIFF_RESET));
684 - read_tree_recursive(the_repository, (struct tree *)o, "",
685 - 0, 0, &match_all, show_tree_object,
686 - rev.diffopt.file);
684 + read_tree(the_repository, (struct tree *)o,
685 + &match_all, show_tree_object,
686 + rev.diffopt.file);
687 rev.shown_one = 1;
688 break;
689 case OBJ_COMMIT:
builtin/ls-files.c
+3 -3
@@ -446,7 +446,7 @@ static int read_one_entry_opt(struct index_state *istate,
446 }
447
448 static int read_one_entry(const struct object_id *oid, struct strbuf *base,
449 - const char *pathname, unsigned mode, int stage,
449 + const char *pathname, unsigned mode,
450 void *context)
451 {
452 struct index_state *istate = context;
@@ -460,7 +460,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base,
460 * the stage that will conflict with the entry being added.
461 */
462 static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
463 - const char *pathname, unsigned mode, int stage,
463 + const char *pathname, unsigned mode,
464 void *context)
465 {
466 struct index_state *istate = context;
@@ -522,7 +522,7 @@ void overlay_tree_on_index(struct index_state *istate,
522
523 if (!fn)
524 fn = read_one_entry_quick;
525 - err = read_tree_recursive(the_repository, tree, "", 0, 1, &pathspec, fn, istate);
525 + err = read_tree(the_repository, tree, &pathspec, fn, istate);
526 if (err)
527 die("unable to read tree entries %s", tree_name);
528
builtin/ls-tree.c
+3 -3
@@ -62,7 +62,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
62 }
63
64 static int show_tree(const struct object_id *oid, struct strbuf *base,
65 - const char *pathname, unsigned mode, int stage, void *context)
65 + const char *pathname, unsigned mode, void *context)
66 {
67 int retval = 0;
68 int baselen;
@@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
185 tree = parse_tree_indirect(&oid);
186 if (!tree)
187 die("not a tree object");
188 - return !!read_tree_recursive(the_repository, tree, "", 0, 0,
189 - &pathspec, show_tree, NULL);
188 + return !!read_tree(the_repository, tree,
189 + &pathspec, show_tree, NULL);
190 }
merge-recursive.c
+3 -3
@@ -453,7 +453,7 @@ static void unpack_trees_finish(struct merge_options *opt)
453
454 static int save_files_dirs(const struct object_id *oid,
455 struct strbuf *base, const char *path,
456 - unsigned int mode, int stage, void *context)
456 + unsigned int mode, void *context)
457 {
458 struct path_hashmap_entry *entry;
459 int baselen = base->len;
@@ -473,8 +473,8 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree)
473 {
474 struct pathspec match_all;
475 memset(&match_all, 0, sizeof(match_all));
476 - read_tree_recursive(opt->repo, tree, "", 0, 0,
477 - &match_all, save_files_dirs, opt);
476 + read_tree(opt->repo, tree,
477 + &match_all, save_files_dirs, opt);
478 }
479
480 static int get_tree_entry_if_blob(struct repository *r,
tree.c
+7 -12
@@ -13,7 +13,6 @@ const char *tree_type = "tree";
13
14 int read_tree_at(struct repository *r,
15 struct tree *tree, struct strbuf *base,
16 - int stage,
16 const struct pathspec *pathspec,
17 read_tree_fn_t fn, void *context)
18 {
@@ -39,7 +38,7 @@ int read_tree_at(struct repository *r,
38 }
39
40 switch (fn(&entry.oid, base,
42 - entry.path, entry.mode, stage, context)) {
41 + entry.path, entry.mode, context)) {
42 case 0:
43 continue;
44 case READ_TREE_RECURSIVE:
@@ -73,7 +72,7 @@ int read_tree_at(struct repository *r,
72 strbuf_add(base, entry.path, len);
73 strbuf_addch(base, '/');
74 retval = read_tree_at(r, lookup_tree(r, &oid),
76 - base, stage, pathspec,
75 + base, pathspec,
76 fn, context);
77 strbuf_setlen(base, oldlen);
78 if (retval)
@@ -82,17 +81,13 @@ int read_tree_at(struct repository *r,
81 return 0;
82 }
83
85 -int read_tree_recursive(struct repository *r,
86 - struct tree *tree,
87 - const char *base, int baselen,
88 - int stage, const struct pathspec *pathspec,
89 - read_tree_fn_t fn, void *context)
84 +int read_tree(struct repository *r,
85 + struct tree *tree,
86 + const struct pathspec *pathspec,
87 + read_tree_fn_t fn, void *context)
88 {
89 struct strbuf sb = STRBUF_INIT;
92 - int ret;
93 -
94 - strbuf_add(&sb, base, baselen);
95 - ret = read_tree_at(r, tree, &sb, stage, pathspec, fn, context);
90 + int ret = read_tree_at(r, tree, &sb, pathspec, fn, context);
91 strbuf_release(&sb);
92 return ret;
93 }
tree.h
+6 -7
@@ -31,17 +31,16 @@ struct tree *parse_tree_indirect(const struct object_id *oid);
31 int cmp_cache_name_compare(const void *a_, const void *b_);
32
33 #define READ_TREE_RECURSIVE 1
34 -typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
34 +typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *);
35
36 int read_tree_at(struct repository *r,
37 struct tree *tree, struct strbuf *base,
38 - int stage,
38 const struct pathspec *pathspec,
39 read_tree_fn_t fn, void *context);
40
42 -int read_tree_recursive(struct repository *r,
43 - struct tree *tree,
44 - const char *base, int baselen,
45 - int stage, const struct pathspec *pathspec,
46 - read_tree_fn_t fn, void *context);
41 +int read_tree(struct repository *r,
42 + struct tree *tree,
43 + const struct pathspec *pathspec,
44 + read_tree_fn_t fn, void *context);
45 +
46 #endif /* TREE_H */