Skip to content

Commit c8fd220

Browse files
committed
Merge branch 'rs/cocci' into maint
Code cleanup. * rs/cocci: use strbuf_add_unique_abbrev() for adding short hashes, part 3 remove unnecessary NULL check before free(3) 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 use strbuf_addstr() for adding constant strings to a strbuf, part 2 add coccicheck make target contrib/coccinelle: fix semantic patch for oid_to_hex_r()
2 parents 0582a34 + a94bb68 commit c8fd220

File tree

15 files changed

+99
-45
lines changed

15 files changed

+99
-45
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ CURL_CONFIG = curl-config
462462
PTHREAD_LIBS = -lpthread
463463
PTHREAD_CFLAGS =
464464
GCOV = gcov
465+
SPATCH = spatch
465466

466467
export TCL_PATH TCLTK_PATH
467468

@@ -2308,6 +2309,18 @@ check: common-cmds.h
23082309
exit 1; \
23092310
fi
23102311

2312+
C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
2313+
%.cocci.patch: %.cocci $(C_SOURCES)
2314+
@echo ' ' SPATCH $<; \
2315+
for f in $(C_SOURCES); do \
2316+
$(SPATCH) --sp-file $< $$f; \
2317+
done >$@ 2>$@.log; \
2318+
if test -s $@; \
2319+
then \
2320+
echo ' ' SPATCH result: $@; \
2321+
fi
2322+
coccicheck: $(patsubst %.cocci,%.cocci.patch,$(wildcard contrib/coccinelle/*.cocci))
2323+
23112324
### Installation rules
23122325

23132326
ifneq ($(filter /%,$(firstword $(template_dir))),)
@@ -2499,6 +2512,7 @@ clean: profile-clean coverage-clean
24992512
$(RM) -r $(GIT_TARNAME) .doc-tmp-dir
25002513
$(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
25012514
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
2515+
$(RM) contrib/coccinelle/*.cocci.patch*
25022516
$(MAKE) -C Documentation/ clean
25032517
ifndef NO_PERL
25042518
$(MAKE) -C gitweb clean

builtin/fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ static void shortlog(const char *name,
395395

396396
for (i = 0; i < subjects.nr; i++)
397397
if (i >= limit)
398-
strbuf_addf(out, " ...\n");
398+
strbuf_addstr(out, " ...\n");
399399
else
400400
strbuf_addf(out, " %s\n", subjects.items[i].string);
401401

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static void write_merge_state(struct commit_list *remoteheads)
940940

941941
strbuf_reset(&buf);
942942
if (fast_forward == FF_NO)
943-
strbuf_addf(&buf, "no-ff");
943+
strbuf_addstr(&buf, "no-ff");
944944
write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
945945
}
946946

builtin/submodule--helper.c

Lines changed: 4 additions & 3 deletions
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;
@@ -749,8 +749,9 @@ static int update_clone_get_next_task(struct child_process *child,
749749
ce = suc->failed_clones[index];
750750
if (!prepare_to_clone_next_submodule(ce, child, suc, err)) {
751751
suc->current ++;
752-
strbuf_addf(err, "BUG: submodule considered for cloning,"
753-
"doesn't need cloning any more?\n");
752+
strbuf_addstr(err, "BUG: submodule considered for "
753+
"cloning, doesn't need cloning "
754+
"any more?\n");
754755
return 0;
755756
}
756757
p = xmalloc(sizeof(*p));

contrib/coccinelle/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.patch*

contrib/coccinelle/free.cocci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@@
2+
expression E;
3+
@@
4+
- if (E)
5+
free(E);

contrib/coccinelle/object_id.cocci

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ expression E1;
2323
+ oid_to_hex(E1)
2424

2525
@@
26-
expression E1;
26+
expression E1, E2;
2727
@@
28-
- sha1_to_hex_r(E1.hash)
29-
+ oid_to_hex_r(&E1)
28+
- sha1_to_hex_r(E1, E2.hash)
29+
+ oid_to_hex_r(E1, &E2)
3030

3131
@@
32-
expression E1;
32+
expression E1, E2;
3333
@@
34-
- sha1_to_hex_r(E1->hash)
35-
+ oid_to_hex_r(E1)
34+
- sha1_to_hex_r(E1, E2->hash)
35+
+ oid_to_hex_r(E1, E2)
3636

3737
@@
3838
expression E1;

contrib/coccinelle/strbuf.cocci

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
30+
@@
31+
expression E1, E2;
32+
@@
33+
- strbuf_addf(E1, "%s", E2);
34+
+ 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ static void fill_metainfo(struct strbuf *msg,
30763076
}
30773077
strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
30783078
find_unique_abbrev(one->oid.hash, abbrev));
3079-
strbuf_addstr(msg, find_unique_abbrev(two->oid.hash, abbrev));
3079+
strbuf_add_unique_abbrev(msg, two->oid.hash, abbrev);
30803080
if (one->mode == two->mode)
30813081
strbuf_addf(msg, " %06o", one->mode);
30823082
strbuf_addf(msg, "%s\n", reset);

merge-recursive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
202202
strbuf_addf(&o->obuf, "virtual %s\n",
203203
merge_remote_util(commit)->name);
204204
else {
205-
strbuf_addf(&o->obuf, "%s ",
206-
find_unique_abbrev(commit->object.oid.hash,
207-
DEFAULT_ABBREV));
205+
strbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash,
206+
DEFAULT_ABBREV);
207+
strbuf_addch(&o->obuf, ' ');
208208
if (parse_commit(commit) != 0)
209-
strbuf_addf(&o->obuf, _("(bad commit)\n"));
209+
strbuf_addstr(&o->obuf, _("(bad commit)\n"));
210210
else {
211211
const char *title;
212212
const char *msg = get_commit_buffer(commit, NULL);

0 commit comments

Comments
 (0)