Re: [PATCH 18/25] list-files: delete redundant cached entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 6, 2015 at 9:52 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
> When both --cached and one of -amdAMD is used together we may have two
> entries of the same path, e.g. "  foo" and "MM foo". In this case it's
> pretty clear that "foo" must be tracked, no need to display "   foo".
> The new function does that.
>
> Helped-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
> diff --git a/builtin/list-files.c b/builtin/list-files.c
> index 14ffd62..31c2336 100644
> --- a/builtin/list-files.c
> +++ b/builtin/list-files.c
> @@ -93,7 +93,10 @@ static int compare_item(const void *a_, const void *b_)
>  {
>         const struct item *a = a_;
>         const struct item *b = b_;
> -       return strcmp(a->path, b->path);
> +       int ret = strcmp(a->path, b->path);
> +       if (ret)
> +               return ret;
> +       return strncmp(a->tag, b->tag, 2);
>  }
>
>  static void free_item(struct item *item)
> @@ -132,7 +135,12 @@ static void remove_duplicates(struct item_list *list)
>         for (src = dst = 1; src < list->nr; src++) {
>                 if (!compare_item(list->items + dst - 1, list->items + src))
>                         free_item(list->items + src);
> -               else
> +               else if ((list->items[dst - 1].tag[0] == ' ' &&
> +                         list->items[dst - 1].tag[1] == ' ' &&
> +                         !strcmp(list->items[src].path, list->items[dst - 1].path))) {
> +                       free_item(list->items + dst - 1);
> +                       list->items[dst - 1] = list->items[src];

I was wondering if you could drop this backward-patching case by
having tag=="  " items sort after tag="xx" items and just fold out the
tag=="  " items normally in the preceding 'if', however, when I
started coding it, I found that the resulting code wasn't any more
pleasant.

> +               } else
>                         list->items[dst++] = list->items[src];
>         }
>         list->nr = dst;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]