Skip to content

Commit 0722553

Browse files
committed
Merge branch 'sb/cocci-pending'
A coding convention around the Coccinelle semantic patches to have two classes to ease code migration process has been proposed and its support has been added to the Makefile. * sb/cocci-pending: coccicheck: introduce 'pending' semantic patches
2 parents 2488849 + dd5d052 commit 0722553

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
@@ -2742,9 +2742,12 @@ endif
27422742
then \
27432743
echo ' ' SPATCH result: $@; \
27442744
fi
2745-
coccicheck: $(addsuffix .patch,$(wildcard contrib/coccinelle/*.cocci))
2745+
coccicheck: $(addsuffix .patch,$(filter-out %.pending.cocci,$(wildcard contrib/coccinelle/*.cocci)))
27462746

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

27492752
### Installation rules
27502753

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)