]>
Commit | Line | Data |
---|---|---|
4950b2a2 DS |
1 | #include "cache.h" |
2 | #include "config.h" | |
3 | #include "builtin.h" | |
4 | #include "parse-options.h" | |
5 | #include "run-command.h" | |
6 | #include "string-list.h" | |
7 | ||
8 | static const char * const for_each_repo_usage[] = { | |
c08cfc39 | 9 | N_("git for-each-repo --config=<config> [--] <arguments>"), |
4950b2a2 DS |
10 | NULL |
11 | }; | |
12 | ||
2b299946 | 13 | static int run_command_on_repo(const char *path, int argc, const char ** argv) |
4950b2a2 DS |
14 | { |
15 | int i; | |
16 | struct child_process child = CHILD_PROCESS_INIT; | |
13d5bbdf | 17 | char *abspath = interpolate_path(path, 0); |
4950b2a2 DS |
18 | |
19 | child.git_cmd = 1; | |
13d5bbdf | 20 | strvec_pushl(&child.args, "-C", abspath, NULL); |
4950b2a2 | 21 | |
2b299946 AH |
22 | for (i = 0; i < argc; i++) |
23 | strvec_push(&child.args, argv[i]); | |
4950b2a2 | 24 | |
13d5bbdf RP |
25 | free(abspath); |
26 | ||
4950b2a2 DS |
27 | return run_command(&child); |
28 | } | |
29 | ||
30 | int cmd_for_each_repo(int argc, const char **argv, const char *prefix) | |
31 | { | |
32 | static const char *config_key = NULL; | |
33 | int i, result = 0; | |
34 | const struct string_list *values; | |
4950b2a2 DS |
35 | |
36 | const struct option options[] = { | |
37 | OPT_STRING(0, "config", &config_key, N_("config"), | |
38 | N_("config key storing a list of repository paths")), | |
39 | OPT_END() | |
40 | }; | |
41 | ||
42 | argc = parse_options(argc, argv, prefix, options, for_each_repo_usage, | |
43 | PARSE_OPT_STOP_AT_NON_OPTION); | |
44 | ||
45 | if (!config_key) | |
46 | die(_("missing --config=<config>")); | |
47 | ||
4950b2a2 DS |
48 | values = repo_config_get_value_multi(the_repository, |
49 | config_key); | |
50 | ||
6c62f015 DS |
51 | /* |
52 | * Do nothing on an empty list, which is equivalent to the case | |
53 | * where the config variable does not exist at all. | |
54 | */ | |
55 | if (!values) | |
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 | } |