git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 8, 2015, 02:39 UTC
Message-ID
<xmqqzj6jbayi.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAPig+cTDHf5Wh92SLHfQ0_GRY0cbpz+ALfiukJJHed6d=QmLdg@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 41 quoted lines
> On Mon, Apr 6, 2015 at 9:52 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> 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@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.

You may read from wt-status and then index (or the other way around) into the set of files to be listed---instead of deduping at the end, you should logically do "add in from index only for entries we did not see in wt-status output". So some deduping is necessary.

But I actually think that the worst aspect of the series this part of the code shows is the same issue I raised in the previous review round in the approach, which has not been addressed at all as far as I can see in this round.

Why does tag[] record the semantic meaning in textual form? Isn't this a sympotom that shows the code is turning the information into textual form way too early, which makes the code very unpleasant to read and hard to maintain and modify.

Previous: Eric SunshineNext: Nguyễn Thái Ngọc Duy
Message 26 of 36 in “list-files redesign”
  1. 00/25 list-files redesignNguyễn Thái Ngọc Duy, Apr 6, 2015
  2. 01/25 ls_colors.c: add $LS_COLORS parsing codeNguyễn Thái Ngọc Duy, Apr 6, 2015
  3. 02/25 ls_colors.c: parse color.ls.* from config fileNguyễn Thái Ngọc Duy, Apr 6, 2015
  4. 03/25 ls_colors.c: add a function to color a file nameNguyễn Thái Ngọc Duy, Apr 6, 2015
  5. 04/25 ls_colors.c: highlight submodules like directoriesNguyễn Thái Ngọc Duy, Apr 6, 2015
  6. 05/25 list-files: command skeletonNguyễn Thái Ngọc Duy, Apr 6, 2015
  7. 06/25 list-files: show paths relative to cwdNguyễn Thái Ngọc Duy, Apr 6, 2015
  8. 07/25 list-files: add tag to each entry, filter duplicate tagsNguyễn Thái Ngọc Duy, Apr 6, 2015
  9. Eric SunshineApr 6, 2015
  10. 08/25 list-files: add --[no-]column, -C and -1Nguyễn Thái Ngọc Duy, Apr 6, 2015
  11. 09/25 list-files: add --max-depth, -R and default to --max-depth=0Nguyễn Thái Ngọc Duy, Apr 6, 2015
  12. 10/25 list-files: show directories as well as filesNguyễn Thái Ngọc Duy, Apr 6, 2015
  13. 11/25 list-files: add --colorNguyễn Thái Ngọc Duy, Apr 6, 2015
  14. Eric SunshineApr 6, 2015
  15. 12/25 list-files: add -F/--classifyNguyễn Thái Ngọc Duy, Apr 6, 2015
  16. 13/25 list-files: new indicator '&' for submodules when -F is usedNguyễn Thái Ngọc Duy, Apr 6, 2015
  17. 14/25 list-files: add --cached and --othersNguyễn Thái Ngọc Duy, Apr 6, 2015
  18. 15/25 list-files: add --ignoredNguyễn Thái Ngọc Duy, Apr 6, 2015
  19. Eric SunshineApr 6, 2015
  20. 16/25 list-files: add --unmergedNguyễn Thái Ngọc Duy, Apr 6, 2015
  21. Eric SunshineApr 6, 2015
  22. 17/25 list-files: add file modification options -[admADM]Nguyễn Thái Ngọc Duy, Apr 6, 2015
  23. Eric SunshineApr 6, 2015
  24. 18/25 list-files: delete redundant cached entriesNguyễn Thái Ngọc Duy, Apr 6, 2015
  25. Eric SunshineApr 6, 2015
  26. Junio C HamanoApr 8, 2015
  27. 19/25 list-files: make alias 'ls' default to 'list-files'Nguyễn Thái Ngọc Duy, Apr 6, 2015
  28. 20/25 list-files: preload indexNguyễn Thái Ngọc Duy, Apr 6, 2015
  29. Eric SunshineApr 6, 2015
  30. 21/25 list-files: reduce match_pathspec calls in matched()Nguyễn Thái Ngọc Duy, Apr 6, 2015
  31. 22/25 list-files: only do diff that is actually usefulNguyễn Thái Ngọc Duy, Apr 6, 2015
  32. 23/25 pathspec: move getenv() code out of prefix_pathspec()Nguyễn Thái Ngọc Duy, Apr 6, 2015
  33. 24/25 list-files: make :(glob) pathspec defaultNguyễn Thái Ngọc Duy, Apr 6, 2015
  34. 25/25 list-files: documentationNguyễn Thái Ngọc Duy, Apr 6, 2015
  35. Eric SunshineApr 6, 2015
  36. Duy NguyenApr 6, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.