git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jacob Keller <jacob.keller@gmail.com>
To: Max Kirillov <max@max630.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	Git mailing list <git@vger.kernel.org>
Subject: Re: [PATCH] describe: fix matching to actually match all patterns
Date: Sat, 16 Sep 2017 00:48:24 -0700	[thread overview]
Message-ID: <CA+P7+xqQQAd4X9PjjbRy7RTZVO6BqomQ2uiRXZ6pCSb-z+RC6Q@mail.gmail.com> (raw)
In-Reply-To: <20170916055344.31866-1-max@max630.net>

On Fri, Sep 15, 2017 at 10:53 PM, Max Kirillov <max@max630.net> wrote:
> `git describe --match` with multiple patterns matches only first pattern.
> If it fails, next patterns are not tried.
>
> Fix it, add test cases and update existing test which has wrong
> expectation.
>
> Signed-off-by: Max Kirillov <max@max630.net>
> ---
>  builtin/describe.c  | 9 ++++++---
>  t/t6120-describe.sh | 6 +++++-
>  2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/describe.c b/builtin/describe.c
> index 89ea1cdd60..94ff2fba0b 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -155,18 +155,21 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
>          * pattern.
>          */
>         if (patterns.nr) {
> +               int found = 0;
>                 struct string_list_item *item;
>
>                 if (!is_tag)
>                         return 0;
>
>                 for_each_string_list_item(item, &patterns) {
> -                       if (!wildmatch(item->string, path + 10, 0))
> +                       if (!wildmatch(item->string, path + 10, 0)) {
> +                               found = 1;
>                                 break;

I see what was wrong. The "if we got here" check is inside the loop,
so after the first wildmatch we never loop again. The fix is to add an
additional variable to store when we found something and exit the
loop, and ensure that we actually did the whole loop without finding a
match.

Thanks for the fix and proper tests!

Regards,
Jake


> +                       }
> +               }
>
> -                       /* If we get here, no pattern matched. */
> +               if (!found)
>                         return 0;
> -               }
>         }
>
>         /* Is it annotated? */
> diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
> index aa74eb8f0d..25110ea55d 100755
> --- a/t/t6120-describe.sh
> +++ b/t/t6120-describe.sh
> @@ -182,10 +182,14 @@ check_describe "test2-lightweight-*" --tags --match="test2-*"
>
>  check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
>
> -check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
> +check_describe "test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
>
>  check_describe "test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
>
> +check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test3-*" HEAD
> +
> +check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
> +
>  test_expect_success 'name-rev with exact tags' '
>         echo A >expect &&
>         tag_object=$(git rev-parse refs/tags/A) &&
> --
> 2.11.0.1122.gc3fec58.dirty
>

      reply	other threads:[~2017-09-16  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-16  5:53 [PATCH] describe: fix matching to actually match all patterns Max Kirillov
2017-09-16  7:48 ` Jacob Keller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+P7+xqQQAd4X9PjjbRy7RTZVO6BqomQ2uiRXZ6pCSb-z+RC6Q@mail.gmail.com \
    --to=jacob.keller@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=max@max630.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).