Re: [PATCH 2/3] name-rev: strip trailing ^0 in when --name-only

2013-07-08 Thread Ramkumar Ramachandra
Junio C Hamano wrote:
 But I do not think name-rev is limited
 to commits, in the sense that you would see this:

 $ git rev-parse v1.8.3 v1.8.3^0 | git name-rev --stdin
 8af06057d0c31a24e8737ae846ac2e116e8bafb9
 edca4152560522a431a51fc0a06147fc680b5b18 (tags/v1.8.3^0)

 The second object is _not_ v1.8.3 but is v1.8.3^0 in the context of
 name-rev, whose purpose is to give you a string you can feed
 rev-parse and get the object name back.  rev-parse v1.8.3 will
 not give you the commit object name, so you need to keep ^0.

Quite frankly, I thought the unstripped ^0 in one codepath was an
unintended quirk.  What exactly do you want name-rev to give you?

  $ git tag foo @^
  $ git name-rev foo
  foo tags/foo

So you can distinguish between annotated tags, unannotated tags, and
head-refs.  Can you get it to tell you anything reliably though?

  $ git tag bar @
  $ git tag -a baz @
  $ git name-rev @
  $ git name-rev bar
  $ git name-rev baz

ref, annotated, or unannotated tag?  I do not think name-rev is
fundamentally different from describe: it is also only dependent on
the commit history graph.  Whether I specify a revision using @, HEAD,
baz, or bar, I should get the same answer (it's just a recursive
peeler).  I'm not sure what you gain by knowing the object type of the
output.  If you wanted to feed something into rev-parse and get out a
commit, you'd send in $REV^0 without bothering about what it is, no?
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] name-rev: strip trailing ^0 in when --name-only

2013-07-07 Thread Ramkumar Ramachandra
236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced
`git name-rev --name-only`, with the intent of using it to implement
`git describe --contains`.  According to the message, one of the primary
objectives of --name-only was to make the output of name-rev match that
of describe.

  $ git describe --contains --all master
  master

  $ git describe --contains --all master~1
  master~1

  $ git describe --contains --all v1.8.3~1
  v1.8.3~1

  $ git describe --contains --all v1.8.3
  v1.8.3^0

The last invocation unnecessarily prints a trailing ^0 (--stdin does
not suffer from this defect).  Fix this.

Signed-off-by: Ramkumar Ramachandra artag...@gmail.com
---
 builtin/name-rev.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 37207a9..8ba5d72 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -186,7 +186,14 @@ static void show_name(const struct object *obj,
if (!name_only)
printf(%s , caller_name ? caller_name : sha1_to_hex(sha1));
name = get_rev_name(obj);
-   if (name)
+
+   if (name  name_only) {
+   /* strip possible trailing ^0 from name */
+   int len = strlen(name);
+   if (len  2  !strcmp(name + len - 2, ^0))
+   len -= 2;
+   printf(%.*s\n, len, name);
+   } else if (name)
printf(%s\n, name);
else if (allow_undefined)
printf(undefined\n);
-- 
1.8.3.2.737.gcbc076a.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] name-rev: strip trailing ^0 in when --name-only

2013-07-07 Thread Junio C Hamano
Ramkumar Ramachandra artag...@gmail.com writes:

 236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced
 `git name-rev --name-only`, with the intent of using it to implement
 `git describe --contains`.  According to the message, one of the primary
 objectives of --name-only was to make the output of name-rev match that
 of describe.

   $ git describe --contains --all master
   master

   $ git describe --contains --all master~1
   master~1

   $ git describe --contains --all v1.8.3~1
   v1.8.3~1

   $ git describe --contains --all v1.8.3
   v1.8.3^0

WRT describe --contains, I do agree that both of these

$ git describe $(git rev-parse v1.8.3^0)
$ git describe --contains $(git rev-parse v1.8.3^0)

should just say v1.8.3 without ~0/^0/~0~0~0 etc. and the last
example you showed will be improved by dropping ^0 at the end.

However.

I was a bit bothered by the description talking _only_ about
describe, but the actual change is to modify what name-rev gives its
direct users as well.  And that made me realize that the patch
itself has an undesirable side effect.

describe is _only_ about commit history graph, so in its context
v1.8.3 means the same thing as v1.8.3^0 (we never want to get a tag;
we always want a commit).  But I do not think name-rev is limited
to commits, in the sense that you would see this:

$ git rev-parse v1.8.3 v1.8.3^0 | git name-rev --stdin
8af06057d0c31a24e8737ae846ac2e116e8bafb9
edca4152560522a431a51fc0a06147fc680b5b18 (tags/v1.8.3^0)

The second object is _not_ v1.8.3 but is v1.8.3^0 in the context of
name-rev, whose purpose is to give you a string you can feed
rev-parse and get the object name back.  rev-parse v1.8.3 will
not give you the commit object name, so you need to keep ^0.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] name-rev: strip trailing ^0 in when --name-only

2013-07-07 Thread Junio C Hamano
Junio C Hamano gits...@pobox.com writes:

 WRT describe --contains, I do agree that both of these

 $ git describe $(git rev-parse v1.8.3^0)
 $ git describe --contains $(git rev-parse v1.8.3^0)
 
 should just say v1.8.3 without ~0/^0/~0~0~0 etc. and the last
 example you showed will be improved by dropping ^0 at the end.

 However.

 I was a bit bothered by the description talking _only_ about
 describe, but the actual change is to modify what name-rev gives its
 direct users as well.  And that made me realize that the patch
 itself has an undesirable side effect.

 describe is _only_ about commit history graph, so in its context
 v1.8.3 means the same thing as v1.8.3^0 (we never want to get a tag;
 we always want a commit).  But I do not think name-rev is limited
 to commits, in the sense that you would see this:

 $ git rev-parse v1.8.3 v1.8.3^0 | git name-rev --stdin
 8af06057d0c31a24e8737ae846ac2e116e8bafb9
 edca4152560522a431a51fc0a06147fc680b5b18 (tags/v1.8.3^0)

 The second object is _not_ v1.8.3 but is v1.8.3^0 in the context of
 name-rev, whose purpose is to give you a string you can feed
 rev-parse and get the object name back.  rev-parse v1.8.3 will
 not give you the commit object name, so you need to keep ^0.

Well, the code in name-rev other than --stdin mode is already
broken (and the documentation half-describes this breakage) in that
it describes the peeled commit and rejects anything other than
commit objects.  The reason I say half-describes is that it only
says that the command takes commit-ish and leaves it unclear if it
comes up with a name for the tag itself that happens to be
commit-ish, or it does so for the commit that is referred by the
tag.

I'll send out a WIP to fix that, and also help the topic to strip
unnecessary ^0 suffix when name-rev is run as an implementation
detail of describe shortly.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html