git-upload-pack: More efficient usage of the has_sha1 array
This patch is based on Junio's proposal. It marks parents of common revs so that they do not clutter up the has_sha1 array. 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:48 UTC
f0243f26f6d8403cd8e83c7d498c81e01a1f1735
1 file changed
+22
-5
upload-pack.c
+22
-5
@@ -3,9 +3,11 @@
3
#include "pkt-line.h"
4
#include "tag.h"
5
#include "object.h"
6
+#include "commit.h"
7
8
static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=nn] <dir>";
9
10
+#define THEY_HAVE (1U << 0)
11
#define OUR_REF (1U << 1)
12
#define WANTED (1U << 2)
13
#define MAX_HAS 256
@@ -89,15 +91,27 @@ static void create_pack_file(void)
91
92
static int got_sha1(char *hex, unsigned char *sha1)
93
{
92
- int nr;
94
if (get_sha1_hex(hex, sha1))
95
die("git-upload-pack: expected SHA1 object, got '%s'", hex);
96
if (!has_sha1_file(sha1))
97
return 0;
97
- nr = nr_has;
98
- if (nr < MAX_HAS) {
99
- memcpy(has_sha1[nr], sha1, 20);
100
- nr_has = nr+1;
98
+ if (nr_has < MAX_HAS) {
99
+ struct object *o = lookup_object(sha1);
100
+ if (!(o && o->parsed))
101
+ o = parse_object(sha1);
102
+ if (!o)
103
+ die("oops (%s)", sha1_to_hex(sha1));
104
+ if (o->type == commit_type) {
105
+ struct commit_list *parents;
106
+ if (o->flags & THEY_HAVE)
107
+ return 0;
108
+ o->flags |= THEY_HAVE;
109
+ for (parents = ((struct commit*)o)->parents;
110
+ parents;
111
+ parents = parents->next)
112
+ parents->item->object.flags |= THEY_HAVE;
113
+ }
114
+ memcpy(has_sha1[nr_has++], sha1, 20);
115
}
116
return 1;
117
}
@@ -108,6 +122,9 @@ static int get_common_commits(void)
122
unsigned char sha1[20];
123
int len;
124
125
+ track_object_refs = 0;
126
+ save_commit_buffer = 0;
127
+
128
for(;;) {
129
len = packet_read_line(0, line, sizeof(line));
130
reset_timeout();