[PATCH 7/9] for-each-ref: prepoplulate all atoms before show_ref()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]