git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Doug Bell <madcityzen@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] show-ref: make --head always show the HEAD ref
Date: Thu, 11 Jul 2013 08:41:00 -0700	[thread overview]
Message-ID: <7v38rlt88j.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1369894105-48434-1-git-send-email-madcityzen@gmail.com> (Doug Bell's message of "Thu, 30 May 2013 01:08:25 -0500")

Doug Bell <madcityzen@gmail.com> writes:

> The docs seem to say that doing
>
> 	git show-ref --head --tags
>
> would show both the HEAD ref and all the tag refs. However, doing
> both --head and either of --tags or --heads would filter out the HEAD
> ref.
>
> Signed-off-by: Doug Bell <madcityzen@gmail.com>
> ---

I think this patch fell through the cracks, and looking at it, I am
somewhat torn.

The command help for "--head" says "show the HEAD reference", which
may mean:

 (1) in addition to everything else the command would do if there
     weren't this option specified, show HEAD;

 (2) show the HEAD and nothing else; or

 (3) add HEAD to the candidates to be shown, but apply the usual
     filtering rule based on --heads, --tags and/or pattern
     arguments.

While the last interpretation is what we have used since the
beginning of the command at 358ddb62 (Add "git show-ref" builtin
command, 2006-09-15), I tend to agree with you that the first
interpretation may make more sense, at least from the end user's
point of view.

But at a deeper level, it makes the command somewhat inconsistent.

What happens in the command is

 - We iterate over "candidates to be shown", which is usually
   "everything under refs/", but with "--head", HEAD is added to
   this set.  For each of these candidates:

   - if one or more <pattern> parameters are given, reject the
     candidate ref if it does not tail-match with any of the
     patterns;

   - if either "--heads" or "--tags" is given, among the ones that
     pass <pattern> filter, check if they:

     - begin with "refs/heads/" (if "--heads" is given); or
     - begin with "refs/tags/" (if "--tags" is given).

     and reject those that don't.

   - show it if it is still surviving after these two tests.

And taht is why "git show-ref --tags master v1.3.0" shows only the
v1.3.0 tag without showing the master branch, and giving "--heads"
instead of "--tags" yields only the master branch without the tag.

The semantics your patch wants, by changing the definition of
"--head" from (3) to (1), is:

 - If "--head" is given, show HEAD no matter what.

 - Iterate over everything under refs/, and for each of them, do the
   same filter-and-show as we currently do (see above).

While I think the new semantics is also understandable as the
current one, and personally I think it is a better behaviour than
the current one, it will require an update to the document to
highlight that "--head" is special-cased in a big way, to bypass all
the filtering that is applied to normal refs.

A few additional observations (these are not complaints to this
patch and please do not take them as such):

 - The command help says "(can be combined with heads)" for "--tags"
   and vice versa, but does not mention their interaction with
   "--head".  This is because we take interpretation (3) above and
   do not treat "--head" as a mechanism to add to <pattern>
   parameter like these two.

 - The command help for "--heads" and "--tags" says "only show
   heads/tags", which technically does not contradict with "can be
   combined with" above, but a logical consequence of combining
   ought to be showing nothing, as a ref cannot be a head (an old
   nomenclature for a "branch") and a tag at the same time.  

I think we should find a word better than "only" to use here, but I
am not sure what would be a good phrase to use.

  reply	other threads:[~2013-07-11 15:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30  6:08 [PATCH] show-ref: make --head always show the HEAD ref Doug Bell
2013-07-11 15:41 ` Junio C Hamano [this message]
2013-07-13  2:01   ` Doug Bell
2013-07-13  2:03   ` [PATCH v2] " Doug Bell
2013-07-13  2:03     ` [PATCH] " Doug Bell
2013-07-15 16:37       ` Junio C Hamano
2013-07-17  0:05         ` [PATCH v3] " Doug Bell
2013-07-17  0:05           ` [PATCH] " Doug Bell

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7v38rlt88j.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=madcityzen@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).