[PATCH v2] follow usage recommendations for branch_get()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Our recommendation is to use branch_get(NULL) to obtain the 'struct
branch*' for the currently checked out branch in the current worktree.
While branch_get("HEAD") produces the same result, it does not follow
the recommended usage and may cause confusion.

Let's change some calls to branch_get() we currently have in our
codebase that do not follow the recommendation, applying the following
semantic patch:

    @@
    @@
    - branch_get("HEAD")
    + branch_get(NULL)

Signed-off-by: Rubén Justo <rjusto@xxxxxxxxx>
---
 builtin/fetch.c | 2 +-
 builtin/pull.c  | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index ab623f41b4..3c1806aae9 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1755,7 +1755,7 @@ static int do_fetch(struct transport *transport,
 	commit_fetch_head(&fetch_head);
 
 	if (set_upstream) {
-		struct branch *branch = branch_get("HEAD");
+		struct branch *branch = branch_get(NULL);
 		struct ref *rm;
 		struct ref *source_ref = NULL;
 
diff --git a/builtin/pull.c b/builtin/pull.c
index 967368ebc6..f93e8610e0 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -335,7 +335,7 @@ static const char *config_get_ff(void)
  */
 static enum rebase_type config_get_rebase(int *rebase_unspecified)
 {
-	struct branch *curr_branch = branch_get("HEAD");
+	struct branch *curr_branch = branch_get(NULL);
 	const char *value;
 
 	if (curr_branch) {
@@ -440,7 +440,7 @@ static int get_only_remote(struct remote *remote, void *cb_data)
  */
 static void NORETURN die_no_merge_candidates(const char *repo, const char **refspecs)
 {
-	struct branch *curr_branch = branch_get("HEAD");
+	struct branch *curr_branch = branch_get(NULL);
 	const char *remote = curr_branch ? curr_branch->remote_name : NULL;
 
 	if (*refspecs) {
@@ -713,7 +713,7 @@ static const char *get_upstream_branch(const char *remote)
 	if (!rm)
 		return NULL;
 
-	curr_branch = branch_get("HEAD");
+	curr_branch = branch_get(NULL);
 	if (!curr_branch)
 		return NULL;
 
@@ -777,7 +777,7 @@ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo,
 	struct child_process cp = CHILD_PROCESS_INIT;
 	struct strbuf sb = STRBUF_INIT;
 
-	curr_branch = branch_get("HEAD");
+	curr_branch = branch_get(NULL);
 	if (!curr_branch)
 		return -1;
 
-- 
2.34.1



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux