aboutsummaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-09-19 11:38:33 -0700
committerJunio C Hamano <gitster@pobox.com>2014-09-19 11:38:33 -0700
commit9ff700ebacffc8fb8cf80daabfb6503cb24dca0b (patch)
tree63213092f97a3522450c6cbea407b80c37f6c3ca /pretty.c
parentceeacc501bc64dcdff180a9250bf2fcea3582837 (diff)
parentf4ef51739343f80c7cb0467244925b3725d65730 (diff)
downloadgit-9ff700ebacffc8fb8cf80daabfb6503cb24dca0b.tar.gz
git-9ff700ebacffc8fb8cf80daabfb6503cb24dca0b.tar.xz
Merge branch 'jk/commit-author-parsing'
Code clean-up. * jk/commit-author-parsing: determine_author_info(): copy getenv output determine_author_info(): reuse parsing functions date: use strbufs in date-formatting functions record_author_date(): use find_commit_header() record_author_date(): fix memory leak on malformed commit commit: provide a function to find a header in a buffer
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/pretty.c b/pretty.c
index 5f012a6b8..63e03b67e 100644
--- a/pretty.c
+++ b/pretty.c
@@ -554,31 +554,11 @@ static void add_merge_info(const struct pretty_print_context *pp,
strbuf_addch(sb, '\n');
}
-static char *get_header(const struct commit *commit, const char *msg,
- const char *key)
+static char *get_header(const char *msg, const char *key)
{
- int key_len = strlen(key);
- const char *line = msg;
-
- while (line) {
- const char *eol = strchrnul(line, '\n'), *next;
-
- if (line == eol)
- return NULL;
- if (!*eol) {
- warning("malformed commit (header is missing newline): %s",
- sha1_to_hex(commit->object.sha1));
- next = NULL;
- } else
- next = eol + 1;
- if (eol - line > key_len &&
- !strncmp(line, key, key_len) &&
- line[key_len] == ' ') {
- return xmemdupz(line + key_len + 1, eol - line - key_len - 1);
- }
- line = next;
- }
- return NULL;
+ size_t len;
+ const char *v = find_commit_header(msg, key, &len);
+ return v ? xmemdupz(v, len) : NULL;
}
static char *replace_encoding_header(char *buf, const char *encoding)
@@ -624,11 +604,10 @@ const char *logmsg_reencode(const struct commit *commit,
if (!output_encoding || !*output_encoding) {
if (commit_encoding)
- *commit_encoding =
- get_header(commit, msg, "encoding");
+ *commit_encoding = get_header(msg, "encoding");
return msg;
}
- encoding = get_header(commit, msg, "encoding");
+ encoding = get_header(msg, "encoding");
if (commit_encoding)
*commit_encoding = encoding;
use_encoding = encoding ? encoding : utf8;