use strbuf_add_unique_abbrev() for adding short hashes, part 2
authorRené Scharfe <l.s.r@web.de>
Tue, 27 Sep 2016 19:11:58 +0000 (21:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Sep 2016 21:02:40 +0000 (14:02 -0700)
Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs
instead of taking detours through find_unique_abbrev() and its static
buffer. This is shorter and a bit more efficient.

1eb47f167d65d1d305b9c196a1bb40eb96117cb1 already converted six cases,
this patch covers three more.

A semantic patch for Coccinelle is included for easier checking for
new cases that might be introduced in the future.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/coccinelle/strbuf.cocci
diff.c
submodule.c
wt-status.c
index 4b7553f833f1553219432d352930a3248d01a48b..1e242983cf60c6056670993684f0994a9a0b7e0e 100644 (file)
@@ -9,3 +9,9 @@ expression E1, E2;
 @@
 - strbuf_addf(E1, "%s", E2);
 + strbuf_addstr(E1, E2);
+
+@@
+expression E1, E2, E3;
+@@
+- strbuf_addstr(E1, find_unique_abbrev(E2, E3));
++ strbuf_add_unique_abbrev(E1, E2, E3);
diff --git a/diff.c b/diff.c
index 534c12e28ea8b077c9fa305a634f7a73cf30589d..ceaac826e21b7afe6c90b41f2338c29da2320d4d 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -3086,7 +3086,7 @@ static void fill_metainfo(struct strbuf *msg,
                }
                strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
                            find_unique_abbrev(one->oid.hash, abbrev));
-               strbuf_addstr(msg, find_unique_abbrev(two->oid.hash, abbrev));
+               strbuf_add_unique_abbrev(msg, two->oid.hash, abbrev);
                if (one->mode == two->mode)
                        strbuf_addf(msg, " %06o", one->mode);
                strbuf_addf(msg, "%s\n", reset);
index 95a7ac544bee28a3cf76e17819680a099a053ec7..1e28437a5ae21d4f8a861278c974841a9b93571e 100644 (file)
@@ -374,7 +374,7 @@ void show_submodule_summary(FILE *f, const char *path,
                        find_unique_abbrev(one, DEFAULT_ABBREV));
        if (!fast_backward && !fast_forward)
                strbuf_addch(&sb, '.');
-       strbuf_addstr(&sb, find_unique_abbrev(two, DEFAULT_ABBREV));
+       strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
        if (message)
                strbuf_addf(&sb, " %s%s\n", message, reset);
        else
index 39470dadf03ca9420aa9da50849ec9c8b409e2ed..fed83e5c824886c15217a454953076aac5f2d185 100644 (file)
@@ -1326,8 +1326,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
        if (!strcmp(cb->buf.buf, "HEAD")) {
                /* HEAD is relative. Resolve it to the right reflog entry. */
                strbuf_reset(&cb->buf);
-               strbuf_addstr(&cb->buf,
-                             find_unique_abbrev(nsha1, DEFAULT_ABBREV));
+               strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);
        }
        return 1;
 }