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

Re: [PATCH v3 4/4] config: add '--show-scope' to print the scope of a config value

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Jan 17, 2020, 21:26 UTC
Message-ID
<CAKPyHN2vZbJparPNVQ1C9nOKk5ZrfeOZWxwbcLnTbwbdJWMLgA@mail.gmail.com>
In-Reply-To
<xmqqsgkddbjz.fsf@gitster-ct.c.googlers.com>
On Fri, Jan 17, 2020 at 10:21 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 65 quoted lines
>
> "Matthew Rogers via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > +--show-scope::
> > +     Similar to `--show-origin` in that it augments the output of
> > +     all queried config options with the scope of that value
> > +     (local, global, system, command).
> > +
> >  --get-colorbool name [stdout-is-tty]::
> >
> >       Find the color setting for `name` (e.g. `color.diff`) and output
> > diff --git a/builtin/config.c b/builtin/config.c
> > index 52a904cfb1..d5931061e8 100644
> > --- a/builtin/config.c
> > +++ b/builtin/config.c
> > @@ -33,6 +33,7 @@ static int end_nul;
> >  static int respect_includes_opt = -1;
> >  static struct config_options config_options;
> >  static int show_origin;
> > +static int show_scope;
> >
> >  #define ACTION_GET (1<<0)
> >  #define ACTION_GET_ALL (1<<1)
> > @@ -155,6 +156,7 @@ static struct option builtin_config_options[] = {
> >       OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
> >       OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
> >       OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
> > +     OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")),
> >       OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
> >       OPT_END(),
> >  };
> > @@ -189,11 +191,43 @@ static void show_config_origin(struct strbuf *buf)
> >       strbuf_addch(buf, term);
> >  }
> >
> > +static const char *scope_to_string(enum config_scope scope)
> > +{
> > +     switch (scope) {
> > +     case CONFIG_SCOPE_LOCAL:
> > +             return "local";
> > +     case CONFIG_SCOPE_GLOBAL:
> > +             return "global";
> > +     case CONFIG_SCOPE_SYSTEM:
> > +             return "system";
> > +     case CONFIG_SCOPE_WORKTREE:
> > +             return "worktree";
> > +     case CONFIG_SCOPE_COMMAND:
> > +             return "command";
> > +     case CONFIG_SCOPE_SUBMODULE:
> > +             return "submodule";
> > +     default:
> > +             return "unknown";
> > +     }
> > +}
>
> It is a shame that with this defined in the main part of the system
> test-tool still needs to carry its own private copy.
>
> I wonder if it results in a better system if we rename this to
>
>         const char *config_scope_name(enum config_scope scope)
>
> made it externally visible, and use it in t/helper/test-config.c
> and get rid of the private copy scope_name() there?
>

+1 and please keep the order in config_scope_name the same as in the enum definition. Will base my 'remote rename & branch.<name>.pushRemote' series on this then.

