diff options
author | Russell Belfer <rb@github.com> | 2014-03-04 15:34:23 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-03-04 15:34:23 -0800 |
commit | f5753999e4cac020c2dd3a4669fe9ba14df93cb5 (patch) | |
tree | 13e38551546181a59c0dae367192008c555e1fee /src/odb_pack.c | |
parent | 0a62caf4e4927cbf74f40d8a2cb44b84267a30da (diff) | |
download | libgit2-f5753999e4cac020c2dd3a4669fe9ba14df93cb5.tar.gz |
Add exists_prefix to ODB backend and ODB API
Diffstat (limited to 'src/odb_pack.c')
-rw-r--r-- | src/odb_pack.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c index 903b00d26..9ab683882 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -493,6 +493,23 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0; } +static int pack_backend__exists_prefix( + git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len) +{ + int error; + struct pack_backend *pb = (struct pack_backend *)backend; + struct git_pack_entry e = {0}; + + error = pack_entry_find_prefix(&e, pb, short_id, len); + + if (error == GIT_ENOTFOUND && !(error = pack_backend__refresh(backend))) + error = pack_entry_find_prefix(&e, pb, short_id, len); + + git_oid_cpy(out, &e.sha1); + + return error; +} + static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) { int error; @@ -612,6 +629,7 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size) backend->parent.read_prefix = &pack_backend__read_prefix; backend->parent.read_header = &pack_backend__read_header; backend->parent.exists = &pack_backend__exists; + backend->parent.exists_prefix = &pack_backend__exists_prefix; backend->parent.refresh = &pack_backend__refresh; backend->parent.foreach = &pack_backend__foreach; backend->parent.writepack = &pack_backend__writepack; |