git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Igor Djordjevic <igor.d.djordjevic@gmail.com>
To: anatoly techtonik <techtonik@gmail.com>, git@vger.kernel.org
Subject: Re: Unify annotated and non-annotated tags
Date: Sat, 11 Nov 2017 02:46:39 +0100	[thread overview]
Message-ID: <ec4be1c2-a0cc-cec8-a566-06c11c8abe06@gmail.com> (raw)
In-Reply-To: <CAPkN8x+MELCnttE+xptKzYXsYPWqbiE59LABrwNBhFroayc+wQ@mail.gmail.com>

Hi Anatoly,

On 10/11/2017 11:58, anatoly techtonik wrote:
> It is hard to work with Git tags, because on low level hash
> of non-annotated tag is pointing to commit, but hash for
> annotated tag is pointing to tag metadata.
> 
> On low level that means that there is no way to get commit
> hash from tag in a single step. If tag is annotated, you need
> to find and parse ^{} string of show-ref, if not, then look for
> string without ^{}.

That is not quite true, as you can always dereference any tag 
(annotated or not) using "<tag>^0" notation, see git-rev-parse[1]:

  "As a special rule, <rev>^0 means the commit itself and is used when 
  <rev> is the object name of a tag object that refers to a commit 
  object."
 
> So, why not just make all tags work the same so that every
> tag has its own hash and you need to dereference it in the
> same way to get commit hash?
> 
> This way I could get all commit hashes with just:
> 
>     git show-ref --tags -d | grep "\^{}"
> 
> or abandon ^{} completely and show commit hashes on -d:
> 
>     git show-ref --tags --dereference
>
Depending on what you would _exactly_ like to do, you could get all 
tagged commit hashes like this:

	git rev-list --tags --no-walk

Note that each commit will be listed only once, even if more tags 
(annotated or not) point to it.

If you would like to mimic output of "git show-ref", repeating 
commits for each tag pointing to it and showing full tag name as 
well, you could do something like this, for example:

	for tag in $(git for-each-ref --format="%(refname)" refs/tags)
	do
		printf '%s %s\n' "$(git rev-parse $tag^0)" "$tag"
	done


Hope that helps a bit.

Regards, Buga

[1] https://git-scm.com/docs/git-rev-parse#git-rev-parse-emltrevgtemegemHEADv1510em

  reply	other threads:[~2017-11-11  1:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 10:58 Unify annotated and non-annotated tags anatoly techtonik
2017-11-11  1:46 ` Igor Djordjevic [this message]
2017-11-11  2:06   ` Junio C Hamano
2017-11-11  2:50     ` Igor Djordjevic
2017-11-23  7:31     ` anatoly techtonik
2017-12-23 13:33     ` anatoly techtonik
     [not found] <201711231458.vANEwUMK048049@elephants.elehost.com>
2017-11-23 15:08 ` Randall S. Becker
2017-11-23 21:24   ` Thomas Braun
2017-11-24  9:52   ` anatoly techtonik
2017-11-24 10:24     ` Ævar Arnfjörð Bjarmason
2017-12-02 21:26       ` anatoly techtonik
2017-12-03  5:54         ` 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

  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=ec4be1c2-a0cc-cec8-a566-06c11c8abe06@gmail.com \
    --to=igor.d.djordjevic@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=techtonik@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).