Skip to content

Commit 938ecaa

Browse files
committed
Merge branch 'jk/pretty-lazy-load-commit'
Some pretty-format specifiers do not need the data in commit object (e.g. "%H"), but we were over-eager to load and parse it, which has been made even lazier. * jk/pretty-lazy-load-commit: pretty: lazy-load commit data when expanding user-format
2 parents 2f79462 + 018b9de commit 938ecaa

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

pretty.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ enum trunc_type {
783783
};
784784

785785
struct format_commit_context {
786+
struct repository *repository;
786787
const struct commit *commit;
787788
const struct pretty_print_context *pretty_ctx;
788789
unsigned commit_header_parsed:1;
@@ -1373,10 +1374,13 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
13731374
return 2;
13741375
}
13751376

1376-
13771377
/* For the rest we have to parse the commit header. */
1378-
if (!c->commit_header_parsed)
1378+
if (!c->commit_header_parsed) {
1379+
msg = c->message =
1380+
repo_logmsg_reencode(c->repository, commit,
1381+
&c->commit_encoding, "UTF-8");
13791382
parse_commit_header(c);
1383+
}
13801384

13811385
switch (placeholder[0]) {
13821386
case 'a': /* author ... */
@@ -1667,25 +1671,22 @@ void repo_format_commit_message(struct repository *r,
16671671
const struct pretty_print_context *pretty_ctx)
16681672
{
16691673
struct format_commit_context context = {
1674+
.repository = r,
16701675
.commit = commit,
16711676
.pretty_ctx = pretty_ctx,
16721677
.wrap_start = sb->len
16731678
};
16741679
const char *output_enc = pretty_ctx->output_encoding;
16751680
const char *utf8 = "UTF-8";
16761681

1677-
/*
1678-
* convert a commit message to UTF-8 first
1679-
* as far as 'format_commit_item' assumes it in UTF-8
1680-
*/
1681-
context.message = repo_logmsg_reencode(r, commit,
1682-
&context.commit_encoding,
1683-
utf8);
1684-
16851682
strbuf_expand(sb, format, format_commit_item, &context);
16861683
rewrap_message_tail(sb, &context, 0, 0, 0);
16871684

1688-
/* then convert a commit message to an actual output encoding */
1685+
/*
1686+
* Convert output to an actual output encoding; note that
1687+
* format_commit_item() will always use UTF-8, so we don't
1688+
* have to bother if that's what the output wants.
1689+
*/
16891690
if (output_enc) {
16901691
if (same_encoding(utf8, output_enc))
16911692
output_enc = NULL;

t/perf/p4205-log-pretty-formats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_description='Tests the performance of various pretty format placeholders'
66

77
test_perf_default_repo
88

9-
for format in %H %h %T %t %P %p %h-%h-%h
9+
for format in %H %h %T %t %P %p %h-%h-%h %an-%ae-%s
1010
do
1111
test_perf "log with $format" "
1212
git log --format=\"$format\" >/dev/null

0 commit comments

Comments
 (0)