Skip to content

Commit

Permalink
unpack-object: cache for non written objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin Koegler authored and Junio C Hamano committed Feb 29, 2008
1 parent d6ffc8d commit 2add1e6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions builtin-unpack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "tag.h"
#include "tree.h"
#include "progress.h"
#include "decorate.h"

static int dry_run, quiet, recover, has_errors;
static const char unpack_usage[] = "git-unpack-objects [-n] [-q] [-r] < pack-file";
Expand All @@ -18,6 +19,18 @@ static unsigned int offset, len;
static off_t consumed_bytes;
static SHA_CTX ctx;

struct obj_buffer {
char *buffer;
unsigned long size;
};

static struct decoration obj_decorate;

static struct obj_buffer *lookup_object_buffer(struct object *base)
{
return lookup_decoration(&obj_decorate, base);
}

/*
* Make sure at least "min" bytes are available in the buffer, and
* return the pointer to the buffer.
Expand Down Expand Up @@ -189,6 +202,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
void *delta_data, *base;
unsigned long base_size;
unsigned char base_sha1[20];
struct object *obj;

if (type == OBJ_REF_DELTA) {
hashcpy(base_sha1, fill(20));
Expand Down Expand Up @@ -252,6 +266,15 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
}
}

obj = lookup_object(base_sha1);
if (obj) {
struct obj_buffer *obj_buf = lookup_object_buffer(obj);
if (obj_buf) {
resolve_delta(nr, obj->type, obj_buf->buffer, obj_buf->size, delta_data, delta_size);
return;
}
}

base = read_sha1_file(base_sha1, &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
Expand Down

0 comments on commit 2add1e6

Please sign in to comment.