http: minor improvements
v2 cover http: minor improvements
This patch series was generated on top of 'next'. It contains some general changes to http usage.
Some highlights:
- add non-ff test cases to "dumb" http push test
- separate init and cleanup of http from http-walker
Changes from v1 (based on comments from Clemens):
- patch 3: don't say "remove condition", since we're actually enabling
it.
- patch 5: in keeping with separating http and http-walker, removed
http_cleanup() from http-walker->cleanup(). - patch 5: move http_cleanup() call after http-walker->cleanup(). This isn't really needed, but do this just in case http-walker->cleanup() does any http operations.
Contents:
[PATCH v2 1/7] t5541-http-push: check that ref is unchanged for non-ff test [PATCH v2 2/7] t554[01]-http-push: refactor, add non-ff tests [PATCH v2 3/7] http-push: remove "|| 1" to enable verbose check [PATCH v2 4/7] http-walker: cleanup more thoroughly
[PATCH v2 5/7] http: init and cleanup separately from http-walker [PATCH v2 6/7] remote-curl: use http_fetch_ref() instead of walker wrapper [PATCH v2 7/7] remote-curl: init walker only when needed
http-fetch.c | 5 ++++- http-push.c | 2 +- http-walker.c | 21 +++++++++++++++++---- remote-curl.c | 21 +++++++++------------ t/lib-httpd.sh | 29 +++++++++++++++++++++++++++++ t/t5540-http-push.sh | 3 +++ t/t5541-http-push.sh | 22 ++-------------------- walker.h | 2 +- 8 files changed, 66 insertions(+), 39 deletions(-)
--
Cheers,
Ray Chuan
PATCH v2 1/7 t5541-http-push: check that ref is unchanged for non-ff test
--- t/t5541-http-push.sh | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
t/t5541-http-push.sh +4 -2
@@ -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' '
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 2/7 t554[01]-http-push: refactor, add non-ff tests
In reply to Tay Ray ChuanMove non-fast forward tests to lib-httpd.sh so that we don't have to duplicate the tests in both t5540 and t5541.
--- t/lib-httpd.sh | 29 +++++++++++++++++++++++++++++ t/t5540-http-push.sh | 3 +++ t/t5541-http-push.sh | 24 ++---------------------- 3 files changed, 34 insertions(+), 22 deletions(-)
t/lib-httpd.sh +29 -0
@@ -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 + ' +}
t/t5540-http-push.sh +3 -0
@@ -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
t/t5541-http-push.sh +2 -22
@@ -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
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 3/7 http-push: remove "|| 1" to enable verbose check
In reply to Tay Ray Chuan--- http-push.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
http-push.c +1 -1
@@ -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);
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 4/7 http-walker: cleanup more thoroughly
In reply to Tay Ray Chuan--- http-walker.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
http-walker.c +17 -0
@@ -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 (); }
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 5/7 http: init and cleanup separately from http-walker
In reply to Tay Ray ChuanPreviously, 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.
--- http-fetch.c | 5 ++++- http-walker.c | 6 +----- remote-curl.c | 7 ++++++- walker.h | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-)
http-fetch.c +4 -1
@@ -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);
http-walker.c +1 -5
@@ -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);
remote-curl.c +6 -1
@@ -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)
@@ -811,6 +811,8 @@ int main(int argc, const char **argv) url = remote->url[0 ]; } +http_init (remote); + do { if (strbuf_getline(&buf, stdin, '\n') == EOF) break;
@@ -856,5 +858,8 @@ int main(int argc, const char **argv) }strbuf_reset (&buf); }while (1 ); + +http_cleanup (); +return 0 ; }
walker.h +1 -1
@@ -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 */
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 6/7 remote-curl: use http_fetch_ref() instead of walker wrapper
In reply to Tay Ray ChuanThe 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.
--- remote-curl.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
remote-curl.c +1 -2
@@ -250,9 +250,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;
Signature · 1 line
1.7.0.26.gbfa16
PATCH v2 7/7 remote-curl: init walker only when needed
In reply to Tay Ray ChuanInvoke get_http_walker() only when fetching with the dumb protocol. Additionally, add an invocation to walker_free() after we're done using the walker.
--- remote-curl.c | 13 +++---------- 1 files changed, 3 insertions(+), 10 deletions(-)
remote-curl.c +3 -10
@@ -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) */
@@ -501,7 +493,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 ;
@@ -553,6 +544,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;
@@ -561,13 +553,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]);
Signature · 1 line
1.7.0.26.gbfa16
Quoted 8 lines · Tay Ray Chuan
Changes from v1 (based on comments from Clemens):
- patch 3: don't say "remove condition", since we're actually enablingit. - patch 5: in keeping with separating http and http-walker, removed http_cleanup() from http-walker->cleanup().- patch 5: move
http_cleanup()call after http-walker->cleanup(). This isn't really needed, but do this just in case http-walker->cleanup() does any http operations.
Thanks.
Quoted 7 lines
[PATCH v2 1/7] t5541-http-push: check that ref is unchanged for non-ff test [PATCH v2 2/7] t554[01]-http-push: refactor, add non-ff tests [PATCH v2 3/7] http-push: remove "|| 1" to enable verbose check [PATCH v2 4/7] http-walker: cleanup more thoroughly
[PATCH v2 5/7] http: init and cleanup separately from http-walker [PATCH v2 6/7] remote-curl: usehttp_fetch_ref()instead of walker wrapper [PATCH v2 7/7] remote-curl: init walker only when needed