1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-17 15:26:12 +02:00
git/contrib/coccinelle
René Scharfe 66e905b7dd use xopen() to handle fatal open(2) failures
Add and apply a semantic patch for using xopen() instead of calling
open(2) and die() or die_errno() explicitly.  This makes the error
messages more consistent and shortens the code.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-25 14:39:08 -07:00
..
.gitignore gitignore: ignore output files of coccicheck make target 2016-09-27 14:02:19 -07:00
README coccicheck: introduce 'pending' semantic patches 2018-11-14 11:22:36 +09:00
array.cocci cocci: allow xcalloc(1, size) 2021-03-15 17:56:07 -07:00
commit.cocci commit: move members graph_pos, generation to a slab 2020-06-17 14:37:30 -07:00
flex_alloc.cocci cocci: FLEX_ALLOC_MEM to FLEX_ALLOC_STR 2019-04-04 18:22:30 +09:00
free.cocci coccinelle: polish FREE_AND_NULL rules 2017-06-29 10:46:16 -07:00
hashmap.cocci coccicheck: detect hashmap_entry.hash assignment 2019-10-07 10:20:09 +09:00
object_id.cocci hex: drop sha1_to_hex() 2019-11-13 10:09:10 +09:00
preincr.cocci cocci: simplify "if (++u > 1)" to "if (u++)" 2018-10-24 10:10:10 +09:00
qsort.cocci remove unnecessary check before QSORT 2016-09-29 15:42:18 -07:00
strbuf.cocci strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other 2019-01-27 16:21:09 -08:00
swap.cocci add SWAP macro 2017-01-30 14:07:45 -08:00
the_repository.pending.cocci pretty: prepare format_commit_message to handle arbitrary repositories 2018-11-14 17:22:40 +09:00
xcalloc.cocci fix xcalloc() argument order 2021-03-08 09:45:04 -08:00
xopen.cocci use xopen() to handle fatal open(2) failures 2021-08-25 14:39:08 -07:00
xstrdup_or_null.cocci abspath: add absolute_pathdup() 2017-01-26 14:51:06 -08: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.