Skip to content

Commit e00f379

Browse files
Johannes Sixtgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e77b0b5 commit e00f379

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

builtin-rev-parse.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ static void show(const char *arg)
9696
puts(arg);
9797
}
9898

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+
99107
/* Output a revision, only if filter allows it */
100108
static void show_rev(int type, const unsigned char *sha1, const char *name)
101109
{
@@ -104,8 +112,6 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
104112
def = NULL;
105113
revs_count++;
106114

107-
if (type != show_type)
108-
putchar('^');
109115
if (symbolic && name) {
110116
if (symbolic == SHOW_SYMBOLIC_FULL) {
111117
unsigned char discard[20];
@@ -122,20 +128,20 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
122128
*/
123129
break;
124130
case 1: /* happy */
125-
show(full);
131+
show_with_type(type, full);
126132
break;
127133
default: /* ambiguous */
128134
error("refname '%s' is ambiguous", name);
129135
break;
130136
}
131137
} else {
132-
show(name);
138+
show_with_type(type, name);
133139
}
134140
}
135141
else if (abbrev)
136-
show(find_unique_abbrev(sha1, abbrev));
142+
show_with_type(type, find_unique_abbrev(sha1, abbrev));
137143
else
138-
show(sha1_to_hex(sha1));
144+
show_with_type(type, sha1_to_hex(sha1));
139145
}
140146

141147
/* Output a flag, only if filter allows it. */

0 commit comments

Comments
 (0)