Skip to content

Commit 4795748

Browse files
avargitster
authored andcommitted
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 ffd31f6 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c9fc42 commit 4795748

File tree

8 files changed

+39
-45
lines changed

8 files changed

+39
-45
lines changed

archive.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int write_directory(struct archiver_context *c)
229229

230230
static int queue_or_write_archive_entry(const struct object_id *oid,
231231
struct strbuf *base, const char *filename,
232-
unsigned mode, int stage, void *context)
232+
unsigned mode, void *context)
233233
{
234234
struct archiver_context *c = context;
235235

@@ -314,10 +314,10 @@ int write_archive_entries(struct archiver_args *args,
314314
git_attr_set_direction(GIT_ATTR_INDEX);
315315
}
316316

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);
321321
if (err == READ_TREE_RECURSIVE)
322322
err = 0;
323323
while (context.bottom) {
@@ -375,7 +375,7 @@ struct path_exists_context {
375375
};
376376

377377
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,
379379
void *context)
380380
{
381381
int ret = -1;
@@ -403,9 +403,9 @@ static int path_exists(struct archiver_args *args, const char *path)
403403
ctx.args = args;
404404
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
405405
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);
409409
clear_pathspec(&ctx.pathspec);
410410
return ret != 0;
411411
}

builtin/checkout.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
114114
}
115115

116116
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)
118118
{
119119
int len;
120120
struct cache_entry *ce;
@@ -155,8 +155,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
155155

156156
static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
157157
{
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);
160160

161161
/* update the index with the given tree's info
162162
* for all args, expanding wildcards, and exit
@@ -322,7 +322,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce,
322322
* If it comes from the tree-ish, we already know it
323323
* matches the pathspec and could just stamp
324324
* 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
326326
* eventually tree_entry_interesting) cannot fill
327327
* ps_matched yet. Once it can, we can avoid calling
328328
* match_pathspec() for _all_ entries when

builtin/log.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
599599

600600
static int show_tree_object(const struct object_id *oid,
601601
struct strbuf *base,
602-
const char *pathname, unsigned mode, int stage, void *context)
602+
const char *pathname, unsigned mode, void *context)
603603
{
604604
FILE *file = context;
605605
fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
@@ -681,9 +681,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
681681
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
682682
name,
683683
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);
687687
rev.shown_one = 1;
688688
break;
689689
case OBJ_COMMIT:

builtin/ls-files.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int read_one_entry_opt(struct index_state *istate,
446446
}
447447

448448
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,
450450
void *context)
451451
{
452452
struct index_state *istate = context;
@@ -460,7 +460,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base,
460460
* the stage that will conflict with the entry being added.
461461
*/
462462
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,
464464
void *context)
465465
{
466466
struct index_state *istate = context;
@@ -522,7 +522,7 @@ void overlay_tree_on_index(struct index_state *istate,
522522

523523
if (!fn)
524524
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);
526526
if (err)
527527
die("unable to read tree entries %s", tree_name);
528528

builtin/ls-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
6262
}
6363

6464
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)
6666
{
6767
int retval = 0;
6868
int baselen;
@@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
185185
tree = parse_tree_indirect(&oid);
186186
if (!tree)
187187
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);
190190
}

merge-recursive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static void unpack_trees_finish(struct merge_options *opt)
453453

454454
static int save_files_dirs(const struct object_id *oid,
455455
struct strbuf *base, const char *path,
456-
unsigned int mode, int stage, void *context)
456+
unsigned int mode, void *context)
457457
{
458458
struct path_hashmap_entry *entry;
459459
int baselen = base->len;
@@ -473,8 +473,8 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree)
473473
{
474474
struct pathspec match_all;
475475
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);
478478
}
479479

480480
static int get_tree_entry_if_blob(struct repository *r,

tree.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const char *tree_type = "tree";
1313

1414
int read_tree_at(struct repository *r,
1515
struct tree *tree, struct strbuf *base,
16-
int stage,
1716
const struct pathspec *pathspec,
1817
read_tree_fn_t fn, void *context)
1918
{
@@ -39,7 +38,7 @@ int read_tree_at(struct repository *r,
3938
}
4039

4140
switch (fn(&entry.oid, base,
42-
entry.path, entry.mode, stage, context)) {
41+
entry.path, entry.mode, context)) {
4342
case 0:
4443
continue;
4544
case READ_TREE_RECURSIVE:
@@ -73,7 +72,7 @@ int read_tree_at(struct repository *r,
7372
strbuf_add(base, entry.path, len);
7473
strbuf_addch(base, '/');
7574
retval = read_tree_at(r, lookup_tree(r, &oid),
76-
base, stage, pathspec,
75+
base, pathspec,
7776
fn, context);
7877
strbuf_setlen(base, oldlen);
7978
if (retval)
@@ -82,17 +81,13 @@ int read_tree_at(struct repository *r,
8281
return 0;
8382
}
8483

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)
9088
{
9189
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);
9691
strbuf_release(&sb);
9792
return ret;
9893
}

tree.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ struct tree *parse_tree_indirect(const struct object_id *oid);
3131
int cmp_cache_name_compare(const void *a_, const void *b_);
3232

3333
#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 *);
3535

3636
int read_tree_at(struct repository *r,
3737
struct tree *tree, struct strbuf *base,
38-
int stage,
3938
const struct pathspec *pathspec,
4039
read_tree_fn_t fn, void *context);
4140

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+
4746
#endif /* TREE_H */

0 commit comments

Comments
 (0)