git-commit-vandalism/contrib/coccinelle
Junio C Hamano 2fb377e569 Merge branch 'rs/cocci-array-copy'
A coccinelle rule (in contrib/) to encourage use of COPY_ARRAY
macro has been improved.

* rs/cocci-array-copy:
  cocci: avoid normalization rules for memcpy
2022-07-19 16:40:18 -07:00
..
tests cocci: generalize "unused" rule to cover more than "strbuf" 2022-07-06 12:24:43 -07:00
.gitignore
array.cocci cocci: avoid normalization rules for memcpy 2022-07-10 14:52:05 -07:00
commit.cocci
equals-null.cocci contrib/coccinnelle: add equals-null.cocci 2022-05-02 09:47:55 -07:00
flex_alloc.cocci
free.cocci cocci: add and apply free_commit_list() rules 2022-04-13 23:56:08 -07:00
hashmap.cocci
object_id.cocci cocci: retire is_null_sha1() rule 2022-06-07 15:53:24 -07:00
preincr.cocci
qsort.cocci
README
strbuf.cocci cocci: allow padding with strbuf_addf() 2022-03-23 11:38:40 -07:00
swap.cocci
the_repository.pending.cocci object-store.h: remove unused has_sha1_file*() 2022-04-01 10:16:10 -07:00
unused.cocci cocci: generalize "unused" rule to cover more than "strbuf" 2022-07-06 12:24:43 -07:00
xcalloc.cocci
xopen.cocci index-pack: use xopen in init_thread 2021-09-10 14:22:50 -07:00
xstrdup_or_null.cocci cocci: drop bogus xstrdup_or_null() rule 2022-04-30 22:23:11 -07:00

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.