Skip to content

Commit f0798e6

Browse files
committed
Merge branch 'rs/cocci'
Code clean-up with help from coccinelle tool continues. * rs/cocci: coccicheck: make transformation for strbuf_addf(sb, "...") more precise use strbuf_add_unique_abbrev() for adding short hashes, part 2 use strbuf_addstr() instead of strbuf_addf() with "%s", part 2 gitignore: ignore output files of coccicheck make target
2 parents 578e602 + 353d84c commit f0798e6

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

builtin/submodule--helper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
753753
if (suc->recursive_prefix)
754754
strbuf_addf(&sb, "%s/%s", suc->recursive_prefix, ce->name);
755755
else
756-
strbuf_addf(&sb, "%s", ce->name);
756+
strbuf_addstr(&sb, ce->name);
757757
strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf);
758758
strbuf_addch(out, '\n');
759759
goto cleanup;

contrib/coccinelle/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.patch*

contrib/coccinelle/strbuf.cocci

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1+
@ strbuf_addf_with_format_only @
2+
expression E;
3+
constant fmt;
4+
@@
5+
strbuf_addf(E,
6+
(
7+
fmt
8+
|
9+
_(fmt)
10+
)
11+
);
12+
13+
@ script:python @
14+
fmt << strbuf_addf_with_format_only.fmt;
15+
@@
16+
cocci.include_match("%" not in fmt)
17+
18+
@ extends strbuf_addf_with_format_only @
19+
@@
20+
- strbuf_addf
21+
+ strbuf_addstr
22+
(E,
23+
(
24+
fmt
25+
|
26+
_(fmt)
27+
)
28+
);
29+
130
@@
231
expression E1, E2;
332
@@
4-
- strbuf_addf(E1, E2);
33+
- strbuf_addf(E1, "%s", E2);
534
+ strbuf_addstr(E1, E2);
35+
36+
@@
37+
expression E1, E2, E3;
38+
@@
39+
- strbuf_addstr(E1, find_unique_abbrev(E2, E3));
40+
+ strbuf_add_unique_abbrev(E1, E2, E3);

diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,7 @@ static void fill_metainfo(struct strbuf *msg,
31093109
}
31103110
strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
31113111
find_unique_abbrev(one->oid.hash, abbrev));
3112-
strbuf_addstr(msg, find_unique_abbrev(two->oid.hash, abbrev));
3112+
strbuf_add_unique_abbrev(msg, two->oid.hash, abbrev);
31133113
if (one->mode == two->mode)
31143114
strbuf_addf(msg, " %06o", one->mode);
31153115
strbuf_addf(msg, "%s\n", reset);

submodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static void show_submodule_header(FILE *f, const char *path,
396396
find_unique_abbrev(one->hash, DEFAULT_ABBREV));
397397
if (!fast_backward && !fast_forward)
398398
strbuf_addch(&sb, '.');
399-
strbuf_addf(&sb, "%s", find_unique_abbrev(two->hash, DEFAULT_ABBREV));
399+
strbuf_add_unique_abbrev(&sb, two->hash, DEFAULT_ABBREV);
400400
if (message)
401401
strbuf_addf(&sb, " %s%s\n", message, reset);
402402
else

wt-status.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
13831383
if (!strcmp(cb->buf.buf, "HEAD")) {
13841384
/* HEAD is relative. Resolve it to the right reflog entry. */
13851385
strbuf_reset(&cb->buf);
1386-
strbuf_addstr(&cb->buf,
1387-
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
1386+
strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);
13881387
}
13891388
return 1;
13901389
}

0 commit comments

Comments
 (0)