All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: John Cai <jcai@gitlab.com>
Cc: Erik Cervin Edin <erik@cervined.in>, git@vger.kernel.org
Subject: Re: bug: git name-rev --stdin --no-undefined on detached head
Date: Fri, 24 Dec 2021 11:42:27 -0800	[thread overview]
Message-ID: <xmqqk0ft3i3g.fsf@gitster.g> (raw)
In-Reply-To: <DA9B4728-C45D-4CA0-A40D-4A81665AB0E6@gitlab.com> (John Cai's message of "Thu, 23 Dec 2021 10:39:23 -0800")

John Cai <jcai@gitlab.com> writes:

> It seems like this bug can be generalized to “git name-rev
> --stdin” does not work with --no-undefined nor --name-only
>
> The --name-only case seems clear to me that we should fix
> it. It’s misleading to return the sha instead of “undefined”
> for a rev without a symbolic name, as a sha could be a symbolic
> name.
>
> I think we can also make the argument that --no-undefined should
> also die in --stdin mode when given a rev without any symbolic
> names.

Hmph, the manual page documents:

    --stdin::
            Transform stdin by substituting all the 40-character SHA-1
            hexes (say $hex) with "$hex ($rev_name)".  When used with
            --name-only, substitute with "$rev_name", omitting $hex
            altogether.  Intended for the scripter's use.

It is unfortunate that the way this option works is confusingly a
bit different from what we learned to expect from the --stdin option
other subcommands like "git pack-objects --stdin" takes.  In short,
these are not equivalent:

	git name-rev [<options>] $string
        printf "%s" "$string" | xargs git name-rev [<options>]
        printf "%s" "$string" | git name-rev --stdin [<options>]

The first two are supposed to be the equivalent, but the third one
is different by design.  Its `--stdin` mode is expected to read
something like this [*]:

	$ cat sample.txt
        A revision that exists 2ae0a9cb82 is shown here,
        and its full name is 2ae0a9cb8298185a94e5998086f380a355dd8907
        while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
        which probably is undescribable hexdigits.

and its designed use is to annotate its input into a more reader
friendly from with refnames where possible.  Here is what we get:

        $ git name-rev --stdin <sample.txt
        A revision that exists 2ae0a9cb82 is shown here,
        and its full name is 2ae0a9cb8298185a94e5998086f380a355dd8907 (master)
        while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
        which probably is undescribable hexdigits.

I notice a few things.

 * An abbreviated commit object name is not affected;

 * A 40-digit string that cannot be described with a reference is
   left alone, without "undefined".

It might be debatable that the latter may want to be annotated with
"undefined", but as the command does not molest other noise strings
like "its" "full" name" in the input, I think the current behaviour
is preferred over appending "(undefined)" after a string we do not
recognize that happens to be 40-hex.

When used with --name-only, we see this:

	$ git name-rev --name-only --stdin <sample.txt
        A revision that exists 2ae0a9cb82 is shown here,
        and its full name is master
        while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
        which probably is undescribable hexdigits.

So, as far as I can see, it is working as described.  If there is
any bug in the things I saw and shown here, it is that it is
misleading to claim that this behaviour is intended for scripter's
use.  It clearly is not scripter friendly when you want to run
"name-rev" on unbounded number of object names you have, which may
not fit on the command line, as that is not how it was designed to
be used.

Two possible things we can do to improve are

 * Fix the documentation; it is not for scripters but for annotating
   text with object names.

 * Possibly add --names-from-standard-input option that would behave
   more like "we cannot afford to stuff all object names on the
   command line, so we feed them one by one from the standard input"
   mode the "--stdin" option of other subcommands use.

I do not think the latter is so important, as it is perfectly OK to
use xargs to split the large input into multiple invocations of
name-rev.  This is unlike "pack-objects --stdin" where the command
needs to see _all_ input in a single invocation.


[Footnote]

* The sample input was produced with

        $ cat >sample.txt <<EOF
        A revision that exists $(git rev-parse --short HEAD) is shown here,
        and its full name is $(git rev-parse HEAD)
        while its tree object is $(git rev-parse HEAD:)
        which probably is undescribable hexdigits.
        EOF

if you want to try it at home ;-)

  parent reply	other threads:[~2021-12-24 19:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22 10:05 bug: git name-rev --stdin --no-undefined on detached head Erik Cervin Edin
2021-12-23 18:39 ` John Cai
2021-12-24  6:09   ` John Cai
2021-12-24 11:44     ` Erik Cervin Edin
2021-12-24 19:42   ` Junio C Hamano [this message]
2021-12-24 20:09     ` John Cai
2021-12-25  0:35     ` Junio C Hamano
2021-12-31 17:16     ` Philip Oakley

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=xmqqk0ft3i3g.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=erik@cervined.in \
    --cc=git@vger.kernel.org \
    --cc=jcai@gitlab.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.