Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Junio C Hamano
Jeff King writes: > What I didn't want to do is deal with it in each callsite, like: OK. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Jeff King
On Wed, Aug 27, 2014 at 12:26:56PM -0700, Junio C Hamano wrote: > I don't mind returning -1 in out_len and have the callers check. > That way will allow callers to easily diagnose this > > tree $T > author $GIT_AUTHOR_IDENT > committer $GIT_COMMITTER_IDENT > encoding enc

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Junio C Hamano
Jeff King writes: > I think they are a direct tradeoff. If you include only the first line, > then callers who want multiple lines have to keep parsing. If you > include multiple lines, then callers who care only about the first line > will have to re-find the newline rather than just using "out

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Jeff King
On Wed, Aug 27, 2014 at 12:05:06PM -0700, Junio C Hamano wrote: > > If you mean including continuation lines in the output, I don't think > > that's a good idea here. It would mean the function would have to copy > > the value out (to get rid of the continuation whitespace) rather than > > point d

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Junio C Hamano
Jeff King writes: > On Wed, Aug 27, 2014 at 10:30:22AM -0700, Junio C Hamano wrote: > >> Jeff King writes: >> >> > +const char *find_commit_header(const char *msg, const char *key, size_t >> > *out_len) >> [...] >> >> Hmph. Does this have to worry about continuation lines in the >> header pa

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Jeff King
On Wed, Aug 27, 2014 at 02:00:16PM -0400, Jeff King wrote: > That may be something some callers want, but they should build it > separately around this find_commit_header, so that callers that want a > single line (like "encoding" or "author") do not have to pay the price. > I didn't bother buildi

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Jeff King
On Wed, Aug 27, 2014 at 10:30:22AM -0700, Junio C Hamano wrote: > Jeff King writes: > > > +const char *find_commit_header(const char *msg, const char *key, size_t > > *out_len) > [...] > > Hmph. Does this have to worry about continuation lines in the > header part e.g. mergetag? If the origi

Re: [PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Junio C Hamano
Jeff King writes: > +const char *find_commit_header(const char *msg, const char *key, size_t > *out_len) > +{ > + int key_len = strlen(key); > + const char *line = msg; > + > + while (line) { > + const char *eol = strchrnul(line, '\n'); > + > + if (line == eol

[PATCH v2 1/6] commit: provide a function to find a header in a buffer

2014-08-27 Thread Jeff King
Usually when we parse a commit, we read it line by line and handle each individual line (e.g., parse_commit and parse_commit_header). Sometimes, however, we only care about extracting a single header. Code in this situation is stuck doing an ad-hoc parse of the commit buffer. Let's provide a reus