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

Re: What's cooking in git.git (Jan 2016, #02; Mon, 11)

From
Jeff King <peff@peff.net>
Date
Jan 13, 2016, 23:22 UTC
Message-ID
<20160113232255.GA17937@sigill.intra.peff.net>
In-Reply-To
<xmqqtwmhkrj2.fsf@gitster.mtv.corp.google.com>
On Wed, Jan 13, 2016 at 03:07:13PM -0800, Junio C Hamano wrote:
Show 13 quoted lines
> > And then after a quiet period we can drop the "_crlf()" and have
> > strbuf_getline() back.
> 
> Actually, I think a patch that
> 
>  - renames strbuf_getline() to strbuf_getdelim(); and
>  - renames strbuf_getline_crlf() to strbuf_getline() 
> 
> on top of the series we already have is sufficient to bring the
> endgame state to us.  The new strbuf_getline() has a different
> function signature from the traditional one, so any topic in flight
> that is unaware of this series can easily be caught, and we can do
> this without a quiet period.
Ah, right, I forgot about the changed function signature.
Show 13 quoted lines
> A more interesting question is if strbuf_getdelim() should take an
> arbitrary byte as its third parameter.  As I said elsewhere, the
> only reason why it is not a "do we use LF or do we use NUL?"
> boolean is because I wrote these codepaths anticipating that there
> might be a value other than NUL and LF that could be useful when I
> introduced line_termination long time ago, but no useful caller that
> uses other useful value has emerged, so I think the interface was
> too broad and too general for its own good.
> 
> It becomes very tempting not to do strbuf_getdelim() at all, but
> instead rewrite the current calls to strbuf_getline() to call one of
> two functions, i.e. strbuf_getline_lf() and strbuf_getline_nul(),
> when we rename strbuf_getline_crlf() to strbuf_getline().

I think you'll end up with some of the callers being a bit uglier. I.e., where we say:

  strbuf_getline(&buf, in, delim);
and "delim" is set elsewhere. These will become:
  if (delim == '\n') /* or maybe even "if (nul_terminate)" */
	strbuf_getline_lf(&buf, in);
  else
	strbuf_getline_nul(&buf, in);

which is a bit less nice. But I guess these cases already need to become uglier if we want them to handle CRLF. Unless we want to wrap the idiom as:

  int strbuf_get_record(struct strbuf *buf,
			FILE *in,
			enum { STRBUF_RECORD_LINE,
			       STRBUF_RECORD_NUL
			     } delim);

and then "-z" option parsers use STRBUF_RECORD_NUL instead of setting a char to '\0'.

> By going that route, those who want to help CRLF situation further
> can then concentrate on output from "git grep strbuf_getline_lf()",
> identify the ones that can be safely turned into strbuf_getline(),
> and do the conversion.

I'm not sure that is any easier than just grepping for strbuf_delim() that takes '\n').

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 19 in “What's cooking in git.git (Jan 2016, #02; Mon, 11)”
  1. Junio C HamanoJan 11, 2016
  2. Mike HommeyJan 12, 2016
  3. Junio C HamanoJan 12, 2016
  4. Edmundo Carmona AntoranzJan 12, 2016
  5. Johannes SchindelinJan 12, 2016
  6. Junio C HamanoJan 12, 2016
  7. Jeff KingJan 12, 2016
  8. Junio C HamanoJan 13, 2016
  9. Jeff KingJan 13, 2016
  10. Junio C HamanoJan 13, 2016
  11. Junio C HamanoJan 13, 2016
  12. Jeff KingJan 14, 2016
  13. David A. GreeneJan 13, 2016
  14. Michael J GruberJan 18, 2016
  15. Jeff KingJan 18, 2016
  16. Eric WongJan 18, 2016
  17. Michael J GruberJan 19, 2016
  18. Duy NguyenJan 25, 2016
  19. Junio C HamanoJan 25, 2016

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.