summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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--;
}