From fe4bc2a5aeb59b5767a3f8f4246ac088d4a13d73 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:25 +0800 Subject: [PATCH 1/7] t5541-http-push: check that ref is unchanged for non-ff test Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- t/t5541-http-push.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 53f54a278..ff947f3e4 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -89,15 +89,17 @@ test_expect_success 'used receive-pack service' ' ' test_expect_success 'non-fast-forward push fails' ' + cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && + HEAD=$(git rev-parse --verify HEAD) && + cd "$ROOT_PATH"/test_repo_clone && git checkout master && echo "changed" > path2 && git commit -a -m path2 --amend && - HEAD=$(git rev-parse --verify HEAD) && !(git push -v origin >output 2>&1) && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - test $HEAD != $(git rev-parse --verify HEAD)) + test $HEAD = $(git rev-parse --verify HEAD)) ' test_expect_success 'non-fast-forward push show ref status' ' From 6cbd6e92616773457574f9755910f44b3c34a983 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:26 +0800 Subject: [PATCH 2/7] t554[01]-http-push: refactor, add non-ff tests Move non-fast forward tests to lib-httpd.sh so that we don't have to duplicate the tests in both t5540 and t5541. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- t/lib-httpd.sh | 29 +++++++++++++++++++++++++++++ t/t5540-http-push.sh | 3 +++ t/t5541-http-push.sh | 24 ++---------------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 28aff887b..da4b8d5a6 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -131,3 +131,32 @@ stop_httpd() { "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop } + +test_http_push_nonff() { + REMOTE_REPO=$1 + LOCAL_REPO=$2 + BRANCH=$3 + + test_expect_success 'non-fast-forward push fails' ' + cd "$REMOTE_REPO" && + HEAD=$(git rev-parse --verify HEAD) && + + cd "$LOCAL_REPO" && + git checkout $BRANCH && + echo "changed" > path2 && + git commit -a -m path2 --amend && + + !(git push -v origin >output 2>&1) && + (cd "$REMOTE_REPO" && + test $HEAD = $(git rev-parse --verify HEAD)) + ' + + test_expect_success 'non-fast-forward push show ref status' ' + grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output + ' + + test_expect_success 'non-fast-forward push shows help message' ' + grep "To prevent you from losing history, non-fast-forward updates were rejected" \ + output + ' +} diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh index bb18f8bfc..37fe87541 100755 --- a/t/t5540-http-push.sh +++ b/t/t5540-http-push.sh @@ -137,6 +137,9 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' ' +test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ + "$ROOT_PATH"/test_repo_clone master + stop_httpd test_done diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index ff947f3e4..795dc2bcd 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -88,28 +88,8 @@ test_expect_success 'used receive-pack service' ' test_cmp exp act ' -test_expect_success 'non-fast-forward push fails' ' - cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - HEAD=$(git rev-parse --verify HEAD) && - - cd "$ROOT_PATH"/test_repo_clone && - git checkout master && - echo "changed" > path2 && - git commit -a -m path2 --amend && - - !(git push -v origin >output 2>&1) && - (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - test $HEAD = $(git rev-parse --verify HEAD)) -' - -test_expect_success 'non-fast-forward push show ref status' ' - grep "^ ! \[rejected\][ ]*master -> master (non-fast-forward)$" output -' - -test_expect_success 'non-fast-forward push shows help message' ' - grep "To prevent you from losing history, non-fast-forward updates were rejected" \ - output -' +test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ + "$ROOT_PATH"/test_repo_clone master test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' ' # create a dissimilarly-named remote ref so that git is unable to match the From b5e59989eb20a8d6257760605052fe1d3fefca88 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:27 +0800 Subject: [PATCH 3/7] http-push: remove "|| 1" to enable verbose check Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- http-push.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-push.c b/http-push.c index 432b20f2d..415b1ab0a 100644 --- a/http-push.c +++ b/http-push.c @@ -1965,7 +1965,7 @@ int main(int argc, char **argv) } if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) { - if (push_verbosely || 1) + if (push_verbosely) fprintf(stderr, "'%s': up-to-date\n", ref->name); if (helper_status) printf("ok %s up to date\n", ref->name); From 09ae9aca14750f00c9e25fd16cdf60819fb410a8 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:28 +0800 Subject: [PATCH 4/7] http-walker: cleanup more thoroughly Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- http-walker.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/http-walker.c b/http-walker.c index 700bc1311..508e35517 100644 --- a/http-walker.c +++ b/http-walker.c @@ -543,6 +543,23 @@ static int fetch_ref(struct walker *walker, struct ref *ref) static void cleanup(struct walker *walker) { + struct walker_data *data = walker->data; + struct alt_base *alt, *alt_next; + + if (data) { + alt = data->alt; + while (alt) { + alt_next = alt->next; + + free(alt->base); + free(alt); + + alt = alt_next; + } + free(data); + walker->data = NULL; + } + http_cleanup(); } From 888692b733b3109874bb570bb0680e93287ed338 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:29 +0800 Subject: [PATCH 5/7] http: init and cleanup separately from http-walker Previously, all our http operations were done with http-walker. With the new remote-curl helper, we find ourselves using http methods outside of http-walker - for example, fetching info/refs. Accomodate this by separating http_init() and http_cleanup() invocations from http-walker. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- http-fetch.c | 5 ++++- http-walker.c | 6 +----- remote-curl.c | 7 ++++++- walker.h | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/http-fetch.c b/http-fetch.c index ffd0ad7e2..762c750d7 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1,5 +1,6 @@ #include "cache.h" #include "exec_cmd.h" +#include "http.h" #include "walker.h" static const char http_fetch_usage[] = "git http-fetch " @@ -69,7 +70,8 @@ int main(int argc, const char **argv) url = rewritten_url; } - walker = get_http_walker(url, NULL); + http_init(NULL); + walker = get_http_walker(url); walker->get_tree = get_tree; walker->get_history = get_history; walker->get_all = get_all; @@ -89,6 +91,7 @@ int main(int argc, const char **argv) } walker_free(walker); + http_cleanup(); free(rewritten_url); diff --git a/http-walker.c b/http-walker.c index 508e35517..ef99ae647 100644 --- a/http-walker.c +++ b/http-walker.c @@ -559,18 +559,14 @@ static void cleanup(struct walker *walker) free(data); walker->data = NULL; } - - http_cleanup(); } -struct walker *get_http_walker(const char *url, struct remote *remote) +struct walker *get_http_walker(const char *url) { char *s; struct walker_data *data = xmalloc(sizeof(struct walker_data)); struct walker *walker = xmalloc(sizeof(struct walker)); - http_init(remote); - data->alt = xmalloc(sizeof(*data->alt)); data->alt->base = xmalloc(strlen(url) + 1); strcpy(data->alt->base, url); diff --git a/remote-curl.c b/remote-curl.c index a904164e4..e8485d155 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -25,7 +25,7 @@ static struct options options; static void init_walker(void) { if (!walker) - walker = get_http_walker(url, remote); + walker = get_http_walker(url); } static int set_option(const char *name, const char *value) @@ -810,6 +810,8 @@ int main(int argc, const char **argv) url = remote->url[0]; } + http_init(remote); + do { if (strbuf_getline(&buf, stdin, '\n') == EOF) break; @@ -855,5 +857,8 @@ int main(int argc, const char **argv) } strbuf_reset(&buf); } while (1); + + http_cleanup(); + return 0; } diff --git a/walker.h b/walker.h index 8a149e110..95e576548 100644 --- a/walker.h +++ b/walker.h @@ -34,6 +34,6 @@ int walker_fetch(struct walker *impl, int targets, char **target, void walker_free(struct walker *walker); -struct walker *get_http_walker(const char *url, struct remote *remote); +struct walker *get_http_walker(const char *url); #endif /* WALKER_H */ From aec49756020d20bd073e4daeaa5d7b4fed1fe300 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:30 +0800 Subject: [PATCH 6/7] remote-curl: use http_fetch_ref() instead of walker wrapper The http-walker implementation of walker->fetch_ref() doesn't do anything special compared to http_fetch_ref() anyway. Remove init_walker() invocation before fetching the ref, since we aren't using the walker wrapper and don't need a walker instance anymore. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- remote-curl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index e8485d155..aa9f27901 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -249,9 +249,8 @@ static struct ref *parse_info_refs(struct discovery *heads) i++; } - init_walker(); ref = alloc_ref("HEAD"); - if (!walker->fetch_ref(walker, ref) && + if (!http_fetch_ref(url, ref) && !resolve_remote_symref(ref, refs)) { ref->next = refs; refs = ref; From 26e1e0b23a1d145f9fee699538c11bbbb996d558 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:31 +0800 Subject: [PATCH 7/7] remote-curl: init walker only when needed Invoke get_http_walker() only when fetching with the dumb protocol. Additionally, add an invocation to walker_free() after we're done using the walker. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- remote-curl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index aa9f27901..1f8bc2db7 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -10,7 +10,6 @@ static struct remote *remote; static const char *url; -static struct walker *walker; struct options { int verbosity; @@ -22,12 +21,6 @@ struct options { }; static struct options options; -static void init_walker(void) -{ - if (!walker) - walker = get_http_walker(url); -} - static int set_option(const char *name, const char *value) { if (!strcmp(name, "verbosity")) { @@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service) } refs_url = strbuf_detach(&buffer, NULL); - init_walker(); http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); /* try again with "plain" url (no ? or & appended) */ @@ -500,7 +492,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads) struct child_process client; int err = 0; - init_walker(); memset(&client, 0, sizeof(client)); client.in = -1; client.out = -1; @@ -552,6 +543,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads) static int fetch_dumb(int nr_heads, struct ref **to_fetch) { + struct walker *walker; char **targets = xmalloc(nr_heads * sizeof(char*)); int ret, i; @@ -560,13 +552,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch) for (i = 0; i < nr_heads; i++) targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1)); - init_walker(); + walker = get_http_walker(url); walker->get_all = 1; walker->get_tree = 1; walker->get_history = 1; walker->get_verbosely = options.verbosity >= 3; walker->get_recover = 0; ret = walker_fetch(walker, nr_heads, targets, NULL, NULL); + walker_free(walker); for (i = 0; i < nr_heads; i++) free(targets[i]);