threads / discuss / 14258

git describe --tags --long barfs on new tags?

Subject: git describe --tags --long barfs on new tags?

## tl;dr

5 messages between Jul 2, 2008 and Jul 3, 2008.

replies: 4people: 5as markdown or json

Mark Burton· Jul 2, 2008, 14:45 UTC · lore
Howdy folks,
Discovered this today:

~/git[master]$ git tag mb ~/git[master]$ git describe v1.5.6.1-156-ge903b40 ~/git[master]$ git describe --tags mb ~/git[master]$ git describe --tags --long Segmentation fault (core dumped)

Hope this is useful info.
BTW - just started using git and I am very impressed with it - took me a while to get my head around the "index" but now I wonder what the problem was.
Cheers,
Mark
Mikael Magnusson· Jul 2, 2008, 19:56 UTC · re: Mark Burton · lore

Re: git describe --tags --long barfs on new tags?

2008/7/2 Mark Burton <markb@ordern.com>:
Show 16 quoted lines
>
> Howdy folks,
>
> Discovered this today:
>
> ~/git[master]$ git tag mb
> ~/git[master]$ git describe
> v1.5.6.1-156-ge903b40
> ~/git[master]$ git describe --tags
> mb
> ~/git[master]$ git describe --tags --long
> Segmentation fault (core dumped)
>
> Hope this is useful info.
>
> BTW - just started using git and I am very impressed with it - took me a while to get my head around the "index" but now I wonder what the problem was.
Here's a backtrace, i tried to follow the code but got confused and gave up.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xa7cd26c0 (LWP 9670)]
0x080615f2 in describe (arg=0x80e4e9e "HEAD", last_one=1) at
builtin-describe.c:207
207				show_suffix(0, n->tag->tagged->sha1);
(gdb) bt
#0  0x080615f2 in describe (arg=0x80e4e9e "HEAD", last_one=1) at
builtin-describe.c:207
#1  0x08061bd8 in cmd_describe (argc=0, argv=0xafcd25f4, prefix=0x0)
at builtin-describe.c:360
#2  0x0804b1bf in handle_internal_command (argc=3, argv=0xafcd25f4) at git.c:252
#3  0x0804b888 in main (argc=3, argv=0x41c294c0) at git.c:463
(gdb) print n
$1 = <value optimized out>
(gdb) print cmit
$3 = (struct commit *) 0x81476a8
(gdb) print cmit->util
$4 = (void *) 0x8147430
(gdb) print *(struct commit_name*)cmit->util
$5 = {tag = 0x0, prio = 1, sha1 =
"\tEt\"±d6ª\033\005\230\237\035ëR\226¼á\017\230",
  path = 0x814744c "mb"}
-- 
Mikael Magnusson
Shawn O. Pearce· Jul 3, 2008, 02:32 UTC · re: Mikael Magnusson · lore

[PATCH] Fix describe --tags --long so it does not segfault

If we match a lightweight (non-annotated tag) as the name to output and --long was requested we do not have a tag, nor do we have a tagged object to display. Instead we must use the object we were passed as input for the long format display.

Reported-by: Mark Burton <markb@ordern.com>
Backtraced-by: Mikael Magnusson <mikachu@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 Thanks Mikael, the backtrace really made it easy to figure out
 what the breakage was here.
 builtin-describe.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index 3da99c1..e515f9c 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -204,7 +204,7 @@ static void describe(const char *arg, int last_one)
 		 */
 		display_name(n);
 		if (longformat)
-			show_suffix(0, n->tag->tagged->sha1);
+			show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1);
 		printf("\n");
 		return;
 	}
-- 
1.5.6.74.g8a5e
Junio C Hamano· Jul 3, 2008, 04:23 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Fix describe --tags --long so it does not segfault

"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 12 quoted lines
> If we match a lightweight (non-annotated tag) as the name to
> output and --long was requested we do not have a tag, nor do
> we have a tagged object to display.  Instead we must use the
> object we were passed as input for the long format display.
>
> Reported-by: Mark Burton <markb@ordern.com>
> Backtraced-by: Mikael Magnusson <mikachu@gmail.com>
> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
> ---
>
>  Thanks Mikael, the backtrace really made it easy to figure out
>  what the breakage was here.

Thanks. I'll squash this in and apply to 'maint'. Perhaps 1.5.6.2 after the 4th holiday.

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index c6be259..2fb672c 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -139,4 +139,6 @@ check_describe "test1-lightweight-*" --tags --match="test1-*"
 
 check_describe "test2-lightweight-*" --tags --match="test2-*"
 
+check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
+
 test_done
Abhijit Menon-Sen· Jul 3, 2008, 02:49 UTC · re: Mikael Magnusson · lore

Re: git describe --tags --long barfs on new tags?

(Sorry for the broken References. I deleted the message before realising that I wanted to reply to it; and I couldn't easily find an mbox archive to snarf the whole message from.)

Show 7 quoted lines
> ~/git[master]$ git tag mb
> ~/git[master]$ git describe
> v1.5.6.1-156-ge903b40
> ~/git[master]$ git describe --tags
> mb
> ~/git[master]$ git describe --tags --long
> Segmentation fault (core dumped)

Not on new tags, but on un-annotated ones (which the --tags brings into consideration). The appended patch fixes the problem for me, but I'd be grateful if someone could confirm that it's the right thing to do.

-- ams
diff --git a/builtin-describe.c b/builtin-describe.c
index 3da99c1..7ed4757 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -203,8 +203,12 @@ static void describe(const char *arg, int last_one)
 		 * Exact match to an existing ref.
 		 */
 		display_name(n);
-		if (longformat)
-			show_suffix(0, n->tag->tagged->sha1);
+		if (longformat) {
+			const unsigned char *sha1 = n->sha1;
+			if (n->tag)
+				sha1 = n->tag->tagged->sha1;
+			show_suffix(0, sha1);
+		}
 		printf("\n");
 		return;
 	}

← back to recent threads