All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] send-email: disable option auto-abbreviation
Date: Fri, 25 Nov 2022 12:31:48 -0500	[thread overview]
Message-ID: <87k03j54aj.fsf@kyleam.com> (raw)
In-Reply-To: <xmqqv8n3cxv9.fsf@gitster.g>

Junio C Hamano writes:

> Kyle Meyer <kyle@kyleam.com> writes:
[...]
>>   fatal: ambiguous argument '3': unknown revision or path not in the
>>   working tree.  [...]
>>
>> Disable Getopt's auto-abbreviation feature so that such options are
>> properly relayed to format-patch.  With this change, there is some
>> risk of breaking external scripts that rely on the abbreviation, but
>> that is hopefully unlikely given that Git does not advertise support
>> for auto-abbreviation and most subcommands do not support it.
>
> I personally have no sympathy to those who drive "format-patch" from
> inside "send-email".

I'm not one of those users myself, but I was prompted to look into this
by a report of the above error on another mailing list [*].  I do
sympathize with "skip the explicit format-patch" users that find that
error confusing.

  [*] https://yhetil.org/guix-patches/20221123190710.26517-1-paren@disroot.org

> Many subcommands of "git" do take uniquely abbreviated double-dashed
> option names, but it is true that we do not allow --vanything to be
> given as -v even when there is no other double-dashed option that
> begins with 'v', so "git send-email -v" that stands for "git
> send-email --validate" indeed is an odd thing.

Thanks for the correction. I didn't realize that many subcommands
supported abbreviated options.  I expected it to be, at most, the
remaining ones written in Perl.  When I tried out a couple of commands,
I convinced myself that auto-abbreviation wasn't generally supported:

  $ git log --onelin
  fatal: unrecognized argument: --onelin
  $ git diff --histog
  error: invalid option: --histog

But I didn't look hard enough.  Trying again, I stumbled onto a few
counterexamples (e.g., `git status --shor` works and so does `git
range-diff --le ...`).

And my claim in the commit message that "Git does not advertise support
for auto-abbreviation" is wrong.  I've now found this bit in gitcli(7):

  Abbreviating long options
  ~~~~~~~~~~~~~~~~~~~~~~~~~
  Commands that support the enhanced option parser accepts unique
  prefix of a long option as if it is fully spelled out, but use this
  with a caution.  For example, `git commit --amen` behaves as if you
  typed `git commit --amend`, but that is true only until a later version
  of Git introduces another option that shares the same prefix,
  e.g. `git commit --amenity` option.

> But robbing "git send-email --val" that expands to "--validate" from
> the users is going a bit too far, I am afraid.

Fair enough.  For the reasons above, the last sentence I wrote in the
commit message is invalid and can't justify the change.

> The right solution for allowing "-v 3" given to "format-patch" I think
> is to make send-email understand it and pass that through.  The
> presence of both ("validate" => \$validate) and ("v" =>
> \$reroll_count) in the GetOptions() argument would prevent "-v" to be
> taken as "--validate" while still allowing "--val" to be used as an
> abbrevatiion, no?

I'd think that would work, yes.  I'll look more into going this route.

With that approach, there are other cases of abbreviation intercepting
valid format patch options.  For example, send-email doesn't have the
short option -n while format-patch does, but that doesn't make it
through to format-patch:

  $ git send-email --dry-run -n @{u} | grep Subj
  Subject: [PATCH] send-email: disable option auto-abbreviation

  $ git send-email --dry-run --numbered @{u} | grep Subj
  Subject: [PATCH 1/1] send-email: disable option auto-abbreviation

> By the way, do we advertise support for any and all options to
> format-patch when the feature to drive it from send-email is used?
> Some of the options (e.g. "-o <directory>") do not make any sense in
> the context I would suspect.

Passing an -o to send-email would cause its format-patch call to fail
because send-email uses -o internally:

  $ git send-email --dry-run -o . @{u}
  fatal: two output directories?
  format-patch -o /tmp/W1ZGCr0hwv -o @{u}: command returned error: 128

In any case, here's the only relevant part I spot from
git-send-email(1):

  Patches can be specified as files, directories (which will send all
  files in the directory), or directly as a revision list.  In the last
  case, any format accepted by linkgit:git-format-patch[1] can be passed
  to git send-email, as well as options understood by
  linkgit:git-format-patch[1].

So, there's no mention that some options like -o do not make sense in
the send-email context, but perhaps that's obvious enough (at least in
my view it's much more obvious than '-v 3' and -n not being valid).

Thanks for the review.

  reply	other threads:[~2022-11-25 17:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  2:00 [PATCH] send-email: disable option auto-abbreviation Kyle Meyer
2022-11-25  7:11 ` Junio C Hamano
2022-11-25 17:31   ` Kyle Meyer [this message]
2022-11-26 20:21     ` [PATCH v2] send-email: relay '-v N' to format-patch Kyle Meyer
2022-11-27  1:25       ` Junio C Hamano
2022-11-28 12:34         ` Ævar Arnfjörð Bjarmason
2022-11-28  9:41       ` 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=87k03j54aj.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.