smart http: use the same connectivity check on cloning
This is an extension of c6807a4 (clone: open a shortcut for connectivity check - 2013-05-26) to reduce the cost of connectivity check at clone time, this time with smart http protocol. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jul 21, 2013 at 15:18 UTC
9ba380481cc3a5ae7706763d71cf8844917ed804
5 files changed
+47
-1
Documentation/git-fetch-pack.txt
+4
@@ -90,6 +90,10 @@ be in a separate packet, and the list must end with a flush packet.
90
--no-progress::
91
Do not show the progress.
92
93
+--check-self-contained-and-connected::
94
+ Output "connectivity-ok" if the received pack is
95
+ self-contained and connected.
96
+
97
-v::
98
Run verbosely.
99
Documentation/gitremote-helpers.txt
+10
@@ -143,6 +143,10 @@ Supported commands: 'list', 'fetch'.
143
+
144
Supported commands: 'list', 'import'.
145
146
+'check-connectivity'::
147
+ Can guarantee that when a clone is requested, the received
148
+ pack is self contained and is connected.
149
+
150
If a helper advertises 'connect', Git will use it if possible and
151
fall back to another capability if the helper requests so when
152
connecting (see the 'connect' command under COMMANDS).
@@ -270,6 +274,9 @@ Optionally may output a 'lock <file>' line indicating a file under
274
GIT_DIR/objects/pack which is keeping a pack until refs can be
275
suitably updated.
276
+
277
+If option 'check-connectivity' is requested, the helper must output
278
+'connectivity-ok' if the clone is self-contained and connected.
279
++
280
Supported if the helper has the "fetch" capability.
281
282
'push' +<src>:<dst>::
@@ -416,6 +423,9 @@ set by Git if the remote helper has the 'option' capability.
423
must not rely on this option being set before
424
connect request occurs.
425
426
+'option check-connectivity' \{'true'|'false'\}::
427
+ Request the helper to check connectivity of a clone.
428
+
429
SEE ALSO
430
--------
431
linkgit:git-remote[1]
builtin/fetch-pack.c
+9
@@ -100,6 +100,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
100
pack_lockfile_ptr = &pack_lockfile;
101
continue;
102
}
103
+ if (!strcmp("--check-self-contained-and-connected", arg)) {
104
+ args.check_self_contained_and_connected = 1;
105
+ continue;
106
+ }
107
usage(fetch_pack_usage);
108
}
109
@@ -152,6 +156,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
156
printf("lock %s\n", pack_lockfile);
157
fflush(stdout);
158
}
159
+ if (args.check_self_contained_and_connected &&
160
+ args.self_contained_and_connected) {
161
+ printf("connectivity-ok\n");
162
+ fflush(stdout);
163
+ }
164
close(fd[0]);
165
close(fd[1]);
166
if (finish_connect(conn))
remote-curl.c
+14
-1
@@ -15,6 +15,7 @@ struct options {
15
int verbosity;
16
unsigned long depth;
17
unsigned progress : 1,
18
+ check_self_contained_and_connected : 1,
19
followtags : 1,
20
dry_run : 1,
21
thin : 1;
@@ -66,6 +67,15 @@ static int set_option(const char *name, const char *value)
67
return -1;
68
return 0;
69
}
70
+ else if (!strcmp(name, "check-connectivity")) {
71
+ if (!strcmp(value, "true"))
72
+ options.check_self_contained_and_connected = 1;
73
+ else if (!strcmp(value, "false"))
74
+ options.check_self_contained_and_connected = 0;
75
+ else
76
+ return -1;
77
+ return 0;
78
+ }
79
else {
80
return 1 /* unsupported */;
81
}
@@ -653,7 +663,7 @@ static int fetch_git(struct discovery *heads,
663
struct strbuf preamble = STRBUF_INIT;
664
char *depth_arg = NULL;
665
int argc = 0, i, err;
656
- const char *argv[15];
666
+ const char *argv[16];
667
668
argv[argc++] = "fetch-pack";
669
argv[argc++] = "--stateless-rpc";
@@ -667,6 +677,8 @@ static int fetch_git(struct discovery *heads,
677
argv[argc++] = "-v";
678
argv[argc++] = "-v";
679
}
680
+ if (options.check_self_contained_and_connected)
681
+ argv[argc++] = "--check-self-contained-and-connected";
682
if (!options.progress)
683
argv[argc++] = "--no-progress";
684
if (options.depth) {
@@ -939,6 +951,7 @@ int main(int argc, const char **argv)
951
printf("fetch\n");
952
printf("option\n");
953
printf("push\n");
954
+ printf("check-connectivity\n");
955
printf("\n");
956
fflush(stdout);
957
} else {
transport-helper.c
+10
@@ -26,6 +26,7 @@ struct helper_data {
26
push : 1,
27
connect : 1,
28
signed_tags : 1,
29
+ check_connectivity : 1,
30
no_disconnect_req : 1;
31
char *export_marks;
32
char *import_marks;
@@ -185,6 +186,8 @@ static struct child_process *get_helper(struct transport *transport)
186
data->bidi_import = 1;
187
else if (!strcmp(capname, "export"))
188
data->export = 1;
189
+ else if (!strcmp(capname, "check-connectivity"))
190
+ data->check_connectivity = 1;
191
else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
192
ALLOC_GROW(refspecs,
193
refspec_nr + 1,
@@ -346,6 +349,9 @@ static int fetch_with_fetch(struct transport *transport,
349
struct strbuf buf = STRBUF_INIT;
350
351
standard_options(transport);
352
+ if (data->check_connectivity &&
353
+ data->transport_options.check_self_contained_and_connected)
354
+ set_helper_option(transport, "check-connectivity", "true");
355
356
for (i = 0; i < nr_heads; i++) {
357
const struct ref *posn = to_fetch[i];
@@ -369,6 +375,10 @@ static int fetch_with_fetch(struct transport *transport,
375
else
376
transport->pack_lockfile = xstrdup(name);
377
}
378
+ else if (data->check_connectivity &&
379
+ data->transport_options.check_self_contained_and_connected &&
380
+ !strcmp(buf.buf, "connectivity-ok"))
381
+ data->transport_options.self_contained_and_connected = 1;
382
else if (!buf.len)
383
break;
384
else