|
12 | 12 | #include "packfile.h" |
13 | 13 | #include "object-store.h" |
14 | 14 | #include "lockfile.h" |
| 15 | +#include "exec-cmd.h" |
15 | 16 |
|
16 | 17 | static int get_st_mode_bits(const char *path, int *mode) |
17 | 18 | { |
@@ -719,19 +720,25 @@ static struct passwd *getpw_str(const char *username, size_t len) |
719 | 720 | } |
720 | 721 |
|
721 | 722 | /* |
722 | | - * Return a string with ~ and ~user expanded via getpw*. If buf != NULL, |
723 | | - * then it is a newly allocated string. Returns NULL on getpw failure or |
724 | | - * 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. |
725 | 725 | * |
726 | | - * 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. |
727 | 730 | */ |
728 | | -char *expand_user_path(const char *path, int real_home) |
| 731 | +char *interpolate_path(const char *path, int real_home) |
729 | 732 | { |
730 | 733 | struct strbuf user_path = STRBUF_INIT; |
731 | 734 | const char *to_copy = path; |
732 | 735 |
|
733 | 736 | if (path == NULL) |
734 | 737 | goto return_null; |
| 738 | + |
| 739 | + if (skip_prefix(path, "%(prefix)/", &path)) |
| 740 | + return system_path(path); |
| 741 | + |
735 | 742 | if (path[0] == '~') { |
736 | 743 | const char *first_slash = strchrnul(path, '/'); |
737 | 744 | const char *username = path + 1; |
@@ -812,7 +819,7 @@ const char *enter_repo(const char *path, int strict) |
812 | 819 | strbuf_add(&validated_path, path, len); |
813 | 820 |
|
814 | 821 | if (used_path.buf[0] == '~') { |
815 | | - char *newpath = expand_user_path(used_path.buf, 0); |
| 822 | + char *newpath = interpolate_path(used_path.buf, 0); |
816 | 823 | if (!newpath) |
817 | 824 | return NULL; |
818 | 825 | strbuf_attach(&used_path, newpath, strlen(newpath), |
|
0 commit comments