threads / patch / 63733

patchpretty: add X-Change-ID to mail formats

Subject: [PATCH] pretty: add X-Change-ID to mail formats

## tl;dr

3 messages between Jul 3, 2025 and Jul 3, 2025. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Drew DeVault· Jul 3, 2025, 07:45 UTC · lore

Introduce the X-Change-ID header to emails prepared by git (i.e. via format-patch, send-email). This allows tools which work with those emails (e.g. patchwork, sourcehut) to meaningfully integrate with tools that assign change IDs to commits.

With some follow-up work, this is also the first step towards ensuring that those change IDs are preserved through from git-send-email to git-am as a change moves through its review lifecycle.

Signed-off-by: Drew DeVault <drew@ddevault.org>
---
I have refrained from implementing the git-am part of this work for now,
on the basis that I'm not sure how downstream tools like Jujutsu would
feel if git wrote the change-id header to new commits. Would that
conflict with some internal deterministic process for coming up with the
change-id that could come up with a different answer, leading to
conflicts? I don't know, so I would appreciate some insights from those
who understand the implications for their downstream systems.

Adding the change ID to outgoing emails is useful on its own, however, so I think this patch is acceptable without the git-am side being initially present.

 pretty.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Show changes to pretty.c +6 −1
diff --git a/pretty.c b/pretty.c
index 0bc8ad8a9a..70fba7b023 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2045,7 +2045,7 @@ static void pp_header(struct pretty_print_context *pp,
 	int parents_shown = 0;
 
 	for (;;) {
-		const char *name, *line = *msg_p;
+		const char *name, *change_id, *line = *msg_p;
 		int linelen = get_one_line(*msg_p);
 
 		if (!linelen)
@@ -2089,6 +2089,11 @@ static void pp_header(struct pretty_print_context *pp,
 			strbuf_grow(sb, linelen + 80);
 			pp_user_info(pp, "Commit", sb, name, encoding);
 		}
+		if (skip_prefix(line, "change-id ", &change_id) &&
+		    cmit_fmt_is_mail(pp->fmt)) {
+			strbuf_addf(sb, "X-Change-ID: %.*s\n",
+				    linelen - 11, change_id);
+		}
 	}
 }
 
-- 
2.50.0
Remo Senekowitsch· Jul 3, 2025, 08:41 UTC · re: Drew DeVault · lore

Re: [PATCH] pretty: add X-Change-ID to mail formats

Hi Drew,
Thank you, this is exciting!
On Thu Jul 3, 2025 at 9:45 AM CEST, Drew DeVault wrote:
Show 6 quoted lines
> I have refrained from implementing the git-am part of this work for now,
> on the basis that I'm not sure how downstream tools like Jujutsu would
> feel if git wrote the change-id header to new commits. Would that
> conflict with some internal deterministic process for coming up with the
> change-id that could come up with a different answer, leading to
> conflicts?

This would be no problem at all. Jujutsu would very much welcome if Git preserved the change-id header, including for patches sent by email. Jujutsu generates the initial change-id randomly and since any part of the commit can change while the change-id remains stable, there is no deterministic process that could be interfered with if Git wrote the change-id header to new commits. So, there are no objections from my side to implementing the git-am part as well. :-)

This can kind of be tested already. Because Jujutsu already writes the change-id header and sends it via git push, it must also be able to import those headers from commits it hasn't seen before. Possible steps to verify this behavior:

* Create a repo with Jujutsu, make some commits, push them to a remote.
  (can be one on the local file system)
* Clone this repo via Git.
* (optional) Confirm with `git cat-file -p @` that the change-id header
  was preserved.
* Run `jj git init --colocate .` to upgrade the git repo to a jj repo.
* Run `jj log` and observe that Jujutsu correctly imported the change-id
  headers of existing commits it didn't know about previously.

Best regards, Remo

Drew DeVault· Jul 3, 2025, 11:32 UTC · re: Remo Senekowitsch · lore

Re: [PATCH] pretty: add X-Change-ID to mail formats

Sweet! I'm going to send a follow-up with git-am support.
On Thu Jul 3, 2025 at 10:41 AM CEST, Remo Senekowitsch wrote:
Show 17 quoted lines
> This can kind of be tested already. Because Jujutsu already writes the
> change-id header and sends it via git push, it must also be able to
> import those headers from commits it hasn't seen before. Possible steps
> to verify this behavior:
>
> * Create a repo with Jujutsu, make some commits, push them to a remote.
>   (can be one on the local file system)
>
> * Clone this repo via Git.
>
> * (optional) Confirm with `git cat-file -p @` that the change-id header
>   was preserved.
>
> * Run `jj git init --colocate .` to upgrade the git repo to a jj repo.
>
> * Run `jj log` and observe that Jujutsu correctly imported the change-id
>   headers of existing commits it didn't know about previously.

I can confirm all of this works with the v2 I'm about to send, though I have ascertained as much through a manual testing procedure that resembles your recommendation here.

One thing I'm less certain about is how to expand the tests in t/ to test this behavior. I'll elaborate in the timely commentary of v2.

← back to recent threads