blame.c: remove 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 Nov 10, 2018 at 06:48 UTC fb998eae6ce90fe7fd9c963a601a8910d9f33561
1 file changed +22 -17
blame.c
+22 -17
@@ -116,35 +116,38 @@ static void verify_working_tree_path(struct repository *r,
116 die("no such path '%s' in HEAD", path);
117 }
118
119 -static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)
119 +static struct commit_list **append_parent(struct repository *r,
120 + struct commit_list **tail,
121 + const struct object_id *oid)
122 {
123 struct commit *parent;
124
123 - parent = lookup_commit_reference(the_repository, oid);
125 + parent = lookup_commit_reference(r, oid);
126 if (!parent)
127 die("no such commit %s", oid_to_hex(oid));
128 return &commit_list_insert(parent, tail)->next;
129 }
130
129 -static void append_merge_parents(struct commit_list **tail)
131 +static void append_merge_parents(struct repository *r,
132 + struct commit_list **tail)
133 {
134 int merge_head;
135 struct strbuf line = STRBUF_INIT;
136
134 - merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
137 + merge_head = open(git_path_merge_head(r), O_RDONLY);
138 if (merge_head < 0) {
139 if (errno == ENOENT)
140 return;
141 die("cannot open '%s' for reading",
139 - git_path_merge_head(the_repository));
142 + git_path_merge_head(r));
143 }
144
145 while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
146 struct object_id oid;
147 if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
148 die("unknown line in '%s': %s",
146 - git_path_merge_head(the_repository), line.buf);
147 - tail = append_parent(tail, &oid);
149 + git_path_merge_head(r), line.buf);
150 + tail = append_parent(r, tail, &oid);
151 }
152 close(merge_head);
153 strbuf_release(&line);
@@ -155,11 +158,13 @@ static void append_merge_parents(struct commit_list **tail)
158 * want to transfer ownership of the buffer to the commit (so we
159 * must use detach).
160 */
158 -static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
161 +static void set_commit_buffer_from_strbuf(struct repository *r,
162 + struct commit *c,
163 + struct strbuf *sb)
164 {
165 size_t len;
166 void *buf = strbuf_detach(sb, &len);
162 - set_commit_buffer(the_repository, c, buf, len);
167 + set_commit_buffer(r, c, buf, len);
168 }
169
170 /*
@@ -185,7 +190,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
190
191 read_index(r->index);
192 time(&now);
188 - commit = alloc_commit_node(the_repository);
193 + commit = alloc_commit_node(r);
194 commit->object.parsed = 1;
195 commit->date = now;
196 parent_tail = &commit->parents;
@@ -193,8 +198,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
198 if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
199 die("no such ref: HEAD");
200
196 - parent_tail = append_parent(parent_tail, &head_oid);
197 - append_merge_parents(parent_tail);
201 + parent_tail = append_parent(r, parent_tail, &head_oid);
202 + append_merge_parents(r, parent_tail);
203 verify_working_tree_path(r, commit, path);
204
205 origin = make_origin(commit, path);
@@ -211,7 +216,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
216 ident, ident, path,
217 (!contents_from ? path :
218 (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
214 - set_commit_buffer_from_strbuf(commit, &msg);
219 + set_commit_buffer_from_strbuf(r, commit, &msg);
220
221 if (!contents_from || strcmp("-", contents_from)) {
222 struct stat st;
@@ -1678,7 +1683,7 @@ static struct commit *find_single_final(struct rev_info *revs,
1683 struct object *obj = revs->pending.objects[i].item;
1684 if (obj->flags & UNINTERESTING)
1685 continue;
1681 - obj = deref_tag(the_repository, obj, NULL, 0);
1686 + obj = deref_tag(revs->repo, obj, NULL, 0);
1687 if (obj->type != OBJ_COMMIT)
1688 die("Non commit %s?", revs->pending.objects[i].name);
1689 if (found)
@@ -1709,14 +1714,14 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
1714
1715 /* Is that sole rev a committish? */
1716 obj = revs->pending.objects[0].item;
1712 - obj = deref_tag(the_repository, obj, NULL, 0);
1717 + obj = deref_tag(revs->repo, obj, NULL, 0);
1718 if (obj->type != OBJ_COMMIT)
1719 return NULL;
1720
1721 /* Do we have HEAD? */
1722 if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
1723 return NULL;
1719 - head_commit = lookup_commit_reference_gently(the_repository,
1724 + head_commit = lookup_commit_reference_gently(revs->repo,
1725 &head_oid, 1);
1726 if (!head_commit)
1727 return NULL;
@@ -1745,7 +1750,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
1750 struct object *obj = revs->pending.objects[i].item;
1751 if (!(obj->flags & UNINTERESTING))
1752 continue;
1748 - obj = deref_tag(the_repository, obj, NULL, 0);
1753 + obj = deref_tag(revs->repo, obj, NULL, 0);
1754 if (obj->type != OBJ_COMMIT)
1755 die("Non commit %s?", revs->pending.objects[i].name);
1756 if (found)