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

[PATCH v4] commit::print_summary(): set rev_info.always_show_header to 1

From
Tay Ray Chuan <rctay89@gmail.com>
Date
Jun 7, 2010, 05:04 UTC
Message-ID
<1275887056-4788-1-git-send-email-rctay89@gmail.com>
In-Reply-To
<1275639660-5344-1-git-send-email-rctay89@gmail.com>

This attempts to fix a regression in git-commit, where non-abbreviated SHA-1s were printed in the summary.

One possible fix would be to set ctx.abbrev to DEFAULT_ABBREV in the `if` block.

However, we remove this codeblock altogether, and set rev.always_show_header. This way, we use back the same show_log() mechanism (instead of format_commit_message()).

Quoting log-tree.c:560:
	shown = log_tree_diff(opt, commit, &log);
	if (!shown && opt->loginfo && opt->always_show_header) {
		log.parent = NULL;
		show_log(opt);
		shown = 1;
	}

This is the only area that always_show_header is checked, so the setting of this flag should only affect this area.

Also, we now die() if log_tree_commit() returns false; add a comment in the area, which may be helpful to future git hackers (eg. diagnosisng trigger of the die()).

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---

This is a reworked version of the third patch of the 'tc/commit-abbrev-fix' series; there are no changes to the first and second patches.

Changes from v3:
 - shift note on the die() and our assumption from the commit message into the
   code (as a comment), as suggested by Junio.
 builtin/commit.c  |   22 +++++++++++++---------
 t/t7502-commit.sh |    4 ++--
 2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index a4e4966..b0c266c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1148,7 +1148,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 	rev.verbose_header = 1;
 	rev.show_root_diff = 1;
 	get_commit_format(format.buf, &rev);
-	rev.always_show_header = 0;
+	rev.always_show_header = 1;
 	rev.diffopt.detect_rename = 1;
 	rev.diffopt.rename_limit = 100;
 	rev.diffopt.break_opt = 0;
@@ -1162,14 +1162,18 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 				head,
 		initial_commit ? " (root-commit)" : "");

-	if (!log_tree_commit(&rev, commit)) {
-		struct pretty_print_context ctx = {0};
-		struct strbuf buf = STRBUF_INIT;
-		ctx.date_mode = DATE_NORMAL;
-		format_commit_message(commit, format.buf + 7, &buf, &ctx);
-		printf("%s\n", buf.buf);
-		strbuf_release(&buf);
-	}
+	/**
+	 * Based on the existing underlying codepaths (log_tree_commit(),
+	 * log_tree_diff(), log_tree_diff_flush(), to name a few), the die()
+	 * should not occur; changes to these codepaths may warrant a revision
+	 * of our handling of this situation.
+	 *
+	 * Tests #1-#3 in t7502 for output formats should aid in detecting such
+	 * breakages.
+	 */
+	if (!log_tree_commit(&rev, commit))
+		die("unable to print summary");
+
 	strbuf_release(&format);
 }

diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index b10541d..08c0247 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -36,12 +36,12 @@ test_expect_success 'output summary format' '
 	check_summary_oneline "" "a change"
 '

-test_expect_failure 'output summary format for commit with an empty diff' '
+test_expect_success 'output summary format for commit with an empty diff' '

 	check_summary_oneline "" "empty" "--allow-empty"
 '

-test_expect_failure 'output summary format for merges' '
+test_expect_success 'output summary format for merges' '

 	git checkout -b recursive-base &&
 	test_commit base file1 &&
--
1.7.1.189.g07419
Previous: Junio C HamanoNext: Michael J Gruber
Message 6 of 23 in “What's cooking in git.git (Jun 2010, #01; Wed, 2)”
  1. Junio C HamanoJun 2, 2010
  2. Tay Ray ChuanJun 3, 2010
  3. 3/3 commit::print_summary(): set rev_info.always_show_header to 1Tay Ray Chuan, Jun 4, 2010
  4. Tay Ray ChuanJun 4, 2010
  5. Junio C HamanoJun 5, 2010
  6. commit::print_summary(): set rev_info.always_show_header to 1Tay Ray Chuan, Jun 7, 2010
  7. Michael J GruberJun 3, 2010
  8. mg/rev-parse-option-sifter-deprecationJonathan Nieder, Jun 3, 2010
  9. 1/2 separate quoting and relative path generationClemens Buchacher, Jun 3, 2010
  10. 2/2 ls-files: allow relative pathspecClemens Buchacher, Jun 3, 2010
  11. Junio C HamanoJun 3, 2010
  12. optimize path_relative()Clemens Buchacher, Jun 4, 2010
  13. Clemens BuchacherJun 4, 2010
  14. setup: document prefixClemens Buchacher, Jun 5, 2010
  15. optimize path_relative()Clemens Buchacher, Jun 5, 2010
  16. Junio C HamanoJun 5, 2010
  17. Thomas RastJun 3, 2010
  18. Eyvind BernhardsenJun 3, 2010
  19. Jonathan NiederJun 4, 2010
  20. Junio C HamanoJun 5, 2010
  21. Jonathan NiederJun 5, 2010
  22. Sverre RabbelierJun 5, 2010
  23. Junio C HamanoJun 6, 2010

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.