Skip to content

Commit 8b8a537

Browse files
peffgitster
authored andcommitted
pretty: add pp_commit_easy function for simple callers
Many callers don't actually care about the pretty print context at all; let's just give them a simple way of pretty-printing a commit without having to create a context struct. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b38456 commit 8b8a537

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

builtin/branch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
436436

437437
commit = item->commit;
438438
if (commit && !parse_commit(commit)) {
439-
struct pretty_print_context ctx = {0};
440-
pretty_print_commit(CMIT_FMT_ONELINE, commit,
441-
&subject, &ctx);
439+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
442440
sub = subject.buf;
443441
}
444442

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,8 @@ static void show_local_changes(struct object *head, struct diff_options *opts)
300300
static void describe_detached_head(char *msg, struct commit *commit)
301301
{
302302
struct strbuf sb = STRBUF_INIT;
303-
struct pretty_print_context ctx = {0};
304303
parse_commit(commit);
305-
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
304+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
306305
fprintf(stderr, "%s %s... %s\n", msg,
307306
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
308307
strbuf_release(&sb);

builtin/log.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
14391439

14401440
if (verbose) {
14411441
struct strbuf buf = STRBUF_INIT;
1442-
struct pretty_print_context ctx = {0};
1443-
pretty_print_commit(CMIT_FMT_ONELINE, commit,
1444-
&buf, &ctx);
1442+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
14451443
printf("%c %s %s\n", sign,
14461444
find_unique_abbrev(commit->object.sha1, abbrev),
14471445
buf.buf);

builtin/shortlog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
141141
const char *author = NULL, *buffer;
142142
struct strbuf buf = STRBUF_INIT;
143143
struct strbuf ufbuf = STRBUF_INIT;
144-
struct pretty_print_context ctx = {0};
145144

146-
pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
145+
pp_commit_easy(CMIT_FMT_RAW, commit, &buf);
147146
buffer = buf.buf;
148147
while (*buffer && *buffer != '\n') {
149148
const char *eol = strchr(buffer, '\n');

builtin/show-branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ static void show_one_commit(struct commit *commit, int no_name)
293293
struct commit_name *name = commit->util;
294294

295295
if (commit->object.parsed) {
296-
struct pretty_print_context ctx = {0};
297-
pretty_print_commit(CMIT_FMT_ONELINE, commit, &pretty, &ctx);
296+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
298297
pretty_str = pretty.buf;
299298
}
300299
if (!prefixcmp(pretty_str, "[PATCH] "))

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ extern void format_commit_message(const struct commit *commit,
9898
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
9999
struct strbuf *sb,
100100
const struct pretty_print_context *context);
101+
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
102+
struct strbuf *sb);
101103
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
102104
const char *line, enum date_mode dmode,
103105
const char *encoding);

pretty.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,3 +1288,10 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
12881288

12891289
free(reencoded);
12901290
}
1291+
1292+
void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
1293+
struct strbuf *sb)
1294+
{
1295+
struct pretty_print_context pp = {0};
1296+
pretty_print_commit(fmt, commit, sb, &pp);
1297+
}

0 commit comments

Comments
 (0)