Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/odb_pack.c')
-rw-r--r--src/odb_pack.c62
1 files changed, 42 insertions, 20 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c
index fd2ca0fd8..3750da37f 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -190,31 +190,39 @@ static int packfile_sort__cb(const void *a_, const void *b_)
}
-
-static int packfile_load__cb(void *_data, git_buf *path)
+static int packfile_load__cb(void *data, git_buf *path)
{
- struct pack_backend *backend = (struct pack_backend *)_data;
+ struct pack_backend *backend = data;
struct git_pack_file *pack;
+ const char *path_str = git_buf_cstr(path);
+ size_t i, cmp_len = git_buf_len(path);
int error;
- size_t i;
- if (git__suffixcmp(path->ptr, ".idx") != 0)
+ if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0)
return 0; /* not an index */
+ cmp_len -= strlen(".idx");
+
for (i = 0; i < backend->packs.length; ++i) {
struct git_pack_file *p = git_vector_get(&backend->packs, i);
- if (memcmp(p->pack_name, git_buf_cstr(path), git_buf_len(path) - strlen(".idx")) == 0)
+
+ if (memcmp(p->pack_name, path_str, cmp_len) == 0)
return 0;
}
error = git_packfile_alloc(&pack, path->ptr);
- if (error == GIT_ENOTFOUND)
- /* ignore missing .pack file as git does */
+
+ /* ignore missing .pack file as git does */
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
return 0;
- else if (error < 0)
- return error;
+ }
+
+ if (!error)
+ error = git_vector_insert(&backend->packs, pack);
+
+ return error;
- return git_vector_insert(&backend->packs, pack);
}
static int pack_entry_find_inner(
@@ -314,13 +322,12 @@ static int pack_entry_find_prefix(
* Implement the git_odb_backend API calls
*
***********************************************************/
-static int pack_backend__refresh(git_odb_backend *_backend)
+static int pack_backend__refresh(git_odb_backend *backend_)
{
- struct pack_backend *backend = (struct pack_backend *)_backend;
-
int error;
struct stat st;
git_buf path = GIT_BUF_INIT;
+ struct pack_backend *backend = (struct pack_backend *)backend_;
if (backend->pack_folder == NULL)
return 0;
@@ -334,12 +341,9 @@ static int pack_backend__refresh(git_odb_backend *_backend)
error = git_path_direach(&path, 0, packfile_load__cb, backend);
git_buf_free(&path);
-
- if (error < 0)
- return -1;
-
git_vector_sort(&backend->packs);
- return 0;
+
+ return error;
}
static int pack_backend__read_header_internal(
@@ -489,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;
@@ -542,7 +563,7 @@ static void pack_backend__writepack_free(struct git_odb_writepack *_writepack)
static int pack_backend__writepack(struct git_odb_writepack **out,
git_odb_backend *_backend,
git_odb *odb,
- git_transfer_progress_callback progress_cb,
+ git_transfer_progress_cb progress_cb,
void *progress_payload)
{
struct pack_backend *backend;
@@ -608,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;