Skip to content

Commit 4edce17

Browse files
pcloudsgitster
authored andcommitted
branch.c: remove the_repository reference
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69d2cfe commit 4edce17

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

branch.c

Lines changed: 11 additions & 10 deletions
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)

branch.h

Lines changed: 6 additions & 2 deletions
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"

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20222022
if (merge_tree(remote_tree))
20232023
return -1;
20242024

2025-
remove_branch_state();
2025+
remove_branch_state(the_repository);
20262026

20272027
return 0;
20282028
}

builtin/branch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
783783
* create_branch takes care of setting up the tracking
784784
* info and making sure new_upstream is correct
785785
*/
786-
create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
786+
create_branch(the_repository, branch->name, new_upstream,
787+
0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
787788
} else if (unset_upstream) {
788789
struct branch *branch = branch_get(argv[0]);
789790
struct strbuf buf = STRBUF_INIT;
@@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
814815
if (track == BRANCH_TRACK_OVERRIDE)
815816
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
816817

817-
create_branch(argv[0], (argc == 2) ? argv[1] : head,
818+
create_branch(the_repository,
819+
argv[0], (argc == 2) ? argv[1] : head,
818820
force, 0, reflog, quiet, track);
819821

820822
} else

builtin/checkout.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
753753
free(refname);
754754
}
755755
else
756-
create_branch(opts->new_branch, new_branch_info->name,
756+
create_branch(the_repository,
757+
opts->new_branch, new_branch_info->name,
757758
opts->new_branch_force ? 1 : 0,
758759
opts->new_branch_force ? 1 : 0,
759760
opts->new_branch_log,
@@ -811,7 +812,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
811812
delete_reflog(old_branch_info->path);
812813
}
813814
}
814-
remove_branch_state();
815+
remove_branch_state(the_repository);
815816
strbuf_release(&msg);
816817
if (!opts->quiet &&
817818
(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
400400
print_new_head_line(lookup_commit_reference(the_repository, &oid));
401401
}
402402
if (!pathspec.nr)
403-
remove_branch_state();
403+
remove_branch_state(the_repository);
404404

405405
return update_ref_status;
406406
}

builtin/revert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
195195
if (cmd == 'q') {
196196
int ret = sequencer_remove_state(opts);
197197
if (!ret)
198-
remove_branch_state();
198+
remove_branch_state(the_repository);
199199
return ret;
200200
}
201201
if (cmd == 'c')

0 commit comments

Comments
 (0)