Skip to content

Commit 9ba3804

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent c6807a4 commit 9ba3804

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

Documentation/git-fetch-pack.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ be in a separate packet, and the list must end with a flush packet.
9090
--no-progress::
9191
Do not show the progress.
9292

93+
--check-self-contained-and-connected::
94+
Output "connectivity-ok" if the received pack is
95+
self-contained and connected.
96+
9397
-v::
9498
Run verbosely.
9599

Documentation/gitremote-helpers.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Supported commands: 'list', 'fetch'.
143143
+
144144
Supported commands: 'list', 'import'.
145145

146+
'check-connectivity'::
147+
Can guarantee that when a clone is requested, the received
148+
pack is self contained and is connected.
149+
146150
If a helper advertises 'connect', Git will use it if possible and
147151
fall back to another capability if the helper requests so when
148152
connecting (see the 'connect' command under COMMANDS).
@@ -270,6 +274,9 @@ Optionally may output a 'lock <file>' line indicating a file under
270274
GIT_DIR/objects/pack which is keeping a pack until refs can be
271275
suitably updated.
272276
+
277+
If option 'check-connectivity' is requested, the helper must output
278+
'connectivity-ok' if the clone is self-contained and connected.
279+
+
273280
Supported if the helper has the "fetch" capability.
274281

275282
'push' +<src>:<dst>::
@@ -416,6 +423,9 @@ set by Git if the remote helper has the 'option' capability.
416423
must not rely on this option being set before
417424
connect request occurs.
418425

426+
'option check-connectivity' \{'true'|'false'\}::
427+
Request the helper to check connectivity of a clone.
428+
419429
SEE ALSO
420430
--------
421431
linkgit:git-remote[1]

builtin/fetch-pack.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
100100
pack_lockfile_ptr = &pack_lockfile;
101101
continue;
102102
}
103+
if (!strcmp("--check-self-contained-and-connected", arg)) {
104+
args.check_self_contained_and_connected = 1;
105+
continue;
106+
}
103107
usage(fetch_pack_usage);
104108
}
105109

@@ -152,6 +156,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
152156
printf("lock %s\n", pack_lockfile);
153157
fflush(stdout);
154158
}
159+
if (args.check_self_contained_and_connected &&
160+
args.self_contained_and_connected) {
161+
printf("connectivity-ok\n");
162+
fflush(stdout);
163+
}
155164
close(fd[0]);
156165
close(fd[1]);
157166
if (finish_connect(conn))

remote-curl.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct options {
1515
int verbosity;
1616
unsigned long depth;
1717
unsigned progress : 1,
18+
check_self_contained_and_connected : 1,
1819
followtags : 1,
1920
dry_run : 1,
2021
thin : 1;
@@ -66,6 +67,15 @@ static int set_option(const char *name, const char *value)
6667
return -1;
6768
return 0;
6869
}
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+
}
6979
else {
7080
return 1 /* unsupported */;
7181
}
@@ -653,7 +663,7 @@ static int fetch_git(struct discovery *heads,
653663
struct strbuf preamble = STRBUF_INIT;
654664
char *depth_arg = NULL;
655665
int argc = 0, i, err;
656-
const char *argv[15];
666+
const char *argv[16];
657667

658668
argv[argc++] = "fetch-pack";
659669
argv[argc++] = "--stateless-rpc";
@@ -667,6 +677,8 @@ static int fetch_git(struct discovery *heads,
667677
argv[argc++] = "-v";
668678
argv[argc++] = "-v";
669679
}
680+
if (options.check_self_contained_and_connected)
681+
argv[argc++] = "--check-self-contained-and-connected";
670682
if (!options.progress)
671683
argv[argc++] = "--no-progress";
672684
if (options.depth) {
@@ -939,6 +951,7 @@ int main(int argc, const char **argv)
939951
printf("fetch\n");
940952
printf("option\n");
941953
printf("push\n");
954+
printf("check-connectivity\n");
942955
printf("\n");
943956
fflush(stdout);
944957
} else {

transport-helper.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct helper_data {
2626
push : 1,
2727
connect : 1,
2828
signed_tags : 1,
29+
check_connectivity : 1,
2930
no_disconnect_req : 1;
3031
char *export_marks;
3132
char *import_marks;
@@ -185,6 +186,8 @@ static struct child_process *get_helper(struct transport *transport)
185186
data->bidi_import = 1;
186187
else if (!strcmp(capname, "export"))
187188
data->export = 1;
189+
else if (!strcmp(capname, "check-connectivity"))
190+
data->check_connectivity = 1;
188191
else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
189192
ALLOC_GROW(refspecs,
190193
refspec_nr + 1,
@@ -346,6 +349,9 @@ static int fetch_with_fetch(struct transport *transport,
346349
struct strbuf buf = STRBUF_INIT;
347350

348351
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");
349355

350356
for (i = 0; i < nr_heads; i++) {
351357
const struct ref *posn = to_fetch[i];
@@ -369,6 +375,10 @@ static int fetch_with_fetch(struct transport *transport,
369375
else
370376
transport->pack_lockfile = xstrdup(name);
371377
}
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;
372382
else if (!buf.len)
373383
break;
374384
else

0 commit comments

Comments
 (0)