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

Re: [PATCH v3 3/5] grep: fix bug when recursing with relative pathspec

From
BWBrandon Williams <bmwill@google.com>
Date
Mar 22, 2017, 21:46 UTC
Message-ID
<20170322214654.GC11254@google.com>
In-Reply-To
<CACsJy8Cu8cgtJzDDM09GoJr5Ny+G+nP17GjZjXng6ZPQv9eXXg@mail.gmail.com>
On 03/21, Duy Nguyen wrote:
Show 8 quoted lines
> On Sat, Mar 18, 2017 at 12:22 AM, Brandon Williams <bmwill@google.com> wrote:
> > 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.
> 
> This part can stand alone as a separate patch right? It would help
> focus on the pathspec thingy first.

I guess it could probably be factored out, though it is necessary for it to work. The issue I was running into was that when no pathspecs were given it would create a 'prefix' pathspec. So if we were in directory 'dir/' the pathspec that would get created would be:

ps.match = "dir/" ps.original = "dir/"

Since it also set the original field it messed up when the child tried to interpret the pathspecs again. I solved this by just passing the raw pathspec through to the child.

Show 23 quoted lines
> 
> > @@ -399,13 +405,12 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
> >  }
> >
> >  static void compile_submodule_options(const struct grep_opt *opt,
> > -                                     const struct pathspec *pathspec,
> > +                                     const char **argv,
> >                                       int cached, int untracked,
> >                                       int opt_exclude, int use_index,
> >                                       int pattern_type_arg)
> >  {
> >         struct grep_pat *pattern;
> > -       int i;
> >
> >         if (recurse_submodules)
> >                 argv_array_push(&submodule_options, "--recurse-submodules");
> 
> Side note. It would be awesome if you could make parse_options() (or a
> new function) do the reverse process: given a 'struct option' with
> valid data, spit out argv_array. Less worrying about git-grep having
> new option but not passed to subgrep by accident. You can have a new
> flag to tell it to ignore certain options if you don't want to pass
> all.

I thought about this for a second but didn't pursue it very far. Mostly because of how you would handle options with callback routines. Maybe if you want the option to be reversible you need to have an additional callback routine to do the conversion? I agree that having this sort of functionality would be nice as it does save you from forgetting about passing on options to a child process.

-- 
Brandon Williams
Previous: Junio C HamanoNext: Brandon Williams
Message 32 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.