Skip to content

Commit 711b276

Browse files
committed
Merge branch 'nd/clone-connectivity-shortcut'
* nd/clone-connectivity-shortcut: smart http: use the same connectivity check on cloning
2 parents 01a2a03 + 9ba3804 commit 711b276

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
@@ -16,6 +16,7 @@ struct options {
1616
int verbosity;
1717
unsigned long depth;
1818
unsigned progress : 1,
19+
check_self_contained_and_connected : 1,
1920
followtags : 1,
2021
dry_run : 1,
2122
thin : 1;
@@ -67,6 +68,15 @@ static int set_option(const char *name, const char *value)
6768
return -1;
6869
return 0;
6970
}
71+
else if (!strcmp(name, "check-connectivity")) {
72+
if (!strcmp(value, "true"))
73+
options.check_self_contained_and_connected = 1;
74+
else if (!strcmp(value, "false"))
75+
options.check_self_contained_and_connected = 0;
76+
else
77+
return -1;
78+
return 0;
79+
}
7080
else {
7181
return 1 /* unsupported */;
7282
}
@@ -654,7 +664,7 @@ static int fetch_git(struct discovery *heads,
654664
struct strbuf preamble = STRBUF_INIT;
655665
char *depth_arg = NULL;
656666
int argc = 0, i, err;
657-
const char *argv[15];
667+
const char *argv[16];
658668

659669
argv[argc++] = "fetch-pack";
660670
argv[argc++] = "--stateless-rpc";
@@ -668,6 +678,8 @@ static int fetch_git(struct discovery *heads,
668678
argv[argc++] = "-v";
669679
argv[argc++] = "-v";
670680
}
681+
if (options.check_self_contained_and_connected)
682+
argv[argc++] = "--check-self-contained-and-connected";
671683
if (!options.progress)
672684
argv[argc++] = "--no-progress";
673685
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
@@ -27,6 +27,7 @@ struct helper_data {
2727
push : 1,
2828
connect : 1,
2929
signed_tags : 1,
30+
check_connectivity : 1,
3031
no_disconnect_req : 1;
3132
char *export_marks;
3233
char *import_marks;
@@ -186,6 +187,8 @@ static struct child_process *get_helper(struct transport *transport)
186187
data->bidi_import = 1;
187188
else if (!strcmp(capname, "export"))
188189
data->export = 1;
190+
else if (!strcmp(capname, "check-connectivity"))
191+
data->check_connectivity = 1;
189192
else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
190193
ALLOC_GROW(refspecs,
191194
refspec_nr + 1,
@@ -349,6 +352,9 @@ static int fetch_with_fetch(struct transport *transport,
349352
struct strbuf buf = STRBUF_INIT;
350353

351354
standard_options(transport);
355+
if (data->check_connectivity &&
356+
data->transport_options.check_self_contained_and_connected)
357+
set_helper_option(transport, "check-connectivity", "true");
352358

353359
for (i = 0; i < nr_heads; i++) {
354360
const struct ref *posn = to_fetch[i];
@@ -372,6 +378,10 @@ static int fetch_with_fetch(struct transport *transport,
372378
else
373379
transport->pack_lockfile = xstrdup(name);
374380
}
381+
else if (data->check_connectivity &&
382+
data->transport_options.check_self_contained_and_connected &&
383+
!strcmp(buf.buf, "connectivity-ok"))
384+
data->transport_options.self_contained_and_connected = 1;
375385
else if (!buf.len)
376386
break;
377387
else

0 commit comments

Comments
 (0)