git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cocci: matching (multiple) identifiers

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 18, 2025, 17:55 UTC
Message-ID
<xmqqbjqlexzd.fsf@gitster.g>
"make coccicheck" seems to work OK at GitHub CI using
    $ spatch --version
    spatch version 1.1.1 compiled with OCaml version 4.13.1
    OCaml scripting support: yes
    Python scripting support: yes
    Syntax of regular expressions: PCRE
but not with 
    $ spatch --version
    spatch version 1.3 compiled with OCaml version 5.3.0
    OCaml scripting support: yes
    Python scripting support: yes
    Syntax of regular expressions: Str

Judging from https://ocaml.org/manual/5.3/api/Str.html, I suspect that this probably is caused by the distinction between BRE vs PCRE. As there is no reasonably clean way to write the multiple choice matches portably between these two pattern languages, let's stop using regexp_constraint and use compare_constraint instead when listing the function names to exclude.

There are other uses of "!~" but they all want to match a single simple token, that should work fine either with BRE or PCRE.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/coccinelle/commit.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git c/contrib/coccinelle/commit.cocci w/contrib/coccinelle/commit.cocci
index af6dd4c20c..c5284604c5 100644
--- c/contrib/coccinelle/commit.cocci
+++ w/contrib/coccinelle/commit.cocci
@@ -25,7 +25,8 @@ expression s;
 // functions, then the recommended transformation will be bogus with
 // repo_get_commit_tree() on the LHS.
 @@
-identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
+identifier f != { repo_get_commit_tree, get_commit_tree_in_graph_one,
+		  load_tree_for_commit, set_commit_tree };
 expression c;
 @@
   f(...) {<...
Next: Junio C Hamano
Message 1 of 5 in “cocci: matching (multiple) identifiers”
  1. cocci: matching (multiple) identifiersJunio C Hamano, Jun 18, 2025
  2. cocci: do not directly access the .d_type member in struct direntJunio C Hamano, Jun 18, 2025
  3. Collin FunkJun 18, 2025
  4. Junio C HamanoJun 18, 2025
  5. Collin FunkJun 18, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.