show-ref: allow -d to work with --verify

Move handling of -d into show_one(), so that it takes effect when --verify is present as well as when it is absent. This is useful when the user wishes to avoid the costly iteration of refs. Signed-off-by: Vladimir Panteleev <git@thecybershadow.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vladimir Panteleev committed Jan 23, 2017 at 18:00 UTC f1627040b9305dc38994f799c172393909b2c70c
2 files changed +21 -11
builtin/show-ref.c
+12 -11
@@ -19,19 +19,27 @@ static const char *exclude_existing_arg;
19
20 static void show_one(const char *refname, const struct object_id *oid)
21 {
22 - const char *hex = find_unique_abbrev(oid->hash, abbrev);
22 + const char *hex;
23 + struct object_id peeled;
24 +
25 + hex = find_unique_abbrev(oid->hash, abbrev);
26 if (hash_only)
27 printf("%s\n", hex);
28 else
29 printf("%s %s\n", hex, refname);
30 +
31 + if (!deref_tags)
32 + return;
33 +
34 + if (!peel_ref(refname, peeled.hash)) {
35 + hex = find_unique_abbrev(peeled.hash, abbrev);
36 + printf("%s %s^{}\n", hex, refname);
37 + }
38 }
39
40 static int show_ref(const char *refname, const struct object_id *oid,
41 int flag, void *cbdata)
42 {
32 - const char *hex;
33 - struct object_id peeled;
34 -
43 if (show_head && !strcmp(refname, "HEAD"))
44 goto match;
45
@@ -79,13 +87,6 @@ match:
87
88 show_one(refname, oid);
89
82 - if (!deref_tags)
83 - return 0;
84 -
85 - if (!peel_ref(refname, peeled.hash)) {
86 - hex = find_unique_abbrev(peeled.hash, abbrev);
87 - printf("%s %s^{}\n", hex, refname);
88 - }
90 return 0;
91 }
92
t/t1403-show-ref.sh
+9
@@ -97,6 +97,9 @@ test_expect_success 'show-ref -d' '
97 git show-ref -d refs/tags/A refs/tags/C >actual &&
98 test_cmp expect actual &&
99
100 + git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
101 + test_cmp expect actual &&
102 +
103 echo $(git rev-parse refs/heads/master) refs/heads/master >expect &&
104 git show-ref -d master >actual &&
105 test_cmp expect actual &&
@@ -116,6 +119,12 @@ test_expect_success 'show-ref -d' '
119 test_cmp expect actual &&
120
121 test_must_fail git show-ref -d --verify heads/master >actual &&
122 + test_cmp expect actual &&
123 +
124 + test_must_fail git show-ref --verify -d A C >actual &&
125 + test_cmp expect actual &&
126 +
127 + test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
128 test_cmp expect actual
129
130 '