Skip to content

Commit 92d52fa

Browse files
rscharfegitster
authored andcommitted
use strbuf_addstr() instead of strbuf_addf() with "%s", part 2
Replace uses of strbuf_addf() for adding strings with more lightweight strbuf_addstr() calls. This is shorter and makes the intent clearer. bc57b9c already converted three cases, this patch covers two 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 7f2817d commit 92d52fa

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
637637
if (suc->recursive_prefix)
638638
strbuf_addf(&sb, "%s/%s", suc->recursive_prefix, ce->name);
639639
else
640-
strbuf_addf(&sb, "%s", ce->name);
640+
strbuf_addstr(&sb, ce->name);
641641
strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf);
642642
strbuf_addch(out, '\n');
643643
goto cleanup;

contrib/coccinelle/strbuf.cocci

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ expression E1, E2;
33
@@
44
- strbuf_addf(E1, E2);
55
+ strbuf_addstr(E1, E2);
6+
7+
@@
8+
expression E1, E2;
9+
@@
10+
- strbuf_addf(E1, "%s", E2);
11+
+ strbuf_addstr(E1, E2);

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_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV));
377+
strbuf_addstr(&sb, find_unique_abbrev(two, DEFAULT_ABBREV));
378378
if (message)
379379
strbuf_addf(&sb, " %s%s\n", message, reset);
380380
else

0 commit comments

Comments
 (0)