Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 branch.c           | 21 +++++++++++----------
 branch.h           |  8 ++++++--
 builtin/am.c       |  2 +-
 builtin/branch.c   |  6 ++++--
 builtin/checkout.c |  5 +++--
 builtin/reset.c    |  2 +-
 builtin/revert.c   |  2 +-
 7 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/branch.c b/branch.c
index 776f55fc66..28b81a7e02 100644
--- a/branch.c
+++ b/branch.c
@@ -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)
diff --git a/branch.h b/branch.h
index 5cace4581f..29c1afa4d0 100644
--- a/branch.h
+++ b/branch.h
@@ -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"
diff --git a/builtin/am.c b/builtin/am.c
index 3ee9a9d2a9..232f3962d7 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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;
 }
diff --git a/builtin/branch.c b/builtin/branch.c
index 0c55f7f065..1be727209b 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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
diff --git a/builtin/checkout.c b/builtin/checkout.c
index acdafc6e4c..169e797675 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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"))))
diff --git a/builtin/reset.c b/builtin/reset.c
index 6d37a35e2e..5b4bbb0fb5 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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;
 }
diff --git a/builtin/revert.c b/builtin/revert.c
index 1fa75b2773..df662d4324 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -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')
-- 
2.19.1.1231.g84aef82467

Reply via email to