branch.c: remove the_repository reference

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-11-10 06:49:00 +01:00 committed by Junio C Hamano
parent 69d2cfe6e8
commit 4edce1729a
7 changed files with 27 additions and 19 deletions

View File

@ -242,7 +242,8 @@ N_("\n"
"will track its remote counterpart, you may want to use\n"
"\"git push -u\" to set the upstream config as you push.");
void create_branch(const char *name, const char *start_name,
void create_branch(struct repository *r,
const char *name, const char *start_name,
int force, int clobber_head_ok, int reflog,
int quiet, enum branch_track track)
{
@ -300,7 +301,7 @@ void create_branch(const char *name, const char *start_name,
break;
}
if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
if ((commit = lookup_commit_reference(r, &oid)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(&oid, &commit->object.oid);
@ -336,15 +337,15 @@ void create_branch(const char *name, const char *start_name,
free(real_ref);
}
void remove_branch_state(void)
void remove_branch_state(struct repository *r)
{
unlink(git_path_cherry_pick_head(the_repository));
unlink(git_path_revert_head(the_repository));
unlink(git_path_merge_head(the_repository));
unlink(git_path_merge_rr(the_repository));
unlink(git_path_merge_msg(the_repository));
unlink(git_path_merge_mode(the_repository));
unlink(git_path_squash_msg(the_repository));
unlink(git_path_cherry_pick_head(r));
unlink(git_path_revert_head(r));
unlink(git_path_merge_head(r));
unlink(git_path_merge_rr(r));
unlink(git_path_merge_msg(r));
unlink(git_path_merge_mode(r));
unlink(git_path_squash_msg(r));
}
void die_if_checked_out(const char *branch, int ignore_current_worktree)

View File

@ -1,6 +1,7 @@
#ifndef BRANCH_H
#define BRANCH_H
struct repository;
struct strbuf;
enum branch_track {
@ -19,6 +20,8 @@ extern enum branch_track git_branch_track;
/*
* Creates a new branch, where:
*
* - r is the repository to add a branch to
*
* - name is the new branch name
*
* - 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;
* that start_name is a tracking branch for (if any).
*
*/
void create_branch(const char *name, const char *start_name,
void create_branch(struct repository *r,
const char *name, const char *start_name,
int force, int clobber_head_ok,
int reflog, int quiet, enum branch_track track);
@ -60,7 +64,7 @@ extern int validate_new_branchname(const char *name, struct strbuf *ref, int for
* Remove information about the state of working on the current
* branch. (E.g., MERGE_HEAD)
*/
void remove_branch_state(void);
void remove_branch_state(struct repository *r);
/*
* Configure local branch "local" as downstream to branch "remote"

View File

@ -2022,7 +2022,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (merge_tree(remote_tree))
return -1;
remove_branch_state();
remove_branch_state(the_repository);
return 0;
}

View File

@ -783,7 +783,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
* create_branch takes care of setting up the tracking
* info and making sure new_upstream is correct
*/
create_branch(branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
create_branch(the_repository, branch->name, new_upstream,
0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
} else if (unset_upstream) {
struct branch *branch = branch_get(argv[0]);
struct strbuf buf = STRBUF_INIT;
@ -814,7 +815,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (track == BRANCH_TRACK_OVERRIDE)
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
create_branch(argv[0], (argc == 2) ? argv[1] : head,
create_branch(the_repository,
argv[0], (argc == 2) ? argv[1] : head,
force, 0, reflog, quiet, track);
} else

View File

@ -753,7 +753,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
free(refname);
}
else
create_branch(opts->new_branch, new_branch_info->name,
create_branch(the_repository,
opts->new_branch, new_branch_info->name,
opts->new_branch_force ? 1 : 0,
opts->new_branch_force ? 1 : 0,
opts->new_branch_log,
@ -811,7 +812,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
delete_reflog(old_branch_info->path);
}
}
remove_branch_state();
remove_branch_state(the_repository);
strbuf_release(&msg);
if (!opts->quiet &&
(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))

View File

@ -400,7 +400,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
print_new_head_line(lookup_commit_reference(the_repository, &oid));
}
if (!pathspec.nr)
remove_branch_state();
remove_branch_state(the_repository);
return update_ref_status;
}

View File

@ -195,7 +195,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
if (cmd == 'q') {
int ret = sequencer_remove_state(opts);
if (!ret)
remove_branch_state();
remove_branch_state(the_repository);
return ret;
}
if (cmd == 'c')