All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, jonathantanmy@google.com, szeder.dev@gmail.com
Subject: Re: [PATCH] Makefile: add pending semantic patches
Date: Fri, 09 Nov 2018 14:18:46 +0900	[thread overview]
Message-ID: <xmqqzhui4ymh.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: 20181108205255.193402-1-sbeller@google.com

Stefan Beller <sbeller@google.com> writes:

> From: SZEDER Gábor <szeder.dev@gmail.com>
>
> Add a description and place on how to use coccinelle for large refactorings
> that happen only once.
>
> Based-on-work-by: SZEDER Gábor <szeder.dev@gmail.com>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> I consider including this patch in a resend instead.
> It outlays the basics of such a new workflow, which we can refine later.

Thanks for tying loose ends.

> diff --git a/contrib/coccinelle/README b/contrib/coccinelle/README
> index 9c2f8879c2..fa09d1abcc 100644
> --- a/contrib/coccinelle/README
> +++ b/contrib/coccinelle/README
> @@ -1,2 +1,62 @@
>  This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
>  semantic patches that might be useful to developers.
> +
> +There are two types of semantic patches:
> +
> + * Using the semantic transformation to check for bad patterns in the code;
> +   This is what the original target 'make coccicheck' is designed to do and
> +   it is expected that any resulting patch indicates a regression.
> +   The patches resulting from 'make coccicheck' are small and infrequent,
> +   so once they are found, they can be sent to the mailing list as per usual.
> +
> +   Example for introducing new patterns:
> +   67947c34ae (convert "hashcmp() != 0" to "!hasheq()", 2018-08-28)
> +   b84c783882 (fsck: s/++i > 1/i++/, 2018-10-24)
> +
> +   Example of fixes using this approach:
> +   248f66ed8e (run-command: use strbuf_addstr() for adding a string to
> +               a strbuf, 2018-03-25)
> +   f919ffebed (Use MOVE_ARRAY, 2018-01-22)
> +
> +   These types of semantic patches are usually part of testing, c.f.
> +   0860a7641b (travis-ci: fail if Coccinelle static analysis found something
> +               to transform, 2018-07-23)

Yup, and I think what we have in 'pu' (including your the_repository
stuff) falls into this category.

I've been paying attention to "make coccicheck" produced patches for
the past few weeks, and so far, I found it _much_ _much_ more
pleasant, compared to having to worry about merge conflicts with the
topics in flight that changes day to day (not just because we add
new topics or update existing topics, but also the order of the
merge changes as topics mature at different rates and jumps over
each other in master..pu history), that "make coccicheck" after
topics are merged to integration branches fixes these issues up as
needed.

> +   3) Apply the semantic patch only partially, where needed for the patch series
> +      that motivates the large scale refactoring and then build that series
> +      on top of it.

It is not quite clear what "needed for the patch series" really
means in the context of this paragraph.  What are the changes that
are not needed, that is still produced if we ran "make coccicheck"?

Are they wrong changes (e.g. a carelessly written read_cache() to
read_index(&the_index) conversion may munge the implementation of
read_cache(...) { return read_index(&the_index, ...); } and make
inifinite recursion)?  Or are they "correct but not immediately
necessary" (e.g. because calling read_cache() does not hurt until
that function gets removed, so rewriting the callers to call
read_index() with &the_index may be correct but not immediately
necessary)?

> +      By applying the semantic patch only partially where needed, the series
> +      is less likely to conflict with other series in flight.

That is correct.

> +      To make it possible to apply the semantic patch partially, there needs
> +      to be mechanism for backwards compatibility to keep those places working
> +      where the semantic patch is not applied. This can be done via a
> +      wrapper function that has the exact name and signature as the function
> +      to be changed.

OK, so this argues for leaving read_cache()-like things to help
other in-flight topics, while a change to encourage the use of
read_index() takes place.  That also makes sense, and this directly
relates to "less likely to conflict" benefit you mentioned above.

But it is still unclear to me then what are "necessary".

... goes and thinks ...

OK, so a series that allows a codepath to work on an arbitrary
in-core istate, for example, may need to update a function to take
istate and use it to call read_index(istate...), and the old code in
such a call chain must have used read_cache(), always operating on
&the_index.  For the purpose of that series, it does not matter if
other codepaths that are not involved in the callchain the series
wants to update are still only working on &the_index, so a change to
turn read_cache() into read_index(&the_index) is *not* necessary
(but still would be correct) and should be left out of the series.
But any change the series makes to the callchain in question that
turns read_cache() into read_index() with something call-specific
(not &the_index) is a necesary one.  Is that a reasonable example
of what these paragraphs wanted to convey with the distinction
between "needed for the patch series" and other changes?


  parent reply	other threads:[~2018-11-09  5:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 22:07 [PATCHv2 00/24] Bring more repository handles into our code base] Stefan Beller
