From 674d1727305211f7ade4ade70440220f74f55162 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 10 Sep 2007 12:35:06 +0200 Subject: Rework pretty_print_commit to use strbufs instead of custom buffers. Also remove the "len" parameter, as: (1) it was used as a max boundary, and every caller used ~0u (2) we check for final NUL no matter what, so it doesn't help for speed. As a result most of the pp_* function takes 3 arguments less, and we need a lot less local variables, this makes the code way more readable, and easier to extend if needed. This patch also fixes some spacing and cosmetic issues. This patch also fixes (as a side effect) a memory leak intoruced in builtin-archive.c at commit df4a394f (fmt was xmalloc'ed and not free'd) Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- builtin-show-branch.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'builtin-show-branch.c') diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 4fa87f6081..07a0c2316b 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -259,16 +259,15 @@ static void join_revs(struct commit_list **list_p, static void show_one_commit(struct commit *commit, int no_name) { - char *pretty = NULL; + struct strbuf pretty; const char *pretty_str = "(unavailable)"; - unsigned long pretty_len = 0; struct commit_name *name = commit->util; + strbuf_init(&pretty, 0); if (commit->object.parsed) { - pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, - &pretty, &pretty_len, - 0, NULL, NULL, 0); - pretty_str = pretty; + pretty_print_commit(CMIT_FMT_ONELINE, commit, + &pretty, 0, NULL, NULL, 0); + pretty_str = pretty.buf; } if (!prefixcmp(pretty_str, "[PATCH] ")) pretty_str += 8; @@ -289,7 +288,7 @@ static void show_one_commit(struct commit *commit, int no_name) find_unique_abbrev(commit->object.sha1, 7)); } puts(pretty_str); - free(pretty); + strbuf_release(&pretty); } static char *ref_name[MAX_REVS + 1]; -- cgit v1.2.3