Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 5a10d23

Browse files
pcloudsgitster
authored andcommitted
pretty: save commit encoding from logmsg_reencode if the caller needs it
The commit encoding is parsed by logmsg_reencode, there's no need for the caller to re-parse it again. The reencoded message now has the new encoding, not the original one. The caller would need to read commit object again before parsing. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1468a58 commit 5a10d23

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ static void get_commit_info(struct commit *commit,
14251425
commit_info_init(ret);
14261426

14271427
encoding = get_log_output_encoding();
1428-
message = logmsg_reencode(commit, encoding);
1428+
message = logmsg_reencode(commit, NULL, encoding);
14291429
get_ac_line(message, "\nauthor ",
14301430
&ret->author, &ret->author_mail,
14311431
&ret->author_time, &ret->author_tz);

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ static const char *read_commit_message(const char *name)
955955
if (!commit)
956956
die(_("could not lookup commit %s"), name);
957957
out_enc = get_commit_output_encoding();
958-
return logmsg_reencode(commit, out_enc);
958+
return logmsg_reencode(commit, NULL, out_enc);
959959
}
960960

961961
static int parse_and_validate_options(int argc, const char *argv[],

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct userformat_want {
101101
extern int has_non_ascii(const char *text);
102102
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
103103
extern char *logmsg_reencode(const struct commit *commit,
104+
char **commit_encoding,
104105
const char *output_encoding);
105106
extern void logmsg_free(char *msg, const struct commit *commit);
106107
extern void get_commit_format(const char *arg, struct rev_info *);

pretty.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ static char *replace_encoding_header(char *buf, const char *encoding)
594594
}
595595

596596
char *logmsg_reencode(const struct commit *commit,
597+
char **commit_encoding,
597598
const char *output_encoding)
598599
{
599600
static const char *utf8 = "UTF-8";
@@ -615,9 +616,15 @@ char *logmsg_reencode(const struct commit *commit,
615616
sha1_to_hex(commit->object.sha1), typename(type));
616617
}
617618

618-
if (!output_encoding || !*output_encoding)
619+
if (!output_encoding || !*output_encoding) {
620+
if (commit_encoding)
621+
*commit_encoding =
622+
get_header(commit, msg, "encoding");
619623
return msg;
624+
}
620625
encoding = get_header(commit, msg, "encoding");
626+
if (commit_encoding)
627+
*commit_encoding = encoding;
621628
use_encoding = encoding ? encoding : utf8;
622629
if (same_encoding(use_encoding, output_encoding)) {
623630
/*
@@ -658,7 +665,8 @@ char *logmsg_reencode(const struct commit *commit,
658665
if (out)
659666
out = replace_encoding_header(out, output_encoding);
660667

661-
free(encoding);
668+
if (!commit_encoding)
669+
free(encoding);
662670
/*
663671
* If the re-encoding failed, out might be NULL here; in that
664672
* case we just return the commit message verbatim.
@@ -1288,7 +1296,7 @@ void format_commit_message(const struct commit *commit,
12881296
context.commit = commit;
12891297
context.pretty_ctx = pretty_ctx;
12901298
context.wrap_start = sb->len;
1291-
context.message = logmsg_reencode(commit, output_enc);
1299+
context.message = logmsg_reencode(commit, NULL, output_enc);
12921300

12931301
strbuf_expand(sb, format, format_commit_item, &context);
12941302
rewrap_message_tail(sb, &context, 0, 0, 0);
@@ -1451,7 +1459,7 @@ void pretty_print_commit(const struct pretty_print_context *pp,
14511459
}
14521460

14531461
encoding = get_log_output_encoding();
1454-
msg = reencoded = logmsg_reencode(commit, encoding);
1462+
msg = reencoded = logmsg_reencode(commit, NULL, encoding);
14551463

14561464
if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
14571465
indent = 0;

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
22912291
* in it.
22922292
*/
22932293
encoding = get_log_output_encoding();
2294-
message = logmsg_reencode(commit, encoding);
2294+
message = logmsg_reencode(commit, NULL, encoding);
22952295

22962296
/* Copy the commit to temporary if we are using "fake" headers */
22972297
if (buf.len)

0 commit comments

Comments
 (0)