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

Re: [PATCH v4 3/8] for-each-repo: run subcommands on configured repos

From
Andrzej Hunt <andrzej@ahunt.org>
Date
May 3, 2021, 16:10 UTC
Message-ID
<cda4f200-2400-e915-e995-36eea2a27c11@ahunt.org>
In-Reply-To
<dd9237927395ef69663ab376a2da74da4654c495.1602782524.git.gitgitgadget@gmail.com>
On 15/10/2020 19:21, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <dstolee@microsoft.com>
[... snip ...]
Show 24 quoted lines
> diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
> new file mode 100644
> index 0000000000..5bba623ff1
> --- /dev/null
> +++ b/builtin/for-each-repo.c
> @@ -0,0 +1,58 @@
> +#include "cache.h"
> +#include "config.h"
> +#include "builtin.h"
> +#include "parse-options.h"
> +#include "run-command.h"
> +#include "string-list.h"
> +
> +static const char * const for_each_repo_usage[] = {
> +	N_("git for-each-repo --config=<config> <command-args>"),
> +	NULL
> +};
> +
> +static int run_command_on_repo(const char *path,
> +			       void *cbdata)
> +{
> +	int i;
> +	struct child_process child = CHILD_PROCESS_INIT;
> +	struct strvec *args = (struct strvec *)cbdata;

I was curious there's a strong reason for declaring args as void * followed by this cast? The most obvious answer seems to be that this probably evolved from a callback - and we could simplify it now?

Show 6 quoted lines
> +
> +	child.git_cmd = 1;
> +	strvec_pushl(&child.args, "-C", path, NULL);
> +
> +	for (i = 0; i < args->nr; i++)
> +		strvec_push(&child.args, args->v[i]);

So here we're copying all of args - and I don't see any way of avoiding it since we're adding it to child's arg list.

Show 25 quoted lines
> +
> +	return run_command(&child);
> +}
> +
> +int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
> +{
> +	static const char *config_key = NULL;
> +	int i, result = 0;
> +	const struct string_list *values;
> +	struct strvec args = STRVEC_INIT;
> +
> +	const struct option options[] = {
> +		OPT_STRING(0, "config", &config_key, N_("config"),
> +			   N_("config key storing a list of repository paths")),
> +		OPT_END()
> +	};
> +
> +	argc = parse_options(argc, argv, prefix, options, for_each_repo_usage,
> +			     PARSE_OPT_STOP_AT_NON_OPTION);
> +
> +	if (!config_key)
> +		die(_("missing --config=<config>"));
> +
> +	for (i = 0; i < argc; i++)
> +		strvec_push(&args, argv[i]);

But why do we have to copy all of argv 1:1 into args here, only to later pass it to run_command_on_repo() which, as described above, copies the entire input again? I suspect this was done to comply with run_command_on_repo()'s API (which takes strvec) - does that seem plausible, or did I miss something?

Which brings me to the real reason for my questions: I noticed we "leak" args (this leak is of no significance since it happens in cmd_*, but LSAN still complains, and I'm trying to get tests running leak-free). My initial inclination was to strvec_clear() or UNLEAK() args - but if we can avoid creating args in the first place we also wouldn't need to clear it later.

My current proposal is therefore to completely remove args and pass argc+argv into run_command_on_repo() - but I wanted to be sure that I didn't miss some important reason to stick with the current approach.

Show 9 quoted lines
> +
> +	values = repo_config_get_value_multi(the_repository,
> +					     config_key);
> +
> +	for (i = 0; !result && i < values->nr; i++)
> +		result = run_command_on_repo(values->items[i].string, &args);
> +
> +	return result;
> +}
[... snip ...]

(I hope this doesn't come across as useless necroposting - I figured it would be easier to clarify these questions on the original thread as opposed to potentially discussing it as part of my next leak-fixing series :) .)

ATB,
   Andrzej
Previous: Derrick Stolee via GitGitGadgetNext: Eric Sunshine
Message 43 of 62 in “Maintenance III: Background maintenance”
  1. 0/7 Maintenance III: Background maintenanceDerrick Stolee via GitGitGadget, Sep 4, 2020
  2. 4/7 maintenance: add [un]register subcommandsDerrick Stolee via GitGitGadget, Sep 4, 2020
  3. 3/7 for-each-repo: run subcommands on configured reposDerrick Stolee via GitGitGadget, Sep 4, 2020
  4. 1/7 maintenance: optionally skip --auto processDerrick Stolee via GitGitGadget, Sep 4, 2020
  5. 7/7 maintenance: add troubleshooting guide to docsDerrick Stolee via GitGitGadget, Sep 4, 2020
  6. 5/7 maintenance: add start/stop subcommandsDerrick Stolee via GitGitGadget, Sep 4, 2020
  7. SZEDER GáborSep 8, 2020
  8. Derrick StoleeSep 8, 2020
  9. Junio C HamanoSep 8, 2020
  10. 2/7 maintenance: add --schedule option and configDerrick Stolee via GitGitGadget, Sep 4, 2020
  11. Đoàn Trần Công DanhSep 8, 2020
  12. Derrick StoleeSep 9, 2020
  13. 6/7 maintenance: recommended schedule in register/startDerrick Stolee via GitGitGadget, Sep 4, 2020
  14. 0/7 Maintenance III: Background maintenanceDerrick Stolee via GitGitGadget, Sep 11, 2020
  15. 1/7 maintenance: optionally skip --auto processDerrick Stolee via GitGitGadget, Sep 11, 2020
  16. 2/7 maintenance: add --schedule option and configDerrick Stolee via GitGitGadget, Sep 11, 2020
  17. 3/7 for-each-repo: run subcommands on configured reposDerrick Stolee via GitGitGadget, Sep 11, 2020
  18. 4/7 maintenance: add [un]register subcommandsDerrick Stolee via GitGitGadget, Sep 11, 2020
  19. Đoàn Trần Công DanhSep 17, 2020
  20. 5/7 maintenance: add start/stop subcommandsDerrick Stolee via GitGitGadget, Sep 11, 2020
  21. 7/7 maintenance: add troubleshooting guide to docsDerrick Stolee via GitGitGadget, Sep 11, 2020
  22. 6/7 maintenance: recommended schedule in register/startDerrick Stolee via GitGitGadget, Sep 11, 2020
  23. Martin ÅgrenSep 29, 2020
  24. Derrick StoleeSep 30, 2020
  25. Derrick StoleeOct 1, 2020
  26. Đoàn Trần Công DanhOct 2, 2020
  27. Derrick StoleeOct 2, 2020
  28. Đoàn Trần Công DanhOct 5, 2020
  29. Derrick StoleeOct 5, 2020
  30. 0/7 Maintenance III: Background maintenanceDerrick Stolee via GitGitGadget, Oct 5, 2020
  31. 3/7 for-each-repo: run subcommands on configured reposDerrick Stolee via GitGitGadget, Oct 5, 2020
  32. 2/7 maintenance: add --schedule option and configDerrick Stolee via GitGitGadget, Oct 5, 2020
  33. 6/7 maintenance: use default schedule if not configuredDerrick Stolee via GitGitGadget, Oct 5, 2020
  34. Martin ÅgrenOct 5, 2020
  35. Derrick StoleeOct 8, 2020
  36. 5/7 maintenance: add start/stop subcommandsDerrick Stolee via GitGitGadget, Oct 5, 2020
  37. 4/7 maintenance: add [un]register subcommandsDerrick Stolee via GitGitGadget, Oct 5, 2020
  38. 7/7 maintenance: add troubleshooting guide to docsDerrick Stolee via GitGitGadget, Oct 5, 2020
  39. 1/7 maintenance: optionally skip --auto processDerrick Stolee via GitGitGadget, Oct 5, 2020
  40. 0/8 Maintenance III: Background maintenanceDerrick Stolee via GitGitGadget, Oct 15, 2020
  41. 1/8 maintenance: optionally skip --auto processDerrick Stolee via GitGitGadget, Oct 15, 2020
  42. 3/8 for-each-repo: run subcommands on configured reposDerrick Stolee via GitGitGadget, Oct 15, 2020
  43. Andrzej HuntMay 3, 2021
  44. Eric SunshineMay 3, 2021
  45. Eric SunshineMay 3, 2021
  46. Derrick StoleeMay 3, 2021
  47. 5/8 maintenance: add start/stop subcommandsDerrick Stolee via GitGitGadget, Oct 15, 2020
  48. Josh SteadmonDec 9, 2020
  49. Josh SteadmonDec 9, 2020
  50. Derrick StoleeDec 9, 2020
  51. Junio C HamanoDec 10, 2020
  52. Derrick StoleeDec 10, 2020
  53. Junio C HamanoDec 10, 2020
  54. 7/8 maintenance: use 'incremental' strategy by defaultDerrick Stolee via GitGitGadget, Oct 15, 2020
  55. 2/8 maintenance: add --schedule option and configDerrick Stolee via GitGitGadget, Oct 15, 2020
  56. Ævar Arnfjörð BjarmasonFeb 9, 2021
  57. Derrick StoleeFeb 9, 2021
  58. Ævar Arnfjörð BjarmasonMay 10, 2021
  59. Junio C HamanoMay 10, 2021
  60. 6/8 maintenance: create maintenance.strategy configDerrick Stolee via GitGitGadget, Oct 15, 2020
  61. 4/8 maintenance: add [un]register subcommandsDerrick Stolee via GitGitGadget, Oct 15, 2020
  62. 8/8 maintenance: add troubleshooting guide to docsDerrick Stolee via GitGitGadget, Oct 15, 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.