提交 05c1eb10 编写于 作者: J Junio C Hamano

push: teach --force-with-lease to smart-http transport

We have been passing enough information to enable the
compare-and-swap logic down to the transport layer, but the
transport helper was not passing it to smart-http transport.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 77aa9348
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "exec_cmd.h" #include "exec_cmd.h"
#include "run-command.h" #include "run-command.h"
#include "pkt-line.h" #include "pkt-line.h"
#include "string-list.h"
#include "sideband.h" #include "sideband.h"
static struct remote *remote; static struct remote *remote;
...@@ -20,6 +21,7 @@ struct options { ...@@ -20,6 +21,7 @@ struct options {
thin : 1; thin : 1;
}; };
static struct options options; static struct options options;
static struct string_list cas_options = STRING_LIST_INIT_DUP;
static int set_option(const char *name, const char *value) static int set_option(const char *name, const char *value)
{ {
...@@ -66,6 +68,13 @@ static int set_option(const char *name, const char *value) ...@@ -66,6 +68,13 @@ static int set_option(const char *name, const char *value)
return -1; return -1;
return 0; return 0;
} }
else if (!strcmp(name, "cas")) {
struct strbuf val = STRBUF_INIT;
strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value);
string_list_append(&cas_options, val.buf);
strbuf_release(&val);
return 0;
}
else { else {
return 1 /* unsupported */; return 1 /* unsupported */;
} }
...@@ -789,8 +798,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs) ...@@ -789,8 +798,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
struct rpc_state rpc; struct rpc_state rpc;
const char **argv; const char **argv;
int argc = 0, i, err; int argc = 0, i, err;
struct string_list_item *cas_option;
argv = xmalloc((10 + nr_spec) * sizeof(char*)); argv = xmalloc((10 + nr_spec + cas_options.nr) * sizeof(char *));
argv[argc++] = "send-pack"; argv[argc++] = "send-pack";
argv[argc++] = "--stateless-rpc"; argv[argc++] = "--stateless-rpc";
argv[argc++] = "--helper-status"; argv[argc++] = "--helper-status";
...@@ -803,6 +813,10 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs) ...@@ -803,6 +813,10 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
else if (options.verbosity > 1) else if (options.verbosity > 1)
argv[argc++] = "--verbose"; argv[argc++] = "--verbose";
argv[argc++] = options.progress ? "--progress" : "--no-progress"; argv[argc++] = options.progress ? "--progress" : "--no-progress";
for_each_string_list_item(cas_option, &cas_options)
argv[argc++] = cas_option->string;
argv[argc++] = url; argv[argc++] = url;
for (i = 0; i < nr_spec; i++) for (i = 0; i < nr_spec; i++)
argv[argc++] = specs[i]; argv[argc++] = specs[i];
......
...@@ -141,10 +141,11 @@ stop_httpd() { ...@@ -141,10 +141,11 @@ stop_httpd() {
-f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
} }
test_http_push_nonff() { test_http_push_nonff () {
REMOTE_REPO=$1 REMOTE_REPO=$1
LOCAL_REPO=$2 LOCAL_REPO=$2
BRANCH=$3 BRANCH=$3
EXPECT_CAS_RESULT=${4-failure}
test_expect_success 'non-fast-forward push fails' ' test_expect_success 'non-fast-forward push fails' '
cd "$REMOTE_REPO" && cd "$REMOTE_REPO" &&
......
...@@ -153,7 +153,7 @@ test_expect_success 'used receive-pack service' ' ...@@ -153,7 +153,7 @@ test_expect_success 'used receive-pack service' '
' '
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
"$ROOT_PATH"/test_repo_clone master "$ROOT_PATH"/test_repo_clone master success
test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' ' 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 # create a dissimilarly-named remote ref so that git is unable to match the
......
...@@ -742,13 +742,15 @@ static void push_update_refs_status(struct helper_data *data, ...@@ -742,13 +742,15 @@ static void push_update_refs_status(struct helper_data *data,
} }
static int push_refs_with_push(struct transport *transport, static int push_refs_with_push(struct transport *transport,
struct ref *remote_refs, int flags) struct ref *remote_refs, int flags)
{ {
int force_all = flags & TRANSPORT_PUSH_FORCE; int force_all = flags & TRANSPORT_PUSH_FORCE;
int mirror = flags & TRANSPORT_PUSH_MIRROR; int mirror = flags & TRANSPORT_PUSH_MIRROR;
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct ref *ref; struct ref *ref;
struct string_list cas_options = STRING_LIST_INIT_DUP;
struct string_list_item *cas_option;
get_helper(transport); get_helper(transport);
if (!data->push) if (!data->push)
...@@ -784,11 +786,29 @@ static int push_refs_with_push(struct transport *transport, ...@@ -784,11 +786,29 @@ static int push_refs_with_push(struct transport *transport,
strbuf_addch(&buf, ':'); strbuf_addch(&buf, ':');
strbuf_addstr(&buf, ref->name); strbuf_addstr(&buf, ref->name);
strbuf_addch(&buf, '\n'); strbuf_addch(&buf, '\n');
/*
* The "--force-with-lease" options without explicit
* values to expect have already been expanded into
* the ref->old_sha1_expect[] field; we can ignore
* transport->smart_options->cas altogether and instead
* can enumerate them from the refs.
*/
if (ref->expect_old_sha1) {
struct strbuf cas = STRBUF_INIT;
strbuf_addf(&cas, "%s:%s",
ref->name, sha1_to_hex(ref->old_sha1_expect));
string_list_append(&cas_options, strbuf_detach(&cas, NULL));
}
} }
if (buf.len == 0) if (buf.len == 0) {
string_list_clear(&cas_options, 0);
return 0; return 0;
}
standard_options(transport); standard_options(transport);
for_each_string_list_item(cas_option, &cas_options)
set_helper_option(transport, "cas", cas_option->string);
if (flags & TRANSPORT_PUSH_DRY_RUN) { if (flags & TRANSPORT_PUSH_DRY_RUN) {
if (set_helper_option(transport, "dry-run", "true") != 0) if (set_helper_option(transport, "dry-run", "true") != 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册