diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-11-18 21:32:53 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-11-18 21:32:53 (GMT) |
commit | 7660da161821ab79b8ecd5019c28843ed7e770a6 (patch) | |
tree | d0993b4af829e0275d6ff7cd0f87b17f69819b7c /builtin/for-each-repo.c | |
parent | c042c455d4ffb9b5ed0c280301b5661f3efad572 (diff) | |
parent | 0016b618182f642771dc589cf0090289f9fe1b4f (diff) | |
download | git-7660da161821ab79b8ecd5019c28843ed7e770a6.zip git-7660da161821ab79b8ecd5019c28843ed7e770a6.tar.gz git-7660da161821ab79b8ecd5019c28843ed7e770a6.tar.bz2 |
Merge branch 'ds/maintenance-part-3'
Parts of "git maintenance" to ease writing crontab entries (and
other scheduling system configuration) for it.
* ds/maintenance-part-3:
maintenance: add troubleshooting guide to docs
maintenance: use 'incremental' strategy by default
maintenance: create maintenance.strategy config
maintenance: add start/stop subcommands
maintenance: add [un]register subcommands
for-each-repo: run subcommands on configured repos
maintenance: add --schedule option and config
maintenance: optionally skip --auto process
Diffstat (limited to 'builtin/for-each-repo.c')
-rw-r--r-- | builtin/for-each-repo.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c new file mode 100644 index 0000000..5bba623 --- /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; + + 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]); + + 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]); + + 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; +} |