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, 07:00 UTC
Message-ID
<7vbpk2sg6m.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1256007988-13321-1-git-send-email-srabbelier@gmail.com>
Sverre Rabbelier <srabbelier@gmail.com> writes:
> Currently the parsing is difficult when not all files have a newline
> at EOF, this patch ensures that even such files have a newline at the
> end of the blame output.

Thanks. This clearly shows that blame was somewhat sloppily written in that it never considered to be fed anything but well formed text files.

My knee-jerk reaction to the issue is that there are two reasonable approaches to the problem:

 (1) Admit that the code is not prepared to take anything but well formed
     text files.  This will lead to adding the necessary LF after reading
     a blob and if it does not end with LF.  After all, I do not trust the
     code (iow, "me") if it is not prepared to take a blob with incomplete
     line to handle the internal comparison between blobs with incomplete
     lines.
 (2) Do the right thing, by coming up with a notation to show that the
     final line is incomplete, perhaps similar to "\No newline ..."
     notation used by "diff".

To put the last sentence of (1) differently, does the code assign blame correctly around the last line of the original blob? What if an older version ended with an incomplete line and a later version changed the line (without adding the terminating LF)? What if a later version changed the line and added the terminating LF? What if a later version only added the terminating LF and did nothing else? Are these three cases handled correctly?

After thinking issues like the above, I read the patch and I see it does not take neither approach. That makes me feel nervous.

By tweaking only the output routine you _might_ be getting correct output, but even then it looks to me like the end result is working correctly not by design but by accident. IOW, the patch may be better than nothing, but somehow it just feels like it is papering over the real issue than being a proper fix.

Or am I worrying too much?
Show 36 quoted lines
> Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
> CC: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>
>     Patch by Dscho, commit message by me. Apologies to Dscho for
>     taking so long to send it :).
>
>  builtin-blame.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-blame.c b/builtin-blame.c
> index 7512773..dd16b22 100644
> --- a/builtin-blame.c
> +++ b/builtin-blame.c
> @@ -1604,6 +1604,9 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
>  		} while (ch != '\n' &&
>  			 cp < sb->final_buf + sb->final_buf_size);
>  	}
> +
> +	if (sb->final_buf_size && cp[-1] != '\n')
> +		putchar('\n');
>  }
>  
>  static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
> @@ -1667,6 +1670,9 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
>  		} while (ch != '\n' &&
>  			 cp < sb->final_buf + sb->final_buf_size);
>  	}
> +
> +	if (sb->final_buf_size && cp[-1] != '\n')
> +		putchar('\n');
>  }
>  
>  static void output(struct scoreboard *sb, int option)
> -- 
> 1.6.5.1.123.ge01f7
Previous: Sverre RabbelierNext: Sverre Rabbelier
Message 2 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.