summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-12 02:01:05 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-13 02:48:52 +0200
commitc968ce2c2c49ca7a559ecb8f7014f777c3a8a5f3 (patch)
tree86baf2c0aaeee3d61dae8d9b8167a3371a7a6607
parent15bcced22379857978d80539da5fdd8f4667ff95 (diff)
downloadlibgit2-cmn/pack-unpack-loop.tar.gz
pack: don't forget to cache the base objectcmn/pack-unpack-loop
The base object is a good cache candidate, so we shouldn't forget to add it to the cache.
-rw-r--r--src/pack.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pack.c b/src/pack.c
index 235e8d3ee..d93ee25f9 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -668,7 +668,6 @@ int git_packfile_unpack(
error = packfile_unpack_compressed(obj, p, &w_curs, &curpos, elem->size, elem->type);
git_mwindow_close(&w_curs);
base_type = elem->type;
- free_base = 1;
}
if (error < 0)
goto cleanup;
@@ -683,7 +682,7 @@ int git_packfile_unpack(
}
/*
- * Finding the object we want as the base element is
+ * Finding the object we want a cached base element is
* problematic, as we need to make sure we don't accidentally
* give the caller the cached object, which it would then feel
* free to free, so we need to copy the data.
@@ -701,6 +700,13 @@ int git_packfile_unpack(
while (elem_pos > 0 && !error) {
git_rawobj base, delta;
+ /*
+ * We can now try to add the base to the cache, as
+ * long as it's not already the cached one.
+ */
+ if (!cached)
+ free_base = !!cache_add(&p->bases, obj, elem->base_key);
+
elem = &stack[elem_pos - 1];
curpos = elem->offset;
error = packfile_unpack_compressed(&delta, p, &w_curs, &curpos, elem->size, elem->type);
@@ -737,11 +743,6 @@ int git_packfile_unpack(
if (error < 0)
break;
- /* only try to cache if we're not handing this buffer off to the caller */
- if (elem_pos != 1 &&
- (error = cache_add(&p->bases, obj, elem->base_key)) < 0)
- goto cleanup;
-
elem_pos--;
}