git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref
@ 2008-05-23 14:13 Johannes Sixt
  2008-05-24  0:02 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Sixt @ 2008-05-23 14:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

From: Johannes Sixt <johannes.sixt@telecom.at>

The intention of --symbolic-full-name is to not print anything if a
revision is not an exact ref. But this command:

    $ git-rev-parse --symbolic-full-name --not master~1

still emitted a sole '^' to stdout (provided that there's no other ref at
master~1). This fixes it.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 builtin-rev-parse.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 0e59707..afa4d6d 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -96,6 +96,14 @@ static void show(const char *arg)
 		puts(arg);
 }

+/* Like show(), but with a negation prefix according to type */
+static void show_with_type(int type, const char *arg)
+{
+	if (type != show_type)
+		putchar('^');
+	show(arg);
+}
+
 /* Output a revision, only if filter allows it */
 static void show_rev(int type, const unsigned char *sha1, const char *name)
 {
@@ -104,8 +112,6 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
 	def = NULL;
 	revs_count++;

-	if (type != show_type)
-		putchar('^');
 	if (symbolic && name) {
 		if (symbolic == SHOW_SYMBOLIC_FULL) {
 			unsigned char discard[20];
@@ -122,20 +128,20 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
 				 */
 				break;
 			case 1: /* happy */
-				show(full);
+				show_with_type(type, full);
 				break;
 			default: /* ambiguous */
 				error("refname '%s' is ambiguous", name);
 				break;
 			}
 		} else {
-			show(name);
+			show_with_type(type, name);
 		}
 	}
 	else if (abbrev)
-		show(find_unique_abbrev(sha1, abbrev));
+		show_with_type(type, find_unique_abbrev(sha1, abbrev));
 	else
-		show(sha1_to_hex(sha1));
+		show_with_type(type, sha1_to_hex(sha1));
 }

 /* Output a flag, only if filter allows it. */
-- 
1.5.5.1.125.gb9f88

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref
  2008-05-23 14:13 [PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref Johannes Sixt
@ 2008-05-24  0:02 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-05-24  0:02 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Git Mailing List

Johannes Sixt <j.sixt@viscovery.net> writes:

> From: Johannes Sixt <johannes.sixt@telecom.at>
>
> The intention of --symbolic-full-name is to not print anything if a
> revision is not an exact ref. But this command:
>
>     $ git-rev-parse --symbolic-full-name --not master~1
>
> still emitted a sole '^' to stdout (provided that there's no other ref at
> master~1).

Well spotted.  Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-05-24  0:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-23 14:13 [PATCH] rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref Johannes Sixt
2008-05-24  0:02 ` Junio C Hamano

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 NNTP newsgroup(s).