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: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 2, 2013 at 15:14 UTC
05c1eb10348f159908becc7a6ed6bbcdab24c893
4 files changed
+40
-5
remote-curl.c
+15
-1
@@ -6,6 +6,7 @@
6
#include "exec_cmd.h"
7
#include "run-command.h"
8
#include "pkt-line.h"
9
+#include "string-list.h"
10
#include "sideband.h"
11
12
static struct remote *remote;
@@ -20,6 +21,7 @@ struct options {
21
thin : 1;
22
};
23
static struct options options;
24
+static struct string_list cas_options = STRING_LIST_INIT_DUP;
25
26
static int set_option(const char *name, const char *value)
27
{
@@ -66,6 +68,13 @@ static int set_option(const char *name, const char *value)
68
return -1;
69
return 0;
70
}
71
+ else if (!strcmp(name, "cas")) {
72
+ struct strbuf val = STRBUF_INIT;
73
+ strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value);
74
+ string_list_append(&cas_options, val.buf);
75
+ strbuf_release(&val);
76
+ return 0;
77
+ }
78
else {
79
return 1 /* unsupported */;
80
}
@@ -789,8 +798,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
798
struct rpc_state rpc;
799
const char **argv;
800
int argc = 0, i, err;
801
+ struct string_list_item *cas_option;
802
793
- argv = xmalloc((10 + nr_spec) * sizeof(char*));
803
+ argv = xmalloc((10 + nr_spec + cas_options.nr) * sizeof(char *));
804
argv[argc++] = "send-pack";
805
argv[argc++] = "--stateless-rpc";
806
argv[argc++] = "--helper-status";
@@ -803,6 +813,10 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
813
else if (options.verbosity > 1)
814
argv[argc++] = "--verbose";
815
argv[argc++] = options.progress ? "--progress" : "--no-progress";
816
+
817
+ for_each_string_list_item(cas_option, &cas_options)
818
+ argv[argc++] = cas_option->string;
819
+
820
argv[argc++] = url;
821
for (i = 0; i < nr_spec; i++)
822
argv[argc++] = specs[i];
t/lib-httpd.sh
+2
-1
@@ -141,10 +141,11 @@ stop_httpd() {
141
-f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
142
}
143
144
-test_http_push_nonff() {
144
+test_http_push_nonff () {
145
REMOTE_REPO=$1
146
LOCAL_REPO=$2
147
BRANCH=$3
148
+ EXPECT_CAS_RESULT=${4-failure}
149
150
test_expect_success 'non-fast-forward push fails' '
151
cd "$REMOTE_REPO" &&
t/t5541-http-push.sh
+1
-1
@@ -153,7 +153,7 @@ test_expect_success 'used receive-pack service' '
153
'
154
155
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
156
- "$ROOT_PATH"/test_repo_clone master
156
+ "$ROOT_PATH"/test_repo_clone master success
157
158
test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
159
# create a dissimilarly-named remote ref so that git is unable to match the
transport-helper.c
+22
-2
@@ -742,13 +742,15 @@ static void push_update_refs_status(struct helper_data *data,
742
}
743
744
static int push_refs_with_push(struct transport *transport,
745
- struct ref *remote_refs, int flags)
745
+ struct ref *remote_refs, int flags)
746
{
747
int force_all = flags & TRANSPORT_PUSH_FORCE;
748
int mirror = flags & TRANSPORT_PUSH_MIRROR;
749
struct helper_data *data = transport->data;
750
struct strbuf buf = STRBUF_INIT;
751
struct ref *ref;
752
+ struct string_list cas_options = STRING_LIST_INIT_DUP;
753
+ struct string_list_item *cas_option;
754
755
get_helper(transport);
756
if (!data->push)
@@ -784,11 +786,29 @@ static int push_refs_with_push(struct transport *transport,
786
strbuf_addch(&buf, ':');
787
strbuf_addstr(&buf, ref->name);
788
strbuf_addch(&buf, '\n');
789
+
790
+ /*
791
+ * The "--force-with-lease" options without explicit
792
+ * values to expect have already been expanded into
793
+ * the ref->old_sha1_expect[] field; we can ignore
794
+ * transport->smart_options->cas altogether and instead
795
+ * can enumerate them from the refs.
796
+ */
797
+ if (ref->expect_old_sha1) {
798
+ struct strbuf cas = STRBUF_INIT;
799
+ strbuf_addf(&cas, "%s:%s",
800
+ ref->name, sha1_to_hex(ref->old_sha1_expect));
801
+ string_list_append(&cas_options, strbuf_detach(&cas, NULL));
802
+ }
803
}
788
- if (buf.len == 0)
804
+ if (buf.len == 0) {
805
+ string_list_clear(&cas_options, 0);
806
return 0;
807
+ }
808
809
standard_options(transport);
810
+ for_each_string_list_item(cas_option, &cas_options)
811
+ set_helper_option(transport, "cas", cas_option->string);
812
813
if (flags & TRANSPORT_PUSH_DRY_RUN) {
814
if (set_helper_option(transport, "dry-run", "true") != 0)