]> git.ipfire.org Git - thirdparty/git.git/commit - pretty.c
commit: provide a function to find a header in a buffer
authorJeff King <peff@peff.net>
Wed, 27 Aug 2014 07:56:01 +0000 (03:56 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Aug 2014 17:25:28 +0000 (10:25 -0700)
commitfe6eb7f2c506190c817407accf27834005a57f2b
treefde1f530c243bfa9b71762fe29862528320f7ec4
parent6c4ab27f2378ce67940b4496365043119d7ffff2
commit: provide a function to find a header in a buffer

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 reusable function to locate a header within
the commit.  The code is modeled after pretty.c's
get_header, which is used to extract the encoding.

Since some callers may not have the "struct commit" to go
along with the buffer, we drop that parameter.  The only
thing lost is a warning for truncated commits, but that's
OK.  This shouldn't happen in practice, and even if it does,
there's no particular reason that this function needs to
complain about it. It either finds the header it was asked
for, or it doesn't (and in the latter case, the caller will
typically complain).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c
commit.h
pretty.c