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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 26, 2011 at 18:27 UTC 8b8a53744f60274ef07e3a2a51995129c8d42f38
7 files changed +14 -12
builtin/branch.c
+1 -3
@@ -436,9 +436,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
436
437 commit = item->commit;
438 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);
440 sub = subject.buf;
441 }
442
builtin/checkout.c
+1 -2
@@ -300,9 +300,8 @@ static void show_local_changes(struct object *head, struct diff_options *opts)
300 static void describe_detached_head(char *msg, struct commit *commit)
301 {
302 struct strbuf sb = STRBUF_INIT;
303 - struct pretty_print_context ctx = {0};
303 parse_commit(commit);
305 - pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
304 + pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
305 fprintf(stderr, "%s %s... %s\n", msg,
306 find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
307 strbuf_release(&sb);
builtin/log.c
+1 -3
@@ -1439,9 +1439,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1439
1440 if (verbose) {
1441 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);
1443 printf("%c %s %s\n", sign,
1444 find_unique_abbrev(commit->object.sha1, abbrev),
1445 buf.buf);
builtin/shortlog.c
+1 -2
@@ -141,9 +141,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
141 const char *author = NULL, *buffer;
142 struct strbuf buf = STRBUF_INIT;
143 struct strbuf ufbuf = STRBUF_INIT;
144 - struct pretty_print_context ctx = {0};
144
146 - pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
145 + pp_commit_easy(CMIT_FMT_RAW, commit, &buf);
146 buffer = buf.buf;
147 while (*buffer && *buffer != '\n') {
148 const char *eol = strchr(buffer, '\n');
builtin/show-branch.c
+1 -2
@@ -293,8 +293,7 @@ static void show_one_commit(struct commit *commit, int no_name)
293 struct commit_name *name = commit->util;
294
295 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);
297 pretty_str = pretty.buf;
298 }
299 if (!prefixcmp(pretty_str, "[PATCH] "))
commit.h
+2
@@ -98,6 +98,8 @@ extern void format_commit_message(const struct commit *commit,
98 extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
99 struct strbuf *sb,
100 const struct pretty_print_context *context);
101 +extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
102 + struct strbuf *sb);
103 void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
104 const char *line, enum date_mode dmode,
105 const char *encoding);
pretty.c
+7
@@ -1288,3 +1288,10 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
1288
1289 free(reencoded);
1290 }
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 +}