rev-parse --symbolic-full-name: don't print '^' if SHA1 is not a ref
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
May 23, 2008 at 16:13 UTC
e00f3790b88ce61f1bdc863011a122b98b43197e
1 file changed
+12
-6
builtin-rev-parse.c
+12
-6
@@ -96,6 +96,14 @@ static void show(const char *arg)
96
puts(arg);
97
}
98
99
+/* Like show(), but with a negation prefix according to type */
100
+static void show_with_type(int type, const char *arg)
101
+{
102
+ if (type != show_type)
103
+ putchar('^');
104
+ show(arg);
105
+}
106
+
107
/* Output a revision, only if filter allows it */
108
static void show_rev(int type, const unsigned char *sha1, const char *name)
109
{
@@ -104,8 +112,6 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
112
def = NULL;
113
revs_count++;
114
107
- if (type != show_type)
108
- putchar('^');
115
if (symbolic && name) {
116
if (symbolic == SHOW_SYMBOLIC_FULL) {
117
unsigned char discard[20];
@@ -122,20 +128,20 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
128
*/
129
break;
130
case 1: /* happy */
125
- show(full);
131
+ show_with_type(type, full);
132
break;
133
default: /* ambiguous */
134
error("refname '%s' is ambiguous", name);
135
break;
136
}
137
} else {
132
- show(name);
138
+ show_with_type(type, name);
139
}
140
}
141
else if (abbrev)
136
- show(find_unique_abbrev(sha1, abbrev));
142
+ show_with_type(type, find_unique_abbrev(sha1, abbrev));
143
else
138
- show(sha1_to_hex(sha1));
144
+ show_with_type(type, sha1_to_hex(sha1));
145
}
146
147
/* Output a flag, only if filter allows it. */