@@ -720,22 +720,30 @@ static struct passwd *getpw_str(const char *username, size_t len)
720
720
}
721
721
722
722
/*
723
- * Return a string with ~ and ~user expanded via getpw*. If buf != NULL,
724
- * then it is a newly allocated string. Returns NULL on getpw failure or
725
- * if path is NULL.
723
+ * Return a string with ~ and ~user expanded via getpw*. Returns NULL on getpw
724
+ * failure or if path is NULL.
726
725
*
727
- * If real_home is true, strbuf_realpath($HOME) is used in the expansion.
726
+ * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion.
727
+ *
728
+ * If the path starts with `%(prefix)/`, the remainder is interpreted as
729
+ * relative to where Git is installed, and expanded to the absolute path.
728
730
*/
729
- char * expand_user_path (const char * path , int real_home )
731
+ char * interpolate_path (const char * path , int real_home )
730
732
{
731
733
struct strbuf user_path = STRBUF_INIT ;
732
734
const char * to_copy = path ;
733
735
734
736
if (path == NULL )
735
737
goto return_null ;
738
+
739
+ if (skip_prefix (path , "%(prefix)/" , & path ))
740
+ return system_path (path );
741
+
736
742
#ifdef __MINGW32__
737
- if (path [0 ] == '/' )
743
+ if (path [0 ] == '/' ) {
744
+ warning (_ ("encountered old-style '%s' that should be '%%(prefix)%s'" ), path , path );
738
745
return system_path (path + 1 );
746
+ }
739
747
#endif
740
748
if (path [0 ] == '~' ) {
741
749
const char * first_slash = strchrnul (path , '/' );
@@ -817,7 +825,7 @@ const char *enter_repo(const char *path, int strict)
817
825
strbuf_add (& validated_path , path , len );
818
826
819
827
if (used_path .buf [0 ] == '~' ) {
820
- char * newpath = expand_user_path (used_path .buf , 0 );
828
+ char * newpath = interpolate_path (used_path .buf , 0 );
821
829
if (!newpath )
822
830
return NULL ;
823
831
strbuf_attach (& used_path , newpath , strlen (newpath ),
0 commit comments