diff options
author | Pat Notz <patnotz@gmail.com> | 2010-11-02 13:59:07 -0600 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-04 13:53:34 -0700 |
commit | a6fa59924d154f2dcfc331357bf553e043aa0242 (patch) | |
tree | 0b70643b0e0a30f6d97acce2a9142af0a80fcde7 /builtin/commit.c | |
parent | c752e7f3e8d96a9673ad248addc9418164bd3ce6 (diff) | |
download | git-a6fa59924d154f2dcfc331357bf553e043aa0242.tar.gz |
commit: helper methods to reduce redundant blocks of code
* builtin/commit.c: Replace block of code with a one-liner call to
logmsg_reencode().
* commit.c: new function for looking up a comit by name
* pretty.c: helper methods for getting output encodings
Add helpers get_log_output_encoding() and
get_commit_output_encoding() that eliminate some messy and duplicate
if-blocks.
Signed-off-by: Pat Notz <patnotz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 66fdd22024..54fcc6d142 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -896,30 +896,14 @@ static int parse_and_validate_options(int argc, const char *argv[], if (!use_message && renew_authorship) die("--reset-author can be used only with -C, -c or --amend."); if (use_message) { - unsigned char sha1[20]; - static char utf8[] = "UTF-8"; const char *out_enc; - char *enc, *end; struct commit *commit; - if (get_sha1(use_message, sha1)) + commit = lookup_commit_reference_by_name(use_message); + if (!commit) die("could not lookup commit %s", use_message); - commit = lookup_commit_reference(sha1); - if (!commit || parse_commit(commit)) - die("could not parse commit %s", use_message); - - enc = strstr(commit->buffer, "\nencoding"); - if (enc) { - end = strchr(enc + 10, '\n'); - enc = xstrndup(enc + 10, end - (enc + 10)); - } else { - enc = utf8; - } - out_enc = git_commit_encoding ? git_commit_encoding : utf8; - - if (strcmp(out_enc, enc)) - use_message_buffer = - reencode_string(commit->buffer, out_enc, enc); + out_enc = get_commit_output_encoding(); + use_message_buffer = logmsg_reencode(commit, out_enc); /* * If we failed to reencode the buffer, just copy it @@ -929,8 +913,6 @@ static int parse_and_validate_options(int argc, const char *argv[], */ if (use_message_buffer == NULL) use_message_buffer = xstrdup(commit->buffer); - if (enc != utf8) - free(enc); } if (!!also + !!only + !!all + !!interactive > 1) |