Skip to content

Commit cde5554

Browse files
committed
Merge branch 'nd/the-index'
More codepaths become aware of working with in-core repository instance other than the default "the_repository". * nd/the-index: (22 commits) rebase-interactive.c: remove the_repository references rerere.c: remove the_repository references pack-*.c: remove the_repository references pack-check.c: remove the_repository references notes-cache.c: remove the_repository references line-log.c: remove the_repository reference diff-lib.c: remove the_repository references delta-islands.c: remove the_repository references cache-tree.c: remove the_repository references bundle.c: remove the_repository references branch.c: remove the_repository reference bisect.c: remove the_repository reference blame.c: remove implicit dependency the_repository sequencer.c: remove implicit dependency on the_repository sequencer.c: remove implicit dependency on the_index transport.c: remove implicit dependency on the_index notes-merge.c: remove implicit dependency the_repository notes-merge.c: remove implicit dependency on the_index list-objects.c: reduce the_repository references list-objects-filter.c: remove implicit dependency on the_index ...
2 parents 3b2f8a0 + 36e7ed6 commit cde5554

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+652
-491
lines changed

Diff for: bisect.c

+28-20
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,15 @@ static struct commit_list *managed_skipped(struct commit_list *list,
626626
return skip_away(list, count);
627627
}
628628

629-
static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
629+
static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
630+
const char *prefix,
630631
const char *bad_format, const char *good_format,
631632
int read_paths)
632633
{
633634
struct argv_array rev_argv = ARGV_ARRAY_INIT;
634635
int i;
635636

636-
repo_init_revisions(the_repository, revs, prefix);
637+
repo_init_revisions(r, revs, prefix);
637638
revs->abbrev = 0;
638639
revs->commit_format = CMIT_FMT_UNSPECIFIED;
639640

@@ -723,23 +724,25 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
723724
return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
724725
}
725726

726-
static struct commit *get_commit_reference(const struct object_id *oid)
727+
static struct commit *get_commit_reference(struct repository *r,
728+
const struct object_id *oid)
727729
{
728-
struct commit *r = lookup_commit_reference(the_repository, oid);
729-
if (!r)
730+
struct commit *c = lookup_commit_reference(r, oid);
731+
if (!c)
730732
die(_("Not a valid commit name %s"), oid_to_hex(oid));
731-
return r;
733+
return c;
732734
}
733735

734-
static struct commit **get_bad_and_good_commits(int *rev_nr)
736+
static struct commit **get_bad_and_good_commits(struct repository *r,
737+
int *rev_nr)
735738
{
736739
struct commit **rev;
737740
int i, n = 0;
738741

739742
ALLOC_ARRAY(rev, 1 + good_revs.nr);
740-
rev[n++] = get_commit_reference(current_bad_oid);
743+
rev[n++] = get_commit_reference(r, current_bad_oid);
741744
for (i = 0; i < good_revs.nr; i++)
742-
rev[n++] = get_commit_reference(good_revs.oid + i);
745+
rev[n++] = get_commit_reference(r, good_revs.oid + i);
743746
*rev_nr = n;
744747

745748
return rev;
@@ -823,12 +826,13 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
823826
free_commit_list(result);
824827
}
825828

