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

Re: [PATCH 03/16] list-files: show paths relative to cwd

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2015, 21:20 UTC
Message-ID
<xmqqsid929rb.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1425896314-10941-4-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 26 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/list-files.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/list-files.c b/builtin/list-files.c
> index b99f2b7..c444a53 100644
> --- a/builtin/list-files.c
> +++ b/builtin/list-files.c
> @@ -3,6 +3,7 @@
>  #include "parse-options.h"
>  #include "pathspec.h"
>  #include "dir.h"
> +#include "quote.h"
>  
>  static struct pathspec pathspec;
>  static const char *prefix;
> @@ -22,7 +23,7 @@ static void add_one(struct string_list *result, const char *name)
>  	struct strbuf sb = STRBUF_INIT;
>  	struct string_list_item *item;
>  
> -	strbuf_addstr(&sb, name);
> +	quote_path_relative(name, prefix_length ? prefix : NULL, &sb);
>  	item = string_list_append(result, strbuf_detach(&sb, NULL));
>  	item->util = (char *)name;
>  }

Hmph, wouldn't it make it more cumbersome and problematic to do things like this here in add_one() phase? I am imagining that the endgame of this program will be

    - populate_cached_entries() reads from the data source (at this
      step, there is just "the index"), calling add_one() whose
      responsibility is to record the paths that are interesting
      to an in-core structure;
    - perform some interesting filtering, annotating, ordering,
      etc. (at this step, there is none) yet to come;
    - display() will iterate over the result and then format the
      result.

For example, if you do the "quote" thing too early, don't codepaths in the later phases have to worry about item->string not matching the original pathname anymore? If you want to do something like "/bin/ls -t", you may have to lstat() the paths for each item, but if these store a path relative to the prefix, wouldn't you have to prepend the prefix again before running lstat()?

I am just wondering if this prefix-stripping and quoting belongs to the output phase, not the input phase.

Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 8 of 29 in “nd/list-files redesign”
  1. 00/16 nd/list-files redesignNguyễn Thái Ngọc Duy, Mar 9, 2015
  2. 01/16 list-files: command skeletonNguyễn Thái Ngọc Duy, Mar 9, 2015
  3. Junio C HamanoMar 12, 2015
  4. 02/16 list-files: make :(glob) pathspec defaultNguyễn Thái Ngọc Duy, Mar 9, 2015
  5. Junio C HamanoMar 12, 2015
  6. Duy NguyenMar 14, 2015
  7. 03/16 list-files: show paths relative to cwdNguyễn Thái Ngọc Duy, Mar 9, 2015
  8. Junio C HamanoMar 12, 2015
  9. Junio C HamanoMar 12, 2015
  10. Duy NguyenMar 14, 2015
  11. Junio C HamanoMar 15, 2015
  12. Duy NguyenMar 15, 2015
  13. 04/16 list-files: add tag to each entry, filter duplicate tagsNguyễn Thái Ngọc Duy, Mar 9, 2015
  14. Junio C HamanoMar 12, 2015
  15. 05/16 list-files: add --[no-]column, -C and -1Nguyễn Thái Ngọc Duy, Mar 9, 2015
  16. 06/16 list-files: add --max-depth and -RNguyễn Thái Ngọc Duy, Mar 9, 2015
  17. 07/16 list-files: show directories as well as filesNguyễn Thái Ngọc Duy, Mar 9, 2015
  18. Eric SunshineMar 10, 2015
  19. Duy NguyenMar 10, 2015
  20. 08/16 list-files: add --colorNguyễn Thái Ngọc Duy, Mar 9, 2015
  21. 09/16 list-files: add -F/--classifyNguyễn Thái Ngọc Duy, Mar 9, 2015
  22. 10/16 list-files: new indicator '&' for submodules when -F is usedNguyễn Thái Ngọc Duy, Mar 9, 2015
  23. 11/16 list-files: add --cached and --othersNguyễn Thái Ngọc Duy, Mar 9, 2015
  24. 12/16 list-files: add --ignoredNguyễn Thái Ngọc Duy, Mar 9, 2015
  25. 13/16 list-files: add --unmergedNguyễn Thái Ngọc Duy, Mar 9, 2015
  26. 14/16 list-files: add file modification options -[admADM]Nguyễn Thái Ngọc Duy, Mar 9, 2015
  27. 15/16 list-files: delete redundant cached entriesNguyễn Thái Ngọc Duy, Mar 9, 2015
  28. Eric SunshineMar 10, 2015
  29. 16/16 list-files: make alias 'ls' default to 'list-files'Nguyễn Thái Ngọc Duy, Mar 9, 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.