From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Erik Faye-Lund <kusmabite@gmail.com>
Subject: [PATCH v2 3/6] record_author_info: use find_commit_header
Date: Wed, 27 Aug 2014 03:56:55 -0400 [thread overview]
Message-ID: <20140827075654.GC26384@peff.net> (raw)
In-Reply-To: <20140827075503.GA19521@peff.net>
This saves us some manual parsing and makes the code more
readable.
Signed-off-by: Jeff King <peff@peff.net>
---
commit.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/commit.c b/commit.c
index 4ff8c66..9416d84 100644
--- a/commit.c
+++ b/commit.c
@@ -584,25 +584,19 @@ define_commit_slab(author_date_slab, unsigned long);
static void record_author_date(struct author_date_slab *author_date,
struct commit *commit)
{
- const char *buf, *line_end, *ident_line;
const char *buffer = get_commit_buffer(commit, NULL);
struct ident_split ident;
+ const char *ident_line;
+ size_t ident_len;
char *date_end;
unsigned long date;
- for (buf = buffer; buf; buf = line_end + 1) {
- line_end = strchrnul(buf, '\n');
- if (!skip_prefix(buf, "author ", &ident_line)) {
- if (!line_end[0] || line_end[1] == '\n')
- goto fail_exit; /* end of header */
- continue;
- }
- if (split_ident_line(&ident,
- ident_line, line_end - ident_line) ||
- !ident.date_begin || !ident.date_end)
- goto fail_exit; /* malformed "author" line */
- break;
- }
+ ident_line = find_commit_header(buffer, "author", &ident_len);
+ if (!ident_line)
+ goto fail_exit; /* no author line */
+ if (split_ident_line(&ident, ident_line, ident_len) ||
+ !ident.date_begin || !ident.date_end)
+ goto fail_exit; /* malformed "author" line */
date = strtoul(ident.date_begin, &date_end, 10);
if (date_end != ident.date_end)
--
2.1.0.346.ga0367b9
next prev parent reply other threads:[~2014-08-27 7:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-27 7:55 [PATCH v2 0/6] clean up author parsing Jeff King
2014-08-27 7:56 ` [PATCH v2 1/6] commit: provide a function to find a header in a buffer Jeff King
2014-08-27 17:30 ` Junio C Hamano
2014-08-27 18:00 ` Jeff King
2014-08-27 18:16 ` Jeff King
2014-08-27 19:05 ` Junio C Hamano
2014-08-27 19:14 ` Jeff King
2014-08-27 19:26 ` Junio C Hamano
2014-08-27 19:38 ` Jeff King
2014-08-27 19:41 ` Junio C Hamano
2014-08-27 7:56 ` [PATCH v2 2/6] record_author_info: fix memory leak on malformed commit Jeff King
2014-08-27 7:56 ` Jeff King [this message]
2014-08-27 7:57 ` [PATCH v2 4/6] use strbufs in date functions Jeff King
2014-08-27 7:57 ` [PATCH v2 5/6] determine_author_info: reuse parsing functions Jeff King
2014-08-27 7:57 ` [PATCH v2 6/6] determine_author_info: copy getenv output Jeff King
2014-08-27 9:06 ` [PATCH v2 0/6] clean up author parsing Christian Couder
2014-08-27 14:18 ` Jeff King
2014-08-27 17:36 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140827075654.GC26384@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=kusmabite@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).