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

Re: Coccinelle for automated refactors

From
Stefan Beller <sbeller@google.com>
Date
Jun 6, 2016, 17:43 UTC
Message-ID
<CAGZ79kbDgP6PJ6F6ksA33qDs==FHDBe8EwE=iBOWe8as_oFLkA@mail.gmail.com>
In-Reply-To
<20160605205518.GA153578@vauxhall.crustytoothpaste.net>

On Sun, Jun 5, 2016 at 1:55 PM, brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 23 quoted lines
> One thing that I've noticed with the struct object_id conversion is that
> most of the work is mechanical transformations of a data member from one
> type into another.  Doing this by hand is both boring and error-prone,
> and it requires a tiresome review of nearly-identical changes.
>
> I've noticed that Coccinelle[0], a tool for automated refactors, has
> been used with great success on LKML, because it understands C well and
> can perform the transformations precisely and rapidly.  It also does
> nice things like indenting the code it modifies if necessary.
>
> An example semantic patch looks like this:
>
> @@
> expression E1;
> @@
> - is_null_sha1(E1.hash)
> + is_null_oid(&E1)
>
> @@
> expression E1;
> @@
> - is_null_sha1(E1->hash)
> + is_null_oid(E1)
So is this all we have to review then?
Show 14 quoted lines
>
> This does what you think it does: transforms calls to is_null_sha1 that
> use the struct object_id hash member into calls to is_null_oid.
>
> I'd like to use this for some of the struct object_id work if others
> think this is a good idea.  I feel it's likely to reduce the reviewing
> overhead and allow people to better reason about the quality and
> behavior of the sent patches.  Of course, I would still review the
> patches manually for errors and improvements, and would still accept
> responsibility for the content of the patches.
>
> If there's interest, I can send a patch with a set of basic object_id
> transforms to make it easier for others to make those changes when
> they're doing work elsewhere in the codebase.
I would be interested in reviewing such a patch.

Thanks, Stefan

Show 6 quoted lines
>
> [0] http://coccinelle.lip6.fr/
> --
> brian m. carlson / brian with sandals: Houston, Texas, US
> +1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
> OpenPGP: https://keybase.io/bk2204
Previous: brian m. carlsonNext: Junio C Hamano
Message 2 of 5 in “Coccinelle for automated refactors”
  1. brian m. carlsonJun 5, 2016
  2. Stefan BellerJun 6, 2016
  3. Junio C HamanoJun 6, 2016
  4. Jacob KellerJun 6, 2016
  5. brian m. carlsonJun 6, 2016

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.