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

Re: [PATCH 02/14] pull: pass verbosity, --progress flags to fetch and merge

From
Paul Tan <pyokagan@gmail.com>
Date
May 21, 2015, 09:48 UTC
Message-ID
<CACRoPnRVcjcegRU8J6a=X6uN=b7fhJyD9=js4LqJ7ORX6gT=jg@mail.gmail.com>
In-Reply-To
<4213f4fa8fb52fb020c2e9b5d78fbf7b@www.dscho.org>
Hi,

On Tue, May 19, 2015 at 1:41 AM, Johannes Schindelin <johannes.schindelin@gmx.de> wrote:

Show 19 quoted lines
> On 2015-05-18 17:05, Paul Tan wrote:
>> diff --git a/builtin/pull.c b/builtin/pull.c
>> index 0b771b9..a4d9c92 100644
>> --- a/builtin/pull.c
>> +++ b/builtin/pull.c
>> @@ -11,16 +11,64 @@
>>  #include "argv-array.h"
>>  #include "run-command.h"
>>
>> +/**
>> + * Given an option opt, where opt->value points to a char* and opt->defval is a
>> + * string, sets opt->value to the evaluation of "--$defval=$arg". If `arg` is
>> + * NULL, then opt->value is set to "--$defval". If unset is true, then
>> + * opt->value is set to "--no-$defval".
>> + */
>> +static int parse_opt_passthru(const struct option *opt, const char
>> *arg, int unset)
>
> How about adding this to parse-options-cb.c in a separate patch? I guess the description could say something like:
Yeah, I was also thinking if the callback could be generalized as well.

Specifically, I wonder if we should re-construct just the last-provided option (the current solution), or all the options (e.g. something like OPT_STRING_LIST). I'm currently working on the rewrite for git-am.sh as well, and it turns out it makes heavy use of the latter, so we probably should support both.

Show 12 quoted lines
> /**
>  * Given an option opt, recreate the command-line option, as strbuf. This is useful
>  * when a command needs to parse a command-line option in order to pass it to yet
>  * another command. This callback can be used in conjunction with the
>  * PARSE_OPT_(OPTARG|NOARG|NONEG) options, but not with PARSE_OPT_LASTARG_DEFAULT
>  * because it expects `defval` to be the name of the command-line option to
>  * reconstruct.
>  *
>  * The result will be stored in opt->value, which is expected to be a pointer to an
>  * strbuf.
>  */
>
Heh, this docstring reads much better than mine.
> Implied by my suggested description, I also propose to put the re-recreated command-line option into a strbuf instead of a char *, to make memory management easier (read: avoid memory leaks).

Unfortunately, the usage of strbuf means that we lose the ability to know if an option was not provided at all (the value is NULL). This is important as some of these options are used to override the default configured behavior.

> You might also want to verify that arg is `NULL` when `unset != 0`. Something like this:

