[PATCH 7/9] for-each-ref: prepoplulate all atoms before show_ref()
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- May 19, 2013, 10:27 UTC
- Message-ID
- <1368959235-27777-8-git-send-email-pclouds@gmail.com>
- In-Reply-To
- <1368959235-27777-1-git-send-email-pclouds@gmail.com>
By the time show_ref() is called, atom values for all refs are ready. This can be taken advantage of later.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- builtin/for-each-ref.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index db5c211..a9d189c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1010,15 +1010,24 @@ static void show_ref(struct strbuf *sb, struct refinfo *info, static void show_refs(struct refinfo **refs, int maxcount, const char *format, int quote_style) { - struct strbuf sb = STRBUF_INIT; + struct strbuf *sb; int i; + sb = xmalloc(sizeof(*sb) * maxcount); for (i = 0; i < maxcount; i++) { - strbuf_reset(&sb); - show_ref(&sb, refs[i], format, quote_style); - fputs(sb.buf, stdout); + strbuf_init(sb + i, 256); + if (!refs[i]->value) { + populate_value(refs[i]); + fill_missing_values(refs[i]->value); + } + } + + for (i = 0; i < maxcount; i++) { + show_ref(sb + i, refs[i], format, quote_style); + fputs(sb[i].buf, stdout); + strbuf_release(sb + i); } - strbuf_release(&sb); + free(sb); } static struct ref_sort *default_sort(void)
-- 1.8.2.83.gc99314b