Re: [PATCH 18/25] list-files: delete redundant cached entries
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 6, 2015, 21:35 UTC
- Message-ID
- <CAPig+cTDHf5Wh92SLHfQ0_GRY0cbpz+ALfiukJJHed6d=QmLdg@mail.gmail.com>
- In-Reply-To
- <1428328354-14897-19-git-send-email-pclouds@gmail.com>
On Mon, Apr 6, 2015 at 9:52 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 34 quoted lines
> 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@sunshineco.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> 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;