use strbuf_add_unique_abbrev() for adding short hashes, part 2

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>

René Scharfe committed Sep 27, 2016 at 21:11 UTC f937d78553ce22505543580ae7958d9f5ffeeb89
4 files changed +9 -4
contrib/coccinelle/strbuf.cocci
+6
@@ -9,3 +9,9 @@ expression E1, E2;
9 @@
10 - strbuf_addf(E1, "%s", E2);
11 + strbuf_addstr(E1, E2);
12 +
13 +@@
14 +expression E1, E2, E3;
15 +@@
16 +- strbuf_addstr(E1, find_unique_abbrev(E2, E3));
17 ++ strbuf_add_unique_abbrev(E1, E2, E3);
diff.c
+1 -1
@@ -3086,7 +3086,7 @@ static void fill_metainfo(struct strbuf *msg,
3086 }
3087 strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
3088 find_unique_abbrev(one->oid.hash, abbrev));
3089 - strbuf_addstr(msg, find_unique_abbrev(two->oid.hash, abbrev));
3089 + strbuf_add_unique_abbrev(msg, two->oid.hash, abbrev);
3090 if (one->mode == two->mode)
3091 strbuf_addf(msg, " %06o", one->mode);
3092 strbuf_addf(msg, "%s\n", reset);
submodule.c
+1 -1
@@ -374,7 +374,7 @@ void show_submodule_summary(FILE *f, const char *path,
374 find_unique_abbrev(one, DEFAULT_ABBREV));
375 if (!fast_backward && !fast_forward)
376 strbuf_addch(&sb, '.');
377 - strbuf_addstr(&sb, find_unique_abbrev(two, DEFAULT_ABBREV));
377 + strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
378 if (message)
379 strbuf_addf(&sb, " %s%s\n", message, reset);
380 else
wt-status.c
+1 -2
@@ -1326,8 +1326,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1326 if (!strcmp(cb->buf.buf, "HEAD")) {
1327 /* HEAD is relative. Resolve it to the right reflog entry. */
1328 strbuf_reset(&cb->buf);
1329 - strbuf_addstr(&cb->buf,
1330 - find_unique_abbrev(nsha1, DEFAULT_ABBREV));
1329 + strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);
1330 }
1331 return 1;
1332 }