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

Re: [PATCH v3 5/5] sparse-checkout: reject arguments in cone-mode that look like patterns

From
Elijah Newren <newren@gmail.com>
Date
Feb 17, 2022, 01:43 UTC
Message-ID
<CABPp-BG8j=cNRDcsm3s7U2F8u3FCvoOLAbeuQTyv+2u1o1-fVA@mail.gmail.com>
In-Reply-To
<af439020-8314-9171-4300-94a5102c8a38@github.com>
On Wed, Feb 16, 2022 at 9:20 AM Victoria Dye <vdye@github.com> wrote:
Show 64 quoted lines
>
> Elijah Newren wrote:
> > On Wed, Feb 16, 2022 at 1:57 AM Ævar Arnfjörð Bjarmason
> > <avarab@gmail.com> wrote:
> >>
> >> On Wed, Feb 16 2022, Elijah Newren via GitGitGadget wrote:
> >>
> >>> From: Elijah Newren <newren@gmail.com>
> >>>
> >>> In sparse-checkout add/set under cone mode, the arguments passed are
> >>> supposed to be directories rather than gitignore-style patterns.
> >>> However, given the amount of effort spent in the manual discussing
> >>> patterns, it is easy for users to assume they need to pass patterns such
> >>> as
> >>>    /foo/*
> >>> or
> >>>    !/bar/*/
> >>> or perhaps they really do ignore the directory rule and specify a
> >>> random gitignore-style pattern like
> >>>    *.c
> >>>
> >>> To help catch such mistakes, throw an error if any of the positional
> >>> arguments:
> >>>   * starts with any of '/!'
> >>>   * contains any of '*\?[]'
> >>
> >> But not "\" itself, we're just escaping the "?" here?...
> >
> > Nah, I just missed that one.  I should add it below.
> >
> >>> +     if (core_sparse_checkout_cone) {
> >>> +             for (i = 0; i < argc; i++) {
> >>> +                     if (argv[i][0] == '/')
> >>> +                             die(_("specify directories rather than patterns (no leading slash)"));
> >>> +                     if (argv[i][0] == '!')
> >>> +                             die(_("specify directories rather than patterns.  If your directory starts with a '!', pass --skip-checks"));
> >>> +                     if (strchr(argv[i], '*') ||
> >>> +                         strchr(argv[i], '?') ||
> >>> +                         strchr(argv[i], '[') ||
> >>> +                         strchr(argv[i], ']'))
> >>> +                             die(_("specify directories rather than patterns.  If your directory really has any of '*?[]' in it, pass --skip-checks"));
> >>
> >> Isn't this nested || a reinvention of a simpler strtok() or strtok_r()
> >> call? I.e. (untested):
> >>
> >>         const char *p;
> >>         const char *wildcards = "*?[]";
> >>         if (strtok_r(argv[i], wildcards, &p))
> >>                 die(_("specify... has ony of '%s' in it...", wildcards));
> >>
> >> That would also allow parameterizing the set of characters for
> >> translators.
> >
> > I considered strtok, but strtok & strtok_r are documented as modifying
> > their argument.  Perhaps they don't modify the argument if they don't
> > find any of the listed tokens, but I didn't want to rely on that since
> > I found no guarantees in the documentation.
>
> Maybe `strpbrk` would work? Unless I'm misunderstanding, it should
> consolidate the condition to one line without potentially modifying the
> arguments. E.g.:
>
>         if (!strpbrk(argv[i], "*?[]"))
>                 die(_("specify directories rather than patterns.  If your directory really has any of '*?[]' in it, pass --skip-checks"));

Ah, perfect -- thanks for the pointer! (Though I think the logic needs to be reversed; error if we find any of those characters rather than error if we don't.)

Previous: Junio C HamanoNext: Elijah Newren
Message 50 of 70 in “RFC: sparse checkout: make --cone mode the default, and check add/set argument validity”
  1. 0/7 RFC: sparse checkout: make --cone mode the default, and check add/set argument validityElijah Newren via GitGitGadget, Feb 13, 2022
  2. 1/7 sparse-checkout: correct reapply's handling of optionsElijah Newren via GitGitGadget, Feb 13, 2022
  3. 3/7 sparse-checkout: pay attention to prefix for {set, add}Elijah Newren via GitGitGadget, Feb 13, 2022
  4. Derrick StoleeFeb 14, 2022
  5. Elijah NewrenFeb 15, 2022
  6. Derrick StoleeFeb 15, 2022
  7. 2/7 sparse-checkout: correctly set non-cone mode when expectedElijah Newren via GitGitGadget, Feb 13, 2022
  8. Derrick StoleeFeb 14, 2022
  9. Elijah NewrenFeb 15, 2022
  10. 4/7 sparse-checkout: error or warn when given individual filesElijah Newren via GitGitGadget, Feb 13, 2022
  11. Derrick StoleeFeb 14, 2022
  12. Elijah NewrenFeb 15, 2022
  13. Derrick StoleeFeb 15, 2022
  14. 6/7 sparse-checkout: reject arguments in cone-mode that look like patternsElijah Newren via GitGitGadget, Feb 13, 2022
  15. 5/7 sparse-checkout: reject non-cone-mode patterns starting with a '#'Elijah Newren via GitGitGadget, Feb 13, 2022
  16. Junio C HamanoFeb 14, 2022
  17. Elijah NewrenFeb 15, 2022
  18. Junio C HamanoFeb 16, 2022
  19. Elijah NewrenFeb 16, 2022
  20. Junio C HamanoFeb 16, 2022
  21. 7/7 sparse-checkout: make --cone the default and deprecate --no-coneElijah Newren via GitGitGadget, Feb 13, 2022
  22. Derrick StoleeFeb 14, 2022
  23. Elijah NewrenFeb 15, 2022
  24. Derrick StoleeFeb 14, 2022
  25. Elijah NewrenFeb 15, 2022
  26. Derrick StoleeFeb 15, 2022
  27. 0/6 sparse checkout: fix a few bugs and check argument validity for set/addElijah Newren via GitGitGadget, Feb 15, 2022
  28. 1/6 sparse-checkout: correct reapply's handling of optionsElijah Newren via GitGitGadget, Feb 15, 2022
  29. 2/6 sparse-checkout: correctly set non-cone mode when expectedElijah Newren via GitGitGadget, Feb 15, 2022
  30. 3/6 sparse-checkout: pay attention to prefix for {set, add}Elijah Newren via GitGitGadget, Feb 15, 2022
  31. Ævar Arnfjörð BjarmasonFeb 17, 2022
  32. Elijah NewrenFeb 18, 2022
  33. 4/6 sparse-checkout: error or warn when given individual filesElijah Newren via GitGitGadget, Feb 15, 2022
  34. Ævar Arnfjörð BjarmasonFeb 17, 2022
  35. 5/6 sparse-checkout: reject non-cone-mode patterns starting with a '#'Elijah Newren via GitGitGadget, Feb 15, 2022
  36. 6/6 sparse-checkout: reject arguments in cone-mode that look like patternsElijah Newren via GitGitGadget, Feb 15, 2022
  37. Derrick StoleeFeb 15, 2022
  38. 0/5 sparse checkout: fix a few bugs and check argument validity for set/addElijah Newren via GitGitGadget, Feb 16, 2022
  39. 2/5 sparse-checkout: correctly set non-cone mode when expectedElijah Newren via GitGitGadget, Feb 16, 2022
  40. 1/5 sparse-checkout: correct reapply's handling of optionsElijah Newren via GitGitGadget, Feb 16, 2022
  41. 3/5 sparse-checkout: pay attention to prefix for {set, add}Elijah Newren via GitGitGadget, Feb 16, 2022
  42. 4/5 sparse-checkout: error or warn when given individual filesElijah Newren via GitGitGadget, Feb 16, 2022
  43. 5/5 sparse-checkout: reject arguments in cone-mode that look like patternsElijah Newren via GitGitGadget, Feb 16, 2022
  44. Ævar Arnfjörð BjarmasonFeb 16, 2022
  45. Elijah NewrenFeb 16, 2022
  46. Victoria DyeFeb 16, 2022
  47. Junio C HamanoFeb 16, 2022
  48. Elijah NewrenFeb 17, 2022
  49. Junio C HamanoFeb 17, 2022
  50. Elijah NewrenFeb 17, 2022
  51. Elijah NewrenFeb 17, 2022
  52. Junio C HamanoFeb 16, 2022
  53. 0/5 sparse checkout: fix a few bugs and check argument validity for set/addElijah Newren via GitGitGadget, Feb 17, 2022
  54. 1/5 sparse-checkout: correct reapply's handling of optionsElijah Newren via GitGitGadget, Feb 17, 2022
  55. 2/5 sparse-checkout: correctly set non-cone mode when expectedElijah Newren via GitGitGadget, Feb 17, 2022
  56. 3/5 sparse-checkout: pay attention to prefix for {set, add}Elijah Newren via GitGitGadget, Feb 17, 2022
  57. Junio C HamanoFeb 17, 2022
  58. 5/5 sparse-checkout: reject arguments in cone-mode that look like patternsElijah Newren via GitGitGadget, Feb 17, 2022
  59. 4/5 sparse-checkout: error or warn when given individual filesElijah Newren via GitGitGadget, Feb 17, 2022
  60. Junio C HamanoFeb 17, 2022
  61. Elijah NewrenFeb 18, 2022
  62. Ævar Arnfjörð BjarmasonFeb 17, 2022
  63. 0/5 sparse checkout: fix a few bugs and check argument validity for set/addElijah Newren via GitGitGadget, Feb 19, 2022
  64. 1/5 sparse-checkout: correct reapply's handling of optionsElijah Newren via GitGitGadget, Feb 19, 2022
  65. 2/5 sparse-checkout: correctly set non-cone mode when expectedElijah Newren via GitGitGadget, Feb 19, 2022
  66. 3/5 sparse-checkout: pay attention to prefix for {set, add}Elijah Newren via GitGitGadget, Feb 19, 2022
  67. 4/5 sparse-checkout: error or warn when given individual filesElijah Newren via GitGitGadget, Feb 19, 2022
  68. 5/5 sparse-checkout: reject arguments in cone-mode that look like patternsElijah Newren via GitGitGadget, Feb 19, 2022
  69. Derrick StoleeFeb 20, 2022
  70. Junio C HamanoFeb 20, 2022

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.