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

Re: [PATCH] Remove the line length limit for graft files

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 27, 2013, 21:14 UTC
Message-ID
<alpine.DEB.1.00.1312272208070.1191@s15462909.onlinehome-server.info>
In-Reply-To
<20131227210447.GE20443@google.com>
Hi,
On Fri, 27 Dec 2013, Jonathan Nieder wrote:
Show 10 quoted lines
> Johannes Schindelin wrote:
> 
> [...]
> > ---
> >  builtin/blame.c |  8 ++++----
> >  commit.c        | 10 +++++-----
> >  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> Is this easy to reproduce so some interested but lazy person could
> write a test?

Yep. Make 25 orphan commits, add a graft line to make the first a merge of the rest.

Show 17 quoted lines
> > --- a/builtin/blame.c
> > +++ b/builtin/blame.c
> > @@ -1804,17 +1804,17 @@ static int prepare_lines(struct scoreboard *sb)
> >  static int read_ancestry(const char *graft_file)
> >  {
> >  	FILE *fp = fopen(graft_file, "r");
> > -	char buf[1024];
> > +	struct strbuf buf = STRBUF_INIT;
> >  	if (!fp)
> >  		return -1;
> > -	while (fgets(buf, sizeof(buf), fp)) {
> > +	while (!strbuf_getwholeline(&buf, fp, '\n')) {
> 
> If there is no newline at EOF, this will skip the last line, while the
> old behavior was to pay attention to it.  I haven't thought through
> whether that's a good or bad change.  Maybe it should just be
> documented?
The way I read
	int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
	{
		int ch;
		if (feof(fp))
			return EOF;
		strbuf_reset(sb);
		while ((ch = fgetc(fp)) != EOF) {
			strbuf_grow(sb, 1);
			sb->buf[sb->len++] = ch;
			if (ch == term)
				break;
		}
		if (ch == EOF && sb->len == 0)
			return EOF;
		sb->buf[sb->len] = '\0';
		return 0;
	}

it returns EOF only if ch == EOF *and* sb->len == 0, i.e. if no characters have been read before hitting EOF.

In other words, strbuf_getwholeline() -- despite requiring an explicit terminating character argument -- does not require the last line to end with that terminating character.

A quick test (in my case, because I am lazy, modifying test-mergesort.c to output the lines that were read by strbuf_getwholeline()) also confirms my suspicion.

Or maybe I missed something?

Ciao, Dscho

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Previous: Jonathan NiederNext: Jonathan Nieder
Message 3 of 9 in “Remove the line length limit for graft files”
  1. Remove the line length limit for graft filesJohannes Schindelin, Dec 27, 2013
  2. Jonathan NiederDec 27, 2013
  3. Johannes SchindelinDec 27, 2013
  4. Jonathan NiederDec 27, 2013
  5. Johannes SchindelinDec 27, 2013
  6. Jonathan NiederDec 27, 2013
  7. Johannes SchindelinDec 27, 2013
  8. Junio C HamanoDec 28, 2013
  9. Junio C HamanoDec 27, 2013

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.