{"thread":{"id":"12478","subject":"[PATCH 3/3] Teach git-fetch to exploit server side automatic tag following","startedAt":"2008-03-04T02:36:20Z","lastAt":"2008-03-04T02:36:20Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"70872","messageId":"20080304023620.GC16152@spearce.org","threadId":"12478","inReplyTo":null,"subject":"[PATCH 3/3] Teach git-fetch to exploit server side automatic tag following","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-03-04T02:36:20Z","receivedAt":"2008-03-04T02:36:20Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If the remote peer upload-pack process supports the auto-follow-tag\nprotocol extension then we can avoid running a second fetch cycle\non the client side by letting the server send us the annotated tags\nalong with the objects it is packing for us.  In the following graph\nwe can now fetch both \"tag1\" and \"tag2\" on the same connection that\nwe fetched \"master\" from the remote when we only have L available\non the local side:\n\n         T - tag1          S - tag2\n        /                 /\n   L - o ------ o ------ B\n    \\                     \\\n     \\                     \\\n      origin/master         master\n\nThe objects for \"tag1\" are implicitly downloaded without our direct\nknowledge.  The existing \"quickfetch\" optimization within git-fetch\ndiscovers that tag1 is complete after the first connection and does\nnot open a second connection.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fetch.c      |    3 +++\n t/t5503-tagfollow.sh |   26 ++++++++++++++++++++++++++\n transport.c          |    5 +++++\n transport.h          |    3 +++\n 4 files changed, 37 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 26c3d74..55f611e 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -555,6 +555,8 @@ static int do_fetch(struct transport *transport,\n \t\t\tread_ref(rm->peer_ref->name, rm->peer_ref->old_sha1);\n \t}\n \n+\tif (tags == TAGS_DEFAULT && autotags)\n+\t\ttransport_set_option(transport, TRANS_OPT_FOLLOWTAGS, \"1\");\n \tif (fetch_refs(transport, ref_map)) {\n \t\tfree_refs(ref_map);\n \t\treturn 1;\n@@ -568,6 +570,7 @@ static int do_fetch(struct transport *transport,\n \t\tref_map = NULL;\n \t\tfind_non_local_tags(transport, &ref_map, &tail);\n \t\tif (ref_map) {\n+\t\t\ttransport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);\n \t\t\ttransport_set_option(transport, TRANS_OPT_DEPTH, \"0\");\n \t\t\tfetch_refs(transport, ref_map);\n \t\t}\ndiff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh\nindex 45ff982..86e5b9b 100755\n--- a/t/t5503-tagfollow.sh\n+++ b/t/t5503-tagfollow.sh\n@@ -121,4 +121,30 @@ test_expect_success 'fetch B, S (commit and tag : 1 connection)' '\n \tgit diff expect actual\n '\n \n+cat - <<EOF >expect\n+#S\n+want $B\n+want $S\n+#E\n+EOF\n+test_expect_success 'new clone fetch master and tags' '\n+\tgit branch -D cat\n+\trm -f $U\n+\t(\n+\t\tmkdir clone2 &&\n+\t\tcd clone2 &&\n+\t\tgit init &&\n+\t\tgit remote add origin .. &&\n+\t\tGIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&\n+\t\ttest $B = $(git rev-parse --verify origin/master) &&\n+\t\ttest $S = $(git rev-parse --verify tag2) &&\n+\t\ttest $B = $(git rev-parse --verify tag2^0) &&\n+\t\ttest $T = $(git rev-parse --verify tag1) &&\n+\t\ttest $A = $(git rev-parse --verify tag1^0)\n+\t) &&\n+\ttest -s $U &&\n+\tcut -d\" \" -f1,2 $U >actual &&\n+\tgit diff expect actual\n+'\n+\n test_done\ndiff --git a/transport.c b/transport.c\nindex 166c1d1..00b45ab 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -560,6 +560,7 @@ static int close_bundle(struct transport *transport)\n struct git_transport_data {\n \tunsigned thin : 1;\n \tunsigned keep : 1;\n+\tunsigned followtags : 1;\n \tint depth;\n \tstruct child_process *conn;\n \tint fd[2];\n@@ -580,6 +581,9 @@ static int set_git_option(struct transport *connection,\n \t} else if (!strcmp(name, TRANS_OPT_THIN)) {\n \t\tdata->thin = !!value;\n \t\treturn 0;\n+\t} else if (!strcmp(name, TRANS_OPT_FOLLOWTAGS)) {\n+\t\tdata->followtags = !!value;\n+\t\treturn 0;\n \t} else if (!strcmp(name, TRANS_OPT_KEEP)) {\n \t\tdata->keep = !!value;\n \t\treturn 0;\n@@ -628,6 +632,7 @@ static int fetch_refs_via_pack(struct transport *transport,\n \targs.keep_pack = data->keep;\n \targs.lock_pack = 1;\n \targs.use_thin_pack = data->thin;\n+\targs.auto_follow_tags = data->followtags;\n \targs.verbose = transport->verbose > 0;\n \targs.depth = data->depth;\n \ndiff --git a/transport.h b/transport.h\nindex 6fb4526..8abfc0a 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -53,6 +53,9 @@ struct transport *transport_get(struct remote *, const char *);\n /* Limit the depth of the fetch if not null */\n #define TRANS_OPT_DEPTH \"depth\"\n \n+/* Aggressively fetch annotated tags if possible */\n+#define TRANS_OPT_FOLLOWTAGS \"followtags\"\n+\n /**\n  * Returns 0 if the option was used, non-zero otherwise. Prints a\n  * message to stderr if the option is not used.\n-- \n1.5.4.3.529.gb25fb\n"}]}