Skip to content

Commit 0116b0e

Browse files
committed
Merge branch 'js/http-custom-headers'
Update tests for "http.extraHeaders=<header>" to be portable back to Apache 2.2 (the original depended on <RequireAll/> which is a more recent feature). * js/http-custom-headers: submodule: ensure that -c http.extraheader is heeded t5551: make the test for extra HTTP headers more robust tests: adjust the configuration for Apache 2.2 Rebased-and-signed-off-by: Johannes Schindelin <[email protected]>
2 parents aa178e6 + 1880f56 commit 0116b0e

16 files changed

+219
-37
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,12 @@ http.emptyAuth::
16751675
a username in the URL, as libcurl normally requires a username for
16761676
authentication.
16771677

1678+
http.extraHeader::
1679+
Pass an additional HTTP header when communicating with a server. If
1680+
more than one such entry exists, all of them are added as extra
1681+
headers. To allow overriding the settings inherited from the system
1682+
config, an empty value will reset the extra headers to the empty list.
1683+
16781684
http.cookieFile::
16791685
File containing previously stored cookie lines which should be used
16801686
in the Git http session, if they match the server. The file format

builtin/submodule--helper.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
118118

119119
return 0;
120120
}
121+
121122
static int clone_submodule(const char *path, const char *gitdir, const char *url,
122123
const char *depth, const char *reference, int quiet)
123124
{
@@ -139,7 +140,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
139140
argv_array_push(&cp.args, path);
140141

141142
cp.git_cmd = 1;
142-
cp.env = local_repo_env;
143+
prepare_submodule_repo_env(&cp.env_array);
143144
cp.no_stdin = 1;
144145

145146
return run_command(&cp);
@@ -180,8 +181,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
180181

181182
const char *const git_submodule_helper_usage[] = {
182183
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
183-
"[--reference <repository>] [--name <name>] [--url <url>]"
184-
"[--depth <depth>] [--] [<path>...]"),
184+
"[--reference <repository>] [--name <name>] [--depth <depth>] "
185+
"--url <url> --path <path>"),
185186
NULL
186187
};
187188

@@ -191,6 +192,10 @@ static int module_clone(int argc, const char **argv, const char *prefix)
191192
if (!path || !*path)
192193
die(_("submodule--helper: unspecified or empty --path"));
193194

