From: Junio C Hamano Date: Wed, 13 Oct 2010 21:59:21 GMT Subject: Re: [PATCHv5 1/8] commit.c: prefer get_header() to manual searching Message-ID: <7vocaxiwjq.fsf@alter.siamese.dyndns.org> In-Reply-To: <1286478657-61581-2-git-send-email-patnotz@gmail.com> "Pat Notz" writes: > diff --git a/commit.h b/commit.h > index 9113bbe..c246c94 100644 > --- a/commit.h > +++ b/commit.h > @@ -87,6 +87,7 @@ struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ > extern char *reencode_commit_message(const struct commit *commit, > const char **encoding_p); > extern void get_commit_format(const char *arg, struct rev_info *); > +extern char *get_header(const struct commit *commit, const char *key); The name of the function was perfectly Ok within the context of pretty.c, as the file was about commit log message and nothing else, but it is a bit mindless to expose it to outside world still with such a generic name. But the bigger question is why the patch doesn't get rid of the bulk of the body of the block and replace it with a call to logmsg_reencode(). diff --git a/builtin/commit.c b/builtin/commit.c index 66fdd22..021fb1c 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -899,7 +899,6 @@ static int parse_and_validate_options(int argc, const char *argv[], 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)) @@ -908,18 +907,8 @@ static int parse_and_validate_options(int argc, const char *argv[], 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); + use_message_buffer = logmsg_reencode(commit, out_enc); /* * If we failed to reencode the buffer, just copy it @@ -929,8 +918,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)