From: Jeff King <peff@peff.net>
To: Edmundo Carmona Antoranz <eantoranz@gmail.com>
Cc: "Derrick Stolee" <stolee@gmail.com>,
"René Scharfe" <l.s.r@web.de>,
whydoubt@gmail.com, "Git List" <git@vger.kernel.org>
Subject: Re: [PATCH] blame.c: replace instance of !oidcmp for oideq
Date: Wed, 9 Sep 2020 15:17:46 -0400 [thread overview]
Message-ID: <20200909191746.GA2514794@coredump.intra.peff.net> (raw)
In-Reply-To: <20200909191345.GA2511547@coredump.intra.peff.net>
On Wed, Sep 09, 2020 at 03:13:46PM -0400, Jeff King wrote:
> Which really _seems_ like a bug in coccinelle, unless I am missing
> something. Because both of those parameters look like object_id pointers
> (and the compiler would be complaining if it were not the case). But I
> also wonder if giving the specific types in the coccinelle rule is
> buying us anything. If you passed two void pointers or ints or whatever
> to !oidcmp(), we'd still want to rewrite it as oideq().
And indeed, just blindly swapping out "struct object_id" for
"expression" in the coccinelle file (patch below), shows another spot
that was missed:
diff -u -p a/packfile.c b/packfile.c
--- a/packfile.c
+++ b/packfile.c
@@ -735,7 +735,7 @@ struct packed_git *add_packed_git(const
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->hash))
- hashclr(p->hash);
+ oidclr(p);
return p;
}
Maybe it's worth being looser in our cocci patch definitions. I'm having
trouble thinking of a downside...
-Peff
-- >8 --
Here's the patch to loosen object_id.cocci. Perhaps we'd want to do the
same in other files.
diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci
index ddf4f22bd7..738c60923e 100644
--- a/contrib/coccinelle/object_id.cocci
+++ b/contrib/coccinelle/object_id.cocci
@@ -1,62 +1,62 @@
@@
-struct object_id OID;
+expression OID;
@@
- is_null_sha1(OID.hash)
+ is_null_oid(&OID)
@@
-struct object_id *OIDPTR;
+expression *OIDPTR;
@@
- is_null_sha1(OIDPTR->hash)
+ is_null_oid(OIDPTR)
@@
-struct object_id OID;
+expression OID;
@@
- hashclr(OID.hash)
+ oidclr(&OID)
@@
identifier f != oidclr;
-struct object_id *OIDPTR;
+expression *OIDPTR;
@@
f(...) {<...
- hashclr(OIDPTR->hash)
+ oidclr(OIDPTR)
...>}
@@
-struct object_id OID1, OID2;
+expression OID1, OID2;
@@
- hashcmp(OID1.hash, OID2.hash)
+ oidcmp(&OID1, &OID2)
@@
identifier f != oidcmp;
-struct object_id *OIDPTR1, OIDPTR2;
+expression *OIDPTR1, OIDPTR2;
@@
f(...) {<...
- hashcmp(OIDPTR1->hash, OIDPTR2->hash)
+ oidcmp(OIDPTR1, OIDPTR2)
...>}
@@
-struct object_id *OIDPTR;
-struct object_id OID;
+expression *OIDPTR;
+expression OID;
@@
- hashcmp(OIDPTR->hash, OID.hash)
+ oidcmp(OIDPTR, &OID)
@@
-struct object_id *OIDPTR;
-struct object_id OID;
+expression *OIDPTR;
+expression OID;
@@
- hashcmp(OID.hash, OIDPTR->hash)
+ oidcmp(&OID, OIDPTR)
@@
-struct object_id *OIDPTR1;
-struct object_id *OIDPTR2;
+expression OIDPTR1;
+expression OIDPTR2;
@@
- oidcmp(OIDPTR1, OIDPTR2) == 0
+ oideq(OIDPTR1, OIDPTR2)
@@ -71,8 +71,8 @@ expression E1, E2;
...>}
@@
-struct object_id *OIDPTR1;
-struct object_id *OIDPTR2;
+expression *OIDPTR1;
+expression *OIDPTR2;
@@
- oidcmp(OIDPTR1, OIDPTR2) != 0
+ !oideq(OIDPTR1, OIDPTR2)
next prev parent reply other threads:[~2020-09-09 19:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-07 17:16 [PATCH] blame.c: replace instance of !oidcmp for oideq Edmundo Carmona Antoranz
2020-09-07 17:21 ` Edmundo Carmona Antoranz
2020-09-08 13:55 ` Edmundo Carmona Antoranz
2020-09-08 19:07 ` Derrick Stolee
2020-09-09 9:11 ` Jeff King
2020-09-09 14:00 ` Edmundo Carmona Antoranz
2020-09-09 17:48 ` Jeff Smith
2020-09-09 19:13 ` Jeff King
2020-09-09 19:17 ` Jeff King [this message]
2020-09-09 19:54 ` René Scharfe
2020-09-09 19:58 ` Jeff King
2020-09-09 20:03 ` Junio C Hamano
2020-09-09 20:06 ` Junio C Hamano
2020-09-09 20:43 ` René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200909191746.GA2514794@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=eantoranz@gmail.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=stolee@gmail.com \
--cc=whydoubt@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).