aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-01-26 04:44:06 -0500
committerJunio C Hamano <gitster@pobox.com>2013-01-26 13:28:21 -0800
commitdd0d388c44c28ebc021a24eeddc60287d4ea249c (patch)
treec2899c33f7bebae72fcc57d5d120a781a63b8ac5 /builtin
parent200ebe362cda2a520219f998d4b2c44767992bdb (diff)
downloadgit-dd0d388c44c28ebc021a24eeddc60287d4ea249c.tar.gz
git-dd0d388c44c28ebc021a24eeddc60287d4ea249c.tar.xz
logmsg_reencode: never return NULL
The logmsg_reencode function will return the reencoded commit buffer, or NULL if reencoding failed or no reencoding was necessary. Since every caller then ends up checking for NULL and just using the commit's original buffer, anyway, we can be a bit more helpful and just return that buffer when we would have returned NULL. Since the resulting string may or may not need to be freed, we introduce a logmsg_free, which checks whether the buffer came from the commit object or not (callers either implemented the same check already, or kept two separate pointers, one to mark the buffer to be used, and one for the to-be-freed string). Pushing this logic into logmsg_* simplifies the callers, and will let future patches lazily load the commit buffer in a single place. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/blame.c9
-rw-r--r--builtin/commit.c14
2 files changed, 6 insertions, 17 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index b431ba320..962e4e3cd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1420,7 +1420,7 @@ static void get_commit_info(struct commit *commit,
{
int len;
const char *subject, *encoding;
- char *reencoded, *message;
+ char *message;
commit_info_init(ret);
@@ -1438,14 +1438,13 @@ static void get_commit_info(struct commit *commit,
sha1_to_hex(commit->object.sha1));
}
encoding = get_log_output_encoding();
- reencoded = logmsg_reencode(commit, encoding);
- message = reencoded ? reencoded : commit->buffer;
+ message = logmsg_reencode(commit, encoding);
get_ac_line(message, "\nauthor ",
&ret->author, &ret->author_mail,
&ret->author_time, &ret->author_tz);
if (!detailed) {
- free(reencoded);
+ logmsg_free(message, commit);
return;
}
@@ -1459,7 +1458,7 @@ static void get_commit_info(struct commit *commit,
else
strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1));
- free(reencoded);
+ logmsg_free(message, commit);
}
/*
diff --git a/builtin/commit.c b/builtin/commit.c
index fbbb40fff..6169f1e2d 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -946,24 +946,14 @@ static void handle_untracked_files_arg(struct wt_status *s)
static const char *read_commit_message(const char *name)
{
- const char *out_enc, *out;
+ const char *out_enc;
struct commit *commit;
commit = lookup_commit_reference_by_name(name);
if (!commit)
die(_("could not lookup commit %s"), name);
out_enc = get_commit_output_encoding();
- out = logmsg_reencode(commit, out_enc);
-
- /*
- * If we failed to reencode the buffer, just copy it
- * byte for byte so the user can try to fix it up.
- * This also handles the case where input and output
- * encodings are identical.
- */
- if (out == NULL)
- out = commit->buffer;
- return out;
+ return logmsg_reencode(commit, out_enc);
}
static int parse_and_validate_options(int argc, const char *argv[],