git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] format-patch: teach `--header-cmd`
@ 2024-03-07 19:59 Kristoffer Haugsbakk
  2024-03-07 19:59 ` [PATCH 1/3] log-tree: take ownership of pointer Kristoffer Haugsbakk
                   ` (3 more replies)
  0 siblings, 4 replies; 34+ messages in thread
From: Kristoffer Haugsbakk @ 2024-03-07 19:59 UTC (permalink / raw)
  To: git; +Cc: Kristoffer Haugsbakk, Jeff King, Maxim Cournoyer

(most of this is from the main commit with some elaboration in parts)

Teach git-format-patch(1) `--header-cmd` (with negation) and the
accompanying config variable `format.headerCmd` which allows the user to
add extra headers per-patch.

§ Motivation

format-patch knows `--add-header`. However, that seems most useful for
series-wide headers; you cannot really control what the header is like
per patch or specifically for the cover letter. To that end, teach
format-patch a new option which runs a command that has access to the
hash of the current commit (if it is a code patch) and the patch count
which is used for the patch files that this command outputs. Also
include an environment variable which tells the version of this API so
that the command can detect and error out in case the API changes.

This is inspired by `--header-cmd` of git-send-email(1).

§ Discussion

One may already get the commit hash from the commit by looking at the message id created by format-patch:

    Message-ID: <48c517ffb3dce2188aba5f0a2c1f4f9dc8df59f0.1709840255.git.code@khaugsbakk.name>

However that does not seem to be documented behavior, and relying on the
message id from various tools seems to have backfired before.[1]

It’s also more convenient to not have to parse any output from
format-patch.

One may also be interested in finding some information based on the
commit hash, not just simply to output the hash itself.

🔗 1: https://lore.kernel.org/git/20231106153214.s5abourejkuiwk64@pengutronix.de/

For example, the command could output a header for the current commit as
well as another header for the previously-published commits:

    X-Commit-Hash: 97b53c04894578b23d0c650f69885f734699afc7
    X-Previous-Commits:
        4ad5d4190649dcb5f26c73a6f15ab731891b9dfd
        d275d1d179b90592ddd7b5da2ae4573b3f7a37b7
        402b7937951073466bf4527caffd38175391c7da

One can imagine that (1) these previous commit hashes were stored on every
commit rewrite and (2) the commits that had been published previously
were also stored. Then the command just needed the current commit hash
in order to look up this information.

Now interested parties can use this information to track where the
patches come from.

This information could of course be given between the
three-dash/three-hyphen line and the patch proper. However, the
hypoethetical project in question might prefer to use this part for
extra patch information written by the author and leave the above
information for tooling; this way the extra information does not need to
disturb the reader.

§ Demonstration

The above current/previous hash example is taken from:

https://lore.kernel.org/git/97b53c04894578b23d0c650f69885f734699afc7.1709670287.git.code@khaugsbakk.name/

§ CC

For patch “log-tree: take ownership of pointer”:

Cc: Jeff King <peff@peff.net>

For the git-send-email(1) `--header-cmd` topic:[1]

Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>

🔗 1: https://lore.kernel.org/git/20230423122744.4865-1-maxim.cournoyer@gmail.com/

Kristoffer Haugsbakk (3):
  log-tree: take ownership of pointer
  format-patch: teach `--header-cmd`
  format-patch: check if header output looks valid

 Documentation/config/format.txt    |  5 ++
 Documentation/git-format-patch.txt | 26 ++++++++++
 builtin/log.c                      | 76 ++++++++++++++++++++++++++++++
 log-tree.c                         | 18 ++++++-
 revision.h                         |  2 +
 t/t4014-format-patch.sh            | 55 +++++++++++++++++++++
 6 files changed, 180 insertions(+), 2 deletions(-)

-- 
2.44.0.169.gd259cac85a8


^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2024-03-22 22:31 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 19:59 [PATCH 0/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 1/3] log-tree: take ownership of pointer Kristoffer Haugsbakk
2024-03-12  9:29   ` Jeff King
2024-03-12 17:43     ` Kristoffer Haugsbakk
2024-03-13  6:54       ` Jeff King
2024-03-13 17:49         ` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 2/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-08 18:30   ` Kristoffer Haugsbakk
2024-03-11 21:29   ` Jean-Noël Avila
2024-03-12  8:13     ` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 3/3] format-patch: check if header output looks valid Kristoffer Haugsbakk
2024-03-19 18:35 ` [PATCH v2 0/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-19 18:35   ` [PATCH v2 1/3] revision: add a per-email field to rev-info Kristoffer Haugsbakk
2024-03-19 21:29     ` Jeff King
2024-03-19 21:41       ` Kristoffer Haugsbakk
2024-03-20  0:25       ` Jeff King
2024-03-20  0:27         ` [PATCH 1/6] shortlog: stop setting pp.print_email_subject Jeff King
2024-03-20  0:28         ` [PATCH 2/6] pretty: split oneline and email subject printing Jeff King
2024-03-22 22:00           ` Kristoffer Haugsbakk
2024-03-20  0:30         ` [PATCH 3/6] pretty: drop print_email_subject flag Jeff King
2024-03-20  0:31         ` [PATCH 4/6] log: do not set up extra_headers for non-email formats Jeff King
2024-03-22 22:04           ` Kristoffer Haugsbakk
2024-03-20  0:35         ` [PATCH 5/6] format-patch: return an allocated string from log_write_email_headers() Jeff King
2024-03-22 22:06           ` Kristoffer Haugsbakk
2024-03-20  0:35         ` [PATCH 6/6] format-patch: simplify after-subject MIME header handling Jeff King
2024-03-22 22:08           ` Kristoffer Haugsbakk
2024-03-20  0:43         ` [PATCH v2 1/3] revision: add a per-email field to rev-info Jeff King
2024-03-22 22:31           ` Kristoffer Haugsbakk
2024-03-22  9:59         ` [PATCH 7/6] format-patch: fix leak of empty header string Jeff King
2024-03-22 10:03           ` Kristoffer Haugsbakk
2024-03-22 16:50           ` Junio C Hamano
2024-03-22 22:16           ` Kristoffer Haugsbakk
2024-03-19 18:35   ` [PATCH v2 2/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-19 18:35   ` [PATCH v2 3/3] format-patch: check if header output looks valid Kristoffer Haugsbakk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).