{"thread":{"id":"12445","subject":"[PATCH v3 6/8] Teach upload-pack to log the received need lines to an fd","startedAt":"2008-03-03T02:35:18Z","lastAt":"2008-03-03T02:35:18Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":3,"patchTotal":8},"messages":[{"id":"70730","messageId":"20080303023518.GF9966@spearce.org","threadId":"12445","inReplyTo":null,"subject":"[PATCH v3 6/8] Teach upload-pack to log the received need lines to an fd","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-03-03T02:35:18Z","receivedAt":"2008-03-03T02:35:18Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"To facilitate testing and verification of the requests sent by\ngit-fetch to the remote side we permit logging the received packet\nlines to the file descriptor specified in GIT_DEBUG_SEND_PACK has\nbeen set.  Special start and end lines are included to indicate\nthe start and end of each connection.\n\n  $ GIT_DEBUG_SEND_PACK=3 git fetch 3>UPLOAD_LOG\n  $ cat UPLOAD_LOG\n  #S\n  want 8e10cf4e007ad7e003463c30c34b1050b039db78 multi_ack side-band-64k thin-pack ofs-delta\n  want ddfa4a33562179aca1ace2bcc662244a17d0b503\n  #E\n  #S\n  want 3253df4d1cf6fb138b52b1938473bcfec1483223 multi_ack side-band-64k thin-pack ofs-delta\n  #E\n\n>From the above trace the first connection opened by git-fetch was to\ndownload two refs (with values 8e and dd) and the second connection\nwas opened to automatically follow an annotated tag (32).\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n upload-pack.c |    9 +++++++++\n 1 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/upload-pack.c b/upload-pack.c\nindex e5421db..660134a 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -35,6 +35,7 @@ static unsigned int timeout;\n  * otherwise maximum packet size (up to 65520 bytes).\n  */\n static int use_sideband;\n+static int debug_fd;\n \n static void reset_timeout(void)\n {\n@@ -444,6 +445,8 @@ static void receive_needs(void)\n \tstatic char line[1000];\n \tint len, depth = 0;\n \n+\tif (debug_fd)\n+\t\twrite_in_full(debug_fd, \"#S\\n\", 3);\n \tfor (;;) {\n \t\tstruct object *o;\n \t\tunsigned char sha1_buf[20];\n@@ -451,6 +454,8 @@ static void receive_needs(void)\n \t\treset_timeout();\n \t\tif (!len)\n \t\t\tbreak;\n+\t\tif (debug_fd)\n+\t\t\twrite_in_full(debug_fd, line, len);\n \n \t\tif (!prefixcmp(line, \"shallow \")) {\n \t\t\tunsigned char sha1[20];\n@@ -506,6 +511,8 @@ static void receive_needs(void)\n \t\t\tadd_object_array(o, NULL, &want_obj);\n \t\t}\n \t}\n+\tif (debug_fd)\n+\t\twrite_in_full(debug_fd, \"#E\\n\", 3);\n \tif (depth == 0 && shallows.nr == 0)\n \t\treturn;\n \tif (depth > 0) {\n@@ -631,6 +638,8 @@ int main(int argc, char **argv)\n \t\tdie(\"'%s': unable to chdir or not a git archive\", dir);\n \tif (is_repository_shallow())\n \t\tdie(\"attempt to fetch/clone from a shallow repository\");\n+\tif (getenv(\"GIT_DEBUG_SEND_PACK\"))\n+\t\tdebug_fd = atoi(getenv(\"GIT_DEBUG_SEND_PACK\"));\n \tupload_pack();\n \treturn 0;\n }\n-- \n1.5.4.3.468.g36990\n\n"}]}