contrib: move "coccinelle/" directory into "tools/"

The Coccinelle tool is an ingrained part of our build infrastructure. It is executed by our CI to detect antipatterns and is used to detect misuses of certain interfaces. It's presence in "contrib/" is thus rather misleading. Promote the configuration into the new "tools/" directory. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 19, 2026 at 06:33 UTC 8ca1b4472ce97ae1d120608f9f02a86fa33d4187
30 files changed +26 -26
Makefile
+20 -20
@@ -1005,8 +1005,8 @@ SPATCH_TEST_FLAGS =
1005 # COMPUTE_HEADER_DEPENDENCIES=no this will be unset too.
1006 SPATCH_USE_O_DEPENDENCIES = YesPlease
1007
1008 -# Set SPATCH_CONCAT_COCCI to concatenate the contrib/cocci/*.cocci
1009 -# files into a single contrib/cocci/ALL.cocci before running
1008 +# Set SPATCH_CONCAT_COCCI to concatenate the tools/coccinelle/*.cocci
1009 +# files into a single tools/coccinelle/ALL.cocci before running
1010 # "coccicheck".
1011 #
1012 # Pros:
@@ -1025,7 +1025,7 @@ SPATCH_USE_O_DEPENDENCIES = YesPlease
1025 # generate a specific patch, e.g. this will always use strbuf.cocci,
1026 # not ALL.cocci:
1027 #
1028 -# make contrib/coccinelle/strbuf.cocci.patch
1028 +# make tools/coccinelle/strbuf.cocci.patch
1029 SPATCH_CONCAT_COCCI = YesPlease
1030
1031 # Rebuild 'coccicheck' if $(SPATCH), its flags etc. change
@@ -3457,15 +3457,15 @@ check:
3457 exit 1; \
3458 fi
3459
3460 -COCCI_GEN_ALL = .build/contrib/coccinelle/ALL.cocci
3461 -COCCI_GLOB = $(wildcard contrib/coccinelle/*.cocci)
3460 +COCCI_GEN_ALL = .build/tools/coccinelle/ALL.cocci
3461 +COCCI_GLOB = $(wildcard tools/coccinelle/*.cocci)
3462 COCCI_RULES_TRACKED = $(COCCI_GLOB:%=.build/%)
3463 COCCI_RULES_TRACKED_NO_PENDING = $(filter-out %.pending.cocci,$(COCCI_RULES_TRACKED))
3464 COCCI_RULES =
3465 COCCI_RULES += $(COCCI_GEN_ALL)
3466 COCCI_RULES += $(COCCI_RULES_TRACKED)
3467 COCCI_NAMES =
3468 -COCCI_NAMES += $(COCCI_RULES:.build/contrib/coccinelle/%.cocci=%)
3468 +COCCI_NAMES += $(COCCI_RULES:.build/tools/coccinelle/%.cocci=%)
3469
3470 COCCICHECK_PENDING = $(filter %.pending.cocci,$(COCCI_RULES))
3471 COCCICHECK = $(filter-out $(COCCICHECK_PENDING),$(COCCI_RULES))
@@ -3480,20 +3480,20 @@ COCCICHECK_PATCHES_PENDING_INTREE = $(COCCICHECK_PATCHES_PENDING:.build/%=%)
3480 # on $(MAKECMDGOALS) that match these $(COCCI_RULES)
3481 COCCI_RULES_GLOB =
3482 COCCI_RULES_GLOB += cocci%
3483 -COCCI_RULES_GLOB += .build/contrib/coccinelle/%
3483 +COCCI_RULES_GLOB += .build/tools/coccinelle/%
3484 COCCI_RULES_GLOB += $(COCCICHECK_PATCHES)
3485 COCCI_RULES_GLOB += $(COCCICHEC_PATCHES_PENDING)
3486 COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_INTREE)
3487 COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_PENDING_INTREE)
3488 COCCI_GOALS = $(filter $(COCCI_RULES_GLOB),$(MAKECMDGOALS))
3489
3490 -COCCI_TEST_RES = $(wildcard contrib/coccinelle/tests/*.res)
3490 +COCCI_TEST_RES = $(wildcard tools/coccinelle/tests/*.res)
3491
3492 $(COCCI_RULES_TRACKED): .build/% : %
3493 $(call mkdir_p_parent_template)
3494 $(QUIET_CP)cp $< $@
3495
3496 -.build/contrib/coccinelle/FOUND_H_SOURCES: $(FOUND_H_SOURCES)
3496 +.build/tools/coccinelle/FOUND_H_SOURCES: $(FOUND_H_SOURCES)
3497 $(call mkdir_p_parent_template)
3498 $(QUIET_GEN) >$@
3499
@@ -3507,12 +3507,12 @@ endif
3507 define cocci-rule
3508
3509 ## Rule for .build/$(1).patch/$(2); Params:
3510 -# $(1) = e.g. ".build/contrib/coccinelle/free.cocci"
3510 +# $(1) = e.g. ".build/tools/coccinelle/free.cocci"
3511 # $(2) = e.g. "grep.c"
3512 # $(3) = e.g. "grep.o"
3513 -COCCI_$(1:.build/contrib/coccinelle/%.cocci=%) += $(1).d/$(2).patch
3513 +COCCI_$(1:.build/tools/coccinelle/%.cocci=%) += $(1).d/$(2).patch
3514 $(1).d/$(2).patch: GIT-SPATCH-DEFINES
3515 -$(1).d/$(2).patch: $(if $(and $(SPATCH_USE_O_DEPENDENCIES),$(wildcard $(3))),$(3),.build/contrib/coccinelle/FOUND_H_SOURCES)
3515 +$(1).d/$(2).patch: $(if $(and $(SPATCH_USE_O_DEPENDENCIES),$(wildcard $(3))),$(3),.build/tools/coccinelle/FOUND_H_SOURCES)
3516 $(1).d/$(2).patch: $(1)
3517 $(1).d/$(2).patch: $(1).d/%.patch : %
3518 $$(call mkdir_p_parent_template)
@@ -3538,13 +3538,13 @@ endif
3538
3539 define spatch-rule
3540
3541 -.build/contrib/coccinelle/$(1).cocci.patch: $$(COCCI_$(1))
3541 +.build/tools/coccinelle/$(1).cocci.patch: $$(COCCI_$(1))
3542 $$(QUIET_SPATCH_CAT)cat $$^ >$$@ && \
3543 if test -s $$@; \
3544 then \
3545 echo ' ' SPATCH result: $$@; \
3546 fi
3547 -contrib/coccinelle/$(1).cocci.patch: .build/contrib/coccinelle/$(1).cocci.patch
3547 +tools/coccinelle/$(1).cocci.patch: .build/tools/coccinelle/$(1).cocci.patch
3548 $$(QUIET_CP)cp $$< $$@
3549
3550 endef
@@ -3558,9 +3558,9 @@ $(COCCI_TEST_RES_GEN): GIT-SPATCH-DEFINES
3558 $(COCCI_TEST_RES_GEN): .build/%.res : %.c
3559 $(COCCI_TEST_RES_GEN): .build/%.res : %.res
3560 ifdef SPATCH_CONCAT_COCCI
3561 -$(COCCI_TEST_RES_GEN): .build/contrib/coccinelle/tests/%.res : $(COCCI_GEN_ALL)
3561 +$(COCCI_TEST_RES_GEN): .build/tools/coccinelle/tests/%.res : $(COCCI_GEN_ALL)
3562 else
3563 -$(COCCI_TEST_RES_GEN): .build/contrib/coccinelle/tests/%.res : contrib/coccinelle/%.cocci
3563 +$(COCCI_TEST_RES_GEN): .build/tools/coccinelle/tests/%.res : tools/coccinelle/%.cocci
3564 endif
3565 $(call mkdir_p_parent_template)
3566 $(QUIET_SPATCH_TEST)$(SPATCH) $(SPATCH_TEST_FLAGS) \
@@ -3576,14 +3576,14 @@ coccicheck-test: $(COCCI_TEST_RES_GEN)
3576 coccicheck: coccicheck-test
3577
3578 ifdef SPATCH_CONCAT_COCCI
3579 -COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = contrib/coccinelle/ALL.cocci.patch
3579 +COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = tools/coccinelle/ALL.cocci.patch
3580 else
3581 COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = $(COCCICHECK_PATCHES_INTREE)
3582 endif
3583 coccicheck: $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES)
3584 ! grep ^ $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES) /dev/null
3585
3586 -# See contrib/coccinelle/README
3586 +# See tools/coccinelle/README
3587 coccicheck-pending: coccicheck-test
3588 coccicheck-pending: $(COCCICHECK_PATCHES_PENDING_INTREE)
3589
@@ -3857,8 +3857,8 @@ profile-clean:
3857
3858 cocciclean:
3859 $(RM) GIT-SPATCH-DEFINES
3860 - $(RM) -r .build/contrib/coccinelle
3861 - $(RM) contrib/coccinelle/*.cocci.patch
3860 + $(RM) -r .build/tools/coccinelle
3861 + $(RM) tools/coccinelle/*.cocci.patch
3862
3863 clean: profile-clean coverage-clean cocciclean
3864 $(RM) -r .build $(UNIT_TEST_BIN)
ci/run-static-analysis.sh
+1 -1
@@ -10,7 +10,7 @@ make coccicheck
10 set +x
11
12 fail=
13 -for cocci_patch in contrib/coccinelle/*.patch
13 +for cocci_patch in tools/coccinelle/*.patch
14 do
15 if test -s "$cocci_patch"
16 then
contrib/meson.build
-1
@@ -2,5 +2,4 @@ foreach feature : get_option('contrib')
2 subdir(feature)
3 endforeach
4
5 -subdir('coccinelle')
5 subdir('credential')
tools/coccinelle/.gitignore renamed
tools/coccinelle/README renamed
+1 -1
@@ -38,7 +38,7 @@ that might be useful to developers.
38 So to aid these large scale refactorings, semantic patches can be used.
39 However we do not want to store them in the same place as the checks for
40 bad patterns, as then automated builds would fail.
41 - That is why semantic patches 'contrib/coccinelle/*.pending.cocci'
41 + That is why semantic patches 'tools/coccinelle/*.pending.cocci'
42 are ignored for checks, and can be applied using 'make coccicheck-pending'.
43
44 This allows to expose plans of pending large scale refactorings without
tools/coccinelle/array.cocci renamed
tools/coccinelle/commit.cocci renamed
tools/coccinelle/config_fn_ctx.pending.cocci renamed
tools/coccinelle/equals-null.cocci renamed
tools/coccinelle/flex_alloc.cocci renamed
tools/coccinelle/free.cocci renamed
tools/coccinelle/git_config_number.cocci renamed
tools/coccinelle/hashmap.cocci renamed
tools/coccinelle/index-compatibility.cocci renamed
tools/coccinelle/meson.build renamed
tools/coccinelle/object_id.cocci renamed
tools/coccinelle/preincr.cocci renamed
tools/coccinelle/qsort.cocci renamed
tools/coccinelle/refs.cocci renamed
tools/coccinelle/spatchcache renamed
+3 -3
@@ -30,7 +30,7 @@
30 # out of control.
31 #
32 # This along with the general incremental "make" support for
33 -# "contrib/coccinelle" makes it viable to (re-)run coccicheck
33 +# "tools/coccinelle" makes it viable to (re-)run coccicheck
34 # e.g. when merging integration branches.
35 #
36 # Note that the "--very-quiet" flag is currently critical. The cache
@@ -42,7 +42,7 @@
42 # to change, so just supply "--very-quiet" for now.
43 #
44 # To use this, simply set SPATCH to
45 -# contrib/coccinelle/spatchcache. Then optionally set:
45 +# tools/coccinelle/spatchcache. Then optionally set:
46 #
47 # [spatchCache]
48 # # Optional: path to a custom spatch
@@ -65,7 +65,7 @@
65 #
66 # redis-cli FLUSHALL
67 # <make && make coccicheck, as above>
68 -# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/contrib/coccinelle | sort | uniq -c
68 +# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/tools/coccinelle | sort | uniq -c
69 # 600 CANTCACHE
70 # 7365 MISS
71 # 7365 SET
tools/coccinelle/strbuf.cocci renamed
tools/coccinelle/swap.cocci renamed
tools/coccinelle/tests/free.c renamed
tools/coccinelle/tests/free.res renamed
tools/coccinelle/the_repository.cocci renamed
tools/coccinelle/xcalloc.cocci renamed
tools/coccinelle/xopen.cocci renamed
tools/coccinelle/xstrdup_or_null.cocci renamed
tools/coccinelle/xstrncmpz.cocci renamed
tools/meson.build
+1
@@ -0,0 +1 @@
1 +subdir('coccinelle')