@@ -1006,6 +1006,28 @@ int get_sha1_mb(const char *name, unsigned char *sha1)
10061006 return st ;
10071007}
10081008
1009+ /* parse @something syntax, when 'something' is not {.*} */
1010+ static int interpret_empty_at (const char * name , int namelen , int len , struct strbuf * buf )
1011+ {
1012+ const char * next ;
1013+
1014+ if (len || name [1 ] == '{' )
1015+ return -1 ;
1016+
1017+ /* make sure it's a single @, or @@{.*}, not @foo */
1018+ next = strchr (name + len + 1 , '@' );
1019+ if (next && next [1 ] != '{' )
1020+ return -1 ;
1021+ if (!next )
1022+ next = name + namelen ;
1023+ if (next != name + 1 )
1024+ return -1 ;
1025+
1026+ strbuf_reset (buf );
1027+ strbuf_add (buf , "HEAD" , 4 );
1028+ return 1 ;
1029+ }
1030+
10091031static int reinterpret (const char * name , int namelen , int len , struct strbuf * buf )
10101032{
10111033 /* we have extra data, which might need further processing */
@@ -1014,7 +1036,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
10141036 int ret ;
10151037
10161038 strbuf_add (buf , name + len , namelen - len );
1017- ret = interpret_branch_name (buf -> buf , & tmp );
1039+ ret = interpret_branch_name (buf -> buf , buf -> len , & tmp );
10181040 /* that data was not interpreted, remove our cruft */
10191041 if (ret < 0 ) {
10201042 strbuf_setlen (buf , used );
@@ -1048,14 +1070,16 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
10481070 * If the input was ok but there are not N branch switches in the
10491071 * reflog, it returns 0.
10501072 */
1051- int interpret_branch_name (const char * name , struct strbuf * buf )
1073+ int interpret_branch_name (const char * name , int namelen , struct strbuf * buf )
10521074{
10531075 char * cp ;
10541076 struct branch * upstream ;
1055- int namelen = strlen (name );
10561077 int len = interpret_nth_prior_checkout (name , buf );
10571078 int tmp_len ;
10581079
1080+ if (!namelen )
1081+ namelen = strlen (name );
1082+
10591083 if (!len ) {
10601084 return len ; /* syntax Ok, not enough switches */
10611085 } else if (len > 0 ) {
@@ -1068,9 +1092,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
10681092 cp = strchr (name , '@' );
10691093 if (!cp )
10701094 return -1 ;
1095+
1096+ len = interpret_empty_at (name , namelen , cp - name , buf );
1097+ if (len > 0 )
1098+ return reinterpret (name , namelen , len , buf );
1099+
10711100 tmp_len = upstream_mark (cp , namelen - (cp - name ));
10721101 if (!tmp_len )
10731102 return -1 ;
1103+
10741104 len = cp + tmp_len - name ;
10751105 cp = xstrndup (name , cp - name );
10761106 upstream = branch_get (* cp ? cp : NULL );
@@ -1102,7 +1132,7 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
11021132int strbuf_branchname (struct strbuf * sb , const char * name )
11031133{
11041134 int len = strlen (name );
1105- int used = interpret_branch_name (name , sb );
1135+ int used = interpret_branch_name (name , len , sb );
11061136
11071137 if (used == len )
11081138 return 0 ;
0 commit comments