mirror of
https://github.com/git/git.git
synced 2024-11-18 19:13:58 +01:00
Merge branch 'tc/http-cleanup'
* tc/http-cleanup: remote-curl: init walker only when needed remote-curl: use http_fetch_ref() instead of walker wrapper http: init and cleanup separately from http-walker http-walker: cleanup more thoroughly http-push: remove "|| 1" to enable verbose check t554[01]-http-push: refactor, add non-ff tests t5541-http-push: check that ref is unchanged for non-ff test
This commit is contained in:
commit
78d909a494
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -543,17 +543,30 @@ static int fetch_ref(struct walker *walker, struct ref *ref)
|
||||
|
||||
static void cleanup(struct walker *walker)
|
||||
{
|
||||
http_cleanup();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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, remote);
|
||||
}
|
||||
|
||||
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) */
|
||||
@ -250,9 +242,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;
|
||||
@ -502,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;
|
||||
@ -554,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;
|
||||
|
||||
@ -562,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]);
|
||||
@ -811,6 +803,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 +850,8 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
strbuf_reset(&buf);
|
||||
} while (1);
|
||||
|
||||
http_cleanup();
|
||||
|
||||
return 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
|
||||
'
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -88,26 +88,8 @@ test_expect_success 'used receive-pack service' '
|
||||
test_cmp exp act
|
||||
'
|
||||
|
||||
test_expect_success 'non-fast-forward push fails' '
|
||||
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_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
|
||||
|
2
walker.h
2
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user