Skip to content

Commit 8465098

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7907fb0 commit 8465098

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/show-ref.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char * const show_ref_usage[] = {
1818
NULL
1919
};
2020

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,
2222
quiet, hash_only, abbrev;
2323

2424
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)
5050

5151
struct show_ref_data {
5252
const char **patterns;
53+
int found_match;
5354
};
5455

5556
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,
7879
}
7980

8081
match:
81-
found_match++;
82+
data->found_match++;
8283

8384
show_one(refname, oid);
8485

@@ -191,7 +192,7 @@ static int cmd_show_ref__patterns(const char **patterns)
191192
} else {
192193
for_each_ref(show_ref, &show_ref_data);
193194
}
194-
if (!found_match)
195+
if (!show_ref_data.found_match)
195196
return 1;
196197

197198
return 0;

0 commit comments

Comments
 (0)