show-ref: fix --verify --hash=length
An earlier optimization for --verify broke a lot of stuff because it did not take interaction with other flags into account. This also fixes an unrelated argument parsing error; --hash=8 should mean the same as "--hash --abbrev=8". Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 17, 2006 at 19:27 UTC
64fe031a7a78894955af217335b46059a36a582d
1 file changed
+15
-10
builtin-show-ref.c
+15
-10
@@ -10,6 +10,15 @@ static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0,
10
found_match = 0, verify = 0, quiet = 0, hash_only = 0, abbrev = 0;
11
static const char **pattern;
12
13
+static void show_one(const char *refname, const unsigned char *sha1)
14
+{
15
+ const char *hex = find_unique_abbrev(sha1, abbrev);
16
+ if (hash_only)
17
+ printf("%s\n", hex);
18
+ else
19
+ printf("%s %s\n", hex, refname);
20
+}
21
+
22
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
23
{
24
struct object *obj;
@@ -58,11 +67,7 @@ match:
67
if (quiet)
68
return 0;
69
61
- hex = find_unique_abbrev(sha1, abbrev);
62
- if (hash_only)
63
- printf("%s\n", hex);
64
- else
65
- printf("%s %s\n", hex, refname);
70
+ show_one(refname, sha1);
71
72
if (!deref_tags)
73
return 0;
@@ -175,13 +180,13 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
180
if (!strncmp(arg, "--hash=", 7) ||
181
(!strncmp(arg, "--abbrev", 8) &&
182
(arg[8] == '=' || arg[8] == '\0'))) {
178
- if (arg[3] != 'h' && !arg[8])
183
+ if (arg[2] != 'h' && !arg[8])
184
/* --abbrev only */
185
abbrev = DEFAULT_ABBREV;
186
else {
187
/* --hash= or --abbrev= */
188
char *end;
184
- if (arg[3] == 'h') {
189
+ if (arg[2] == 'h') {
190
hash_only = 1;
191
arg += 7;
192
}
@@ -218,10 +223,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
223
unsigned char sha1[20];
224
225
while (*pattern) {
221
- if (resolve_ref(*pattern, sha1, 1, NULL)) {
226
+ if (!strncmp(*pattern, "refs/", 5) &&
227
+ resolve_ref(*pattern, sha1, 1, NULL)) {
228
if (!quiet)
223
- printf("%s %s\n",
224
- sha1_to_hex(sha1), *pattern);
229
+ show_one(*pattern, sha1);
230
}
231
else if (!quiet)
232
die("'%s' - not a valid ref", *pattern);