{"thread":{"id":"58739","subject":"bug: git format prints no final newline","startedAt":"2022-11-03T03:15:11Z","lastAt":"2022-11-03T04:43:31Z","messageCount":2,"participants":["Evan Benn","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"466372","messageId":"CAKz_xw2X+eapmASqG7V=RXehh7=LN24m+MJPn-wx80oZAZHBnQ@mail.gmail.com","threadId":"58739","inReplyTo":null,"subject":"bug: git format prints no final newline","fromName":"Evan Benn","fromEmail":"evanbenn@google.com","sentAt":"2022-11-03T03:14:37Z","receivedAt":"2022-11-03T03:15:11Z","isPatch":false,"sender":{"key":"evanbenn@google.com","avatar":null},"body":"This command omits the final newline:\n\ngit log --format=format:\"%H\"\n\ncheck with: `| tail | cat -A`\n\nThis command doesn't, but there is an extra newline between each line of course:\n\ngit log --format=format:\"%H%n\"\n\nThis seems to be intentional in the code, a newline is printed before\neach line except the first:\n\nhttps://github.com/git/git/blob/master/log-tree.c#L664\n\nIt seems more correct to print a newline after every line, but the\ncode is very hairy so I am keen to get any feedback before attempting\nthat.\n\nThanks\n"},{"id":"466378","messageId":"Y2NG6u1TVdDBZAZE@coredump.intra.peff.net","threadId":"58739","inReplyTo":"CAKz_xw2X+eapmASqG7V=RXehh7=LN24m+MJPn-wx80oZAZHBnQ@mail.gmail.com","subject":"Re: bug: git format prints no final newline","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-03T04:43:22Z","receivedAt":"2022-11-03T04:43:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 03, 2022 at 02:14:37PM +1100, Evan Benn wrote:\n\n> This command omits the final newline:\n> \n> git log --format=format:\"%H\"\n\nThis is the intended behavior. See the section on \"tformat:\" in \"git\nhelp log\", and the discussion of \"terminator\" vs \"separator\" semantics.\n\nThe \"separator\" semantics are helpful for most multiline formats (where\nyour separator is probably a blank line, and you don't want an extra one\nat the end). Terminator is more useful for one-line outputs.\n\nI think one could argue that the terminator one is what most people want\nand would be a better default, but \"format\" is the way it is for\nhistorical compatibility. If you use the do-what-I-mean form of:\n\n  git log --format=%H\n\nthen it defaults to tformat (notice no \"format:\" or \"tformat:\" keyword;\nwe infer from the presence of \"%H\" in the name that it's a custom\nformat, and that is what defaults to tformat).\n\n-Peff\n"}]}