@@ -748,54 +748,59 @@ int git_odb_expand_ids(
748
748
size_t count )
749
749
{
750
750
size_t len , i ;
751
- int error ;
752
751
753
752
assert (db && ids );
754
753
755
754
for (i = 0 ; i < count ; i ++ ) {
756
755
git_odb_expand_id * query = & ids [i ];
757
- git_oid * actual_id = NULL , tmp ;
756
+ git_oid actual_id ;
758
757
git_otype query_type = (query -> type == GIT_OBJ_ANY ) ? 0 : query -> type ;
759
758
git_otype actual_type = 0 ;
759
+ int error = GIT_EAMBIGUOUS ;
760
760
761
761
/* if we were given a full object ID, simply look it up */
762
762
if (query -> length >= GIT_OID_HEXSZ ) {
763
763
error = git_odb_read_header (& len , & actual_type , db , & query -> id );
764
+ git_oid_cpy (& actual_id , & query -> id );
764
765
}
765
766
766
- /* otherwise, resolve the short id to full, then (optionally)
767
- * read the header.
767
+ /*
768
+ * otherwise, resolve the short id to full if it's long enough, then
769
+ * (optionally) read the header
768
770
*/
769
771
else if (query -> length >= GIT_OID_MINPREFIXLEN ) {
770
- error = odb_exists_prefix_1 (& tmp ,
771
- db , & query -> id , query -> length , false);
772
-
773
- if (!error ) {
774
- actual_id = & tmp ;
775
- error = git_odb_read_header (& len , & actual_type , db , & tmp );
776
- }
772
+ error = odb_exists_prefix_1 (& actual_id , db , & query -> id , query -> length , false);
773
+ if (!error )
774
+ error = git_odb_read_header (& len , & actual_type , db , & actual_id );
777
775
}
778
776
779
- if (error < 0 && error != GIT_ENOTFOUND && error != GIT_EAMBIGUOUS )
780
- break ;
781
-
782
- if (error == 0 && (query_type == actual_type || !query_type )) {
783
- if (actual_id )
784
- git_oid_cpy (& query -> id , actual_id );
777
+ /* Ensure that the looked up type matches the type we were expecting */
778
+ if (query_type && query_type != actual_type )
779
+ error = GIT_ENOTFOUND ;
785
780
781
+ switch (error ) {
782
+ case 0 :
783
+ git_oid_cpy (& query -> id , & actual_id );
786
784
query -> length = GIT_OID_HEXSZ ;
787
785
query -> type = actual_type ;
788
- } else {
786
+ break ;
787
+
788
+ /* the object is missing or ambiguous */
789
+ case GIT_ENOTFOUND :
790
+ case GIT_EAMBIGUOUS :
789
791
memset (& query -> id , 0 , sizeof (git_oid ));
790
792
query -> length = 0 ;
791
793
query -> type = 0 ;
794
+ break ;
795
+
796
+ /* something went very wrong with the ODB; bail hard */
797
+ default :
798
+ return error ;
792
799
}
793
800
}
794
801
795
- if (!error )
796
- giterr_clear ();
797
-
798
- return error ;
802
+ giterr_clear ();
803
+ return 0 ;
799
804
}
800
805
801
806
int git_odb_read_header (size_t * len_p , git_otype * type_p , git_odb * db , const git_oid * id )
0 commit comments