@matheusbsbs / matheus-bagliano / commits / 70a0c6fe39
Fork 0

[PATCH] Limit the number of requests outstanding in ssh-fetch.

This completes fetches if there are more than 100 outstanding requests and there are more to prefetch. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Daniel Barkalow committed Oct 4, 2005 at 00:24 UTC 70a0c6fe39da7e3f68836051408bc8eb3ce60ba7
1 file changed +27 -1
ssh-fetch.c
+27 -1
@@ -36,12 +36,26 @@ static ssize_t force_write(int fd, void *buffer, size_t length)
36 return ret;
37 }
38
39 +static int prefetches = 0;
40 +
41 +static struct object_list *in_transit = NULL;
42 +static struct object_list **end_of_transit = &in_transit;
43 +
44 void prefetch(unsigned char *sha1)
45 {
46 char type = 'o';
47 + struct object_list *node;
48 + if (prefetches > 100) {
49 + fetch(in_transit->item->sha1);
50 + }
51 + node = xmalloc(sizeof(struct object_list));
52 + node->next = NULL;
53 + node->item = lookup_unknown_object(sha1);
54 + *end_of_transit = node;
55 + end_of_transit = &node->next;
56 force_write(fd_out, &type, 1);
57 force_write(fd_out, sha1, 20);
44 - //memcpy(requested + 20 * prefetches++, sha1, 20);
58 + prefetches++;
59 }
60
61 static char conn_buf[4096];
@@ -51,6 +65,18 @@ int fetch(unsigned char *sha1)
65 {
66 int ret;
67 signed char remote;
68 + struct object_list *temp;
69 +
70 + if (memcmp(sha1, in_transit->item->sha1, 20)) {
71 + // we must have already fetched it to clean the queue
72 + return has_sha1_file(sha1) ? 0 : -1;
73 + }
74 + prefetches--;
75 + temp = in_transit;
76 + in_transit = in_transit->next;
77 + if (!in_transit)
78 + end_of_transit = &in_transit;
79 + free(temp);
80
81 if (conn_buf_posn) {
82 remote = conn_buf[0];