Skip to content

Commit e092073

Browse files
pcloudsgitster
authored andcommitted
tree.c: make read_tree*() take 'struct repository *'
These functions call tree_entry_interesting() which will soon require a 'struct index_state *' to be passed in. Instead of just changing the function signature to take an index, update to take a repo instead because these functions do need object database access. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0e94dab commit e092073

File tree

8 files changed

+35
-23
lines changed

8 files changed

+35
-23
lines changed

archive.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ int write_archive_entries(struct archiver_args *args,
285285
git_attr_set_direction(GIT_ATTR_INDEX);
286286
}
287287

288-
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
288+
err = read_tree_recursive(args->repo, args->tree, "",
289+
0, 0, &args->pathspec,
289290
queue_or_write_archive_entry,
290291
&context);
291292
if (err == READ_TREE_RECURSIVE)
@@ -346,7 +347,8 @@ static int path_exists(struct archiver_args *args, const char *path)
346347
ctx.args = args;
347348
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
348349
ctx.pathspec.recursive = 1;
349-
ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
350+
ret = read_tree_recursive(args->repo, args->tree, "",
351+
0, 0, &ctx.pathspec,
350352
reject_entry, &ctx);
351353
clear_pathspec(&ctx.pathspec);
352354
return ret != 0;

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
115115

116116
static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
117117
{
118-
read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
118+
read_tree_recursive(the_repository, tree, "", 0, 0,
119+
pathspec, update_some, NULL);
119120

120121
/* update the index with the given tree's info
121122
* for all args, expanding wildcards, and exit

builtin/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
641641
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
642642
name,
643643
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
644-
read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
645-
show_tree_object, rev.diffopt.file);
644+
read_tree_recursive(the_repository, (struct tree *)o, "",
645+
0, 0, &match_all, show_tree_object,
646+
rev.diffopt.file);
646647
rev.shown_one = 1;
647648
break;
648649
case OBJ_COMMIT:

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void overlay_tree_on_index(struct index_state *istate,
441441
PATHSPEC_PREFER_CWD, prefix, matchbuf);
442442
} else
443443
memset(&pathspec, 0, sizeof(pathspec));
444-
if (read_tree(tree, 1, &pathspec, istate))
444+
if (read_tree(the_repository, tree, 1, &pathspec, istate))
445445
die("unable to read tree entries %s", tree_name);
446446

447447
for (i = 0; i < istate->cache_nr; i++) {

builtin/ls-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +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(tree, "", 0, 0, &pathspec, show_tree, NULL);
188+
return !!read_tree_recursive(the_repository, tree, "", 0, 0,
189+
&pathspec, show_tree, NULL);
189190
}

merge-recursive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ static void get_files_dirs(struct merge_options *o, struct tree *tree)
463463
{
464464
struct pathspec match_all;
465465
memset(&match_all, 0, sizeof(match_all));
466-
read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o);
466+
read_tree_recursive(the_repository, tree, "", 0, 0,
467+
&match_all, save_files_dirs, o);
467468
}
468469

469470
static int get_tree_entry_if_blob(const struct object_id *tree,

tree.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
6060
ADD_CACHE_JUST_APPEND);
6161
}
6262

63-
static int read_tree_1(struct tree *tree, struct strbuf *base,
63+
static int read_tree_1(struct repository *r,
64+
struct tree *tree, struct strbuf *base,
6465
int stage, const struct pathspec *pathspec,
6566
read_tree_fn_t fn, void *context)
6667
{
@@ -99,7 +100,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
99100
else if (S_ISGITLINK(entry.mode)) {
100101
struct commit *commit;
101102

102-
commit = lookup_commit(the_repository, entry.oid);
103+
commit = lookup_commit(r, entry.oid);
103104
if (!commit)
104105
die("Commit %s in submodule path %s%s not found",
105106
oid_to_hex(entry.oid),
@@ -118,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
118119
len = tree_entry_len(&entry);
119120
strbuf_add(base, entry.path, len);
120121
strbuf_addch(base, '/');
121-
retval = read_tree_1(lookup_tree(the_repository, &oid),
122+
retval = read_tree_1(r, lookup_tree(r, &oid),
122123
base, stage, pathspec,
123124
fn, context);
124125
strbuf_setlen(base, oldlen);
@@ -128,7 +129,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
128129
return 0;
129130
}
130131

131-
int read_tree_recursive(struct tree *tree,
132+
int read_tree_recursive(struct repository *r,
133+
struct tree *tree,
132134
const char *base, int baselen,
133135
int stage, const struct pathspec *pathspec,
134136
read_tree_fn_t fn, void *context)
@@ -137,7 +139,7 @@ int read_tree_recursive(struct tree *tree,
137139
int ret;
138140

139141
strbuf_add(&sb, base, baselen);
140-
ret = read_tree_1(tree, &sb, stage, pathspec, fn, context);
142+
ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context);
141143
strbuf_release(&sb);
142144
return ret;
143145
}
@@ -152,8 +154,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
152154
ce2->name, ce2->ce_namelen, ce_stage(ce2));
153155
}
154156

155-
int read_tree(struct tree *tree, int stage, struct pathspec *match,
156-
struct index_state *istate)
157+
int read_tree(struct repository *r, struct tree *tree, int stage,
158+
struct pathspec *match, struct index_state *istate)
157159
{
158160
read_tree_fn_t fn = NULL;
159161
int i, err;
@@ -181,7 +183,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
181183

182184
if (!fn)
183185
fn = read_one_entry_quick;
184-
err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
186+
err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate);
185187
if (fn == read_one_entry || err)
186188
return err;
187189

tree.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "object.h"
55

6-
extern const char *tree_type;
6+
struct repository;
77
struct strbuf;
88

99
struct tree {
@@ -12,6 +12,8 @@ struct tree {
1212
unsigned long size;
1313
};
1414

15+
extern const char *tree_type;
16+
1517
struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
1618

1719
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
@@ -29,12 +31,14 @@ struct tree *parse_tree_indirect(const struct object_id *oid);
2931
#define READ_TREE_RECURSIVE 1
3032
typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
3133

32-
extern int read_tree_recursive(struct tree *tree,
33-
const char *base, int baselen,
34-
int stage, const struct pathspec *pathspec,
35-
read_tree_fn_t fn, void *context);
34+
int read_tree_recursive(struct repository *r,
35+
struct tree *tree,
36+
const char *base, int baselen,
37+
int stage, const struct pathspec *pathspec,
38+
read_tree_fn_t fn, void *context);
3639

37-
extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,
38-
struct index_state *istate);
40+
int read_tree(struct repository *r, struct tree *tree,
41+
int stage, struct pathspec *pathspec,
42+
struct index_state *istate);
3943

4044
#endif /* TREE_H */

0 commit comments

Comments
 (0)