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

Re: [PATCH v2 4/4] ls-files: fix bug when recursing with relative pathspec

From
BWBrandon Williams <bmwill@google.com>
Date
Mar 15, 2017, 17:02 UTC
Message-ID
<20170315170232.GA159137@google.com>
In-Reply-To
<CAGZ79kaRP0Gbw+zwot_vYo7E=7GMwU7chJsJ7TL8g4TJwivC5Q@mail.gmail.com>
On 03/14, Stefan Beller wrote:
Show 74 quoted lines
> On Tue, Mar 14, 2017 at 3:11 PM, Brandon Williams <bmwill@google.com> wrote:
> > When using the --recurse-submodules flag with a relative pathspec which
> > includes "..", an error is produced inside the child process spawned for a
> > submodule.  When creating the pathspec struct in the child, the ".." is
> > interpreted to mean "go up a directory" which causes an error stating that the
> > path ".." is outside of the repository.
> >
> > While it is true that ".." is outside the scope of the submodule, it is
> > confusing to a user who originally invoked the command where ".." was indeed
> > still inside the scope of the superproject.  Since the child process launched
> > for the submodule has some context that it is operating underneath a
> > superproject, this error could be avoided.
> >
> > This patch fixes the bug by passing the 'prefix' to the child process.  Now
> > each child process that works on a submodule has two points of reference to the
> > superproject: (1) the 'super_prefix' which is the path from the root of the
> > superproject down to root of the submodule and (2) the 'prefix' which is the
> > path from the root of the superproject down to the directory where the user
> > invoked the git command.
> >
> > With these two pieces of information a child process can correctly interpret
> > the pathspecs provided by the user as well as being able to properly format its
> > output relative to the directory the user invoked the original command from.
> >
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> >  builtin/ls-files.c                     | 41 +++++++++++++++++-----------------
> >  t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++++++++++++++++
> >  2 files changed, 60 insertions(+), 20 deletions(-)
> >
> > diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> > index 1c0f057d0..d449e46db 100644
> > --- a/builtin/ls-files.c
> > +++ b/builtin/ls-files.c
> > @@ -30,7 +30,7 @@ static int line_terminator = '\n';
> >  static int debug_mode;
> >  static int show_eol;
> >  static int recurse_submodules;
> > -static struct argv_array submodules_options = ARGV_ARRAY_INIT;
> > +static struct argv_array submodule_options = ARGV_ARRAY_INIT;
> >
> >  static const char *prefix;
> >  static const char *super_prefix;
> > @@ -172,20 +172,27 @@ static void show_killed_files(struct dir_struct *dir)
> >  /*
> >   * Compile an argv_array with all of the options supported by --recurse_submodules
> >   */
> > -static void compile_submodule_options(const struct dir_struct *dir, int show_tag)
> > +static void compile_submodule_options(const char **argv,
> > +                                     const struct dir_struct *dir,
> > +                                     int show_tag)
> >  {
> >         if (line_terminator == '\0')
> > -               argv_array_push(&submodules_options, "-z");
> > +               argv_array_push(&submodule_options, "-z");
> >         if (show_tag)
> > -               argv_array_push(&submodules_options, "-t");
> > +               argv_array_push(&submodule_options, "-t");
> >         if (show_valid_bit)
> > -               argv_array_push(&submodules_options, "-v");
> > +               argv_array_push(&submodule_options, "-v");
> >         if (show_cached)
> > -               argv_array_push(&submodules_options, "--cached");
> > +               argv_array_push(&submodule_options, "--cached");
> >         if (show_eol)
> > -               argv_array_push(&submodules_options, "--eol");
> > +               argv_array_push(&submodule_options, "--eol");
> >         if (debug_mode)
> > -               argv_array_push(&submodules_options, "--debug");
> > +               argv_array_push(&submodule_options, "--debug");
> 
> Up to here we only rename a variable? If you want to help reviewers,
> please separate this into two patches. One refactoring, stating it doesn't
> change behavior; and the other adding the behavioral changes.
I can do that.
Show 7 quoted lines
> 
> > +
> > +       /* Add Pathspecs */
> > +       argv_array_push(&submodule_options, "--");
> > +       for (; *argv; argv++)
> > +               argv_array_push(&submodule_options, *argv);
> >  }
-- 
Brandon Williams
Previous: Stefan BellerNext: Brandon Williams
Message 27 of 48 in “recursing submodules with relative pathspec (grep and ls-files)”
  1. 0/5 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Feb 24, 2017
  2. 1/5 grep: illustrate bug when recursing with relative pathspecBrandon Williams, Feb 24, 2017
  3. Duy NguyenFeb 26, 2017
  4. Brandon WilliamsFeb 27, 2017
  5. 2/5 pathspec: add PATHSPEC_FROMROOT flagBrandon Williams, Feb 24, 2017
  6. Stefan BellerFeb 25, 2017
  7. 3/5 grep: fix bug when recuring with relative pathspecBrandon Williams, Feb 24, 2017
  8. Junio C HamanoFeb 28, 2017
  9. Brandon WilliamsMar 2, 2017
  10. 5/5 ls-files: fix bug when recuring with relative pathspecBrandon Williams, Feb 24, 2017
  11. Junio C HamanoFeb 28, 2017
  12. Brandon WilliamsMar 2, 2017
  13. 4/5 ls-files: illustrate bug when recursing with relative pathspecBrandon Williams, Feb 24, 2017
  14. Brandon WilliamsFeb 27, 2017
  15. grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 6, 2017
  16. 0/4 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Mar 14, 2017
  17. 1/4 grep: fix help text typoBrandon Williams, Mar 14, 2017
  18. Stefan BellerMar 14, 2017
  19. Brandon WilliamsMar 15, 2017
  20. 2/4 setup: allow for prefix to be passed to git commandsBrandon Williams, Mar 14, 2017
  21. Johannes SchindelinMar 14, 2017
  22. Brandon WilliamsMar 14, 2017
  23. 3/4 grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 14, 2017
  24. Stefan BellerMar 14, 2017
  25. 4/4 ls-files: fix bug when recursing with relative pathspecBrandon Williams, Mar 14, 2017
  26. Stefan BellerMar 14, 2017
  27. Brandon WilliamsMar 15, 2017
  28. 0/5 recursing submodules with relative pathspec (grep and ls-files)Brandon Williams, Mar 17, 2017
  29. 3/5 grep: fix bug when recursing with relative pathspecBrandon Williams, Mar 17, 2017
  30. Duy NguyenMar 21, 2017
  31. Junio C HamanoMar 21, 2017
  32. Brandon WilliamsMar 22, 2017
  33. 5/5 ls-files: fix bug when recursing with relative pathspecBrandon Williams, Mar 17, 2017
  34. 4/5 ls-files: fix typo in variable nameBrandon Williams, Mar 17, 2017
  35. 2/5 setup: allow for prefix to be passed to git commandsBrandon Williams, Mar 17, 2017
  36. Stefan BellerMar 17, 2017
  37. Junio C HamanoMar 17, 2017
  38. Brandon WilliamsMar 17, 2017
  39. Junio C HamanoMar 17, 2017
  40. Brandon WilliamsMar 17, 2017
  41. Junio C HamanoMar 17, 2017
  42. Brandon WilliamsMar 20, 2017
  43. Junio C HamanoMar 21, 2017
  44. Stefan BellerMar 28, 2017
  45. Brandon WilliamsMar 17, 2017
  46. Stefan BellerMar 17, 2017
  47. Brandon WilliamsMar 17, 2017
  48. 1/5 grep: fix help text typoBrandon Williams, Mar 17, 2017

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.