Bert
Show 75 quoted lines
> > diff --git a/config.h b/config.h
> > index f383a71404..91f851e925 100644
> > --- a/config.h
> > +++ b/config.h
> > @@ -35,10 +35,21 @@ struct object_id;
> >
> >  #define CONFIG_REGEX_NONE ((void *)1)
> >
> > +enum config_scope {
> > +     CONFIG_SCOPE_UNKNOWN = 0,
> > +     CONFIG_SCOPE_SYSTEM,
> > +     CONFIG_SCOPE_GLOBAL,
> > +     CONFIG_SCOPE_LOCAL,
> > +     CONFIG_SCOPE_WORKTREE,
> > +     CONFIG_SCOPE_COMMAND,
> > +     CONFIG_SCOPE_SUBMODULE,
> > +};
> > +
>
> And this is the logical place to make an external definition, if we
> were to go that route.
>
> > diff --git a/t/t1300-config.sh b/t/t1300-config.sh
> > index 983a0a1583..b654a6d2f9 100755
> > --- a/t/t1300-config.sh
> > +++ b/t/t1300-config.sh
> > @@ -1766,6 +1766,64 @@ test_expect_success !MINGW '--show-origin blob ref' '
> >       test_cmp expect output
> >  '
> >
> > +test_expect_success '--show-scope with --list' '
> > +     cat >expect <<-EOF &&
> > +             global  user.global=true
> > +             global  user.override=global
> > +             global  include.path=$INCLUDE_DIR/absolute.include
> > +             global  user.absolute=include
> > +             local   user.local=true
> > +             local   user.override=local
> > +             local   include.path=../include/relative.include
> > +             local   user.relative=include
> > +             command user.cmdline=true
> > +     EOF
>
> The HERE-DOC is over-indented.  All the body lines should align with
> cat and EOF.  The same comment applies to many "<<-" added by this
> patch---mimick the "<<-" that appear in earlier part of the same
> file.
>
> > +test_expect_success !MINGW '--show-scope with --blob' '
> > +     blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
> > +     cat >expect <<-EOF &&
> > +             command user.custom=true
> > +     EOF
> > +     git config --blob=$blob --show-scope --list >output &&
> > +     test_cmp expect output
> > +'
>
> Missing blank line between two tests.
>
> I wonder if we want to revamp the tests for --show-origin that wants
> to make sure a funny filename is quoted properly.  For that purpose,
> CUSTOM_CONFIG_FILE is given a funny pathname, and it would have been
> OK to use that only for a single "do we quote properly?" test, but
> instead we use that same funnily-named file as the source in many
> places where we do not *care* how --show-origin quotes the pathname
> at all, and end up having to skip with !MINGW.
>
> It's a bad tradition that started at 45bf3297 ("t1300: fix the new
> --show-origin tests on Windows", 2016-03-23), I guess, and is not a
> new problem introduced by this patch, but it should stop so that we
> can have a better test coverage everywhere.
>
> Other than that, I think that the new feature added by this series
> is a sensible one.  Thanks for working on it.
>
Previous: Junio C HamanoNext: Matt Rogers
Message 34 of 98 in “config: allow user to know scope of config options”
  1. 0/1 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Dec 18, 2019
  2. 1/1 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Dec 18, 2019
  3. Junio C HamanoDec 18, 2019
  4. Jeff KingDec 19, 2019
  5. Junio C HamanoDec 19, 2019
  6. Philip OakleyDec 18, 2019
  7. mattr94@gmail.comDec 19, 2019
  8. Junio C HamanoDec 19, 2019
  9. Matt RogersDec 20, 2019
  10. Junio C HamanoDec 21, 2019
  11. Matt RogersDec 21, 2019
  12. Junio C HamanoDec 21, 2019
  13. 0/4 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 9, 2020
  14. 1/4 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 9, 2020
  15. Junio C HamanoJan 9, 2020
  16. Matt RogersJan 9, 2020
  17. Jeff KingJan 10, 2020
  18. 2/4 config: fix config scope enumMatthew Rogers via GitGitGadget, Jan 9, 2020
  19. Junio C HamanoJan 9, 2020
  20. Matt RogersJan 9, 2020
  21. 3/4 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 9, 2020
  22. Junio C HamanoJan 9, 2020
  23. Matt RogersJan 9, 2020
  24. 4/4 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 9, 2020
  25. Junio C HamanoJan 9, 2020
  26. Matt RogersJan 9, 2020
  27. 0/4 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 17, 2020
  28. 1/4 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 17, 2020
  29. 3/4 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 17, 2020
  30. Junio C HamanoJan 17, 2020
  31. Matt RogersJan 18, 2020
  32. 4/4 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 17, 2020
  33. Junio C HamanoJan 17, 2020
  34. Bert WesargJan 17, 2020
  35. Matt RogersJan 18, 2020
  36. 2/4 config: refine config scope enumMatthew Rogers via GitGitGadget, Jan 17, 2020
  37. Junio C HamanoJan 17, 2020
  38. Matt RogersJan 18, 2020
  39. Junio C HamanoJan 18, 2020
  40. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 24, 2020
  41. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 24, 2020
  42. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 24, 2020
  43. Junio C HamanoJan 24, 2020
  44. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 24, 2020
  45. Junio C HamanoJan 24, 2020
  46. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 24, 2020
  47. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 24, 2020
  48. Junio C HamanoJan 24, 2020
  49. Junio C HamanoJan 24, 2020
  50. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 24, 2020
  51. Junio C HamanoJan 24, 2020
  52. Junio C HamanoJan 24, 2020
  53. Matt RogersJan 24, 2020
  54. Junio C HamanoJan 25, 2020
  55. Junio C HamanoJan 24, 2020
  56. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 25, 2020
  57. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 25, 2020
  58. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 25, 2020
  59. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 25, 2020
  60. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 25, 2020
  61. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 25, 2020
  62. Junio C HamanoJan 27, 2020
  63. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 25, 2020
  64. Junio C HamanoJan 27, 2020
  65. Matt RogersJan 28, 2020
  66. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 29, 2020
  67. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 29, 2020
  68. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 29, 2020
  69. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 29, 2020
  70. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 29, 2020
  71. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 29, 2020
  72. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 29, 2020
  73. Bert WesargJan 29, 2020
  74. Matt RogersJan 29, 2020
  75. Junio C HamanoFeb 5, 2020
  76. Junio C HamanoJan 29, 2020
  77. 00/10 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Feb 10, 2020
  78. 01/10 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Feb 10, 2020
  79. 03/10 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Feb 10, 2020
  80. 05/10 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Feb 10, 2020
  81. Junio C HamanoFeb 10, 2020
  82. 02/10 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Feb 10, 2020
  83. 07/10 config: preserve scope in do_git_config_sequenceMatthew Rogers via GitGitGadget, Feb 10, 2020
  84. Junio C HamanoFeb 10, 2020
  85. 06/10 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Feb 10, 2020
  86. Junio C HamanoFeb 10, 2020
  87. 10/10 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Feb 10, 2020
  88. 09/10 submodule-config: add subomdule config scopeMatthew Rogers via GitGitGadget, Feb 10, 2020
  89. Junio C HamanoFeb 10, 2020
  90. 08/10 config: teach git_config_source to remember its scopeMatthew Rogers via GitGitGadget, Feb 10, 2020
  91. Junio C HamanoFeb 10, 2020
  92. 04/10 config: make scope_name non-static and rename itMatthew Rogers via GitGitGadget, Feb 10, 2020
  93. Junio C HamanoFeb 10, 2020
  94. Junio C HamanoFeb 10, 2020
  95. Matt RogersFeb 11, 2020
  96. Emily ShafferFeb 11, 2020
  97. Junio C HamanoFeb 11, 2020
  98. Matt RogersFeb 11, 2020

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.