]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/for-each-repo.c
cache.h: remove this no-longer-used header
[thirdparty/git.git] / builtin / for-each-repo.c
CommitLineData
4950b2a2 1#include "builtin.h"
bc5c5ec0 2#include "config.h"
f394e093 3#include "gettext.h"
4950b2a2 4#include "parse-options.h"
d1cbe1e6
EN
5#include "path.h"
6#include "repository.h"
4950b2a2
DS
7#include "run-command.h"
8#include "string-list.h"
9
10static const char * const for_each_repo_usage[] = {
c08cfc39 11 N_("git for-each-repo --config=<config> [--] <arguments>"),
4950b2a2
DS
12 NULL
13};
14
2b299946 15static int run_command_on_repo(const char *path, int argc, const char ** argv)
4950b2a2
DS
16{
17 int i;
18 struct child_process child = CHILD_PROCESS_INIT;
13d5bbdf 19 char *abspath = interpolate_path(path, 0);
4950b2a2
DS
20
21 child.git_cmd = 1;
13d5bbdf 22 strvec_pushl(&child.args, "-C", abspath, NULL);
4950b2a2 23
2b299946
AH
24 for (i = 0; i < argc; i++)
25 strvec_push(&child.args, argv[i]);
4950b2a2 26
13d5bbdf
RP
27 free(abspath);
28
4950b2a2
DS
29 return run_command(&child);
30}
31
32int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
33{
34 static const char *config_key = NULL;
35 int i, result = 0;
36 const struct string_list *values;
f7b2ff95 37 int err;
4950b2a2
DS
38
39 const struct option options[] = {
40 OPT_STRING(0, "config", &config_key, N_("config"),
41 N_("config key storing a list of repository paths")),
42 OPT_END()
43 };
44
45 argc = parse_options(argc, argv, prefix, options, for_each_repo_usage,
46 PARSE_OPT_STOP_AT_NON_OPTION);
47
48 if (!config_key)
49 die(_("missing --config=<config>"));
50
3611f746 51 err = repo_config_get_string_multi(the_repository, config_key, &values);
f7b2ff95
ÆAB
52 if (err < 0)
53 usage_msg_optf(_("got bad config --config=%s"),
54 for_each_repo_usage, options, config_key);
55 else if (err)
6c62f015
DS
56 return 0;
57
4950b2a2 58 for (i = 0; !result && i < values->nr; i++)
2b299946 59 result = run_command_on_repo(values->items[i].string, argc, argv);
4950b2a2
DS
60
61 return result;
62}