git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Git List <git@vger.kernel.org>, bfields@redhat.com
Subject: Re: [PATCH 3/4] am: support --show-current-patch=raw as a synonym for--show-current-patch
Date: Wed, 19 Feb 2020 14:34:43 -0500	[thread overview]
Message-ID: <CAPig+cQOZwA3aAzBko-RL8UnW77DuBY-s_-J2D+35Ofn=fFfsg@mail.gmail.com> (raw)
In-Reply-To: <20200219161352.13562-4-pbonzini@redhat.com>

On Wed, Feb 19, 2020 at 11:15 AM <pbonzini@redhat.com> wrote:
> [...]
> We would like therefore to add a new mode to "git am" that copies
> .git/rebase-merge/patch to stdout.  In order to preserve backwards
> compatibility, "git am --show-current-patch"'s behavior as to stay as

s/as to/has to/

> is, and the new functionality will be added as an optional
> argument to --show-current-patch.  As a start, add the code to parse
> submodes.  For now "raw" is the only valid submode, and it prints
> the full e-mail message just like "git am --show-current-patch".
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> diff --git a/builtin/am.c b/builtin/am.c
> @@ -2078,7 +2082,14 @@ static int show_patch(struct am_state *state)
> -       patch_path = am_path(state, msgnum(state));
> +       switch (sub_mode) {
> +       case SHOW_PATCH_RAW:
> +               patch_path = am_path(state, msgnum(state));
> +               break;
> +       default:
> +               abort();
> +       }

I expect that this abort() is likely to go away in the next patch, so
it's not such a big deal, but the usual way to indicate that this is
an impossible condition is with BUG() rather than abort(). So, if you
happen to re-roll for some reason, perhaps consider using BUG()
instead.

> @@ -2130,8 +2141,42 @@ enum resume_type {
> +static int parse_opt_show_current_patch(const struct option *opt, const char *arg, int unset)
> +{
> +       int new_value = SHOW_PATCH_RAW;
> +
> +       if (arg) {
> +               for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
> +                       if (!strcmp(arg, valid_modes[new_value]))
> +                               break;
> +               }
> +               if (new_value >= ARRAY_SIZE(valid_modes))
> +                       return error(_("Invalid value for --show-current-patch: %s"), arg);
> +       }

I think the more typical way of coding this in this project is to
initialize 'new_value' to -1. Doing so will make it easier to some day
add a configuration value as fallback for when the sub-mode is not
specified on the command line. So, it would look something like this:

    int submode = -1;
    if (arg) {
        int i;
        for (i = 0; i < ARRAY_SIZE(valid_modes); i++)
            if (!strcmp(arg, valid_modes[i]))
                break;
        if (i >= ARRAY_SIZE(valid_modes))
            return error(_("invalid value for --show-current-patch: %s"), arg);
        submode = i;
    }

    /* fall back to config value */
    if (submode < 0) {
        /* check if config value available and assign 'sudmode' */
    }

> +       if (resume->mode == RESUME_SHOW_PATCH && new_value != resume->sub_mode)
> +               return error(_("--show-current-patch=%s is incompatible with "
> +                              "--show-current-patch=%s"),
> +                            arg, valid_modes[resume->sub_mode]);

So, this allows --show-current-patch=<foo> to be specified multiple
times but only as long as <foo> is the same each time, and errors out
otherwise. That's rather harsh and makes it difficult for someone to
override a value specified earlier on the command line (say, coming
from a Git alias). The typical way this is handled is "last wins"
rather than making it an error.

> +       resume->mode = RESUME_SHOW_PATCH;
> +       resume->sub_mode = new_value;
> +       return 0;
> +}

  reply	other threads:[~2020-02-19 19:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 16:13 [PATCH 0/4] am: provide a replacement for "cat .git/rebase-apply/patch" pbonzini
2020-02-19 16:13 ` [PATCH 1/4] parse-options: convert "command mode" to a flag pbonzini
2020-02-19 19:11   ` Eric Sunshine
2020-02-20 16:00     ` Johannes Schindelin
2020-02-19 19:15   ` Junio C Hamano
2020-02-19 21:05     ` Paolo Bonzini
2020-02-19 16:13 ` [PATCH 2/4] am: convert "resume" variable to a struct pbonzini
2020-02-19 19:19   ` Junio C Hamano
2020-02-19 21:05     ` Paolo Bonzini
2020-02-19 16:13 ` [PATCH 3/4] am: support --show-current-patch=raw as a synonym for--show-current-patch pbonzini
2020-02-19 19:34   ` Eric Sunshine [this message]
2020-02-19 20:17     ` Junio C Hamano
2020-02-19 20:53       ` Paolo Bonzini
2020-02-19 16:13 ` [PATCH 4/4] am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch pbonzini
2020-02-19 19:49   ` Eric Sunshine

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='CAPig+cQOZwA3aAzBko-RL8UnW77DuBY-s_-J2D+35Ofn=fFfsg@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=bfields@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=pbonzini@redhat.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).