Skip to content

Commit 89044ba

Browse files
peffgitster
authored andcommitted
submodule: stop sanitizing config options
The point of having a whitelist of command-line config options to pass to submodules was two-fold: 1. It prevented obvious nonsense like using core.worktree for multiple repos. 2. It could prevent surprise when the user did not mean for the options to leak to the submodules (e.g., http.sslverify=false). For case 1, the answer is mostly "if it hurts, don't do that". For case 2, we can note that any such example has a matching inverted surprise (e.g., a user who meant http.sslverify=true to apply everywhere, but it didn't). So this whitelist is probably not giving us any benefit, and is already creating a hassle as people propose things to put on it. Let's just drop it entirely. Note that we still need to keep a special code path for "prepare the submodule environment", because we still have to take care to pass through $GIT_CONFIG_PARAMETERS (and block the rest of the repo-specific environment variables). We can do this easily from within the submodule shell script, which lets us drop the submodule--helper option entirely (and it's OK to do so because as a "--" program, it is entirely a private implementation detail). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c12e865 commit 89044ba

File tree

5 files changed

+4
-93
lines changed

5 files changed

+4
-93
lines changed

builtin/submodule--helper.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,6 @@ static int module_clone(int argc, const char **argv, const char *prefix)
260260
return 0;
261261
}
262262

263-
static int module_sanitize_config(int argc, const char **argv, const char *prefix)
264-
{
265-
struct strbuf sanitized_config = STRBUF_INIT;
266-
267-
if (argc > 1)
268-
usage(_("git submodule--helper sanitize-config"));
269-
270-
git_config_from_parameters(sanitize_submodule_config, &sanitized_config);
271-
if (sanitized_config.len)
272-
printf("%s\n", sanitized_config.buf);
273-
274-
strbuf_release(&sanitized_config);
275-
276-
return 0;
277-
}
278-
279263
struct cmd_struct {
280264
const char *cmd;
281265
int (*fn)(int, const char **, const char *);
@@ -285,7 +269,6 @@ static struct cmd_struct commands[] = {
285269
{"list", module_list},
286270
{"name", module_name},
287271
{"clone", module_clone},
288-
{"sanitize-config", module_sanitize_config},
289272
};
290273

291274
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)

git-submodule.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ isnumber()
197197
# of the settings from GIT_CONFIG_PARAMETERS.
198198
sanitize_submodule_env()
199199
{
200-
sanitized_config=$(git submodule--helper sanitize-config)
200+
save_config=$GIT_CONFIG_PARAMETERS
201201
clear_local_git_env
202-
GIT_CONFIG_PARAMETERS=$sanitized_config
202+
GIT_CONFIG_PARAMETERS=$save_config
203203
export GIT_CONFIG_PARAMETERS
204204
}
205205

submodule.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,50 +1098,13 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
10981098
strbuf_release(&rel_path);
10991099
free((void *)real_work_tree);
11001100
}
1101-
/*
1102-
* Rules to sanitize configuration variables that are Ok to be passed into
1103-
* submodule operations from the parent project using "-c". Should only
1104-
* include keys which are both (a) safe and (b) necessary for proper
1105-
* operation.
1106-
*/
1107-
static int submodule_config_ok(const char *var)
1108-
{
1109-
if (starts_with(var, "credential."))
1110-
return 1;
1111-
return 0;
1112-
}
1113-
1114-
int sanitize_submodule_config(const char *var, const char *value, void *data)
1115-
{
1116-
struct strbuf *out = data;
1117-
1118-
if (submodule_config_ok(var)) {
1119-
if (out->len)
1120-
strbuf_addch(out, ' ');
1121-
1122-
if (value)
1123-
sq_quotef(out, "%s=%s", var, value);
1124-
else
1125-
sq_quote_buf(out, var);
1126-
}
1127-
1128-
return 0;
1129-
}
11301101

11311102
void prepare_submodule_repo_env(struct argv_array *out)
11321103
{
11331104
const char * const *var;
11341105

11351106
for (var = local_repo_env; *var; var++) {
1136-
if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {
1137-
struct strbuf sanitized_config = STRBUF_INIT;
1138-
git_config_from_parameters(sanitize_submodule_config,
1139-
&sanitized_config);
1140-
argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf);
1141-
strbuf_release(&sanitized_config);
1142-
} else {
1107+
if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
11431108
argv_array_push(out, *var);
1144-
}
11451109
}
1146-
11471110
}

submodule.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,10 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
4343
int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
4444
void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
4545

46-
/*
47-
* This function is intended as a callback for use with
48-
* git_config_from_parameters(). It ignores any config options which
49-
* are not suitable for passing along to a submodule, and accumulates the rest
50-
* in "data", which must be a pointer to a strbuf. The end result can
51-
* be put into $GIT_CONFIG_PARAMETERS for passing to a sub-process.
52-
*/
53-
int sanitize_submodule_config(const char *var, const char *value, void *data);
54-
5546
/*
5647
* Prepare the "env_array" parameter of a "struct child_process" for executing
5748
* a submodule by clearing any repo-specific envirionment variables, but
58-
* retaining any config approved by sanitize_submodule_config().
49+
* retaining any config in the environment.
5950
*/
6051
void prepare_submodule_repo_env(struct argv_array *out);
6152

t/t7412-submodule--helper.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)