Message ID | d52a5e8ced2adc5c9315edea9fc497d1ffa30125.1698314128.git.ps@pks.im (mailing list archive) |
---|---|
State | Accepted |
Commit | 84650989b7055a9016972b8430c882d7d8582e4f |
Headers | show |
Series | show-ref: introduce mode to check for ref existence | expand |
On Thu, Oct 26, 2023 at 11:56:42AM +0200, Patrick Steinhardt wrote: > When passing patterns to git-show-ref(1) we're checking whether any > reference matches -- if none does, we indicate this condition via an > unsuccessful exit code. s/does/do, but not a big enough deal to reroll IMHO. > 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> > --- > builtin/show-ref.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) Looks all good to me! Thanks, Taylor
diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 90481c58492..c30c01785cc 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -18,7 +18,7 @@ static const char * const show_ref_usage[] = { NULL }; -static int deref_tags, show_head, tags_only, heads_only, found_match, verify, +static int deref_tags, show_head, tags_only, heads_only, verify, quiet, hash_only, abbrev; 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) struct show_ref_data { const char **patterns; + int found_match; }; 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, } match: - found_match++; + data->found_match++; show_one(refname, oid); @@ -187,7 +188,7 @@ static int cmd_show_ref__patterns(const char **patterns) } else { for_each_ref(show_ref, &show_ref_data); } - if (!found_match) + if (!show_ref_data.found_match) return 1; return 0;
When passing patterns to git-show-ref(1) we're checking whether any reference matches -- if none does, 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> --- builtin/show-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)