git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Pranit Bauva <pranit.bauva@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH/RFC] parse-options.c: make OPTION__COUNTUP consider negative values
Date: Sun, 20 Mar 2016 00:10:10 -0400	[thread overview]
Message-ID: <20160320041009.GA18312@sigill.intra.peff.net> (raw)
In-Reply-To: <CAFZEwPOib-3JJQ+ufAbmNf1HYb5003LJw_paF2s9L8OK59N0PQ@mail.gmail.com>

On Fri, Mar 18, 2016 at 04:53:34PM +0530, Pranit Bauva wrote:

> > And we would need to verify that all of the existing callers are OK with
> > this. Did you check that that (not rhetorical; I suspect they are all
> > OK, but somebody needs to check)?
> 
> I did a grep on parse-options.h and saw that only "verbose", "quiet"
> and "force" use OPT_COUNTUP().
> I then did a git grep for "verbose = -1", "quiet = -1"
> But with "force = -1" showed that "builtin/clean.c" uses it. On a bit
> careful examination, this patch would not make difference to it.

Yeah, I see that it handles the config for force separately, and then
munges the "-1" into 0 before we get to parse_options.

There are uses of COUNTUP in cmd_hash_object() and test-parse-options.c,
but I think they are both fine.

Grepping for "verbose = -1" would miss any cases where we call the
argument something else (e.g., apply_verbosely). So I think it would be
more thorough to grep for OPT__VERBOSE, etc, and then follow-up on
whatever variable they use.

I just did so, and I didn't see any problems.

> > We are also changing semantics without changing the interface, which
> > means any topics in flight (that you _cannot_ review, because you have
> > not seen them yet) may be subtly broken. To me that is not an absolute
> > deal-breaker, but something to weigh against the utility of the change.
> 
> As I am new here, I don't really know how to go about with this. Could
> you describe in a little detail so that I can work on it?

A more canonical example is changing a function return value. Imagine I
have a function which returns "1" for success and "0" for error, and I
want to change it to return "0" for success and "-1" for error. If I do
so and update each caller, then merging with a branch that has a new
caller will not result in any conflicts (there is no textual link
between the callers and the function), but the result will be subtly
broken (the new caller will get the error-check wrong).

So we generally try to find some way that the compiler will notice the
breakage. E.g., if the function changes name when the return value
semantics change, or if it gains a new argument at the same time, then
the compiler will notice and complain. We still have to fix it up during
the merge, of course, but it's easy to spot.

Likewise here. If you change the semantics of OPT_COUNTUP(), then any
branch which introduces a new use of "int foo = -1" and expects the old
semantics will be subtly broken.

The obvious fix would be to switch the name (to OPT_COUNTUP_DEFAULT() or
something). But that's a bit painful, as almost nobody uses COUNTUP
directly, so we'd need OPT__VERBOSE_DEFAULT().

I do think we could also declare that it's sufficiently unlikely for
somebody to have been using the old semantics for OPT_COUNTUP() with
a negative integer (as it does not really do anything useful), and just
accept the risk.

Which in the end is the same as ignoring the problem in the first place,
but there is a big difference between not thinking about the problem,
and thinking about it and deciding it's not a problem. :)

-Peff

  reply	other threads:[~2016-03-20  4:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16 23:16 [PATCH/RFC] parse-options.c: make OPTION__COUNTUP consider negative values Pranit Bauva
2016-03-17  1:50 ` Jeff King
2016-03-17  7:28   ` Eric Sunshine
2016-03-17  8:14     ` Eric Sunshine
2016-03-17 20:22     ` Pranit Bauva
2016-03-18 11:23   ` Pranit Bauva
2016-03-20  4:10     ` Jeff King [this message]
2016-03-20  9:07       ` Pranit Bauva

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=20160320041009.GA18312@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=pranit.bauva@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 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 NNTP newsgroup(s).