revision.c: reduce implicit dependency the_repository

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 Sep 21, 2018 at 17:57 UTC b3c7eef9b0581f06be67418f130d33d7a7c490cb
3 files changed +29 -25
list-objects.c
+5 -3
@@ -196,7 +196,7 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
196 struct commit *parent = parents->item;
197 if (!(parent->object.flags & UNINTERESTING))
198 continue;
199 - mark_tree_uninteresting(get_commit_tree(parent));
199 + mark_tree_uninteresting(revs->repo, get_commit_tree(parent));
200 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
201 parent->object.flags |= SHOWN;
202 show_edge(parent);
@@ -213,7 +213,8 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
213 struct commit *commit = list->item;
214
215 if (commit->object.flags & UNINTERESTING) {
216 - mark_tree_uninteresting(get_commit_tree(commit));
216 + mark_tree_uninteresting(revs->repo,
217 + get_commit_tree(commit));
218 if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
219 commit->object.flags |= SHOWN;
220 show_edge(commit);
@@ -228,7 +229,8 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
229 struct commit *commit = (struct commit *)obj;
230 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
231 continue;
231 - mark_tree_uninteresting(get_commit_tree(commit));
232 + mark_tree_uninteresting(revs->repo,
233 + get_commit_tree(commit));
234 if (!(obj->flags & SHOWN)) {
235 obj->flags |= SHOWN;
236 show_edge(commit);
revision.c
+23 -21
@@ -51,7 +51,8 @@ static void mark_blob_uninteresting(struct blob *blob)
51 blob->object.flags |= UNINTERESTING;
52 }
53
54 -static void mark_tree_contents_uninteresting(struct tree *tree)
54 +static void mark_tree_contents_uninteresting(struct repository *r,
55 + struct tree *tree)
56 {
57 struct tree_desc desc;
58 struct name_entry entry;
@@ -63,10 +64,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
64 while (tree_entry(&desc, &entry)) {
65 switch (object_type(entry.mode)) {
66 case OBJ_TREE:
66 - mark_tree_uninteresting(lookup_tree(the_repository, entry.oid));
67 + mark_tree_uninteresting(r, lookup_tree(r, entry.oid));
68 break;
69 case OBJ_BLOB:
69 - mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
70 + mark_blob_uninteresting(lookup_blob(r, entry.oid));
71 break;
72 default:
73 /* Subproject commit - not in this repository */
@@ -81,7 +82,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
82 free_tree_buffer(tree);
83 }
84
84 -void mark_tree_uninteresting(struct tree *tree)
85 +void mark_tree_uninteresting(struct repository *r, struct tree *tree)
86 {
87 struct object *obj;
88
@@ -92,7 +93,7 @@ void mark_tree_uninteresting(struct tree *tree)
93 if (obj->flags & UNINTERESTING)
94 return;
95 obj->flags |= UNINTERESTING;
95 - mark_tree_contents_uninteresting(tree);
96 + mark_tree_contents_uninteresting(r, tree);
97 }
98
99 struct commit_stack {
@@ -198,7 +199,7 @@ void add_head_to_pending(struct rev_info *revs)
199 struct object *obj;
200 if (get_oid("HEAD", &oid))
201 return;
201 - obj = parse_object(the_repository, &oid);
202 + obj = parse_object(revs->repo, &oid);
203 if (!obj)
204 return;
205 add_pending_object(revs, obj, "HEAD");
@@ -210,7 +211,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
211 {
212 struct object *object;
213
213 - object = parse_object(the_repository, oid);
214 + object = parse_object(revs->repo, oid);
215 if (!object) {
216 if (revs->ignore_missing)
217 return object;
@@ -247,7 +248,7 @@ static struct commit *handle_commit(struct rev_info *revs,
248 add_pending_object(revs, object, tag->tag);
249 if (!tag->tagged)
250 die("bad tag");
250 - object = parse_object(the_repository, &tag->tagged->oid);
251 + object = parse_object(revs->repo, &tag->tagged->oid);
252 if (!object) {
253 if (revs->ignore_missing_links || (flags & UNINTERESTING))
254 return NULL;
@@ -297,7 +298,7 @@ static struct commit *handle_commit(struct rev_info *revs,
298 if (!revs->tree_objects)
299 return NULL;
300 if (flags & UNINTERESTING) {
300 - mark_tree_contents_uninteresting(tree);
301 + mark_tree_contents_uninteresting(revs->repo, tree);
302 return NULL;
303 }
304 add_pending_object_with_path(revs, object, name, mode, path);
@@ -1253,7 +1254,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
1254 {
1255 struct all_refs_cb *cb = cb_data;
1256 if (!is_null_oid(oid)) {
1256 - struct object *o = parse_object(the_repository, oid);
1257 + struct object *o = parse_object(cb->all_revs->repo, oid);
1258 if (o) {
1259 o->flags |= cb->all_flags;
1260 /* ??? CMDLINEFLAGS ??? */
@@ -1312,7 +1313,7 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
1313
1314 cb.all_revs = revs;
1315 cb.all_flags = flags;
1315 - cb.refs = get_main_ref_store(the_repository);
1316 + cb.refs = get_main_ref_store(revs->repo);
1317 for_each_reflog(handle_one_reflog, &cb);
1318
1319 if (!revs->single_worktree)
@@ -1326,7 +1327,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1327 int i;
1328
1329 if (it->entry_count >= 0) {
1329 - struct tree *tree = lookup_tree(the_repository, &it->oid);
1330 + struct tree *tree = lookup_tree(revs->repo, &it->oid);
1331 add_pending_object_with_path(revs, &tree->object, "",
1332 040000, path->buf);
1333 }
@@ -1352,7 +1353,7 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
1353 if (S_ISGITLINK(ce->ce_mode))
1354 continue;
1355
1355 - blob = lookup_blob(the_repository, &ce->oid);
1356 + blob = lookup_blob(revs->repo, &ce->oid);
1357 if (!blob)
1358 die("unable to add index blob to traversal");
1359 add_pending_object_with_path(revs, &blob->object, "",
@@ -1585,8 +1586,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
1586 *dotdot = '\0';
1587 }
1588
1588 - a_obj = parse_object(the_repository, &a_oid);
1589 - b_obj = parse_object(the_repository, &b_oid);
1589 + a_obj = parse_object(revs->repo, &a_oid);
1590 + b_obj = parse_object(revs->repo, &b_oid);
1591 if (!a_obj || !b_obj)
1592 return dotdot_missing(arg, dotdot, revs, symmetric);
1593
@@ -1599,8 +1600,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
1600 struct commit *a, *b;
1601 struct commit_list *exclude;
1602
1602 - a = lookup_commit_reference(the_repository, &a_obj->oid);
1603 - b = lookup_commit_reference(the_repository, &b_obj->oid);
1603 + a = lookup_commit_reference(revs->repo, &a_obj->oid);
1604 + b = lookup_commit_reference(revs->repo, &b_obj->oid);
1605 if (!a || !b)
1606 return dotdot_missing(arg, dotdot, revs, symmetric);
1607
@@ -2208,7 +2209,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
2209 BUG("--single-worktree cannot be used together with submodule");
2210 refs = get_submodule_ref_store(submodule);
2211 } else
2211 - refs = get_main_ref_store(the_repository);
2212 + refs = get_main_ref_store(revs->repo);
2213
2214 /*
2215 * NOTE!
@@ -2889,9 +2890,10 @@ void reset_revision_walk(void)
2890 static int mark_uninteresting(const struct object_id *oid,
2891 struct packed_git *pack,
2892 uint32_t pos,
2892 - void *unused)
2893 + void *cb)
2894 {
2894 - struct object *o = parse_object(the_repository, oid);
2895 + struct rev_info *revs = cb;
2896 + struct object *o = parse_object(revs->repo, oid);
2897 o->flags |= UNINTERESTING | SEEN;
2898 return 0;
2899 }
@@ -2924,7 +2926,7 @@ int prepare_revision_walk(struct rev_info *revs)
2926 revs->treesame.name = "treesame";
2927
2928 if (revs->exclude_promisor_objects) {
2927 - for_each_packed_object(mark_uninteresting, NULL,
2929 + for_each_packed_object(mark_uninteresting, revs,
2930 FOR_EACH_OBJECT_PROMISOR_ONLY);
2931 }
2932
revision.h
+1 -1
@@ -280,7 +280,7 @@ void put_revision_mark(const struct rev_info *revs,
280 const struct commit *commit);
281
282 void mark_parents_uninteresting(struct commit *commit);
283 -void mark_tree_uninteresting(struct tree *tree);
283 +void mark_tree_uninteresting(struct repository *r, struct tree *tree);
284
285 void show_object_with_name(FILE *, struct object *, const char *);
286