git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* bug: git format prints no final newline
@ 2022-11-03  3:14 Evan Benn
  2022-11-03  4:43 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Evan Benn @ 2022-11-03  3:14 UTC (permalink / raw
  To: git

This command omits the final newline:

git log --format=format:"%H"

check with: `| tail | cat -A`

This command doesn't, but there is an extra newline between each line of course:

git log --format=format:"%H%n"

This seems to be intentional in the code, a newline is printed before
each line except the first:

https://github.com/git/git/blob/master/log-tree.c#L664

It seems more correct to print a newline after every line, but the
code is very hairy so I am keen to get any feedback before attempting
that.

Thanks

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

* Re: bug: git format prints no final newline
  2022-11-03  3:14 bug: git format prints no final newline Evan Benn
@ 2022-11-03  4:43 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2022-11-03  4:43 UTC (permalink / raw
  To: Evan Benn; +Cc: git

On Thu, Nov 03, 2022 at 02:14:37PM +1100, Evan Benn wrote:

> This command omits the final newline:
> 
> git log --format=format:"%H"

This is the intended behavior. See the section on "tformat:" in "git
help log", and the discussion of "terminator" vs "separator" semantics.

The "separator" semantics are helpful for most multiline formats (where
your separator is probably a blank line, and you don't want an extra one
at the end). Terminator is more useful for one-line outputs.

I think one could argue that the terminator one is what most people want
and would be a better default, but "format" is the way it is for
historical compatibility. If you use the do-what-I-mean form of:

  git log --format=%H

then it defaults to tformat (notice no "format:" or "tformat:" keyword;
we infer from the presence of "%H" in the name that it's a custom
format, and that is what defaults to tformat).

-Peff

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

end of thread, other threads:[~2022-11-03  4:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-03  3:14 bug: git format prints no final newline Evan Benn
2022-11-03  4:43 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).