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>
Nguyễn Thái Ngọc Duy committed
Nov 18, 2018 at 17:47 UTC
e092073d643b17c82d72cf692fbfaea9c9796f11
8 files changed
+35
-23
archive.c
+4
-2
@@ -285,7 +285,8 @@ int write_archive_entries(struct archiver_args *args,
285
git_attr_set_direction(GIT_ATTR_INDEX);
286
}
287
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,
290
queue_or_write_archive_entry,
291
&context);
292
if (err == READ_TREE_RECURSIVE)
@@ -346,7 +347,8 @@ static int path_exists(struct archiver_args *args, const char *path)
347
ctx.args = args;
348
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
349
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,
352
reject_entry, &ctx);
353
clear_pathspec(&ctx.pathspec);
354
return ret != 0;
builtin/checkout.c
+2
-1
@@ -115,7 +115,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
115
116
static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
117
{
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);
120
121
/* update the index with the given tree's info
122
* for all args, expanding wildcards, and exit
builtin/log.c
+3
-2
@@ -641,8 +641,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
641
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
642
name,
643
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);
647
rev.shown_one = 1;
648
break;
649
case OBJ_COMMIT:
builtin/ls-files.c
+1
-1
@@ -441,7 +441,7 @@ void overlay_tree_on_index(struct index_state *istate,
441
PATHSPEC_PREFER_CWD, prefix, matchbuf);
442
} else
443
memset(&pathspec, 0, sizeof(pathspec));
444
- if (read_tree(tree, 1, &pathspec, istate))
444
+ if (read_tree(the_repository, tree, 1, &pathspec, istate))
445
die("unable to read tree entries %s", tree_name);
446
447
for (i = 0; i < istate->cache_nr; i++) {
builtin/ls-tree.c
+2
-1
@@ -185,5 +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(tree, "", 0, 0, &pathspec, show_tree, NULL);
188
+ return !!read_tree_recursive(the_repository, tree, "", 0, 0,
189
+ &pathspec, show_tree, NULL);
190
}
merge-recursive.c
+2
-1
@@ -463,7 +463,8 @@ static void get_files_dirs(struct merge_options *o, struct tree *tree)
463
{
464
struct pathspec match_all;
465
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);
468
}
469
470
static int get_tree_entry_if_blob(const struct object_id *tree,
tree.c
+10
-8
@@ -60,7 +60,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
60
ADD_CACHE_JUST_APPEND);
61
}
62
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,
65
int stage, const struct pathspec *pathspec,
66
read_tree_fn_t fn, void *context)
67
{
@@ -99,7 +100,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
100
else if (S_ISGITLINK(entry.mode)) {
101
struct commit *commit;
102
102
- commit = lookup_commit(the_repository, entry.oid);
103
+ commit = lookup_commit(r, entry.oid);
104
if (!commit)
105
die("Commit %s in submodule path %s%s not found",
106
oid_to_hex(entry.oid),
@@ -118,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
119
len = tree_entry_len(&entry);
120
strbuf_add(base, entry.path, len);
121
strbuf_addch(base, '/');
121
- retval = read_tree_1(lookup_tree(the_repository, &oid),
122
+ retval = read_tree_1(r, lookup_tree(r, &oid),
123
base, stage, pathspec,
124
fn, context);
125
strbuf_setlen(base, oldlen);
@@ -128,7 +129,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
129
return 0;
130
}
131
131
-int read_tree_recursive(struct tree *tree,
132
+int read_tree_recursive(struct repository *r,
133
+ struct tree *tree,
134
const char *base, int baselen,
135
int stage, const struct pathspec *pathspec,
136
read_tree_fn_t fn, void *context)
@@ -137,7 +139,7 @@ int read_tree_recursive(struct tree *tree,
139
int ret;
140
141
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);
143
strbuf_release(&sb);
144
return ret;
145
}
@@ -152,8 +154,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
154
ce2->name, ce2->ce_namelen, ce_stage(ce2));
155
}
156
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)
159
{
160
read_tree_fn_t fn = NULL;
161
int i, err;
@@ -181,7 +183,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
183
184
if (!fn)
185
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);
187
if (fn == read_one_entry || err)
188
return err;
189
tree.h
+11
-7
@@ -3,7 +3,7 @@
3
4
#include "object.h"
5
6
-extern const char *tree_type;
6
+struct repository;
7
struct strbuf;
8
9
struct tree {
@@ -12,6 +12,8 @@ struct tree {
12
unsigned long size;
13
};
14
15
+extern const char *tree_type;
16
+
17
struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
18
19
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);
31
#define READ_TREE_RECURSIVE 1
32
typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
33
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);
39
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);
43
44
#endif /* TREE_H */