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

Re: [PATCH v6 4/4] ls-files: add pathspec matching for submodules

From
Stefan Beller <sbeller@google.com>
Date
Oct 4, 2016, 17:56 UTC
Message-ID
<CAGZ79kbFiK0Wb6zpuyybwUOeXo-H=9oDpO8wnXihYmP8VwAHFQ@mail.gmail.com>
In-Reply-To
<1475185723-36871-5-git-send-email-bmwill@google.com>
On Thu, Sep 29, 2016 at 2:48 PM, Brandon Williams <bmwill@google.com> wrote:
Show 38 quoted lines
> Pathspecs can be a bit tricky when trying to apply them to submodules.
> The main challenge is that the pathspecs will be with respect to the
> superproject and not with respect to paths in the submodule.  The
> approach this patch takes is to pass in the identical pathspec from the
> superproject to the submodule in addition to the submodule-prefix, which
> is the path from the root of the superproject to the submodule, and then
> we can compare an entry in the submodule prepended with the
> submodule-prefix to the pathspec in order to determine if there is a
> match.
>
> This patch also permits the pathspec logic to perform a prefix match against
> submodules since a pathspec could refer to a file inside of a submodule.
> Due to limitations in the wildmatch logic, a prefix match is only done
> literally.  If any wildcard character is encountered we'll simply punt
> and produce a false positive match.  More accurate matching will be done
> once inside the submodule.  This is due to the superproject not knowing
> what files could exist in the submodule.
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
>  Documentation/git-ls-files.txt         |   3 +-
>  builtin/ls-files.c                     |  27 +++++++--
>  dir.c                                  |  46 +++++++++++++-
>  dir.h                                  |   4 ++
>  t/t3007-ls-files-recurse-submodules.sh | 108 ++++++++++++++++++++++++++++++++-
>  5 files changed, 175 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
> index ea01d45..51ec9a1 100644
> --- a/Documentation/git-ls-files.txt
> +++ b/Documentation/git-ls-files.txt
> @@ -140,8 +140,7 @@ a space) at the start of each line:
>
>  --recurse-submodules::
>         Recursively calls ls-files on each submodule in the repository.
> -       Currently there is only support for the --cached mode without a
> -       pathspec.
> +       Currently there is only support for the --cached.

s/--cached/--cached mode/ ? The "the" in front of --cached sounds a bit strange for a non native speaker here.

Show 9 quoted lines
> +       /*
> +        * Find common prefix for all pathspec's
> +        * This is used as a performance optimization which unfortunately cannot
> +        * be done when recursing into submodules
> +        */
> +       if (recurse_submodules)
> +               max_prefix = NULL;
> +       else
> +               max_prefix = common_prefix(&pathspec);

Nit of the day: While this is readable, you may want to explore how this reads shorter as

    max_prefix = recurse_submodules ? NULL : common_prefix(&pathspec);
