summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2016-03-09 16:41:08 +0100
committerVicent Marti <tanoku@gmail.com>2016-03-09 16:43:43 +0100
commite78d2ac9398a2b23349c3b22cbdeb9f2392ffdc8 (patch)
treebc3f161c83466d7bea236c3ee252ace165e3beda /src/odb.c
parent4416aa77499ef20c14c7a777e1ac7ae40a567d07 (diff)
downloadlibgit2-e78d2ac9398a2b23349c3b22cbdeb9f2392ffdc8.tar.gz
odb: Refactor `git_odb_expand_ids`
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/odb.c b/src/odb.c
index c67c5475d..17f9b37b8 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -782,37 +782,42 @@ int git_odb_expand_ids(
for (i = 0; i < count; i++) {
git_odb_expand_id *query = &ids[i];
- git_oid actual_id;
- git_otype query_type = (query->type == GIT_OBJ_ANY) ? 0 : query->type;
- git_otype actual_type = 0;
int error = GIT_EAMBIGUOUS;
- /* if we were given a full object ID, simply look it up */
- if (query->length >= GIT_OID_HEXSZ) {
- error = odb_otype_fast(&actual_type, db, &query->id);
- git_oid_cpy(&actual_id, &query->id);
+ if (!query->type)
+ query->type = GIT_OBJ_ANY;
+
+ /* if we have a short OID, expand it first */
+ if (query->length >= GIT_OID_MINPREFIXLEN && query->length < GIT_OID_HEXSZ) {
+ git_oid actual_id;
+
+ error = odb_exists_prefix_1(&actual_id, db, &query->id, query->length, false);
+ if (!error) {
+ git_oid_cpy(&query->id, &actual_id);
+ query->length = GIT_OID_HEXSZ;
+ }
}
/*
- * otherwise, resolve the short id to full if it's long enough, then
- * (optionally) read the header
+ * now we ought to have a 40-char OID, either because we've expanded it
+ * or because the user passed a full OID. Ensure its type is right.
*/
- else if (query->length >= GIT_OID_MINPREFIXLEN) {
- error = odb_exists_prefix_1(&actual_id, db, &query->id, query->length, false);
- if (!error)
- error = odb_otype_fast(&actual_type, db, &actual_id);
- }
+ if (query->length >= GIT_OID_HEXSZ) {
+ git_otype actual_type;
- /* Ensure that the looked up type matches the type we were expecting */
- if (query_type && query_type != actual_type)
- error = GIT_ENOTFOUND;
+ error = odb_otype_fast(&actual_type, db, &query->id);
+ if (!error) {
+ if (query->type != GIT_OBJ_ANY && query->type != actual_type)
+ error = GIT_ENOTFOUND;
+ else
+ query->type = actual_type;
+ }
+ }
switch (error) {
+ /* no errors, so we've successfully expanded the OID */
case 0:
- git_oid_cpy(&query->id, &actual_id);
- query->length = GIT_OID_HEXSZ;
- query->type = actual_type;
- break;
+ continue;
/* the object is missing or ambiguous */
case GIT_ENOTFOUND: