You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Abhishek Kumar c49c82aa4c commit: move members graph_pos, generation to a slab 5 years ago
..
.gitignore gitignore: ignore output files of coccicheck make target 8 years ago
README coccicheck: introduce 'pending' semantic patches 6 years ago
array.cocci coccinelle: use COPY_ARRAY for copying arrays 6 years ago
commit.cocci commit: move members graph_pos, generation to a slab 5 years ago
flex_alloc.cocci cocci: FLEX_ALLOC_MEM to FLEX_ALLOC_STR 6 years ago
free.cocci coccinelle: polish FREE_AND_NULL rules 8 years ago
hashmap.cocci coccicheck: detect hashmap_entry.hash assignment 5 years ago
object_id.cocci hex: drop sha1_to_hex() 5 years ago
preincr.cocci cocci: simplify "if (++u > 1)" to "if (u++)" 6 years ago
qsort.cocci remove unnecessary check before QSORT 8 years ago
strbuf.cocci strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other 6 years ago
swap.cocci add SWAP macro 8 years ago
the_repository.pending.cocci pretty: prepare format_commit_message to handle arbitrary repositories 6 years ago
xstrdup_or_null.cocci abspath: add absolute_pathdup() 8 years ago

README

This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
semantic patches that might be useful to developers.

There are two types of semantic patches:

* Using the semantic transformation to check for bad patterns in the code;
The target 'make coccicheck' is designed to check for these patterns and
it is expected that any resulting patch indicates a regression.
The patches resulting from 'make coccicheck' are small and infrequent,
so once they are found, they can be sent to the mailing list as per usual.

Example for introducing new patterns:
67947c34ae (convert "hashcmp() != 0" to "!hasheq()", 2018-08-28)
b84c783882 (fsck: s/++i > 1/i++/, 2018-10-24)

Example of fixes using this approach:
248f66ed8e (run-command: use strbuf_addstr() for adding a string to
a strbuf, 2018-03-25)
f919ffebed (Use MOVE_ARRAY, 2018-01-22)

These types of semantic patches are usually part of testing, c.f.
0860a7641b (travis-ci: fail if Coccinelle static analysis found something
to transform, 2018-07-23)

* Using semantic transformations in large scale refactorings throughout
the code base.

When applying the semantic patch into a real patch, sending it to the
mailing list in the usual way, such a patch would be expected to have a
lot of textual and semantic conflicts as such large scale refactorings
change function signatures that are used widely in the code base.
A textual conflict would arise if surrounding code near any call of such
function changes. A semantic conflict arises when other patch series in
flight introduce calls to such functions.

So to aid these large scale refactorings, semantic patches can be used.
However we do not want to store them in the same place as the checks for
bad patterns, as then automated builds would fail.
That is why semantic patches 'contrib/coccinelle/*.pending.cocci'
are ignored for checks, and can be applied using 'make coccicheck-pending'.

This allows to expose plans of pending large scale refactorings without
impacting the bad pattern checks.