@matheusbsbs / matheus-bagliano / commits / af2d3aa4d8
Fork 0

Revert recent fetch-pack/upload-pack updates.

Let's have it simmer a bit longer in the proposed updates branch and shake the problems out. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 25, 2005 at 14:55 UTC af2d3aa4d84fd3475d9b676f669eab3c4227189f
3 files changed +72 -196
connect.c
+1 -4
@@ -59,11 +59,8 @@ int get_ack(int fd, unsigned char *result_sha1)
59 if (!strcmp(line, "NAK"))
60 return 0;
61 if (!strncmp(line, "ACK ", 3)) {
62 - if (!get_sha1_hex(line+4, result_sha1)) {
63 - if (strstr(line+45, "continue"))
64 - return 2;
62 + if (!get_sha1_hex(line+4, result_sha1))
63 return 1;
66 - }
64 }
65 die("git-fetch_pack: expected ACK/NAK, got '%s'", line);
66 }
fetch-pack.c
+44 -155
@@ -13,123 +13,18 @@ static const char fetch_pack_usage[] =
13 static const char *exec = "git-upload-pack";
14
15 #define COMPLETE (1U << 0)
16 -#define COMMON (1U << 1)
17 -#define COMMON_REF (1U << 2 | COMMON)
18 -#define SEEN (1U << 3)
19 -#define POPPED (1U << 4)
20 -
21 -static struct commit_list *rev_list = NULL;
22 -static struct commit_list *rev_list_end = NULL;
23 -static unsigned long non_common_revs = 0;
24 -
25 -static void rev_list_append(struct commit *commit, int mark)
26 -{
27 - if (!(commit->object.flags & mark)) {
28 - commit->object.flags |= mark;
29 -
30 - if (rev_list == NULL) {
31 - commit_list_insert(commit, &rev_list);
32 - rev_list_end = rev_list;
33 - } else {
34 - commit_list_insert(commit, &(rev_list_end->next));
35 - rev_list_end = rev_list_end->next;
36 - }
37 -
38 - if (!(commit->object.flags & COMMON))
39 - non_common_revs++;
40 - }
41 -}
42 -
43 -static int rev_list_append_sha1(const char *path, const unsigned char *sha1)
44 -{
45 - struct object *o = deref_tag(parse_object(sha1));
46 -
47 - if (o->type == commit_type)
48 - rev_list_append((struct commit *)o, SEEN);
49 -
50 - return 0;
51 -}
52 -
53 -static void mark_common(struct commit *commit)
54 -{
55 - if (commit != NULL && !(commit->object.flags & COMMON)) {
56 - struct object *o = (struct object *)commit;
57 - o->flags |= COMMON;
58 - if (!(o->flags & SEEN))
59 - rev_list_append(commit, SEEN);
60 - else {
61 - struct commit_list *parents;
62 -
63 - if (!(o->flags & POPPED))
64 - non_common_revs--;
65 - if (!o->parsed)
66 - parse_commit(commit);
67 - for (parents = commit->parents;
68 - parents;
69 - parents = parents->next)
70 - mark_common(parents->item);
71 - }
72 - }
73 -}
74 -
75 -/*
76 - Get the next rev to send, ignoring the common.
77 -*/
78 -
79 -static const unsigned char* get_rev()
80 -{
81 - struct commit *commit = NULL;
82 -
83 - while (commit == NULL) {
84 - unsigned int mark;
85 - struct commit_list* parents;
86 -
87 - if (rev_list == NULL || non_common_revs == 0)
88 - return NULL;
89 -
90 - commit = rev_list->item;
91 - if (!(commit->object.parsed))
92 - parse_commit(commit);
93 - commit->object.flags |= POPPED;
94 - if (!(commit->object.flags & COMMON))
95 - non_common_revs--;
96 -
97 - parents = commit->parents;
98 -
99 - if (commit->object.flags & COMMON) {
100 - /* do not send "have", and ignore ancestors */
101 - commit = NULL;
102 - mark = COMMON | SEEN;
103 - } else if (commit->object.flags & COMMON_REF)
104 - /* send "have", and ignore ancestors */
105 - mark = COMMON | SEEN;
106 - else
107 - /* send "have", also for its ancestors */
108 - mark = SEEN;
109 -
110 - while (parents) {
111 - if (mark & COMMON)
112 - mark_common(parents->item);
113 - else
114 - rev_list_append(parents->item, mark);
115 - parents = parents->next;
116 - }
117 -
118 - rev_list = rev_list->next;
119 - }
120 -
121 - return commit->object.sha1;
122 -}
16
17 static int find_common(int fd[2], unsigned char *result_sha1,
18 struct ref *refs)
19 {
20 int fetching;
128 - int count = 0, flushes = 0, multi_ack = 0, retval;
129 - const unsigned char *sha1;
130 -
131 - for_each_ref(rev_list_append_sha1);
21 + static char line[1000];
22 + static char rev_command[1024];
23 + int count = 0, flushes = 0, retval, rev_command_len;
24 + FILE *revs;
25
26 + strcpy(rev_command, "git-rev-list $(git-rev-parse --all)");
27 + rev_command_len = strlen(rev_command);
28 fetching = 0;
29 for ( ; refs ; refs = refs->next) {
30 unsigned char *remote = refs->old_sha1;
@@ -147,31 +42,46 @@ static int find_common(int fd[2], unsigned char *result_sha1,
42 */
43 if (((o = lookup_object(remote)) != NULL) &&
44 (o->flags & COMPLETE)) {
150 - o = deref_tag(o);
151 -
152 - if (o->type == commit_type)
153 - rev_list_append((struct commit *)o,
154 - COMMON_REF | SEEN);
155 -
45 + struct commit_list *p;
46 + struct commit *commit =
47 + (struct commit *) (o = deref_tag(o));
48 + if (!o)
49 + goto repair;
50 + if (o->type != commit_type)
51 + continue;
52 + p = commit->parents;
53 + while (p &&
54 + rev_command_len + 44 < sizeof(rev_command)) {
55 + snprintf(rev_command + rev_command_len, 44,
56 + " ^%s",
57 + sha1_to_hex(p->item->object.sha1));
58 + rev_command_len += 43;
59 + p = p->next;
60 + }
61 continue;
62 }
158 -
159 - packet_write(fd[1], "want %s multi_ack\n", sha1_to_hex(remote));
63 + repair:
64 + packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
65 fetching++;
66 }
67 packet_flush(fd[1]);
68 if (!fetching)
69 return 1;
70
166 - flushes = 0;
71 + revs = popen(rev_command, "r");
72 + if (!revs)
73 + die("unable to run 'git-rev-list'");
74 +
75 + flushes = 1;
76 retval = -1;
168 - while ((sha1 = get_rev())) {
77 + while (fgets(line, sizeof(line), revs) != NULL) {
78 + unsigned char sha1[20];
79 + if (get_sha1_hex(line, sha1))
80 + die("git-fetch-pack: expected object name, got crud");
81 packet_write(fd[1], "have %s\n", sha1_to_hex(sha1));
82 if (verbose)
83 fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
84 if (!(31 & ++count)) {
173 - int ack;
174 -
85 packet_flush(fd[1]);
86 flushes++;
87
@@ -181,48 +91,27 @@ static int find_common(int fd[2], unsigned char *result_sha1,
91 */
92 if (count == 32)
93 continue;
184 -
185 - do {
186 - ack = get_ack(fd[0], result_sha1);
187 - if (verbose && ack)
188 - fprintf(stderr, "got ack %d %s\n", ack,
189 - sha1_to_hex(result_sha1));
190 - if (ack == 1) {
191 - if (!multi_ack)
192 - flushes = 0;
193 - retval = 0;
194 - goto done;
195 - } else if (ack == 2) {
196 - multi_ack = 1;
197 - mark_common((struct commit *)
198 - lookup_object(result_sha1));
199 - retval = 0;
200 - }
201 - } while(ack);
94 + if (get_ack(fd[0], result_sha1)) {
95 + flushes = 0;
96 + retval = 0;
97 + if (verbose)
98 + fprintf(stderr, "got ack\n");
99 + break;
100 + }
101 flushes--;
102 }
103 }
205 -done:
206 - if (multi_ack) {
207 - packet_flush(fd[1]);
208 - flushes++;
209 - }
104 + pclose(revs);
105 packet_write(fd[1], "done\n");
106 if (verbose)
107 fprintf(stderr, "done\n");
213 - if (retval != 0)
214 - flushes++;
108 while (flushes) {
109 + flushes--;
110 if (get_ack(fd[0], result_sha1)) {
111 if (verbose)
218 - fprintf(stderr, "got ack %s\n",
219 - sha1_to_hex(result_sha1));
220 - if (!multi_ack)
221 - return 0;
222 - retval = 0;
223 - continue;
112 + fprintf(stderr, "got ack\n");
113 + return 0;
114 }
225 - flushes--;
115 }
116 return retval;
117 }
upload-pack.c
+27 -37
@@ -3,14 +3,12 @@
3 #include "pkt-line.h"
4 #include "tag.h"
5 #include "object.h"
6 -#include "commit.h"
6
7 static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=nn] <dir>";
8
10 -#define THEY_HAVE (1U << 0)
9 #define MAX_HAS 256
10 #define MAX_NEEDS 256
13 -static int nr_has = 0, nr_needs = 0, multi_ack = 0;
11 +static int nr_has = 0, nr_needs = 0;
12 static unsigned char has_sha1[MAX_HAS][20];
13 static unsigned char needs_sha1[MAX_NEEDS][20];
14 static unsigned int timeout = 0;
@@ -87,27 +85,15 @@ static void create_pack_file(void)
85
86 static int got_sha1(char *hex, unsigned char *sha1)
87 {
88 + int nr;
89 if (get_sha1_hex(hex, sha1))
90 die("git-upload-pack: expected SHA1 object, got '%s'", hex);
91 if (!has_sha1_file(sha1))
92 return 0;
94 - if (nr_has < MAX_HAS) {
95 - struct object *o = lookup_object(sha1);
96 - if (!(o && o->parsed))
97 - o = parse_object(sha1);
98 - if (!o)
99 - die("oops (%s)", sha1_to_hex(sha1));
100 - if (o->type == commit_type) {
101 - struct commit_list *parents;
102 - if (o->flags & THEY_HAVE)
103 - return 0;
104 - o->flags |= THEY_HAVE;
105 - for (parents = ((struct commit*)o)->parents;
106 - parents;
107 - parents = parents->next)
108 - parents->item->object.flags |= THEY_HAVE;
109 - }
110 - memcpy(has_sha1[nr_has++], sha1, 20);
93 + nr = nr_has;
94 + if (nr < MAX_HAS) {
95 + memcpy(has_sha1[nr], sha1, 20);
96 + nr_has = nr+1;
97 }
98 return 1;
99 }
@@ -118,36 +104,44 @@ static int get_common_commits(void)
104 unsigned char sha1[20];
105 int len;
106
121 - track_object_refs = 0;
122 - save_commit_buffer = 0;
123 -
107 for(;;) {
108 len = packet_read_line(0, line, sizeof(line));
109 reset_timeout();
110
111 if (!len) {
129 - if (multi_ack || nr_has == 0)
130 - packet_write(1, "NAK\n");
112 + packet_write(1, "NAK\n");
113 continue;
114 }
115 len = strip(line, len);
116 if (!strncmp(line, "have ", 5)) {
135 - if (got_sha1(line+5, sha1) &&
136 - (multi_ack || nr_has == 1))
137 - packet_write(1, "ACK %s%s\n",
138 - sha1_to_hex(sha1),
139 - multi_ack && nr_has < MAX_HAS ?
140 - " continue" : "");
117 + if (got_sha1(line+5, sha1)) {
118 + packet_write(1, "ACK %s\n", sha1_to_hex(sha1));
119 + break;
120 + }
121 continue;
122 }
123 if (!strcmp(line, "done")) {
144 - if (nr_has > 0)
145 - return 0;
124 packet_write(1, "NAK\n");
125 return -1;
126 }
127 die("git-upload-pack: expected SHA1 list, got '%s'", line);
128 }
129 +
130 + for (;;) {
131 + len = packet_read_line(0, line, sizeof(line));
132 + reset_timeout();
133 + if (!len)
134 + continue;
135 + len = strip(line, len);
136 + if (!strncmp(line, "have ", 5)) {
137 + got_sha1(line+5, sha1);
138 + continue;
139 + }
140 + if (!strcmp(line, "done"))
141 + break;
142 + die("git-upload-pack: expected SHA1 list, got '%s'", line);
143 + }
144 + return 0;
145 }
146
147 static int receive_needs(void)
@@ -176,10 +170,6 @@ static int receive_needs(void)
170 if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf))
171 die("git-upload-pack: protocol error, "
172 "expected to get sha, not '%s'", line);
179 -
180 - if (strstr(line+45, "multi_ack"))
181 - multi_ack = 1;
182 -
173 needs++;
174 }
175 }