@matheusbsbs / matheus-bagliano / commits / 1baaae5e1f
Fork 0

Make maximal use of the remote refs

When git-fetch-pack gets the remote refs, it does not need to filter them right away, but it can see which refs are common (taking advantage of the patch which makes git-fetch-pack not use git-rev-list). This means that we ask get_remote_heads() to return all remote refs, including the funny refs, and filtering them with a separate function later. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Oct 28, 2005 at 04:47 UTC 1baaae5e1f9ac09aafe11b5aa4daa69bae68173b
1 file changed +52 -20
fetch-pack.c
+52 -20
@@ -153,16 +153,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
153 * reachable and we have already scanned it.
154 */
155 if (((o = lookup_object(remote)) != NULL) &&
156 - (o->flags & COMPLETE)) {
157 - o = deref_tag(o);
158 -
159 - if (o->type == commit_type) {
160 - struct commit *commit = (struct commit *)o;
161 -
162 - rev_list_push(commit, COMMON_REF | SEEN);
163 -
164 - mark_common(commit, 1, 1);
165 - }
156 + (o->flags & COMPLETE)) {
157 continue;
158 }
159
@@ -247,7 +238,29 @@ static void mark_recent_complete_commits(unsigned long cutoff)
238 }
239 }
240
250 -static int everything_local(struct ref *refs)
241 +static void filter_refs(struct ref **refs, int nr_match, char **match)
242 +{
243 + struct ref *prev, *current, *next;
244 +
245 + if (!nr_match)
246 + return;
247 +
248 + for (prev = NULL, current = *refs; current; current = next) {
249 + next = current->next;
250 + if ((!memcmp(current->name, "refs/", 5) &&
251 + check_ref_format(current->name + 5)) ||
252 + !path_match(current->name, nr_match, match)) {
253 + if (prev == NULL)
254 + *refs = next;
255 + else
256 + prev->next = next;
257 + free(current);
258 + } else
259 + prev = current;
260 + }
261 +}
262 +
263 +static int everything_local(struct ref **refs, int nr_match, char **match)
264 {
265 struct ref *ref;
266 int retval;
@@ -256,7 +269,7 @@ static int everything_local(struct ref *refs)
269 track_object_refs = 0;
270 save_commit_buffer = 0;
271
259 - for (ref = refs; ref; ref = ref->next) {
272 + for (ref = *refs; ref; ref = ref->next) {
273 struct object *o;
274
275 o = parse_object(ref->old_sha1);
@@ -278,28 +291,47 @@ static int everything_local(struct ref *refs)
291 if (cutoff)
292 mark_recent_complete_commits(cutoff);
293
281 - for (retval = 1; refs ; refs = refs->next) {
282 - const unsigned char *remote = refs->old_sha1;
294 + /*
295 + * Mark all complete remote refs as common refs.
296 + * Don't mark them common yet; the server has to be told so first.
297 + */
298 + for (ref = *refs; ref; ref = ref->next) {
299 + struct object *o = deref_tag(lookup_object(ref->old_sha1));
300 +
301 + if (!o || o->type != commit_type || !(o->flags & COMPLETE))
302 + continue;
303 +
304 + if (!(o->flags & SEEN)) {
305 + rev_list_push((struct commit *)o, COMMON_REF | SEEN);
306 +
307 + mark_common((struct commit *)o, 1, 1);
308 + }
309 + }
310 +
311 + filter_refs(refs, nr_match, match);
312 +
313 + for (retval = 1, ref = *refs; ref ; ref = ref->next) {
314 + const unsigned char *remote = ref->old_sha1;
315 unsigned char local[20];
316 struct object *o;
317
286 - o = parse_object(remote);
318 + o = lookup_object(remote);
319 if (!o || !(o->flags & COMPLETE)) {
320 retval = 0;
321 if (!verbose)
322 continue;
323 fprintf(stderr,
324 "want %s (%s)\n", sha1_to_hex(remote),
293 - refs->name);
325 + ref->name);
326 continue;
327 }
328
297 - memcpy(refs->new_sha1, local, 20);
329 + memcpy(ref->new_sha1, local, 20);
330 if (!verbose)
331 continue;
332 fprintf(stderr,
333 "already have %s (%s)\n", sha1_to_hex(remote),
302 - refs->name);
334 + ref->name);
335 }
336 return retval;
337 }
@@ -311,12 +343,12 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
343 int status;
344 pid_t pid;
345
314 - get_remote_heads(fd[0], &ref, nr_match, match, 1);
346 + get_remote_heads(fd[0], &ref, 0, NULL, 0);
347 if (!ref) {
348 packet_flush(fd[1]);
349 die("no matching remote head");
350 }
319 - if (everything_local(ref)) {
351 + if (everything_local(&ref, nr_match, match)) {
352 packet_flush(fd[1]);
353 goto all_done;
354 }