зеркало из https://github.com/microsoft/git.git
Merge branch 'tc/http-urls-ends-with-slash'
* tc/http-urls-ends-with-slash: http-fetch: rework url handling http-push: add trailing slash at arg-parse time, instead of later on http-push: check path length before using it http-push: Normalise directory names when pushing to some WebDAV servers http-backend: use end_url_with_slash() url: add str wrapper for end_url_with_slash() shift end_url_with_slash() from http.[ch] to url.[ch] t5550-http-fetch: add test for http-fetch t5550-http-fetch: add missing '&&'
This commit is contained in:
Коммит
a0078dee90
2
Makefile
2
Makefile
|
@ -1948,7 +1948,7 @@ builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
|
||||||
builtin/tar-tree.o archive-tar.o: tar.h
|
builtin/tar-tree.o archive-tar.o: tar.h
|
||||||
connect.o transport.o http-backend.o: url.h
|
connect.o transport.o http-backend.o: url.h
|
||||||
http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
|
http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
|
||||||
http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
|
http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h
|
||||||
|
|
||||||
xdiff-interface.o $(XDIFF_OBJS): \
|
xdiff-interface.o $(XDIFF_OBJS): \
|
||||||
xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
|
xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
|
||||||
|
|
|
@ -510,9 +510,7 @@ static char* getdir(void)
|
||||||
die("GIT_PROJECT_ROOT is set but PATH_INFO is not");
|
die("GIT_PROJECT_ROOT is set but PATH_INFO is not");
|
||||||
if (daemon_avoid_alias(pathinfo))
|
if (daemon_avoid_alias(pathinfo))
|
||||||
die("'%s': aliased", pathinfo);
|
die("'%s': aliased", pathinfo);
|
||||||
strbuf_addstr(&buf, root);
|
end_url_with_slash(&buf, root);
|
||||||
if (buf.buf[buf.len - 1] != '/')
|
|
||||||
strbuf_addch(&buf, '/');
|
|
||||||
if (pathinfo[0] == '/')
|
if (pathinfo[0] == '/')
|
||||||
pathinfo++;
|
pathinfo++;
|
||||||
strbuf_addstr(&buf, pathinfo);
|
strbuf_addstr(&buf, pathinfo);
|
||||||
|
|
16
http-fetch.c
16
http-fetch.c
|
@ -14,8 +14,7 @@ int main(int argc, const char **argv)
|
||||||
int commits;
|
int commits;
|
||||||
const char **write_ref = NULL;
|
const char **write_ref = NULL;
|
||||||
char **commit_id;
|
char **commit_id;
|
||||||
const char *url;
|
char *url = NULL;
|
||||||
char *rewritten_url = NULL;
|
|
||||||
int arg = 1;
|
int arg = 1;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int get_tree = 0;
|
int get_tree = 0;
|
||||||
|
@ -57,19 +56,14 @@ int main(int argc, const char **argv)
|
||||||
commit_id = (char **) &argv[arg++];
|
commit_id = (char **) &argv[arg++];
|
||||||
commits = 1;
|
commits = 1;
|
||||||
}
|
}
|
||||||
url = argv[arg];
|
|
||||||
|
if (argv[arg])
|
||||||
|
str_end_url_with_slash(argv[arg], &url);
|
||||||
|
|
||||||
prefix = setup_git_directory();
|
prefix = setup_git_directory();
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
if (url && url[strlen(url)-1] != '/') {
|
|
||||||
rewritten_url = xmalloc(strlen(url)+2);
|
|
||||||
strcpy(rewritten_url, url);
|
|
||||||
strcat(rewritten_url, "/");
|
|
||||||
url = rewritten_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
http_init(NULL);
|
http_init(NULL);
|
||||||
walker = get_http_walker(url);
|
walker = get_http_walker(url);
|
||||||
walker->get_tree = get_tree;
|
walker->get_tree = get_tree;
|
||||||
|
@ -93,7 +87,7 @@ int main(int argc, const char **argv)
|
||||||
walker_free(walker);
|
walker_free(walker);
|
||||||
http_cleanup();
|
http_cleanup();
|
||||||
|
|
||||||
free(rewritten_url);
|
free(url);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
31
http-push.c
31
http-push.c
|
@ -1090,6 +1090,10 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
|
||||||
if (tag_closed) {
|
if (tag_closed) {
|
||||||
if (!strcmp(ctx->name, DAV_PROPFIND_RESP) && ls->dentry_name) {
|
if (!strcmp(ctx->name, DAV_PROPFIND_RESP) && ls->dentry_name) {
|
||||||
if (ls->dentry_flags & IS_DIR) {
|
if (ls->dentry_flags & IS_DIR) {
|
||||||
|
|
||||||
|
/* ensure collection names end with slash */
|
||||||
|
str_end_url_with_slash(ls->dentry_name, &ls->dentry_name);
|
||||||
|
|
||||||
if (ls->flags & PROCESS_DIRS) {
|
if (ls->flags & PROCESS_DIRS) {
|
||||||
ls->userFunc(ls);
|
ls->userFunc(ls);
|
||||||
}
|
}
|
||||||
|
@ -1112,8 +1116,16 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
path += repo->path_len;
|
const char *url = repo->url;
|
||||||
ls->dentry_name = xstrdup(path);
|
if (repo->path)
|
||||||
|
url = repo->path;
|
||||||
|
if (strncmp(path, url, repo->path_len))
|
||||||
|
error("Parsed path '%s' does not match url: '%s'\n",
|
||||||
|
path, url);
|
||||||
|
else {
|
||||||
|
path += repo->path_len;
|
||||||
|
ls->dentry_name = xstrdup(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (!strcmp(ctx->name, DAV_PROPFIND_COLLECTION)) {
|
} else if (!strcmp(ctx->name, DAV_PROPFIND_COLLECTION)) {
|
||||||
ls->dentry_flags |= IS_DIR;
|
ls->dentry_flags |= IS_DIR;
|
||||||
|
@ -1789,7 +1801,6 @@ int main(int argc, char **argv)
|
||||||
int new_refs;
|
int new_refs;
|
||||||
struct ref *ref, *local_refs;
|
struct ref *ref, *local_refs;
|
||||||
struct remote *remote;
|
struct remote *remote;
|
||||||
char *rewritten_url = NULL;
|
|
||||||
|
|
||||||
git_extract_argv0_path(argv[0]);
|
git_extract_argv0_path(argv[0]);
|
||||||
|
|
||||||
|
@ -1835,8 +1846,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
if (!repo->url) {
|
if (!repo->url) {
|
||||||
char *path = strstr(arg, "//");
|
char *path = strstr(arg, "//");
|
||||||
repo->url = arg;
|
str_end_url_with_slash(arg, &repo->url);
|
||||||
repo->path_len = strlen(arg);
|
repo->path_len = strlen(repo->url);
|
||||||
if (path) {
|
if (path) {
|
||||||
repo->path = strchr(path+2, '/');
|
repo->path = strchr(path+2, '/');
|
||||||
if (repo->path)
|
if (repo->path)
|
||||||
|
@ -1872,15 +1883,6 @@ int main(int argc, char **argv)
|
||||||
remote->url[remote->url_nr++] = repo->url;
|
remote->url[remote->url_nr++] = repo->url;
|
||||||
http_init(remote);
|
http_init(remote);
|
||||||
|
|
||||||
if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
|
|
||||||
rewritten_url = xmalloc(strlen(repo->url)+2);
|
|
||||||
strcpy(rewritten_url, repo->url);
|
|
||||||
strcat(rewritten_url, "/");
|
|
||||||
repo->path = rewritten_url + (repo->path - repo->url);
|
|
||||||
repo->path_len++;
|
|
||||||
repo->url = rewritten_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
is_running_queue = 0;
|
is_running_queue = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2088,7 +2090,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(rewritten_url);
|
|
||||||
if (info_ref_lock)
|
if (info_ref_lock)
|
||||||
unlock_remote(info_ref_lock);
|
unlock_remote(info_ref_lock);
|
||||||
free(repo);
|
free(repo);
|
||||||
|
|
7
http.c
7
http.c
|
@ -743,13 +743,6 @@ static inline int hex(int v)
|
||||||
return 'A' + v - 10;
|
return 'A' + v - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_url_with_slash(struct strbuf *buf, const char *url)
|
|
||||||
{
|
|
||||||
strbuf_addstr(buf, url);
|
|
||||||
if (buf->len && buf->buf[buf->len - 1] != '/')
|
|
||||||
strbuf_addstr(buf, "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *quote_ref_url(const char *base, const char *ref)
|
static char *quote_ref_url(const char *base, const char *ref)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
2
http.h
2
http.h
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
#include "url.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We detect based on the cURL version if multi-transfer is
|
* We detect based on the cURL version if multi-transfer is
|
||||||
|
@ -117,7 +118,6 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url,
|
||||||
int only_two_digit_prefix);
|
int only_two_digit_prefix);
|
||||||
extern char *get_remote_object_url(const char *url, const char *hex,
|
extern char *get_remote_object_url(const char *url, const char *hex,
|
||||||
int only_two_digit_prefix);
|
int only_two_digit_prefix);
|
||||||
extern void end_url_with_slash(struct strbuf *buf, const char *url);
|
|
||||||
|
|
||||||
/* Options for http_request_*() */
|
/* Options for http_request_*() */
|
||||||
#define HTTP_NO_CACHE 1
|
#define HTTP_NO_CACHE 1
|
||||||
|
|
|
@ -30,7 +30,8 @@ test_expect_success 'create http-accessible bare repository' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'clone http repository' '
|
test_expect_success 'clone http repository' '
|
||||||
git clone $HTTPD_URL/dumb/repo.git clone &&
|
git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
|
||||||
|
cp -R clone-tmpl clone &&
|
||||||
test_cmp file clone/file
|
test_cmp file clone/file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -44,11 +45,22 @@ test_expect_success 'clone http repository with authentication' '
|
||||||
test_expect_success 'fetch changes via http' '
|
test_expect_success 'fetch changes via http' '
|
||||||
echo content >>file &&
|
echo content >>file &&
|
||||||
git commit -a -m two &&
|
git commit -a -m two &&
|
||||||
git push public
|
git push public &&
|
||||||
(cd clone && git pull) &&
|
(cd clone && git pull) &&
|
||||||
test_cmp file clone/file
|
test_cmp file clone/file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch changes via manual http-fetch' '
|
||||||
|
cp -R clone-tmpl clone2 &&
|
||||||
|
|
||||||
|
HEAD=$(git rev-parse --verify HEAD) &&
|
||||||
|
(cd clone2 &&
|
||||||
|
git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
|
||||||
|
git checkout master-new &&
|
||||||
|
test $HEAD = $(git rev-parse --verify HEAD)) &&
|
||||||
|
test_cmp file clone2/file
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'http remote detects correct HEAD' '
|
test_expect_success 'http remote detects correct HEAD' '
|
||||||
git push public master:other &&
|
git push public master:other &&
|
||||||
(cd clone &&
|
(cd clone &&
|
||||||
|
|
14
url.c
14
url.c
|
@ -125,3 +125,17 @@ char *url_decode_parameter_value(const char **query)
|
||||||
struct strbuf out = STRBUF_INIT;
|
struct strbuf out = STRBUF_INIT;
|
||||||
return url_decode_internal(query, "&", &out, 1);
|
return url_decode_internal(query, "&", &out, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void end_url_with_slash(struct strbuf *buf, const char *url)
|
||||||
|
{
|
||||||
|
strbuf_addstr(buf, url);
|
||||||
|
if (buf->len && buf->buf[buf->len - 1] != '/')
|
||||||
|
strbuf_addstr(buf, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
void str_end_url_with_slash(const char *url, char **dest) {
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
end_url_with_slash(&buf, url);
|
||||||
|
free(*dest);
|
||||||
|
*dest = strbuf_detach(&buf, NULL);
|
||||||
|
}
|
||||||
|
|
3
url.h
3
url.h
|
@ -7,4 +7,7 @@ extern char *url_decode(const char *url);
|
||||||
extern char *url_decode_parameter_name(const char **query);
|
extern char *url_decode_parameter_name(const char **query);
|
||||||
extern char *url_decode_parameter_value(const char **query);
|
extern char *url_decode_parameter_value(const char **query);
|
||||||
|
|
||||||
|
extern void end_url_with_slash(struct strbuf *buf, const char *url);
|
||||||
|
extern void str_end_url_with_slash(const char *url, char **dest);
|
||||||
|
|
||||||
#endif /* URL_H */
|
#endif /* URL_H */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче