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

Re: [PATCH v2] rev-list: add option for --pretty=format without header

From
Jeff King <peff@peff.net>
Date
Jul 12, 2021, 18:13 UTC
Message-ID
<YOyGYs+uDr7tYxON@coredump.intra.peff.net>
In-Reply-To
<20210711215510.191626-1-sandals@crustytoothpaste.net>
On Sun, Jul 11, 2021 at 09:55:10PM +0000, brian m. carlson wrote:
Show 16 quoted lines
> In general, we encourage users to use plumbing commands, like git
> rev-list, over porcelain commands, like git log, when scripting.
> However, git rev-list has one glaring problem that prevents it from
> being used in certain cases: when --pretty is used with a custom format,
> it always prints out a line containing "commit" and the object ID.  This
> makes it unsuitable for many scripting needs, and forces users to use
> git log instead.
> 
> While we can't change this behavior for backwards compatibility, we can
> add an option to suppress this behavior, so let's do so, and call it
> "--no-commit-header".  Additionally, add the corresponding positive
> option to switch it back on.
> 
> Note that this option doesn't affect the built-in formats, only custom
> formats.  This is exactly the same behavior as users already have from
> git log and is what most users will be used to.
Thanks for working on this. It has bugged me for at least a decade. :)

I do wish this had been made the default when we introduced --pretty=format, but I agree we can't just change it now. This could be something to keep in mind for future deprecation (or a large breaking version). People would have to start saying --commit-header now to future-proof themselves if they really want the current behavior. I'm OK to leave any plans / warnings like that for future work.

The patch looks correct to me. I did have one small nit:
Show 13 quoted lines
> diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
> index 5bf2a85f69..23388f36c3 100644
> --- a/Documentation/rev-list-options.txt
> +++ b/Documentation/rev-list-options.txt
> @@ -1064,6 +1064,14 @@ ifdef::git-rev-list[]
>  --header::
>  	Print the contents of the commit in raw-format; each record is
>  	separated with a NUL character.
> +
> +--no-commit-header::
> +	Suppress the header line containing "commit" and the object ID printed before
> +	the specified format.  This has no effect on the built-in formats; only custom
> +	formats are affected.

It wasn't immediately obvious to me what "custom formats" meant here. I don't think we use that term elsewhere, nor do we seem to have a succinct phrase for the concept. Maybe something like:

  only custom formats (i.e., `--pretty=format:`) are affected.
helps without making it too clunky?
-Peff
Previous: brian m. carlsonNext: brian m. carlson
Message 8 of 9 in “rev-list: add option for --pretty without header”
  1. rev-list: add option for --pretty without headerbrian m. carlson, Jul 6, 2021
  2. Christian CouderJul 9, 2021
  3. Junio C HamanoJul 9, 2021
  4. brian m. carlsonJul 11, 2021
  5. rev-list: add option for --pretty=format without headerbrian m. carlson, Jul 11, 2021
  6. Christian CouderJul 12, 2021
  7. brian m. carlsonJul 13, 2021
  8. Jeff KingJul 12, 2021
  9. brian m. carlsonJul 13, 2021

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.