builtin/show-ref: stop using global variable to count matches
When passing patterns to git-show-ref(1) we're checking whether any reference matches -- if none do, we indicate this condition via an unsuccessful exit code. We're using a global variable to count these matches, which is required because the counter is getting incremented in a callback function. But now that we have the `struct show_ref_data` in place, we can get rid of the global variable and put the counter in there instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Oct 31, 2023 at 09:16 UTC
84650989b7055a9016972b8430c882d7d8582e4f
1 file changed
+4
-3
builtin/show-ref.c
+4
-3
@@ -18,7 +18,7 @@ static const char * const show_ref_usage[] = {
18
NULL
19
};
20
21
-static int deref_tags, show_head, tags_only, heads_only, found_match, verify,
21
+static int deref_tags, show_head, tags_only, heads_only, verify,
22
quiet, hash_only, abbrev;
23
24
static void show_one(const char *refname, const struct object_id *oid)
@@ -50,6 +50,7 @@ static void show_one(const char *refname, const struct object_id *oid)
50
51
struct show_ref_data {
52
const char **patterns;
53
+ int found_match;
54
};
55
56
static int show_ref(const char *refname, const struct object_id *oid,
@@ -78,7 +79,7 @@ static int show_ref(const char *refname, const struct object_id *oid,
79
}
80
81
match:
81
- found_match++;
82
+ data->found_match++;
83
84
show_one(refname, oid);
85
@@ -191,7 +192,7 @@ static int cmd_show_ref__patterns(const char **patterns)
192
} else {
193
for_each_ref(show_ref, &show_ref_data);
194
}
194
- if (!found_match)
195
+ if (!show_ref_data.found_match)
196
return 1;
197
198
return 0;