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

Re: [PATCH] blame: make sure that the last line ends in an LF

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 20, 2009, 20:28 UTC
Message-ID
<7viqe9n72w.fsf@alter.siamese.dyndns.org>
In-Reply-To
<fabb9a1e0910201304j2730e6f3j1ebc5c17be07dd12@mail.gmail.com>
Sverre Rabbelier <srabbelier@gmail.com> writes:
Show 57 quoted lines
> On Tue, Oct 20, 2009 at 11:55, Junio C Hamano <gitster@pobox.com> wrote:
>> That is kind of surprising ;-) as I do remember that I never thought about
>> this issue of dealing with the incomplete lines while writing the blame
>> algorithm.  I actually didn't even think about "well this will not work
>> because I am ignoring the incomplete lines".
>
> I used the following repo for testing:
>
> $ git init
> Initialized empty Git repository in /home/sverre/code/test/.git/
> $ echo "first line" > test
> $ git add test
> $ git commit -m "initial"
> [master (root-commit) d573d06] initial
>  1 files changed, 1 insertions(+), 0 deletions(-)
>  create mode 100644 test
> $ echo -n "second line, no newline" >> test
> $ git add test
> $ git commit -m "second"
> [master 76ad2f9] second
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> Regular output looks good:
>
> $ git blame test
> ^d573d06 (Sverre Rabbelier 2009-10-20 12:30:56 -0500 1) first line
> 76ad2f90 (Sverre Rabbelier 2009-10-20 12:31:57 -0500 2) second line, no newline
>
> Porcelain output looks good too:
>
> $ git blame -p test
> d573d06f0dd50148ba8e59bf8f1ef8fa7ee9fc88 1 1 1
> author Sverre Rabbelier
> author-mail <srabbelier@gmail.com>
> author-time 1256059856
> author-tz -0500
> committer Sverre Rabbelier
> committer-mail <srabbelier@gmail.com>
> committer-time 1256059856
> committer-tz -0500
> summary initial
> boundary
> filename test
>         first line
> 76ad2f90bde689a65715e37afd37d45942c74954 2 2 1
> author Sverre Rabbelier
> author-mail <srabbelier@gmail.com>
> author-time 1256059917
> author-tz -0500
> committer Sverre Rabbelier
> committer-mail <srabbelier@gmail.com>
> committer-time 1256059917
> committer-tz -0500
> summary second
> previous d573d06f0dd50148ba8e59bf8f1ef8fa7ee9fc88 test
> filename test
>         second line, no newline
Thanks.

For both styles of output, adding an extra LF after "no newline" would be necessary to make the output legible (for human) and parsable (for scripts).

In addition, it would help Porcelains to re-construct the final text if you added a boolean "incomplete-line" (put it on its own line, immediately after "filename test" line). Then they will know that LF after "second line, no newline" was not there in the original and was added for parsability.

I am not sure what we want to do for non-porcelain output (other than adding the extra LF at the end). Assuming that they are meant to be read by humans (and casual scripts that do not bother reading --porcelain format), it might be best not to add any extra marking.

Previous: Sverre RabbelierNext: Sverre Rabbelier
Message 8 of 9 in “blame: make sure that the last line ends in an LF”
  1. blame: make sure that the last line ends in an LFSverre Rabbelier, Oct 20, 2009
  2. Junio C HamanoOct 20, 2009
  3. Sverre RabbelierOct 20, 2009
  4. Junio C HamanoOct 20, 2009
  5. Johannes SchindelinOct 20, 2009
  6. Junio C HamanoOct 20, 2009
  7. Sverre RabbelierOct 20, 2009
  8. Junio C HamanoOct 20, 2009
  9. Sverre RabbelierOct 22, 2009

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.