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

[RFC PATCH 2/2] pretty: add 'I' placeholder for patch-id

From
Michael McClimon <michael@mcclimon.org>
Date
Oct 22, 2023, 02:28 UTC
Message-ID
<20231022022800.69219-3-michael@mcclimon.org>
In-Reply-To
<20231022022800.69219-1-michael@mcclimon.org>

This doesn't actually work yet, and the test is probably in the wrong place, but I think it's sort of close enough to send an RFC patch to ask some questions.

Signed-off-by: Michael McClimon <michael@mcclimon.org>
---
 pretty.c                      | 11 +++++++++++
 t/t4205-log-pretty-formats.sh |  7 +++++++
 2 files changed, 18 insertions(+)
diff --git a/pretty.c b/pretty.c
index cf964b06..47e2e6e9 100644
--- a/pretty.c
+++ b/pretty.c
@@ -19,6 +19,7 @@
 #include "trailer.h"
 #include "run-command.h"
 #include "object-name.h"
+#include "patch-ids.h"
 
 /*
  * The limit for formatting directives, which enable the caller to append
@@ -1571,6 +1572,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 						 c->pretty_ctx->abbrev);
 		}
 		return 1;
+	case 'I':
+		{
+			struct diff_options diffopt;
+			struct object_id patch_id;
+			repo_diff_setup(the_repository, &diffopt);
+			if (commit_patch_id(commit, &diffopt, &patch_id, 0))
+				die(_("cannot get patch id"));
+			strbuf_addstr(sb, oid_to_hex(&patch_id));
+			return 1;
+		}
 	case 'm':		/* left/right/bottom */
 		strbuf_addstr(sb, get_revision_mark(NULL, commit));
 		return 1;
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index e3d655e6..1e9fdcfe 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -38,6 +38,13 @@ test_expect_success 'set up basic repos' '
 	git config --unset i18n.commitEncoding
 '
 
+# %I placeholder
+test_expect_success '%I placeholder is a patch-id' '
+	git diff-tree --patch-with-raw HEAD | git patch-id >expected &&
+	git show -s --pretty="%I %H" >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'alias builtin format' '
 	git log --pretty=oneline >expected &&
 	git config pretty.test-alias oneline &&
-- 
2.42.0.424.gceadf0f3
Previous: Michael McClimonNext: Jeff King
Message 3 of 4 in “pretty: add %I formatting for patch-id”
  1. 0/2 pretty: add %I formatting for patch-idMichael McClimon, Oct 22, 2023
  2. 1/2 patch-ids: add const modifier to commitMichael McClimon, Oct 22, 2023
  3. 2/2 pretty: add 'I' placeholder for patch-idMichael McClimon, Oct 22, 2023
  4. Jeff KingOct 25, 2023

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.