diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-08-06 00:35:20 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-08-18 02:34:08 +0200 |
commit | c1af5a3935025f486156cdfe3b006700e73f0a49 (patch) | |
tree | 146efe5813abc0808ae51193a1029b045606a24e /src/pack.c | |
parent | 061047ccb6d9453928fcd3baf94b18fad792f1a0 (diff) | |
download | libgit2-c1af5a3935025f486156cdfe3b006700e73f0a49.tar.gz |
Implement cooperative caching
When indexing a file with ref deltas, a temporary cache for the
offsets has to be built, as we don't have an index file yet. If the
user takes the responsiblity for filling the cache, the packing code
will look there first when it finds a ref delta.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pack.c b/src/pack.c index f0ebf9d37..4b43e7cf1 100644 --- a/src/pack.c +++ b/src/pack.c @@ -473,6 +473,18 @@ off_t get_delta_base( return 0; /* out of bound */ *curpos += used; } else if (type == GIT_OBJ_REF_DELTA) { + /* If we have the cooperative cache, search in it first */ + if (p->has_cache) { + int pos; + struct git_pack_entry key; + + git_oid_fromraw(&key.sha1, base_info); + pos = git_vector_bsearch(&p->cache, &key); + if (pos >= 0) { + *curpos += 20; + return ((struct git_pack_entry *)git_vector_get(&p->cache, pos))->offset; + } + } /* The base entry _must_ be in the same pack */ if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < GIT_SUCCESS) return git__rethrow(GIT_EPACKCORRUPTED, "Base entry delta is not in the same pack"); |