tree: add repository argument to lookup_tree

Add a repository argument to allow the callers of lookup_tree to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jun 28, 2018 at 18:21 UTC f86bcc7b2ce6cad68ba1a48a528e380c6126705e
19 files changed +31 -24
builtin/am.c
+4 -2
@@ -32,6 +32,7 @@
32 #include "apply.h"
33 #include "string-list.h"
34 #include "packfile.h"
35 +#include "repository.h"
36
37 /**
38 * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -1400,9 +1401,10 @@ static void write_index_patch(const struct am_state *state)
1401 FILE *fp;
1402
1403 if (!get_oid_tree("HEAD", &head))
1403 - tree = lookup_tree(&head);
1404 + tree = lookup_tree(the_repository, &head);
1405 else
1405 - tree = lookup_tree(the_hash_algo->empty_tree);
1406 + tree = lookup_tree(the_repository,
1407 + the_repository->hash_algo->empty_tree);
1408
1409 fp = xfopen(am_path(state, "patch"), "w");
1410 init_revisions(&rev_info, NULL);
builtin/diff-tree.c
+1 -1
@@ -46,7 +46,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
46 struct tree *tree2;
47 if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
48 return error("Need exactly two trees, separated by a space");
49 - tree2 = lookup_tree(&oid);
49 + tree2 = lookup_tree(the_repository, &oid);
50 if (!tree2 || parse_tree(tree2))
51 return -1;
52 printf("%s %s\n", oid_to_hex(&tree1->object.oid),
builtin/diff.c
+2 -1
@@ -386,7 +386,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
386 add_head_to_pending(&rev);
387 if (!rev.pending.nr) {
388 struct tree *tree;
389 - tree = lookup_tree(the_hash_algo->empty_tree);
389 + tree = lookup_tree(the_repository,
390 + the_repository->hash_algo->empty_tree);
391 add_pending_object(&rev, &tree->object, "HEAD");
392 }
393 break;
builtin/reflog.c
+1 -1
@@ -66,7 +66,7 @@ static int tree_is_complete(const struct object_id *oid)
66 int complete;
67 struct tree *tree;
68
69 - tree = lookup_tree(oid);
69 + tree = lookup_tree(the_repository, oid);
70 if (!tree)
71 return 0;
72 if (tree->object.flags & SEEN)
cache-tree.c
+2 -1
@@ -671,7 +671,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
671 cnt++;
672 else {
673 struct cache_tree_sub *sub;
674 - struct tree *subtree = lookup_tree(entry.oid);
674 + struct tree *subtree = lookup_tree(the_repository,
675 + entry.oid);
676 if (!subtree->object.parsed)
677 parse_tree(subtree);
678 sub = cache_tree_sub(it, entry.path);
commit-graph.c
+1 -1
@@ -344,7 +344,7 @@ static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *
344 GRAPH_DATA_WIDTH * (c->graph_pos);
345
346 hashcpy(oid.hash, commit_data);
347 - c->maybe_tree = lookup_tree(&oid);
347 + c->maybe_tree = lookup_tree(the_repository, &oid);
348
349 return c->maybe_tree;
350 }
commit.c
+1 -1
@@ -383,7 +383,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
383 if (get_oid_hex(bufptr + 5, &parent) < 0)
384 return error("bad tree pointer in commit %s",
385 oid_to_hex(&item->object.oid));
386 - item->maybe_tree = lookup_tree(&parent);
386 + item->maybe_tree = lookup_tree(the_repository, &parent);
387 bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
388 pptr = &item->parents;
389
fsck.c
+1 -1
@@ -407,7 +407,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
407 continue;
408
409 if (S_ISDIR(entry.mode)) {
410 - obj = (struct object *)lookup_tree(entry.oid);
410 + obj = (struct object *)lookup_tree(the_repository, entry.oid);
411 if (name && obj)
412 put_object_name(options, obj, "%s%s/", name,
413 entry.path);
http-push.c
+2 -1
@@ -1311,7 +1311,8 @@ static struct object_list **process_tree(struct tree *tree,
1311 while (tree_entry(&desc, &entry))
1312 switch (object_type(entry.mode)) {
1313 case OBJ_TREE:
1314 - p = process_tree(lookup_tree(entry.oid), p);
1314 + p = process_tree(lookup_tree(the_repository, entry.oid),
1315 + p);
1316 break;
1317 case OBJ_BLOB:
1318 p = process_blob(lookup_blob(the_repository, entry.oid),
list-objects.c
+1 -1
@@ -158,7 +158,7 @@ static void process_tree(struct rev_info *revs,
158
159 if (S_ISDIR(entry.mode))
160 process_tree(revs,
161 - lookup_tree(entry.oid),
161 + lookup_tree(the_repository, entry.oid),
162 show, base, entry.path,
163 cb_data, filter_fn, filter_data);
164 else if (S_ISGITLINK(entry.mode))
merge-recursive.c
+3 -3
@@ -158,7 +158,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
158 }
159 if (!oidcmp(&two->object.oid, &shifted))
160 return two;
161 - return lookup_tree(&shifted);
161 + return lookup_tree(the_repository, &shifted);
162 }
163
164 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -416,7 +416,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
416 return NULL;
417 }
418
419 - result = lookup_tree(&active_cache_tree->oid);
419 + result = lookup_tree(the_repository, &active_cache_tree->oid);
420
421 return result;
422 }
@@ -3405,7 +3405,7 @@ int merge_recursive(struct merge_options *o,
3405 /* if there is no common ancestor, use an empty tree */
3406 struct tree *tree;
3407
3408 - tree = lookup_tree(the_hash_algo->empty_tree);
3408 + tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
3409 merged_common_ancestors = make_virtual_commit(tree, "ancestor");
3410 }
3411
object.c
+1 -1
@@ -200,7 +200,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
200 obj = &blob->object;
201 }
202 } else if (type == OBJ_TREE) {
203 - struct tree *tree = lookup_tree(oid);
203 + struct tree *tree = lookup_tree(the_repository, oid);
204 if (tree) {
205 obj = &tree->object;
206 if (!tree->buffer)
reachable.c
+1 -1
@@ -88,7 +88,7 @@ static void add_recent_object(const struct object_id *oid,
88 obj = parse_object_or_die(oid, NULL);
89 break;
90 case OBJ_TREE:
91 - obj = (struct object *)lookup_tree(oid);
91 + obj = (struct object *)lookup_tree(the_repository, oid);
92 break;
93 case OBJ_BLOB:
94 obj = (struct object *)lookup_blob(the_repository, oid);
revision.c
+2 -2
@@ -63,7 +63,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
63 while (tree_entry(&desc, &entry)) {
64 switch (object_type(entry.mode)) {
65 case OBJ_TREE:
66 - mark_tree_uninteresting(lookup_tree(entry.oid));
66 + mark_tree_uninteresting(lookup_tree(the_repository, entry.oid));
67 break;
68 case OBJ_BLOB:
69 mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
@@ -1322,7 +1322,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1322 int i;
1323
1324 if (it->entry_count >= 0) {
1325 - struct tree *tree = lookup_tree(&it->oid);
1325 + struct tree *tree = lookup_tree(the_repository, &it->oid);
1326 add_pending_object_with_path(revs, &tree->object, "",
1327 040000, path->buf);
1328 }
sequencer.c
+1 -1
@@ -433,7 +433,7 @@ static int read_oneliner(struct strbuf *buf,
433
434 static struct tree *empty_tree(void)
435 {
436 - return lookup_tree(the_hash_algo->empty_tree);
436 + return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
437 }
438
439 static int error_dirty_index(struct replay_opts *opts)
tag.c
+1 -1
@@ -156,7 +156,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
156 if (!strcmp(type, blob_type)) {
157 item->tagged = (struct object *)lookup_blob(the_repository, &oid);
158 } else if (!strcmp(type, tree_type)) {
159 - item->tagged = (struct object *)lookup_tree(&oid);
159 + item->tagged = (struct object *)lookup_tree(the_repository, &oid);
160 } else if (!strcmp(type, commit_type)) {
161 item->tagged = (struct object *)lookup_commit(&oid);
162 } else if (!strcmp(type, tag_type)) {
tree.c
+2 -2
@@ -120,7 +120,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
120 len = tree_entry_len(&entry);
121 strbuf_add(base, entry.path, len);
122 strbuf_addch(base, '/');
123 - retval = read_tree_1(lookup_tree(&oid),
123 + retval = read_tree_1(lookup_tree(the_repository, &oid),
124 base, stage, pathspec,
125 fn, context);
126 strbuf_setlen(base, oldlen);
@@ -195,7 +195,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
195 return 0;
196 }
197
198 -struct tree *lookup_tree(const struct object_id *oid)
198 +struct tree *lookup_tree_the_repository(const struct object_id *oid)
199 {
200 struct object *obj = lookup_object(the_repository, oid->hash);
201 if (!obj)
tree.h
+2 -1
@@ -12,7 +12,8 @@ struct tree {
12 unsigned long size;
13 };
14
15 -struct tree *lookup_tree(const struct object_id *oid);
15 +#define lookup_tree(r, oid) lookup_tree_##r(oid)
16 +struct tree *lookup_tree_the_repository(const struct object_id *oid);
17
18 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
19
walker.c
+2 -1
@@ -49,7 +49,8 @@ static int process_tree(struct walker *walker, struct tree *tree)
49 if (S_ISGITLINK(entry.mode))
50 continue;
51 if (S_ISDIR(entry.mode)) {
52 - struct tree *tree = lookup_tree(entry.oid);
52 + struct tree *tree = lookup_tree(the_repository,
53 + entry.oid);
54 if (tree)
55 obj = &tree->object;
56 }