195+
if (argc || !url)
196+
usage_with_options(git_submodule_helper_usage,
197+
module_clone_options);
198+
194199
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
195200
sm_gitdir = xstrdup(absolute_path(sb.buf));
196201
strbuf_reset(&sb);

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void git_config_push_parameter(const char *text)
162162
{
163163
struct strbuf env = STRBUF_INIT;
164164
const char *old = getenv(CONFIG_DATA_ENVIRONMENT);
165-
if (old) {
165+
if (old && *old) {
166166
strbuf_addstr(&env, old);
167167
strbuf_addch(&env, ' ');
168168
}

git-submodule.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ isnumber()
192192
n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
193193
}
194194

195+
# Sanitize the local git environment for use within a submodule. We
196+
# can't simply use clear_local_git_env since we want to preserve some
197+
# of the settings from GIT_CONFIG_PARAMETERS.
198+
sanitize_submodule_env()
199+
{
200+
save_config=$GIT_CONFIG_PARAMETERS
201+
clear_local_git_env
202+
GIT_CONFIG_PARAMETERS=$save_config
203+
export GIT_CONFIG_PARAMETERS
204+
}
205+
195206
#
196207
# Add a new submodule to the working tree, .gitmodules and the index
197208
#
@@ -347,9 +358,9 @@ Use -f if you really want to add it." >&2
347358
echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
348359
fi
349360
fi
350-
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" "$reference" "$depth" || exit
361+
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
351362
(
352-
clear_local_git_env
363+
sanitize_submodule_env
353364
cd "$sm_path" &&
354365
# ash fails to wordsplit ${branch:+-b "$branch"...}
355366
case "$branch" in
@@ -418,7 +429,7 @@ cmd_foreach()
418429
name=$(git submodule--helper name "$sm_path")
419430
(
420431
prefix="$prefix$sm_path/"
421-
clear_local_git_env
432+
sanitize_submodule_env
422433
cd "$sm_path" &&
423434
sm_path=$(relative_path "$sm_path") &&
424435
# we make $path available to scripts ...
@@ -592,14 +603,14 @@ cmd_deinit()
592603
}
593604

594605
is_tip_reachable () (
595-
clear_local_git_env
606+
sanitize_submodule_env &&
596607
cd "$1" &&
597608
rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
598609
test -z "$rev"
599610
)
600611

601612
fetch_in_submodule () (
602-
clear_local_git_env
613+
sanitize_submodule_env &&
603614
cd "$1" &&
604615
case "$2" in
605616
'')
@@ -727,11 +738,11 @@ Maybe you want to use 'update --init'?")"
727738

728739
if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
729740
then
730-
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
741+
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" ${reference:+"$reference"} ${depth:+"$depth"} || exit
731742
cloned_modules="$cloned_modules;$name"
732743
subsha1=
733744
else
734-
subsha1=$(clear_local_git_env; cd "$sm_path" &&
745+
subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
735746
git rev-parse --verify HEAD) ||
736747
die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
737748
fi
@@ -741,11 +752,11 @@ Maybe you want to use 'update --init'?")"
741752
if test -z "$nofetch"
742753
then
743754
# Fetch remote before determining tracking $sha1
744-
(clear_local_git_env; cd "$sm_path" && git-fetch) ||
755+
(sanitize_submodule_env; cd "$sm_path" && git-fetch) ||
745756
die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
746757
fi
747-
remote_name=$(clear_local_git_env; cd "$sm_path" && get_default_remote)
748-
sha1=$(clear_local_git_env; cd "$sm_path" &&
758+
remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
759+
sha1=$(sanitize_submodule_env; cd "$sm_path" &&
749760
git rev-parse --verify "${remote_name}/${branch}") ||
750761
die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
751762
fi
@@ -810,7 +821,7 @@ Maybe you want to use 'update --init'?")"
810821
die "$(eval_gettext "Invalid update mode '$update_module' for submodule '$name'")"
811822
esac
812823

813-
if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
824+
if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
814825
then
815826
say "$say_msg"
816827
elif test -n "$must_die_on_failure"
@@ -826,7 +837,7 @@ Maybe you want to use 'update --init'?")"
826837
then
827838
(
828839
prefix="$prefix$sm_path/"
829-
clear_local_git_env
840+
sanitize_submodule_env
830841
cd "$sm_path" &&
831842
eval cmd_update
832843
)
@@ -864,7 +875,7 @@ Maybe you want to use 'update --init'?")"
864875

865876
set_name_rev () {
866877
revname=$( (
867-
clear_local_git_env
878+
sanitize_submodule_env
868879
cd "$1" && {
869880
git describe "$2" 2>/dev/null ||
870881
git describe --tags "$2" 2>/dev/null ||
@@ -1148,7 +1159,7 @@ cmd_status()
11481159
else
11491160
if test -z "$cached"
11501161
then
1151-
sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
1162+
sha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD)
11521163
fi
11531164
set_name_rev "$sm_path" "$sha1"
11541165
say "+$sha1 $displaypath$revname"
@@ -1158,7 +1169,7 @@ cmd_status()
11581169
then
11591170
(
11601171
prefix="$displaypath/"
1161-
clear_local_git_env
1172+
sanitize_submodule_env
11621173
wt_prefix=
11631174
cd "$sm_path" &&
11641175
eval cmd_status
@@ -1233,7 +1244,7 @@ cmd_sync()
12331244
if test -e "$sm_path"/.git
12341245
then
12351246
(
1236-
clear_local_git_env
1247+
sanitize_submodule_env
12371248
cd "$sm_path"
12381249
remote=$(get_default_remote)
12391250
git config remote."$remote".url "$sub_origin_url"

http-push.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void curl_setup_http(CURL *curl, const char *url,
211211
static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)
212212
{
213213
struct strbuf buf = STRBUF_INIT;
214-
struct curl_slist *dav_headers = NULL;
214+
struct curl_slist *dav_headers = http_copy_default_headers();
215215

216216
if (options & DAV_HEADER_IF) {
217217
strbuf_addf(&buf, "If: (<%s>)", lock->token);
@@ -417,7 +417,7 @@ static void start_put(struct transfer_request *request)
417417
static void start_move(struct transfer_request *request)
418418
{
419419
struct active_request_slot *slot;
420-
struct curl_slist *dav_headers = NULL;
420+
struct curl_slist *dav_headers = http_copy_default_headers();
421421

422422
slot = get_active_slot();
423423
slot->callback_func = process_response;
@@ -845,7 +845,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
845845
char *ep;
846846
char timeout_header[25];
847847
struct remote_lock *lock = NULL;
848-
struct curl_slist *dav_headers = NULL;
848+
struct curl_slist *dav_headers = http_copy_default_headers();
849849
struct xml_ctx ctx;
850850
char *escaped;
851851

@@ -1126,7 +1126,7 @@ static void remote_ls(const char *path, int flags,
11261126
struct slot_results results;
11271127
struct strbuf in_buffer = STRBUF_INIT;
11281128
struct buffer out_buffer = { STRBUF_INIT, 0 };
1129-
struct curl_slist *dav_headers = NULL;
1129+
struct curl_slist *dav_headers = http_copy_default_headers();
11301130
struct xml_ctx ctx;
11311131
struct remote_ls_ctx ls;
11321132

@@ -1204,7 +1204,7 @@ static int locking_available(void)
12041204
struct slot_results results;
12051205
struct strbuf in_buffer = STRBUF_INIT;
12061206
struct buffer out_buffer = { STRBUF_INIT, 0 };
1207-
struct curl_slist *dav_headers = NULL;
1207+
struct curl_slist *dav_headers = http_copy_default_headers();
12081208
struct xml_ctx ctx;
12091209
int lock_flags = 0;
12101210
char *escaped;

http.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static unsigned long http_auth_methods = CURLAUTH_ANY;
114114

115115
static struct curl_slist *pragma_header;
116116
static struct curl_slist *no_pragma_header;
117+
static struct curl_slist *extra_http_headers;
117118

118119
static struct active_request_slot *active_queue_head;
119120

@@ -323,6 +324,19 @@ static int http_options(const char *var, const char *value, void *cb)
323324
#endif
324325
}
325326

327+
if (!strcmp("http.extraheader", var)) {
328+
if (!value) {
329+
return config_error_nonbool(var);
330+
} else if (!*value) {
331+
curl_slist_free_all(extra_http_headers);
332+
extra_http_headers = NULL;
333+
} else {
334+
extra_http_headers =
335+
curl_slist_append(extra_http_headers, value);
336+
}
337+
return 0;
338+
}
339+
326340
/* Fall back on the default ones */
327341
return git_default_config(var, value, cb);
328342
}
@@ -678,8 +692,10 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
678692
if (remote)
679693
var_override(&http_proxy_authmethod, remote->http_proxy_authmethod);
680694

681-
pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
682-
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
695+
pragma_header = curl_slist_append(http_copy_default_headers(),
696+
"Pragma: no-cache");
697+
no_pragma_header = curl_slist_append(http_copy_default_headers(),
698+
"Pragma:");
683699

684700
#ifdef USE_CURL_MULTI
685701
{
@@ -765,6 +781,9 @@ void http_cleanup(void)
765781
#endif
766782
curl_global_cleanup();
767783

784+
curl_slist_free_all(extra_http_headers);
785+
extra_http_headers = NULL;
786+
768787
curl_slist_free_all(pragma_header);
769788
pragma_header = NULL;
770789

@@ -1163,6 +1182,16 @@ int run_one_slot(struct active_request_slot *slot,
11631182
return handle_curl_result(results);
11641183
}
11651184

1185+
struct curl_slist *http_copy_default_headers(void)
1186+
{
1187+
struct curl_slist *headers = NULL, *h;
1188+
1189+
for (h = extra_http_headers; h; h = h->next)
1190+
headers = curl_slist_append(headers, h->data);
1191+
1192+
return headers;
1193+
}
1194+
11661195
static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf)
11671196
{
11681197
char *ptr;
@@ -1380,7 +1409,7 @@ static int http_request(const char *url,
13801409
{
13811410
struct active_request_slot *slot;
13821411
struct slot_results results;
1383-
struct curl_slist *headers = NULL;
1412+
struct curl_slist *headers = http_copy_default_headers();
13841413
struct strbuf buf = STRBUF_INIT;
13851414
const char *accept_language;
13861415
int ret;

http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ extern void step_active_slots(void);
106106
extern void http_init(struct remote *remote, const char *url,
107107
int proactive_auth);
108108
extern void http_cleanup(void);
109+
extern struct curl_slist *http_copy_default_headers(void);
109110

110111
extern long int git_curl_ipresolve;
111112
extern int active_requests;

quote.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
4343
free(to_free);
4444
}
4545

46+
void sq_quotef(struct strbuf *dst, const char *fmt, ...)
47+
{
48+
struct strbuf src = STRBUF_INIT;
49+
50+
va_list ap;
51+
va_start(ap, fmt);
52+
strbuf_vaddf(&src, fmt, ap);
53+
va_end(ap);
54+
55+
sq_quote_buf(dst, src.buf);
56+
strbuf_release(&src);
57+
}
58+
4659
void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
4760
{
4861
int i;

quote.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ struct strbuf;
2525
* sq_quote_buf() writes to an existing buffer of specified size; it
2626
* will return the number of characters that would have been written
2727
* excluding the final null regardless of the buffer size.
28+
*
29+
* sq_quotef() quotes the entire formatted string as a single result.
2830
*/
2931

3032
extern void sq_quote_buf(struct strbuf *, const char *src);
3133
extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
34+
extern void sq_quotef(struct strbuf *, const char *fmt, ...);
3235

3336
/* This unwraps what sq_quote() produces in place, but returns
3437
* NULL if the input does not look like what sq_quote would have

remote-curl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int run_slot(struct active_request_slot *slot,
474474
static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
475475
{
476476
struct active_request_slot *slot;
477-
struct curl_slist *headers = NULL;
477+
struct curl_slist *headers = http_copy_default_headers();
478478
struct strbuf buf = STRBUF_INIT;
479479
int err;
480480

@@ -503,7 +503,7 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
503503
static int post_rpc(struct rpc_state *rpc)
504504
{
505505
struct active_request_slot *slot;
506-
struct curl_slist *headers = NULL;
506+
struct curl_slist *headers = http_copy_default_headers();
507507
int use_gzip = rpc->gzip_request;
508508
char *gzip_body = NULL;
509509
size_t gzip_size = 0;

0 commit comments

Comments
 (0)