{"thread":{"id":"34503","subject":"[PATCH] Let index-pack help with connectivity check on cloning via smart http","startedAt":"2013-07-21T08:18:05Z","lastAt":"2013-07-21T08:18:05Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"223866","messageId":"1374394685-16589-1-git-send-email-pclouds@gmail.com","threadId":"34503","inReplyTo":null,"subject":"[PATCH] Let index-pack help with connectivity check on cloning via smart http","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-07-21T08:18:05Z","receivedAt":"2013-07-21T08:18:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is an extension of c6807a4 (clone: open a shortcut for\nconnectivity check - 2013-05-26) to reduce the cost of connectivity\ncheck at clone time, this time with smart http protocol.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/git-fetch-pack.txt    |  4 ++++\n Documentation/gitremote-helpers.txt | 10 ++++++++++\n builtin/fetch-pack.c                |  9 +++++++++\n remote-curl.c                       | 15 ++++++++++++++-\n transport-helper.c                  | 10 ++++++++++\n 5 files changed, 47 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt\nindex 1e71754..444b805 100644\n--- a/Documentation/git-fetch-pack.txt\n+++ b/Documentation/git-fetch-pack.txt\n@@ -90,6 +90,10 @@ be in a separate packet, and the list must end with a flush packet.\n --no-progress::\n \tDo not show the progress.\n \n+--check-self-contained-and-connected::\n+\tOutput \"connectivity-ok\" if the received pack is\n+\tself-contained and connected.\n+\n -v::\n \tRun verbosely.\n \ndiff --git a/Documentation/gitremote-helpers.txt b/Documentation/gitremote-helpers.txt\nindex 0827f69..bc069c2 100644\n--- a/Documentation/gitremote-helpers.txt\n+++ b/Documentation/gitremote-helpers.txt\n@@ -143,6 +143,10 @@ Supported commands: 'list', 'fetch'.\n +\n Supported commands: 'list', 'import'.\n \n+'check-connectivity'::\n+\tCan guarantee that when a clone is requested, the received\n+\tpack is self contained and is connected.\n+\n If a helper advertises 'connect', Git will use it if possible and\n fall back to another capability if the helper requests so when\n connecting (see the 'connect' command under COMMANDS).\n@@ -270,6 +274,9 @@ Optionally may output a 'lock <file>' line indicating a file under\n GIT_DIR/objects/pack which is keeping a pack until refs can be\n suitably updated.\n +\n+If option 'check-connectivity' is requested, the helper must output\n+'connectivity-ok' if the clone is self-contained and connected.\n++\n Supported if the helper has the \"fetch\" capability.\n \n 'push' +<src>:<dst>::\n@@ -416,6 +423,9 @@ set by Git if the remote helper has the 'option' capability.\n \tmust not rely on this option being set before\n \tconnect request occurs.\n \n+'option check-connectivity' \\{'true'|'false'\\}::\n+\tRequest the helper to check connectivity of a clone.\n+\n SEE ALSO\n --------\n linkgit:git-remote[1]\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex aba4465..3e19d71 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -100,6 +100,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \t\t\tpack_lockfile_ptr = &pack_lockfile;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(\"--check-self-contained-and-connected\", arg)) {\n+\t\t\targs.check_self_contained_and_connected = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tusage(fetch_pack_usage);\n \t}\n \n@@ -152,6 +156,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \t\tprintf(\"lock %s\\n\", pack_lockfile);\n \t\tfflush(stdout);\n \t}\n+\tif (args.check_self_contained_and_connected &&\n+\t    args.self_contained_and_connected) {\n+\t\tprintf(\"connectivity-ok\\n\");\n+\t\tfflush(stdout);\n+\t}\n \tclose(fd[0]);\n \tclose(fd[1]);\n \tif (finish_connect(conn))\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 5b3ce9e..6918668 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -16,6 +16,7 @@ struct options {\n \tint verbosity;\n \tunsigned long depth;\n \tunsigned progress : 1,\n+\t\tcheck_self_contained_and_connected : 1,\n \t\tfollowtags : 1,\n \t\tdry_run : 1,\n \t\tthin : 1;\n@@ -67,6 +68,15 @@ static int set_option(const char *name, const char *value)\n \t\t\treturn -1;\n \t\treturn 0;\n \t}\n+\telse if (!strcmp(name, \"check-connectivity\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.check_self_contained_and_connected = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.check_self_contained_and_connected = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n \telse {\n \t\treturn 1 /* unsupported */;\n \t}\n@@ -654,7 +664,7 @@ static int fetch_git(struct discovery *heads,\n \tstruct strbuf preamble = STRBUF_INIT;\n \tchar *depth_arg = NULL;\n \tint argc = 0, i, err;\n-\tconst char *argv[15];\n+\tconst char *argv[16];\n \n \targv[argc++] = \"fetch-pack\";\n \targv[argc++] = \"--stateless-rpc\";\n@@ -668,6 +678,8 @@ static int fetch_git(struct discovery *heads,\n \t\targv[argc++] = \"-v\";\n \t\targv[argc++] = \"-v\";\n \t}\n+\tif (options.check_self_contained_and_connected)\n+\t\targv[argc++] = \"--check-self-contained-and-connected\";\n \tif (!options.progress)\n \t\targv[argc++] = \"--no-progress\";\n \tif (options.depth) {\n@@ -939,6 +951,7 @@ int main(int argc, const char **argv)\n \t\t\tprintf(\"fetch\\n\");\n \t\t\tprintf(\"option\\n\");\n \t\t\tprintf(\"push\\n\");\n+\t\t\tprintf(\"check-connectivity\\n\");\n \t\t\tprintf(\"\\n\");\n \t\t\tfflush(stdout);\n \t\t} else {\ndiff --git a/transport-helper.c b/transport-helper.c\nindex db9bd18..e39b032 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -27,6 +27,7 @@ struct helper_data {\n \t\tpush : 1,\n \t\tconnect : 1,\n \t\tsigned_tags : 1,\n+\t\tcheck_connectivity : 1,\n \t\tno_disconnect_req : 1;\n \tchar *export_marks;\n \tchar *import_marks;\n@@ -186,6 +187,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->bidi_import = 1;\n \t\telse if (!strcmp(capname, \"export\"))\n \t\t\tdata->export = 1;\n+\t\telse if (!strcmp(capname, \"check-connectivity\"))\n+\t\t\tdata->check_connectivity = 1;\n \t\telse if (!data->refspecs && !prefixcmp(capname, \"refspec \")) {\n \t\t\tALLOC_GROW(refspecs,\n \t\t\t\t   refspec_nr + 1,\n@@ -349,6 +352,9 @@ static int fetch_with_fetch(struct transport *transport,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstandard_options(transport);\n+\tif (data->check_connectivity &&\n+\t    data->transport_options.check_self_contained_and_connected)\n+\t\tset_helper_option(transport, \"check-connectivity\", \"true\");\n \n \tfor (i = 0; i < nr_heads; i++) {\n \t\tconst struct ref *posn = to_fetch[i];\n@@ -372,6 +378,10 @@ static int fetch_with_fetch(struct transport *transport,\n \t\t\telse\n \t\t\t\ttransport->pack_lockfile = xstrdup(name);\n \t\t}\n+\t\telse if (data->check_connectivity &&\n+\t\t\t data->transport_options.check_self_contained_and_connected &&\n+\t\t\t !strcmp(buf.buf, \"connectivity-ok\"))\n+\t\t\tdata->transport_options.self_contained_and_connected = 1;\n \t\telse if (!buf.len)\n \t\t\tbreak;\n \t\telse\n-- \n1.8.2.83.gc99314b\n"}]}