@matheusbsbs / matheus-bagliano / commits / 49aaddd102
Fork 0

Teach upload-pack to log the received need lines to an fd

To facilitate testing and verification of the requests sent by git-fetch to the remote side we permit logging the received packet lines to the file descriptor specified in GIT_DEBUG_SEND_PACK has been set. Special start and end lines are included to indicate the start and end of each connection. $ GIT_DEBUG_SEND_PACK=3 git fetch 3>UPLOAD_LOG $ cat UPLOAD_LOG #S want 8e10cf4e007ad7e003463c30c34b1050b039db78 multi_ack side-band-64k thin-pack ofs-delta want ddfa4a33562179aca1ace2bcc662244a17d0b503 #E #S want 3253df4d1cf6fb138b52b1938473bcfec1483223 multi_ack side-band-64k thin-pack ofs-delta #E >From the above trace the first connection opened by git-fetch was to download two refs (with values 8e and dd) and the second connection was opened to automatically follow an annotated tag (32). Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Mar 2, 2008 at 21:35 UTC 49aaddd102aff1f0fc986629f3dc22a872f202ce
1 file changed +9
upload-pack.c
+9
@@ -35,6 +35,7 @@ static unsigned int timeout;
35 * otherwise maximum packet size (up to 65520 bytes).
36 */
37 static int use_sideband;
38 +static int debug_fd;
39
40 static void reset_timeout(void)
41 {
@@ -444,6 +445,8 @@ static void receive_needs(void)
445 static char line[1000];
446 int len, depth = 0;
447
448 + if (debug_fd)
449 + write_in_full(debug_fd, "#S\n", 3);
450 for (;;) {
451 struct object *o;
452 unsigned char sha1_buf[20];
@@ -451,6 +454,8 @@ static void receive_needs(void)
454 reset_timeout();
455 if (!len)
456 break;
457 + if (debug_fd)
458 + write_in_full(debug_fd, line, len);
459
460 if (!prefixcmp(line, "shallow ")) {
461 unsigned char sha1[20];
@@ -506,6 +511,8 @@ static void receive_needs(void)
511 add_object_array(o, NULL, &want_obj);
512 }
513 }
514 + if (debug_fd)
515 + write_in_full(debug_fd, "#E\n", 3);
516 if (depth == 0 && shallows.nr == 0)
517 return;
518 if (depth > 0) {
@@ -631,6 +638,8 @@ int main(int argc, char **argv)
638 die("'%s': unable to chdir or not a git archive", dir);
639 if (is_repository_shallow())
640 die("attempt to fetch/clone from a shallow repository");
641 + if (getenv("GIT_DEBUG_SEND_PACK"))
642 + debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK"));
643 upload_pack();
644 return 0;
645 }