Skip to content

Commit 6b948a7

Browse files
committed
Merge branch 'jk/maint-pass-c-config-in-env'
* jk/maint-pass-c-config-in-env: do not pass "git -c foo=bar" params to transport helpers pass "git -c foo=bar" params through environment
2 parents 9f44723 + 655e8d9 commit 6b948a7

5 files changed

Lines changed: 83 additions & 5 deletions

File tree

cache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ static inline enum object_type object_type(unsigned int mode)
378378
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
379379
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
380380
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
381+
#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
381382
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
382383
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
383384
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
@@ -396,7 +397,7 @@ static inline enum object_type object_type(unsigned int mode)
396397
* environment creation or simple walk of the list.
397398
* The number of non-NULL entries is available as a macro.
398399
*/
399-
#define LOCAL_REPO_ENV_SIZE 8
400+
#define LOCAL_REPO_ENV_SIZE 9
400401
extern const char *const local_repo_env[LOCAL_REPO_ENV_SIZE + 1];
401402

402403
extern int is_bare_repository_cfg;
@@ -973,7 +974,9 @@ extern int update_server_info(int);
973974
typedef int (*config_fn_t)(const char *, const char *, void *);
974975
extern int git_default_config(const char *, const char *, void *);
975976
extern int git_config_from_file(config_fn_t fn, const char *, void *);
977+
extern void git_config_push_parameter(const char *text);
976978
extern int git_config_parse_parameter(const char *text);
979+
extern int git_config_parse_environment(void);
977980
extern int git_config_from_parameters(config_fn_t fn, void *data);
978981
extern int git_config(config_fn_t fn, void *);
979982
extern int git_parse_ulong(const char *, unsigned long *);

config.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cache.h"
99
#include "exec_cmd.h"
1010
#include "strbuf.h"
11+
#include "quote.h"
1112

1213
#define MAXNAME (256)
1314

@@ -34,6 +35,19 @@ static void lowercase(char *p)
3435
*p = tolower(*p);
3536
}
3637

38+
void git_config_push_parameter(const char *text)
39+
{
40+
struct strbuf env = STRBUF_INIT;
41+
const char *old = getenv(CONFIG_DATA_ENVIRONMENT);
42+
if (old) {
43+
strbuf_addstr(&env, old);
44+
strbuf_addch(&env, ' ');
45+
}
46+
sq_quote_buf(&env, text);
47+
setenv(CONFIG_DATA_ENVIRONMENT, env.buf, 1);
48+
strbuf_release(&env);
49+
}
50+
3751
int git_config_parse_parameter(const char *text)
3852
{
3953
struct config_item *ct;
@@ -61,6 +75,37 @@ int git_config_parse_parameter(const char *text)
6175
return 0;
6276
}
6377

78+
int git_config_parse_environment(void) {
79+
const char *env = getenv(CONFIG_DATA_ENVIRONMENT);
80+
char *envw;
81+
const char **argv = NULL;
82+
int nr = 0, alloc = 0;
83+
int i;
84+
85+
if (!env)
86+
return 0;
87+
/* sq_dequote will write over it */
88+
envw = xstrdup(env);
89+
90+
if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) {
91+
free(envw);
92+
return error("bogus format in " CONFIG_DATA_ENVIRONMENT);
93+
}
94+
95+
for (i = 0; i < nr; i++) {
96+
if (git_config_parse_parameter(argv[i]) < 0) {
97+
error("bogus config parameter: %s", argv[i]);
98+
free(argv);
99+
free(envw);
100+
return -1;
101+
}
102+
}
103+
104+
free(argv);
105+
free(envw);
106+
return 0;
107+
}
108+
64109
static int get_next_char(void)
65110
{
66111
int c;
@@ -773,7 +818,14 @@ int git_config_global(void)
773818

774819
int git_config_from_parameters(config_fn_t fn, void *data)
775820
{
821+
static int loaded_environment;
776822
const struct config_item *ct;
823+
824+
if (!loaded_environment) {
825+
if (git_config_parse_environment() < 0)
826+
return -1;
827+
loaded_environment = 1;
828+
}
777829
for (ct = config_parameters; ct; ct = ct->next)
778830
if (fn(ct->name, ct->value, data) < 0)
779831
return -1;
@@ -812,10 +864,9 @@ int git_config(config_fn_t fn, void *data)
812864
}
813865
free(repo_config);
814866

815-
if (config_parameters) {
816-
ret += git_config_from_parameters(fn, data);
867+
ret += git_config_from_parameters(fn, data);
868+
if (config_parameters)
817869
found += 1;
818-
}
819870

820871
if (found == 0)
821872
return -1;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
7373
const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
7474
ALTERNATE_DB_ENVIRONMENT,
7575
CONFIG_ENVIRONMENT,
76+
CONFIG_DATA_ENVIRONMENT,
7677
DB_ENVIRONMENT,
7778
GIT_DIR_ENVIRONMENT,
7879
GIT_WORK_TREE_ENVIRONMENT,

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
137137
fprintf(stderr, "-c expects a configuration string\n" );
138138
usage(git_usage_string);
139139
}
140-
git_config_parse_parameter((*argv)[1]);
140+
git_config_push_parameter((*argv)[1]);
141141
(*argv)++;
142142
(*argc)--;
143143
} else {

t/t5400-send-pack.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ test_expect_success 'refuse deleting push with denyDeletes' '
9494
test_must_fail git send-pack ./victim :extra master
9595
'
9696

97+
test_expect_success 'cannot override denyDeletes with git -c send-pack' '
98+
(
99+
cd victim &&
100+
test_might_fail git branch -D extra &&
101+
git config receive.denyDeletes true &&
102+
git branch extra master
103+
) &&
104+
test_must_fail git -c receive.denyDeletes=false \
105+
send-pack ./victim :extra master
106+
'
107+
108+
test_expect_success 'override denyDeletes with git -c receive-pack' '
109+
(
110+
cd victim &&
111+
test_might_fail git branch -D extra &&
112+
git config receive.denyDeletes true &&
113+
git branch extra master
114+
) &&
115+
git send-pack \
116+
--receive-pack="git -c receive.denyDeletes=false receive-pack" \
117+
./victim :extra master
118+
'
119+
97120
test_expect_success 'denyNonFastforwards trumps --force' '
98121
(
99122
cd victim &&

0 commit comments

Comments
 (0)