git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 3/6] format-patch: refactor branch name calculation

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 7, 2013, 17:46 UTC
Message-ID
<1365356784-24872-4-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1365356784-24872-1-git-send-email-felipe.contreras@gmail.com>

By moving the part that relies on rev->pending earlier, where we are already checking the special case where there's only one ref.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/log.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index e0c8b6f..cd942ee 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1049,15 +1049,6 @@ static char *find_branch_name(struct rev_info *rev)
 	if (0 <= positive) {
 		ref = rev->cmdline.rev[positive].name;
 		tip_sha1 = rev->cmdline.rev[positive].item->sha1;
-	} else if (!rev->cmdline.nr && rev->pending.nr == 1 &&
-		   !strcmp(rev->pending.objects[0].name, "HEAD")) {
-		/*
-		 * No actual ref from command line, but "HEAD" from
-		 * rev->def was added in setup_revisions()
-		 * e.g. format-patch --cover-letter -12
-		 */
-		ref = "HEAD";
-		tip_sha1 = rev->pending.objects[0].item->sha1;
 	} else {
 		return NULL;
 	}
@@ -1288,28 +1279,36 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	}
 
 	if (rev.pending.nr == 1) {
+		int check_head = 0;
+
 		if (rev.max_count < 0 && !rev.show_root_diff) {
 			/*
 			 * This is traditional behaviour of "git format-patch
 			 * origin" that prepares what the origin side still
 			 * does not have.
 			 */
-			unsigned char sha1[20];
-			const char *ref;
-
 			rev.pending.objects[0].item->flags |= UNINTERESTING;
 			add_head_to_pending(&rev);
-			ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
-			if (ref && !prefixcmp(ref, "refs/heads/"))
-				branch_name = xstrdup(ref + strlen("refs/heads/"));
-			else
-				branch_name = xstrdup(""); /* no branch */
+			check_head = 1;
 		}
 		/*
 		 * Otherwise, it is "format-patch -22 HEAD", and/or
 		 * "format-patch --root HEAD".  The user wants
 		 * get_revision() to do the usual traversal.
 		 */
+
+		if (!strcmp(rev.pending.objects[0].name, "HEAD"))
+			check_head = 1;
+
+		if (check_head) {
+			unsigned char sha1[20];
+			const char *ref;
+			ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
+			if (ref && !prefixcmp(ref, "refs/heads/"))
+				branch_name = xstrdup(ref + strlen("refs/heads/"));
+			else
+				branch_name = xstrdup(""); /* no branch */
+		}
 	}
 
 	/*
-- 
1.8.2
Previous: Felipe ContrerasNext: Felipe Contreras
Message 5 of 13 in “send-email: configuration improvements”
  1. 0/6 send-email: configuration improvementsFelipe Contreras, Apr 7, 2013
  2. 1/6 send-email: make annotate configurableFelipe Contreras, Apr 7, 2013
  3. Jakub NarębskiApr 9, 2013
  4. 2/6 format-patch: improve head calculation for cover-letterFelipe Contreras, Apr 7, 2013
  5. 3/6 format-patch: refactor branch name calculationFelipe Contreras, Apr 7, 2013
  6. 4/6 log: update to OPT_BOOLFelipe Contreras, Apr 7, 2013
  7. 5/6 format-patch: add format.cover-letter configurationFelipe Contreras, Apr 7, 2013
  8. Simon RuderichApr 7, 2013
  9. Jonathan NiederApr 7, 2013
  10. t/README: --immediate skips cleanup commands for failed testsSimon Ruderich, Apr 9, 2013
  11. Junio C HamanoApr 9, 2013
  12. t/README: --immediate skips cleanup commands for failed testsSimon Ruderich, Apr 9, 2013
  13. 6/6 format-patch: trivial cleanupsFelipe Contreras, Apr 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.