@@ -235,18 +235,21 @@ static int ambiguous_path(const char *path, int len)
235235
236236static int get_sha1_basic (const char * str , int len , unsigned char * sha1 )
237237{
238- static const char * prefix [] = {
239- "" ,
240- "refs" ,
241- "refs/tags" ,
242- "refs/heads" ,
243- "refs/remotes" ,
238+ static const char * fmt [] = {
239+ "/%.*s" ,
240+ "refs/%.*s" ,
241+ "refs/tags/%.*s" ,
242+ "refs/heads/%.*s" ,
243+ "refs/remotes/%.*s" ,
244+ "refs/remotes/%.*s/HEAD" ,
244245 NULL
245246 };
246247 const char * * p ;
247248 const char * warning = "warning: refname '%.*s' is ambiguous.\n" ;
248249 char * pathname ;
249250 int already_found = 0 ;
251+ unsigned char * this_result ;
252+ unsigned char sha1_from_ref [20 ];
250253
251254 if (len == 40 && !get_sha1_hex (str , sha1 ))
252255 return 0 ;
@@ -255,11 +258,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
255258 if (ambiguous_path (str , len ))
256259 return -1 ;
257260
258- for (p = prefix ; * p ; p ++ ) {
259- unsigned char sha1_from_ref [20 ];
260- unsigned char * this_result =
261- already_found ? sha1_from_ref : sha1 ;
262- pathname = git_path ("%s/%.*s" , * p , len , str );
261+ for (p = fmt ; * p ; p ++ ) {
262+ this_result = already_found ? sha1_from_ref : sha1 ;
263+ pathname = git_path (* p , len , str );
263264 if (!read_ref (pathname , this_result )) {
264265 if (warn_ambiguous_refs ) {
265266 if (already_found &&
0 commit comments