Stefan Beller <sbel...@google.com> writes:

> The prefix check is not related the check of pathspec magic; also there
> is no code that is relevant after we'd break the loop on a match for
> "prefix:". So move the check before the loop and shortcircuit the outer
> loop.
>
> Signed-off-by: Stefan Beller <sbel...@google.com>
> ---

What were we thinking back when we added this in the middle of the
loop at 233c3e6c (parse_pathspec: preserve prefix length via
PATHSPEC_PREFIX_ORIGIN, 2013-07-14)?  I am a bit embarrassed.

>  pathspec.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/pathspec.c b/pathspec.c
> index eba37c2..4dff252 100644
> --- a/pathspec.c
> +++ b/pathspec.c
> @@ -107,21 +107,22 @@ static void eat_long_magic(struct pathspec_item *item, 
> const char *elt,
>                       nextat = copyfrom + len;
>               if (!len)
>                       continue;
> +
> +             if (starts_with(copyfrom, "prefix:")) {
> +                     char *endptr;
> +                     *pathspec_prefix = strtol(copyfrom + 7,
> +                                               &endptr, 10);
> +                     if (endptr - copyfrom != len)
> +                             die(_("invalid parameter for pathspec magic 
> 'prefix'"));
> +                     continue;
> +             }
> +
>               for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) {
>                       if (strlen(pathspec_magic[i].name) == len &&
>                           !strncmp(pathspec_magic[i].name, copyfrom, len)) {
>                               *magic |= pathspec_magic[i].bit;
>                               break;
>                       }
> -                     if (starts_with(copyfrom, "prefix:")) {
> -                             char *endptr;
> -                             *pathspec_prefix = strtol(copyfrom + 7,
> -                                                       &endptr, 10);
> -                             if (endptr - copyfrom != len)
> -                                     die(_("invalid parameter for pathspec 
> magic 'prefix'"));
> -                             /* "i" would be wrong, but it does not matter */
> -                             break;
> -                     }
>               }
>               if (ARRAY_SIZE(pathspec_magic) <= i)
>                       die(_("Invalid pathspec magic '%.*s' in '%s'"),
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to