Skip to content

Commit dd5d052

Browse files
szedergitster
authored andcommitted
coccicheck: introduce 'pending' semantic patches
Teach `make coccicheck` to avoid patches named "*.pending.cocci" and handle them separately in a new `make coccicheck-pending` instead. This means that we can separate "critical" patches from "FYI" patches. The former target can continue causing Travis to fail its static analysis job, while the latter can let us keep an eye on ongoing (pending) transitions without them causing too much fallout. Document the intended use-cases around these two targets. As the process around the pending patches is not yet fully explored, leave that out. Signed-off-by: SZEDER Gábor <[email protected]> Based-on-work-by: SZEDER Gábor <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8858448 commit dd5d052

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,9 +2740,12 @@ endif
27402740
then \
27412741
echo ' ' SPATCH result: $@; \
27422742
fi
2743-
coccicheck: $(addsuffix .patch,$(wildcard contrib/coccinelle/*.cocci))
2743+
coccicheck: $(addsuffix .patch,$(filter-out %.pending.cocci,$(wildcard contrib/coccinelle/*.cocci)))
27442744

2745-
.PHONY: coccicheck
2745+
# See contrib/coccinelle/README
2746+
coccicheck-pending: $(addsuffix .patch,$(wildcard contrib/coccinelle/*.pending.cocci))
2747+
2748+
.PHONY: coccicheck coccicheck-pending
27462749

27472750
### Installation rules
27482751

contrib/coccinelle/README

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
11
This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
22
semantic patches that might be useful to developers.
3+
4+
There are two types of semantic patches:
5+
6+
* Using the semantic transformation to check for bad patterns in the code;
7+
The target 'make coccicheck' is designed to check for these patterns and
8+
it is expected that any resulting patch indicates a regression.
9+
The patches resulting from 'make coccicheck' are small and infrequent,
10+
so once they are found, they can be sent to the mailing list as per usual.
11+
12+
Example for introducing new patterns:
13+
67947c34ae (convert "hashcmp() != 0" to "!hasheq()", 2018-08-28)
14+
b84c783882 (fsck: s/++i > 1/i++/, 2018-10-24)
15+
16+
Example of fixes using this approach:
17+
248f66ed8e (run-command: use strbuf_addstr() for adding a string to
18+
a strbuf, 2018-03-25)
19+
f919ffebed (Use MOVE_ARRAY, 2018-01-22)
20+
21+
These types of semantic patches are usually part of testing, c.f.
22+
0860a7641b (travis-ci: fail if Coccinelle static analysis found something
23+
to transform, 2018-07-23)
24+
25+
* Using semantic transformations in large scale refactorings throughout
26+
the code base.
27+
28+
When applying the semantic patch into a real patch, sending it to the
29+
mailing list in the usual way, such a patch would be expected to have a
30+
lot of textual and semantic conflicts as such large scale refactorings
31+
change function signatures that are used widely in the code base.
32+
A textual conflict would arise if surrounding code near any call of such
33+
function changes. A semantic conflict arises when other patch series in
34+
flight introduce calls to such functions.
35+
36+
So to aid these large scale refactorings, semantic patches can be used.
37+
However we do not want to store them in the same place as the checks for
38+
bad patterns, as then automated builds would fail.
39+
That is why semantic patches 'contrib/coccinelle/*.pending.cocci'
40+
are ignored for checks, and can be applied using 'make coccicheck-pending'.
41+
42+
This allows to expose plans of pending large scale refactorings without
43+
impacting the bad pattern checks.

0 commit comments

Comments
 (0)