From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/2] branch.c: remove explicit reference to the_repository
Date: Wed, 15 Aug 2018 18:23:07 +0200 [thread overview]
Message-ID: <20180815162308.17747-1-pclouds@gmail.com> (raw)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
branch.c | 22 ++++++++++++----------
branch.h | 7 +++++--
builtin/am.c | 2 +-
builtin/branch.c | 6 ++++--
builtin/checkout.c | 5 +++--
builtin/reset.c | 2 +-
6 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/branch.c b/branch.c
index ecd710d730..0baa1f6877 100644
--- a/branch.c
+++ b/branch.c
@@ -244,7 +244,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 *repo,
+ const char *name, const char *start_name,
int force, int clobber_head_ok, int reflog,
int quiet, enum branch_track track)
{
@@ -302,7 +303,8 @@ void create_branch(const char *name, const char *start_name,
break;
}
- if ((commit = lookup_commit_reference(the_repository, &oid)) == NULL)
+ commit = lookup_commit_reference(repo, &oid);
+ if (!commit)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(&oid, &commit->object.oid);
@@ -338,15 +340,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 *repo)
{
- 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(repo));
+ unlink(git_path_revert_head(repo));
+ unlink(git_path_merge_head(repo));
+ unlink(git_path_merge_rr(repo));
+ unlink(git_path_merge_msg(repo));
+ unlink(git_path_merge_mode(repo));
+ unlink(git_path_squash_msg(repo));
}
void die_if_checked_out(const char *branch, int ignore_current_worktree)
diff --git a/branch.h b/branch.h
index 473d0a93e9..14d8282927 100644
--- a/branch.h
+++ b/branch.h
@@ -3,6 +3,8 @@
/* Functions for acting on the information about branches. */
+struct repository;
+
/*
* Creates a new branch, where:
*
@@ -24,7 +26,8 @@
* 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 *repo,
+ const char *name, const char *start_name,
int force, int clobber_head_ok,
int reflog, int quiet, enum branch_track track);
@@ -47,7 +50,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 *);
/*
* Configure local branch "local" as downstream to branch "remote"
diff --git a/builtin/am.c b/builtin/am.c
index 2c19e69f58..7abe39939e 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2017,7 +2017,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 4fc55c3508..e04d528ce1 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -795,7 +795,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;
@@ -831,7 +832,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 516136a23a..4756018272 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -653,7 +653,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,
@@ -711,7 +712,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 11cd0dcb8c..d90ccdb839 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -399,7 +399,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;
}
--
2.18.0.1004.g6639190530
next reply other threads:[~2018-08-15 16:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-15 16:23 Nguyễn Thái Ngọc Duy [this message]
2018-08-15 16:23 ` [PATCH 2/2] cherry-pick: fix --quit not deleting CHERRY_PICK_HEAD Nguyễn Thái Ngọc Duy
2018-08-15 17:09 ` Stefan Beller
2018-08-15 17:17 ` Duy Nguyen
2018-08-15 17:22 ` Stefan Beller
2018-08-15 17:26 ` Junio C Hamano
2018-08-15 17:30 ` Duy Nguyen
2018-08-15 17:33 ` Junio C Hamano
2018-08-16 16:06 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
2018-08-16 17:02 ` Junio C Hamano
2018-08-15 16:48 ` [PATCH 1/2] branch.c: remove explicit reference to the_repository Elijah Newren
2018-08-15 16:52 ` Duy Nguyen
2018-08-15 16:58 ` Stefan Beller
2018-08-15 17:11 ` Duy Nguyen
2018-08-15 17:38 ` Junio C Hamano
2018-08-15 17:43 ` Duy Nguyen
2018-08-15 17:20 ` Junio C Hamano
2018-08-15 17:23 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180815162308.17747-1-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).