@matheusbsbs / matheus-bagliano / commits / 794f9fe7db
Fork 0

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 23, 2005 at 03:36 UTC 794f9fe7db30e2aff8f8f0543c6d18bf579cdbc2
1 file changed +20 -5
upload-pack.c
+20 -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 MAX_HAS 256
12 #define MAX_NEEDS 256
13 static int nr_has = 0, nr_needs = 0;
@@ -85,15 +87,25 @@ static void create_pack_file(void)
87
88 static int got_sha1(char *hex, unsigned char *sha1)
89 {
88 - int nr;
90 if (get_sha1_hex(hex, sha1))
91 die("git-upload-pack: expected SHA1 object, got '%s'", hex);
92 if (!has_sha1_file(sha1))
93 return 0;
93 - nr = nr_has;
94 - if (nr < MAX_HAS) {
95 - memcpy(has_sha1[nr], sha1, 20);
96 - nr_has = nr+1;
94 + if (nr_has < MAX_HAS) {
95 + struct object *o = lookup_object(sha1);
96 + if (!o || (!o->parsed && !parse_object(sha1)))
97 + die("oops (%s)", sha1_to_hex(sha1));
98 + if (o->type == commit_type) {
99 + struct commit_list *parents;
100 + if (o->flags & THEY_HAVE)
101 + return 0;
102 + o->flags |= THEY_HAVE;
103 + for (parents = ((struct commit*)o)->parents;
104 + parents;
105 + parents = parents->next)
106 + parents->item->object.flags |= THEY_HAVE;
107 + }
108 + memcpy(has_sha1[nr_has++], sha1, 20);
109 }
110 return 1;
111 }
@@ -104,6 +116,9 @@ static int get_common_commits(void)
116 unsigned char sha1[20];
117 int len;
118
119 + track_object_refs = 0;
120 + save_commit_buffer = 0;
121 +
122 for(;;) {
123 len = packet_read_line(0, line, sizeof(line));
124 reset_timeout();