Do not ask for objects known to be complete.
On top of optimization by Linus not to ask refs that already match, we can walk our refs and not issue "want" for things that are known to be reachable from them. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 19, 2005 at 14:27 UTC
49bb805e69f97e75472e54a68e9eb24e08dee011
1 file changed
+62
-2
fetch-pack.c
+62
-2
@@ -1,6 +1,9 @@
1
#include "cache.h"
2
#include "refs.h"
3
#include "pkt-line.h"
4
+#include "commit.h"
5
+#include "tag.h"
6
+#include <time.h>
7
#include <sys/wait.h>
8
9
static int quiet;
@@ -78,16 +81,73 @@ static int find_common(int fd[2], unsigned char *result_sha1,
81
return retval;
82
}
83
84
+#define COMPLETE (1U << 0)
85
+static struct commit_list *complete = NULL;
86
+
87
+static int mark_complete(const char *path, const unsigned char *sha1)
88
+{
89
+ struct object *o = parse_object(sha1);
90
+
91
+ while (o && o->type == tag_type) {
92
+ o->flags |= COMPLETE;
93
+ o = parse_object(((struct tag *)o)->tagged->sha1);
94
+ }
95
+ if (o->type == commit_type) {
96
+ struct commit *commit = (struct commit *)o;
97
+ commit->object.flags |= COMPLETE;
98
+ insert_by_date(commit, &complete);
99
+ }
100
+ return 0;
101
+}
102
+
103
+static void mark_recent_complete_commits(unsigned long cutoff)
104
+{
105
+ while (complete && cutoff <= complete->item->date) {
106
+ if (verbose)
107
+ fprintf(stderr, "Marking %s as complete\n",
108
+ sha1_to_hex(complete->item->object.sha1));
109
+ pop_most_recent_commit(&complete, COMPLETE);
110
+ }
111
+}
112
+
113
static int everything_local(struct ref *refs)
114
{
115
+ struct ref *ref;
116
int retval;
117
+ unsigned long cutoff = 0;
118
+
119
+ track_object_refs = 0;
120
+ save_commit_buffer = 0;
121
+
122
+ for (ref = refs; ref; ref = ref->next) {
123
+ struct object *o;
124
+
125
+ o = parse_object(ref->old_sha1);
126
+ if (!o)
127
+ continue;
128
+
129
+ /* We already have it -- which may mean that we were
130
+ * in sync with the other side at some time after
131
+ * that (it is OK if we guess wrong here).
132
+ */
133
+ if (o->type == commit_type) {
134
+ struct commit *commit = (struct commit *)o;
135
+ if (!cutoff || cutoff < commit->date)
136
+ cutoff = commit->date;
137
+ }
138
+ }
139
+
140
+ for_each_ref(mark_complete);
141
+ if (cutoff)
142
+ mark_recent_complete_commits(cutoff);
143
144
for (retval = 1; refs ; refs = refs->next) {
145
const unsigned char *remote = refs->old_sha1;
146
unsigned char local[20];
147
+ struct object *o;
148
89
- if (read_ref(git_path("%s", refs->name), local) < 0 ||
90
- memcmp(remote, local, 20)) {
149
+ o = parse_object(remote);
150
+ if (!o || !(o->flags & COMPLETE)) {
151
retval = 0;
152
if (!verbose)
153
continue;