826-
static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
829+
static int check_ancestors(struct repository *r, int rev_nr,
830+
struct commit **rev, const char *prefix)
827831
{
828832
struct rev_info revs;
829833
int res;
830834

831-
bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
835+
bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
832836

833837
bisect_common(&revs);
834838
res = (revs.commits != NULL);
@@ -847,7 +851,9 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
847851
* If a merge base must be tested by the user, its source code will be
848852
* checked out to be tested by the user and we will exit.
849853
*/
850-
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
854+
static void check_good_are_ancestors_of_bad(struct repository *r,
855+
const char *prefix,
856+
int no_checkout)
851857
{
852858
char *filename = git_pathdup("BISECT_ANCESTORS_OK");
853859
struct stat st;
@@ -866,8 +872,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
866872
goto done;
867873

868874
/* Check if all good revs are ancestor of the bad rev. */
869-
rev = get_bad_and_good_commits(&rev_nr);
870-
if (check_ancestors(rev_nr, rev, prefix))
875+
rev = get_bad_and_good_commits(r, &rev_nr);
876+
if (check_ancestors(r, rev_nr, rev, prefix))
871877
check_merge_bases(rev_nr, rev, no_checkout);
872878
free(rev);
873879

@@ -885,12 +891,14 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
885891
/*
886892
* This does "git diff-tree --pretty COMMIT" without one fork+exec.
887893
*/
888-
static void show_diff_tree(const char *prefix, struct commit *commit)
894+
static void show_diff_tree(struct repository *r,
895+
const char *prefix,
896+
struct commit *commit)
889897
{
890898
struct rev_info opt;
891899

892900
/* diff-tree init */
893-
repo_init_revisions(the_repository, &opt, prefix);
901+
repo_init_revisions(r, &opt, prefix);
894902
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
895903
opt.abbrev = 0;
896904
opt.diff = 1;
@@ -945,7 +953,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
945953
* If no_checkout is non-zero, the bisection process does not
946954
* checkout the trial commit but instead simply updates BISECT_HEAD.
947955
*/
948-
int bisect_next_all(const char *prefix, int no_checkout)
956+
int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
949957
{
950958
struct rev_info revs;
951959
struct commit_list *tried;
@@ -957,9 +965,9 @@ int bisect_next_all(const char *prefix, int no_checkout)
957965
if (read_bisect_refs())
958966
die(_("reading bisect refs failed"));
959967

960-
check_good_are_ancestors_of_bad(prefix, no_checkout);
968+
check_good_are_ancestors_of_bad(r, prefix, no_checkout);
961969

962-
bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
970+
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
963971
revs.limited = 1;
964972

965973
bisect_common(&revs);
@@ -993,7 +1001,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
9931001
exit_if_skipped_commits(tried, current_bad_oid);
9941002
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
9951003
term_bad);
996-
show_diff_tree(prefix, revs.commits->item);
1004+
show_diff_tree(r, prefix, revs.commits->item);
9971005
/* This means the bisection process succeeded. */
9981006
exit(10);
9991007
}

Diff for: bisect.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BISECT_H
33

44
struct commit_list;
5+
struct repository;
56

67
/*
78
* Find bisection. If something is found, `reaches` will be the number of
@@ -30,7 +31,9 @@ struct rev_list_info {
3031
const char *header_prefix;
3132
};
3233

33-
extern int bisect_next_all(const char *prefix, int no_checkout);
34+
extern int bisect_next_all(struct repository *r,
35+
const char *prefix,
36+
int no_checkout);
3437

3538
extern int estimate_bisect_steps(int all);
3639

Diff for: blame.c

+22-17
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,38 @@ static void verify_working_tree_path(struct repository *r,
116116
die("no such path '%s' in HEAD", path);
117117
}
118118

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)
120122
{
121123
struct commit *parent;
122124

123-
parent = lookup_commit_reference(the_repository, oid);
125+
parent = lookup_commit_reference(r, oid);
124126
if (!parent)
125127
die("no such commit %s", oid_to_hex(oid));
126128
return &commit_list_insert(parent, tail)->next;
127129
}
128130

129-
static void append_merge_parents(struct commit_list **tail)
131+
static void append_merge_parents(struct repository *r,
132+
struct commit_list **tail)
130133
{
131134
int merge_head;
132135
struct strbuf line = STRBUF_INIT;
133136

134-
merge_head = open(git_path_merge_head(the_repository), O_RDONLY);
137+
merge_head = open(git_path_merge_head(r), O_RDONLY);
135138
if (merge_head < 0) {
136139
if (errno == ENOENT)
137140
return;
138141
die("cannot open '%s' for reading",
139-
git_path_merge_head(the_repository));
142+
git_path_merge_head(r));
140143
}
141144

142145
while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
143146
struct object_id oid;
144147
if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
145148
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);
148151
}
149152
close(merge_head);
150153
strbuf_release(&line);
@@ -155,11 +158,13 @@ static void append_merge_parents(struct commit_list **tail)
155158
* want to transfer ownership of the buffer to the commit (so we
156159
* must use detach).
157160
*/
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)
159164
{
160165
size_t len;
161166
void *buf = strbuf_detach(sb, &len);
162-
set_commit_buffer(the_repository, c, buf, len);
167+
set_commit_buffer(r, c, buf, len);
163168
}
164169

165170
/*
@@ -185,16 +190,16 @@ static struct commit *fake_working_tree_commit(struct repository *r,
185190

186191
read_index(r->index);
187192
time(&now);
188-
commit = alloc_commit_node(the_repository);
193+
commit = alloc_commit_node(r);
189194
commit->object.parsed = 1;
190195
commit->date = now;
191196
parent_tail = &commit->parents;
192197

193198
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
194199
die("no such ref: HEAD");
195200

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);
198203
verify_working_tree_path(r, commit, path);
199204

200205
origin = make_origin(commit, path);
@@ -211,7 +216,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
211216
ident, ident, path,
212217
(!contents_from ? path :
213218
(!strcmp(contents_from, "-") ? "standard input" : contents_from)));
214-
set_commit_buffer_from_strbuf(commit, &msg);
219+
set_commit_buffer_from_strbuf(r, commit, &msg);
215220

216221
if (!contents_from || strcmp("-", contents_from)) {
217222
struct stat st;
@@ -1678,7 +1683,7 @@ static struct commit *find_single_final(struct rev_info *revs,
16781683
struct object *obj = revs->pending.objects[i].item;
16791684
if (obj->flags & UNINTERESTING)
16801685
continue;
1681-
obj = deref_tag(the_repository, obj, NULL, 0);
1686+
obj = deref_tag(revs->repo, obj, NULL, 0);
16821687
if (obj->type != OBJ_COMMIT)
16831688
die("Non commit %s?", revs->pending.objects[i].name);
16841689
if (found)
@@ -1709,14 +1714,14 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
17091714

17101715
/* Is that sole rev a committish? */
17111716
obj = revs->pending.objects[0].item;
1712-
obj = deref_tag(the_repository, obj, NULL, 0);
1717+
obj = deref_tag(revs->repo, obj, NULL, 0);
17131718
if (obj->type != OBJ_COMMIT)
17141719
return NULL;
17151720

17161721
/* Do we have HEAD? */
17171722
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
17181723
return NULL;
1719-
head_commit = lookup_commit_reference_gently(the_repository,
1724+
head_commit = lookup_commit_reference_gently(revs->repo,
17201725
&head_oid, 1);
17211726
if (!head_commit)
17221727
return NULL;
@@ -1745,7 +1750,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
17451750
struct object *obj = revs->pending.objects[i].item;
17461751
if (!(obj->flags & UNINTERESTING))
17471752
continue;
1748-
obj = deref_tag(the_repository, obj, NULL, 0);
1753+
obj = deref_tag(revs->repo, obj, NULL, 0);
17491754
if (obj->type != OBJ_COMMIT)
17501755
die("Non commit %s?", revs->pending.objects[i].name);
17511756
if (found)

Diff for: branch.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ N_("\n"
242242
"will track its remote counterpart, you may want to use\n"
243243
"\"git push -u\" to set the upstream config as you push.");
244244

245-
void create_branch(const char *name, const char *start_name,
245+
void create_branch(struct repository *r,
246+
const char *name, const char *start_name,
246247
int force, int clobber_head_ok, int reflog,
247248
int quiet, enum branch_track track)
248249
{
@@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
300301
break;
301302
}
302303

303-
if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
304+
if ((commit = lookup_commit_reference(r, &oid)) == NULL)
304305
die(_("Not a valid branch point: '%s'."), start_name);
305306
oidcpy(&oid, &commit->object.oid);
306307

@@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,
336337
free(real_ref);
337338
}
338339

339-
void remove_branch_state(void)
340+
void remove_branch_state(struct repository *r)
340341
{
341-
unlink(git_path_cherry_pick_head(the_repository));
342-
unlink(git_path_revert_head(the_repository));
343-
unlink(git_path_merge_head(the_repository));
344-
unlink(git_path_merge_rr(the_repository));
345-
unlink(git_path_merge_msg(the_repository));
346-
unlink(git_path_merge_mode(the_repository));
347-
unlink(git_path_squash_msg(the_repository));
342+
unlink(git_path_cherry_pick_head(r));
343+
unlink(git_path_revert_head(r));
344+
unlink(git_path_merge_head(r));
345+
unlink(git_path_merge_rr(r));
346+
unlink(git_path_merge_msg(r));
347+
unlink(git_path_merge_mode(r));
348+
unlink(git_path_squash_msg(r));
348349
}
349350

350351
void die_if_checked_out(const char *branch, int ignore_current_worktree)

Diff for: branch.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef BRANCH_H
22
#define BRANCH_H
33

4+
struct repository;
45
struct strbuf;
56

67
enum branch_track {
@@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;
1920
/*
2021
* Creates a new branch, where:
2122
*
23+
* - r is the repository to add a branch to
24+
*
2225
* - name is the new branch name
2326
*
2427
* - start_name is the name of the existing branch that the new branch should
@@ -37,7 +40,8 @@ extern enum branch_track git_branch_track;
3740
* that start_name is a tracking branch for (if any).
3841
*
3942
*/
40-
void create_branch(const char *name, const char *start_name,
43+
void create_branch(struct repository *r,
44+
const char *name, const char *start_name,
4145
int force, int clobber_head_ok,
4246
int reflog, int quiet, enum branch_track track);
4347

@@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for
6064
* Remove information about the state of working on the current
6165
* branch. (E.g., MERGE_HEAD)
6266
*/
63-
void remove_branch_state(void);
67+
void remove_branch_state(struct repository *r);
6468

6569
/*
6670
* Configure local branch "local" as downstream to branch "remote"

Diff for: builtin/am.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
19701970
if (merge_tree(remote_tree))
19711971
return -1;
19721972

1973-
remove_branch_state();
1973+
remove_branch_state(the_repository);
19741974

19751975
return 0;
19761976
}
@@ -1981,7 +1981,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
19811981
static void am_rerere_clear(void)
19821982
{
19831983
struct string_list merge_rr = STRING_LIST_INIT_DUP;
1984-
rerere_clear(&merge_rr);
1984+
rerere_clear(the_repository, &merge_rr);
19851985
string_list_clear(&merge_rr, 1);
19861986
}
19871987

Diff for: builtin/bisect--helper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
137137

138138
switch (cmdmode) {
139139
case NEXT_ALL:
140-
return bisect_next_all(prefix, no_checkout);
140+
return bisect_next_all(the_repository, prefix, no_checkout);
141141
case WRITE_TERMS:
142142
if (argc != 2)
143143
return error(_("--write-terms requires two arguments"));

0 commit comments

Comments
 (0)