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

[PATCH v4 2/6] format-patch: improve head calculation for cover-letter

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

If we do it after the revision traversal we can be sure that this is indeed a commit that will be processed (i.e. not a merge) and it's the top most one (thus removing the NEEDSWORK comment, at least we show the same as 'git diff --stat').

While we are at it, since we know there's nothing to generate, exit sooner in all cases, like --cover-letter currently does.

Also, if there's nothing to generate and cover-letter is specified, a different code-path might be triggered that is not currently covered in the test-case, so add a test for it.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/log.c           | 22 ++++------------------
 t/t4014-format-patch.sh |  5 +++++
 2 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 8f0b2e8..e0c8b6f 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1319,24 +1319,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.show_root_diff = 1;
 
 	if (cover_letter) {
-		/*
-		 * NEEDSWORK:randomly pick one positive commit to show
-		 * diffstat; this is often the tip and the command
-		 * happens to do the right thing in most cases, but a
-		 * complex command like "--cover-letter a b c ^bottom"
-		 * picks "c" and shows diffstat between bottom..c
-		 * which may not match what the series represents at
-		 * all and totally broken.
-		 */
-		int i;
-		for (i = 0; i < rev.pending.nr; i++) {
-			struct object *o = rev.pending.objects[i].item;
-			if (!(o->flags & UNINTERESTING))
-				head = (struct commit *)o;
-		}
-		/* There is nothing to show; it is not an error, though. */
-		if (!head)
-			return 0;
 		if (!branch_name)
 			branch_name = find_branch_name(&rev);
 	}
@@ -1372,6 +1354,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		list = xrealloc(list, nr * sizeof(list[0]));
 		list[nr - 1] = commit;
 	}
+	if (nr == 0)
+		/* nothing to do */
+		return 0;
+	head = list[0];
 	total = nr;
 	if (!keep_subject && auto_number && total > 1)
 		numbered = 1;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 7fa3647..71b35e7 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1021,4 +1021,9 @@ test_expect_success 'cover letter using branch description (6)' '
 	grep hello actual >/dev/null
 '
 
+test_expect_success 'cover letter with nothing' '
+	git format-patch --stdout --cover-letter >actual &&
+	test_line_count = 0 actual
+'
+
 test_done
-- 
1.8.2
Previous: Jakub NarębskiNext: Felipe Contreras
Message 4 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.