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
path: root/src/odb.c
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2012-05-12 22:01:39 +0400
committerHan-Wen Nienhuys <hanwen@xs4all.nl>2012-05-12 22:50:19 +0400
commit24634c6fd02b2240e4a93fad70a08220f8fb793a (patch)
tree74188351355bc3c8818957d8343d5c3308dcf18a /src/odb.c
parentb72969e0643cb561b42aceec4d1a18ce9c782c09 (diff)
Handle duplicate objects from different backends in git_odb_read_prefix().
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/odb.c b/src/odb.c
index 934b317ed..03cd912e9 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -557,9 +557,9 @@ int git_odb_read_prefix(
{
unsigned int i;
int error = GIT_ENOTFOUND;
- git_oid full_oid;
+ git_oid found_full_oid = {{0}};
git_rawobj raw;
- int found = 0;
+ bool found = false;
assert(out && db);
@@ -575,25 +575,30 @@ int git_odb_read_prefix(
return 0;
}
- for (i = 0; i < db->backends.length && found < 2; ++i) {
+ for (i = 0; i < db->backends.length; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
git_odb_backend *b = internal->backend;
if (b->read != NULL) {
+ git_oid full_oid;
error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, short_id, len);
- if (!error)
- found++;
- else if (error != GIT_ENOTFOUND && error != GIT_EPASSTHROUGH)
+ if (error == GIT_ENOTFOUND || error == GIT_EPASSTHROUGH)
+ continue;
+
+ if (error)
return error;
+
+ if (found && git_oid_cmp(&full_oid, &found_full_oid))
+ return git_odb__error_ambiguous("multiple matches for prefix");
+ found_full_oid = full_oid;
+ found = true;
}
}
- if (found == 0)
+ if (!found)
return git_odb__error_notfound("no match for prefix", short_id);
- if (found > 1)
- return git_odb__error_ambiguous("multiple matches for prefix");
- *out = git_cache_try_store(&db->cache, new_odb_object(&full_oid, &raw));
+ *out = git_cache_try_store(&db->cache, new_odb_object(&found_full_oid, &raw));
return 0;
}