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

[RFH] disable bogus .maybe_tree suggestion by Coccinelle?

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2024, 18:08 UTC
Message-ID
<xmqq1q9ybsnl.fsf@gitster.g>

Josh at $WORK noticed that "make coccicheck" shows tons of false positives to tell us to avoid direct access to the .maybe_tree member of a commit object, even for those that are meant to be excluded from the rewrite rule, like this:

        diff -u -p a/commit-graph.c b/commit-graph.c
        --- a/commit-graph.c
        +++ b/commit-graph.c
        @@ -905,7 +905,7 @@ static void fill_commit_graph_info(struc
         static inline void set_commit_tree(struct commit *c, struct tree *t)
         {
        -	c->maybe_tree = t;
        +	repo_get_commit_tree(specify_the_right_repo_here, c) = t;
         }
         static int fill_commit_in_graph(struct repository *r,

It turns out that "make coccicheck" shows the same undesirable suggestions, even in a checkout of 301b8c7f (commit.c: add repo_get_commit_tree(), 2019-04-16) that added these rules.

If nobody has a better idea (which would obviously to "fix" it so that we still are reminded to think twice before directly accessing the .maybe_tree member without these false positives), I'd propose to remove these rules.

The box I observed the sympotom had this
    $ spatch --version
    spatch version 1.1.1 compiled with OCaml version 4.14.1
    Flags passed to the configure script: --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --enable-ocaml --enable-python --with-python=python3 --enable-opt
    OCaml scripting support: yes
    Python scripting support: yes
    Syntax of regular expressions: Str
---
 contrib/coccinelle/commit.cocci | 23 -----------------------
 1 file changed, 23 deletions(-)
diff --git c/contrib/coccinelle/commit.cocci w/contrib/coccinelle/commit.cocci
index af6dd4c20c..397f01b9ff 100644
--- c/contrib/coccinelle/commit.cocci
+++ w/contrib/coccinelle/commit.cocci
@@ -10,29 +10,6 @@ expression c;
 - c->maybe_tree->object.oid.hash
 + get_commit_tree_oid(c)->hash
 
-@@
-identifier f !~ "^set_commit_tree$";
-expression c;
-expression s;
-@@
-  f(...) {<...
-- c->maybe_tree = s
-+ set_commit_tree(c, s)
-  ...>}
-
-// These excluded functions must access c->maybe_tree directly.
-// Note that if c->maybe_tree is written somewhere outside of these
-// 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)$";
-expression c;
-@@
-  f(...) {<...
-- c->maybe_tree
-+ repo_get_commit_tree(specify_the_right_repo_here, c)
-  ...>}
-
 @@
 struct commit *c;
 expression E;
Message 1 of 1 in “[RFH] disable bogus .maybe_tree suggestion by Coccinelle?”
  1. Junio C HamanoJan 30, 2024

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.