Do not feed rev-list an invalid SHA1 expression.
The previous round to optimize fetch-pack has a small bug that feeds SHA1^ ("parent commit") before making sure SHA1 is actually a commit (or a tag that eventually dereferences to a commit). Also it did not help culling the known-to-be-common parents if the common one was a merge. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 19, 2005 at 18:28 UTC
4dab94d52e25b6a53a715613ec5b06b42b240106
1 file changed
+23
-9
fetch-pack.c
+23
-9
@@ -28,22 +28,36 @@ static int find_common(int fd[2], unsigned char *result_sha1,
28
fetching = 0;
29
for ( ; refs ; refs = refs->next) {
30
unsigned char *remote = refs->old_sha1;
31
+ struct object *o;
32
33
/*
33
- If that object is complete (i.e. it is a descendant of a
34
- local ref), we don't want it, nor its descendants.
35
- */
36
- if (has_sha1_file(remote)
37
- && parse_object(remote)->flags & COMPLETE) {
38
- if (rev_command_len + 44 < sizeof(rev_command)) {
34
+ * If that object is complete (i.e. it is an ancestor of a
35
+ * local ref), we tell them we have it but do not have to
36
+ * tell them about its ancestors, which they already know
37
+ * about.
38
+ */
39
+ if (has_sha1_file(remote) &&
40
+ ((o = parse_object(remote)) != NULL) &&
41
+ (o->flags & COMPLETE)) {
42
+ struct commit_list *p;
43
+ struct commit *commit =
44
+ (struct commit *) (o = deref_tag(o));
45
+ if (!o)
46
+ goto repair;
47
+ if (o->type != commit_type)
48
+ continue;
49
+ p = commit->parents;
50
+ while (p &&
51
+ rev_command_len + 44 < sizeof(rev_command)) {
52
snprintf(rev_command + rev_command_len, 44,
40
- " ^%s^", sha1_to_hex(remote));
53
+ " ^%s",
54
+ sha1_to_hex(p->item->object.sha1));
55
rev_command_len += 43;
56
+ p = p->next;
57
}
43
-
58
continue;
59
}
46
-
60
+ repair:
61
packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
62
fetching++;
63
}