git/contrib/coccinelle
SZEDER Gábor 279ffad17d coccinelle: avoid wrong transformation suggestions from commit.cocci
The semantic patch 'contrib/coccinelle/commit.cocci' added in
2e27bd7731 (treewide: replace maybe_tree with accessor methods,
2018-04-06) is supposed to "ensure that all references to the
'maybe_tree' member of struct commit are either mutations or accesses
through get_commit_tree()".  So get_commit_tree() clearly must be able
to directly access the 'maybe_tree' member, and 'commit.cocci' has a
bit of a roundabout workaround to ensure that get_commit_tree()'s
direct access in its return statement is not transformed: after all
references to 'maybe_tree' have been transformed to a call to
get_commit_tree(), including the reference in get_commit_tree()
itself, the last rule transforms back a 'return get_commit_tree()'
statement, back then found only in get_commit_tree() itself, to a
direct access.

Unfortunately, already the very next commit shows that this workaround
is insufficient: 7b8a21dba1 (commit-graph: lazy-load trees for
commits, 2018-04-06) extends get_commit_tree() with a condition
directly accessing the 'maybe_tree' member, and Coccinelle with
'commit.cocci' promptly detects it and suggests a transformation to
avoid it.  This transformation is clearly wrong, because calling
get_commit_tree() to access 'maybe_tree' _in_ get_commit_tree() would
obviously lead to recursion.  Furthermore, the same commit added
another, more specialized getter function get_commit_tree_in_graph(),
whose legitimate direct access to 'maybe_tree' triggers a similar
wrong transformation suggestion.

Exclude both of these getter functions from the general rule in
'commit.cocci' that matches their direct accesses to 'maybe_tree'.
Also exclude load_tree_for_commit(), which, as static helper funcion
of get_commit_tree_in_graph(), has legitimate direct access to
'maybe_tree' as well.

The last rule transforming back 'return get_commit_tree()' statements
to direct accesses thus became unnecessary, remove it.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Acked-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-05-02 13:38:52 +09:00
..
.gitignore gitignore: ignore output files of coccicheck make target 2016-09-27 14:02:19 -07:00
array.cocci coccinelle: remove parentheses that become unnecessary 2017-10-02 13:02:26 +09:00
commit.cocci coccinelle: avoid wrong transformation suggestions from commit.cocci 2018-05-02 13:38:52 +09:00
free.cocci coccinelle: polish FREE_AND_NULL rules 2017-06-29 10:46:16 -07:00
object_id.cocci cocci: avoid self-references in object_id transformations 2016-11-01 10:58:39 -07:00
qsort.cocci remove unnecessary check before QSORT 2016-09-29 15:42:18 -07:00
README contrib/coccinelle: add basic Coccinelle transforms 2016-06-28 11:39:02 -07:00
strbuf.cocci Merge branch 'rs/cocci-strbuf-addf-to-addstr' 2018-02-15 14:55:44 -08:00
swap.cocci add SWAP macro 2017-01-30 14:07:45 -08: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.