?
Show 11 quoted lines
> +       git ls-files --recurse-submodules "sub" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "sub/" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "sub/file" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "su*/file" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "su?/file" >actual &&
> +       test_cmp expect actual
> +'
Show 8 quoted lines
> +
> +       git ls-files --recurse-submodules "s??/file" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "s???file" >actual &&
> +       test_cmp expect actual &&
> +       git ls-files --recurse-submodules "s*file" >actual &&
> +       test_cmp expect actual
>  '
Thanks for the tests!
Previous: Brandon WilliamsNext: Brandon Williams
Message 59 of 67 in “recursive support for ls-files”
  1. 0/3 recursive support for ls-filesBrandon Williams, Sep 24, 2016
  2. 1/3 submodules: make submodule-prefix option an envvarBrandon Williams, Sep 24, 2016
  3. Junio C HamanoSep 25, 2016
  4. 2/3 ls-files: optionally recurse into submodulesBrandon Williams, Sep 24, 2016
  5. 3/3 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 24, 2016
  6. Jeff KingSep 25, 2016
  7. Brandon WilliamsSep 25, 2016
  8. Junio C HamanoSep 25, 2016
  9. Brandon WilliamsSep 26, 2016
  10. Junio C HamanoSep 26, 2016
  11. Brandon WilliamsSep 26, 2016
  12. Junio C HamanoSep 26, 2016
  13. 0/4 recursive support for ls-filesBrandon Williams, Sep 26, 2016
  14. 1/4 submodules: make submodule-prefix optionBrandon Williams, Sep 26, 2016
  15. Junio C HamanoSep 27, 2016
  16. Brandon WilliamsSep 27, 2016
  17. Junio C HamanoSep 27, 2016
  18. Brandon WilliamsSep 27, 2016
  19. 2/4 ls-files: optionally recurse into submodulesBrandon Williams, Sep 26, 2016
  20. Junio C HamanoSep 27, 2016
  21. Brandon WilliamsSep 27, 2016
  22. 4/4 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 26, 2016
  23. Junio C HamanoSep 27, 2016
  24. Brandon WilliamsSep 27, 2016
  25. 3/4 ls-files: pass through safe options for --recurse-submodulesBrandon Williams, Sep 26, 2016
  26. Junio C HamanoSep 27, 2016
  27. Junio C HamanoSep 27, 2016
  28. Brandon WilliamsSep 27, 2016
  29. Junio C HamanoSep 27, 2016
  30. Stefan BellerSep 27, 2016
  31. Brandon WilliamsSep 28, 2016
  32. Junio C HamanoSep 28, 2016
  33. Brandon WilliamsSep 27, 2016
  34. Junio C HamanoSep 27, 2016
  35. Brandon WilliamsSep 27, 2016
  36. Junio C HamanoSep 27, 2016
  37. 0/4 recursive support for ls-filesBrandon Williams, Sep 28, 2016
  38. 1/4 git: make super-prefix optionBrandon Williams, Sep 28, 2016
  39. Stefan BellerSep 28, 2016
  40. Junio C HamanoSep 28, 2016
  41. Jeff KingSep 29, 2016
  42. Brandon WilliamsSep 29, 2016
  43. 2/4 ls-files: optionally recurse into submodulesBrandon Williams, Sep 28, 2016
  44. Stefan BellerSep 28, 2016
  45. Junio C HamanoSep 28, 2016
  46. 3/4 ls-files: pass through safe options for --recurse-submodulesBrandon Williams, Sep 28, 2016
  47. 4/4 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 28, 2016
  48. 0/4 recursive support for ls-filesBrandon Williams, Sep 29, 2016
  49. 1/4 git: make super-prefix optionBrandon Williams, Sep 29, 2016
  50. Stefan BellerOct 4, 2016
  51. Junio C HamanoOct 4, 2016
  52. Jeff KingOct 4, 2016
  53. 2/4 ls-files: optionally recurse into submodulesBrandon Williams, Sep 29, 2016
  54. 3/4 ls-files: pass through safe options for --recurse-submodulesBrandon Williams, Sep 29, 2016
  55. Junio C HamanoSep 30, 2016
  56. Brandon WilliamsSep 30, 2016
  57. Brandon WilliamsSep 30, 2016
  58. 4/4 ls-files: add pathspec matching for submodulesBrandon Williams, Sep 29, 2016
  59. Stefan BellerOct 4, 2016
  60. 0/4 recursive support for ls-filesBrandon Williams, Oct 7, 2016
  61. 1/4 git: make super-prefix optionBrandon Williams, Oct 7, 2016
  62. 2/4 ls-files: optionally recurse into submodulesBrandon Williams, Oct 7, 2016
  63. 3/4 ls-files: pass through safe options for --recurse-submodulesBrandon Williams, Oct 7, 2016
  64. 4/4 ls-files: add pathspec matching for submodulesBrandon Williams, Oct 7, 2016
  65. Stefan BellerOct 7, 2016
  66. Stefan BellerOct 7, 2016
  67. Brandon WilliamsOct 7, 2016

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.