unpack-object: cache for non written objects
Preventing objects with broken links entering the repository means, that write of some objects must be delayed. This patch adds a cache to keep the object data in memory. The delta resolving code must also search in the cache. Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Koegler committed
Feb 25, 2008 at 22:46 UTC
2add1e6db44c81e19cd4263317b53f3c1339e61b
1 file changed
+23
builtin-unpack-objects.c
+23
@@ -8,6 +8,7 @@
8
#include "tag.h"
9
#include "tree.h"
10
#include "progress.h"
11
+#include "decorate.h"
12
13
static int dry_run, quiet, recover, has_errors;
14
static const char unpack_usage[] = "git-unpack-objects [-n] [-q] [-r] < pack-file";
@@ -18,6 +19,18 @@ static unsigned int offset, len;
19
static off_t consumed_bytes;
20
static SHA_CTX ctx;
21
22
+struct obj_buffer {
23
+ char *buffer;
24
+ unsigned long size;
25
+};
26
+
27
+static struct decoration obj_decorate;
28
+
29
+static struct obj_buffer *lookup_object_buffer(struct object *base)
30
+{
31
+ return lookup_decoration(&obj_decorate, base);
32
+}
33
+
34
/*
35
* Make sure at least "min" bytes are available in the buffer, and
36
* return the pointer to the buffer.
@@ -189,6 +202,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
202
void *delta_data, *base;
203
unsigned long base_size;
204
unsigned char base_sha1[20];
205
+ struct object *obj;
206
207
if (type == OBJ_REF_DELTA) {
208
hashcpy(base_sha1, fill(20));
@@ -252,6 +266,15 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
266
}
267
}
268
269
+ obj = lookup_object(base_sha1);
270
+ if (obj) {
271
+ struct obj_buffer *obj_buf = lookup_object_buffer(obj);
272
+ if (obj_buf) {
273
+ resolve_delta(nr, obj->type, obj_buf->buffer, obj_buf->size, delta_data, delta_size);
274
+ return;
275
+ }
276
+ }
277
+
278
base = read_sha1_file(base_sha1, &type, &base_size);
279
if (!base) {
280
error("failed to read delta-pack base object %s",