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

Re: [PATCH 08/16] use skip_prefix to avoid magic numbers

From
Jeff King <peff@peff.net>
Date
Jul 1, 2014, 17:35 UTC
Message-ID
<20140701173502.GA12777@sigill.intra.peff.net>
In-Reply-To
<xmqqa993b8so.fsf@gitster.dls.corp.google.com>
On Mon, Jun 23, 2014 at 02:44:23PM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > diff --git a/connect.c b/connect.c
> > index 94a6650..37ff018 100644
> > --- a/connect.c
> > +++ b/connect.c
> > @@ -140,12 +141,12 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
> >  		if (!len)
> >  			break;
> >  
> > -		if (len > 4 && starts_with(buffer, "ERR "))
> > -			die("remote error: %s", buffer + 4);
> > +		if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
> > +			die("remote error: %s", arg);
> 
> Makes one wonder if we should do something special to a line with
> only "ERR " and nothing else on it, which the other end may have
> meant us to give a blank line to make the output more readable.

I don't think that would buy us much. We have always accepted only a single ERR line and died immediately. So any changes of that nature would have to be made in the client, and then servers would have to wait N time units before it was safe to start using the feature (otherwise old clients just get the blank line!).

I also don't think blank lines by themselves are useful. You'd want them in addition to being able to handle multiple lines. So a nicer fix is more along the lines of "accept multiple ERR lines, including blank lines, followed by a terminating line ("ERRDONE" or something).

Then servers can do:
  ERR unable to access foo.git: Printer on fire
  ERR
  ERR You may have misspelled the repository name. Did you mean:
  ERR
  ERR  foobar.git
  ERRDONE

Old clients would see the first line and die. Newer clients would print the helpful hint. Servers would just need to make sure that the first line stands on its own to cover both cases.

> A fix, if one turns out to be needed, is outside the scope of this
> patch, though, I think.
Yeah, definitely a separate topic.

It is not something I think anybody has asked for, but I can imagine a site like GitHub making use of it (we already show custom errors for http, but there's no room beyond the single ERR line). And teaching the clients now expands the options for servers later. So it might be worth doing just as a potential feature.

-Peff
Previous: Junio C HamanoNext: Jeff King
Message 18 of 33 in “skip_prefix refactoring and cleanups”
  1. 0/16 skip_prefix refactoring and cleanupsJeff King, Jun 18, 2014
  2. 01/16 parse_diff_color_slot: drop ofs parameterJeff King, Jun 18, 2014
  3. 02/16 daemon: mark some strings as constJeff King, Jun 18, 2014
  4. 03/16 avoid using skip_prefix as a booleanJeff King, Jun 18, 2014
  5. 04/16 refactor skip_prefix to return a booleanJeff King, Jun 18, 2014
  6. Eric SunshineJun 20, 2014
  7. Jeff KingJun 20, 2014
  8. Eric SunshineJun 20, 2014
  9. Jeff KingJun 20, 2014
  10. Junio C HamanoJun 23, 2014
  11. Jeff KingJun 23, 2014
  12. builtin/clone.c: detect a clone starting at a tag correctlyJunio C Hamano, Jun 23, 2014
  13. 05/16 apply: use skip_prefix instead of raw additionJeff King, Jun 18, 2014
  14. 06/16 fast-import: fix read of uninitialized argv memoryJeff King, Jun 18, 2014
  15. 07/16 transport-helper: avoid reading past end-of-stringJeff King, Jun 18, 2014
  16. 08/16 use skip_prefix to avoid magic numbersJeff King, Jun 18, 2014
  17. Junio C HamanoJun 23, 2014
  18. Jeff KingJul 1, 2014
  19. 09/16 use skip_prefix to avoid repeating stringsJeff King, Jun 18, 2014
  20. 10/16 fast-import: use skip_prefix for parsing inputJeff King, Jun 18, 2014
  21. Eric SunshineJun 20, 2014
  22. Jeff KingJun 20, 2014
  23. Eric SunshineJun 20, 2014
  24. 11/16 daemon: use skip_prefix to avoid magic numbersJeff King, Jun 18, 2014
  25. 12/16 stat_opt: check extra strlen callJeff King, Jun 18, 2014
  26. 13/16 fast-import: refactor parsing of spacesJeff King, Jun 18, 2014
  27. 14/16 fetch-pack: refactor parsing in get_ackJeff King, Jun 18, 2014
  28. Eric SunshineJun 20, 2014
  29. 15/16 git: avoid magic number with skip_prefixJeff King, Jun 18, 2014
  30. 16/16 use skip_prefix to avoid repeated calculationsJeff King, Jun 18, 2014
  31. Tanay AbhraJun 19, 2014
  32. 17/16 http-push: refactor parsing of remote object namesJeff King, Jun 19, 2014
  33. Jeff KingJun 19, 2014

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.