2018-10-30 22:07 ` [PATCH 01/24] Makefile: add pending semantic patches Stefan Beller
2018-10-31  6:42   ` Junio C Hamano
2018-11-08 20:52   ` [PATCH] " Stefan Beller
2018-11-09  4:55     ` Martin Ågren
2018-11-09 20:50       ` Stefan Beller
2018-11-09  5:18     ` Junio C Hamano [this message]
2018-11-09 21:58       ` Stefan Beller
2018-11-13 15:48         ` SZEDER Gábor
2018-11-14  4:15           ` Junio C Hamano
2018-11-10  0:10     ` [PATCH] coccicheck: introduce 'pending' " Stefan Beller
2018-11-10 20:37       ` Martin Ågren
2018-11-12 21:19       ` Josh Steadmon
2018-11-13 16:02       ` SZEDER Gábor
2018-10-30 22:07 ` [PATCH 02/24] sha1_file: allow read_object to read objects in arbitrary repositories Stefan Beller
2018-10-30 22:07 ` [PATCH 03/24] packfile: allow has_packed_and_bad to handle " Stefan Beller
2018-10-30 22:07 ` [PATCH 04/24] object-store: allow read_object_file_extended to read from " Stefan Beller
2018-10-30 22:07 ` [PATCH 05/24] object-store: prepare read_object_file to deal with " Stefan Beller
2018-10-30 22:07 ` [PATCH 06/24] object-store: prepare has_{sha1, object}_file[_with_flags] to handle " Stefan Beller
2018-10-30 22:08 ` [PATCH 07/24] object: parse_object to honor its repository argument Stefan Beller
2018-10-30 22:08 ` [PATCH 08/24] commit: allow parse_commit* to handle arbitrary repositories Stefan Beller
2018-10-30 22:08 ` [PATCH 09/24] commit-reach.c: allow paint_down_to_common " Stefan Beller
2018-10-30 22:08 ` [PATCH 10/24] commit-reach.c: allow merge_bases_many " Stefan Beller
2018-10-30 22:08 ` [PATCH 11/24] commit-reach.c: allow remove_redundant " Stefan Beller
2018-10-30 22:08 ` [PATCH 12/24] commit-reach.c: allow get_merge_bases_many_0 " Stefan Beller
2018-10-30 22:08 ` [PATCH 13/24] commit-reach: prepare get_merge_bases " Stefan Beller
2018-10-30 22:08 ` [PATCH 14/24] commit-reach: prepare in_merge_bases[_many] " Stefan Beller
2018-10-30 22:08 ` [PATCH 15/24] commit: prepare get_commit_buffer " Stefan Beller
2018-10-30 22:08 ` [PATCH 16/24] commit: prepare repo_unuse_commit_buffer " Stefan Beller
2018-10-30 22:08 ` [PATCH 17/24] commit: prepare logmsg_reencode " Stefan Beller
2018-10-30 22:08 ` [PATCH 18/24] pretty: prepare format_commit_message " Stefan Beller
2018-10-30 22:08 ` [PATCH 19/24] submodule: use submodule repos for object lookup Stefan Beller
2018-11-02 13:03   ` Derrick Stolee
2018-11-02 17:23     ` Stefan Beller
2018-11-02 17:27       ` Derrick Stolee
2018-10-30 22:08 ` [PATCH 20/24] submodule: don't add submodule as odb for push Stefan Beller
2018-10-30 22:08 ` [PATCH 21/24] commit-graph: convert remaining function to handle arbitrary repositories Stefan Beller
2018-10-30 22:08 ` [PATCH 22/24] commit: make free_commit_buffer and release_commit_memory repository agnostic Stefan Beller
2018-10-30 22:08 ` [PATCH 23/24] path.h: make REPO_GIT_PATH_FUNC " Stefan Beller
2018-10-30 22:08 ` [PATCH 24/24] t/helper/test-repository: celebrate independence from the_repository Stefan Beller
2018-10-31  6:41 ` [PATCHv2 00/24] Bring more repository handles into our code base] Junio C Hamano
2018-11-01 19:45   ` Stefan Beller
2018-11-02  2:00     ` Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzhui4ymh.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=sbeller@google.com \
    --cc=szeder.dev@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.