@@ -782,37 +782,42 @@ int git_odb_expand_ids(
782
782
783
783
for (i = 0 ; i < count ; i ++ ) {
784
784
git_odb_expand_id * query = & ids [i ];
785
- git_oid actual_id ;
786
- git_otype query_type = (query -> type == GIT_OBJ_ANY ) ? 0 : query -> type ;
787
- git_otype actual_type = 0 ;
788
785
int error = GIT_EAMBIGUOUS ;
789
786
790
- /* if we were given a full object ID, simply look it up */
791
- if (query -> length >= GIT_OID_HEXSZ ) {
792
- error = odb_otype_fast (& actual_type , db , & query -> id );
793
- git_oid_cpy (& actual_id , & query -> id );
787
+ if (!query -> type )
788
+ query -> type = GIT_OBJ_ANY ;
789
+
790
+ /* if we have a short OID, expand it first */
791
+ if (query -> length >= GIT_OID_MINPREFIXLEN && query -> length < GIT_OID_HEXSZ ) {
792
+ git_oid actual_id ;
793
+
794
+ error = odb_exists_prefix_1 (& actual_id , db , & query -> id , query -> length , false);
795
+ if (!error ) {
796
+ git_oid_cpy (& query -> id , & actual_id );
797
+ query -> length = GIT_OID_HEXSZ ;
798
+ }
794
799
}
795
800
796
801
/*
797
- * otherwise, resolve the short id to full if it's long enough, then
798
- * (optionally) read the header
802
+ * now we ought to have a 40-char OID, either because we've expanded it
803
+ * or because the user passed a full OID. Ensure its type is right.
799
804
*/
800
- else if (query -> length >= GIT_OID_MINPREFIXLEN ) {
801
- error = odb_exists_prefix_1 (& actual_id , db , & query -> id , query -> length , false);
802
- if (!error )
803
- error = odb_otype_fast (& actual_type , db , & actual_id );
804
- }
805
+ if (query -> length >= GIT_OID_HEXSZ ) {
806
+ git_otype actual_type ;
805
807
806
- /* Ensure that the looked up type matches the type we were expecting */
807
- if (query_type && query_type != actual_type )
808
- error = GIT_ENOTFOUND ;
808
+ error = odb_otype_fast (& actual_type , db , & query -> id );
809
+ if (!error ) {
810
+ if (query -> type != GIT_OBJ_ANY && query -> type != actual_type )
811
+ error = GIT_ENOTFOUND ;
812
+ else
813
+ query -> type = actual_type ;
814
+ }
815
+ }
809
816
810
817
switch (error ) {
818
+ /* no errors, so we've successfully expanded the OID */
811
819
case 0 :
812
- git_oid_cpy (& query -> id , & actual_id );
813
- query -> length = GIT_OID_HEXSZ ;
814
- query -> type = actual_type ;
815
- break ;
820
+ continue ;
816
821
817
822
/* the object is missing or ambiguous */
818
823
case GIT_ENOTFOUND :
0 commit comments