Hmm, would there be a situation where arg is NULL when `unset != 0`? At first glance in the source code, it won't unless PARSE_OPT_LASTARG_DEFAULT is set, I guess. Anyway, there's no harm in being careful, though I think it's more likely that an invalid pointer is passed in through "arg", which we can't detect :-(.

Show 27 quoted lines
> int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
> {
>         struct strbuf *buf = opt->value;
>
>         assert(opt->defval);
>         strbuf_reset(buf);
>         if (unset) {
>                 assert(!arg);
>                 strbuf_addf(buf, "--no-%s", opt->defval);
>         }
>         else {
>                 strbuf_addf(buf, "--%s", opt->defval);
>                 if (arg)
>                         strbuf_addf(buf, "=%s", arg);
>         }
>
>         return 0;
> }
>
>>  static struct option pull_options[] = {
>> +     /* Shared options */
>> +     OPT__VERBOSITY(&opt_verbosity),
>> +     { OPTION_CALLBACK, 0, "progress", &opt_progress, NULL,
>> +       N_("force progress reporting"),
>> +       PARSE_OPT_NOARG, parse_opt_passthru},
>
> I *think* there is a '(intptr_t) "progress"' missing...

Ugh. I think this shows that relying on "defval" is too error-prone. Anyway, it is only required for the options -n (which maps to --no-stat), and --summary (which maps to --stat), so we should probably make it such that if defval is not provided, we fallback to using long_name or short_name.

Show 15 quoted lines
>>  /**
>> + * Pushes "-q" or "-v" switches into arr to match the opt_verbosity level.
>> + */
>> +static void argv_push_verbosity(struct argv_array *arr)
>> +{
>> +     int verbosity;
>> +
>> +     for (verbosity = opt_verbosity; verbosity > 0; verbosity--)
>> +             argv_array_push(arr, "-v");
>> +
>> +     for (verbosity = opt_verbosity; verbosity < 0; verbosity++)
>> +             argv_array_push(arr, "-q");
>> +}
>
> Hmm... I guess this is *really* nit-picky, but I'd rather use "i" instead of "verbosity" because the second loop is about quietness instead of verbosity ;-)
Well, my thinking was that a negative verbosity *is* quietness ;-).

Thanks, Paul

Previous: Johannes SchindelinNext: Johannes Schindelin
Message 6 of 43 in “Make git-pull a builtin”
  1. 00/14 Make git-pull a builtinPaul Tan, May 18, 2015
  2. 01/14 pull: implement fetch + mergePaul Tan, May 18, 2015
  3. Johannes SchindelinMay 18, 2015
  4. 02/14 pull: pass verbosity, --progress flags to fetch and mergePaul Tan, May 18, 2015
  5. Johannes SchindelinMay 18, 2015
  6. Paul TanMay 21, 2015
  7. Johannes SchindelinMay 21, 2015
  8. Paul TanMay 22, 2015
  9. 03/14 pull: pass git-merge's options to git-mergePaul Tan, May 18, 2015
  10. 04/14 pull: pass git-fetch's options to git-fetchPaul Tan, May 18, 2015
  11. 05/14 pull: error on no merge candidatesPaul Tan, May 18, 2015
  12. Johannes SchindelinMay 18, 2015
  13. 06/14 pull: support pull.ff configPaul Tan, May 18, 2015
  14. Johannes SchindelinMay 18, 2015
  15. Paul TanMay 21, 2015
  16. 07/14 pull: check if in unresolved merge statePaul Tan, May 18, 2015
  17. Johannes SchindelinMay 18, 2015
  18. 08/14 pull: fast-forward working tree if head is updatedPaul Tan, May 18, 2015
  19. Johannes SchindelinMay 18, 2015
  20. 09/14 pull: implement pulling into an unborn branchPaul Tan, May 18, 2015
  21. 10/14 pull: set reflog messagePaul Tan, May 18, 2015
  22. Johannes SchindelinMay 18, 2015
  23. Junio C HamanoMay 18, 2015
  24. Paul TanMay 21, 2015
  25. 11/14 pull: teach git pull about --rebasePaul Tan, May 18, 2015
  26. Stefan BellerMay 18, 2015
  27. Johannes SchindelinMay 19, 2015
  28. Paul TanMay 31, 2015
  29. Paul TanJun 2, 2015
  30. 12/14 pull: configure --rebase via branch.<name>.rebase or pull.rebasePaul Tan, May 18, 2015
  31. Stefan BellerMay 18, 2015
  32. 13/14 pull --rebase: exit early when the working directory is dirtyPaul Tan, May 18, 2015
  33. 14/14 pull --rebase: error on no merge candidate casesPaul Tan, May 18, 2015
  34. Stefan BellerMay 19, 2015
  35. Johannes SchindelinMay 19, 2015
  36. Junio C HamanoMay 19, 2015
  37. Paul TanMay 22, 2015
  38. Johannes SchindelinMay 22, 2015
  39. Stefan BellerMay 22, 2015
  40. Junio C HamanoMay 18, 2015
  41. Paul TanMay 30, 2015
  42. Paul TanMay 30, 2015
  43. Johannes SchindelinMay 18, 2015

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.