Skip to content

Commit f937d78

Browse files
rscharfegitster
authored andcommitted
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. 1eb47f1 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92d52fa commit f937d78

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

contrib/coccinelle/strbuf.cocci

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ expression E1, E2;
99
@@
1010
- strbuf_addf(E1, "%s", E2);
1111
+ 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3086,7 +3086,7 @@ static void fill_metainfo(struct strbuf *msg,
30863086
}
30873087
strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
30883088
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);
30903090
if (one->mode == two->mode)
30913091
strbuf_addf(msg, " %06o", one->mode);
30923092
strbuf_addf(msg, "%s\n", reset);

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void show_submodule_summary(FILE *f, const char *path,
374374
find_unique_abbrev(one, DEFAULT_ABBREV));
375375
if (!fast_backward && !fast_forward)
376376
strbuf_addch(&sb, '.');
377-
strbuf_addstr(&sb, find_unique_abbrev(two, DEFAULT_ABBREV));
377+
strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
378378
if (message)
379379
strbuf_addf(&sb, " %s%s\n", message, reset);
380380
else

wt-status.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
13261326
if (!strcmp(cb->buf.buf, "HEAD")) {
13271327
/* HEAD is relative. Resolve it to the right reflog entry. */
13281328
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);
13311330
}
13321331
return 1;
13331332
}

0 commit comments

Comments
 (0)