Use a better name for the function interpolating paths

It is not immediately clear what `expand_user_path()` means, so let's rename it to `interpolate_path()`. This also opens the path for interpolating more than just a home directory. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 24, 2021 at 22:06 UTC a03b097d6307763c6778f5a1f194fbcbd158a5f7
7 files changed +11 -11
builtin/credential-cache.c
+1 -1
@@ -90,7 +90,7 @@ static char *get_socket_path(void)
90 {
91 struct stat sb;
92 char *old_dir, *socket;
93 - old_dir = expand_user_path("~/.git-credential-cache", 0);
93 + old_dir = interpolate_path("~/.git-credential-cache", 0);
94 if (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))
95 socket = xstrfmt("%s/socket", old_dir);
96 else
builtin/credential-store.c
+1 -1
@@ -173,7 +173,7 @@ int cmd_credential_store(int argc, const char **argv, const char *prefix)
173 if (file) {
174 string_list_append(&fns, file);
175 } else {
176 - if ((file = expand_user_path("~/.git-credentials", 0)))
176 + if ((file = interpolate_path("~/.git-credentials", 0)))
177 string_list_append_nodup(&fns, file);
178 file = xdg_config_home("credentials");
179 if (file)
builtin/gc.c
+1 -1
@@ -1542,7 +1542,7 @@ static char *launchctl_service_filename(const char *name)
1542 struct strbuf filename = STRBUF_INIT;
1543 strbuf_addf(&filename, "~/Library/LaunchAgents/%s.plist", name);
1544
1545 - expanded = expand_user_path(filename.buf, 1);
1545 + expanded = interpolate_path(filename.buf, 1);
1546 if (!expanded)
1547 die(_("failed to expand path '%s'"), filename.buf);
1548
cache.h
+1 -1
@@ -1246,7 +1246,7 @@ typedef int create_file_fn(const char *path, void *cb);
1246 int raceproof_create_file(const char *path, create_file_fn fn, void *cb);
1247
1248 int mkdir_in_gitdir(const char *path);
1249 -char *expand_user_path(const char *path, int real_home);
1249 +char *interpolate_path(const char *path, int real_home);
1250 const char *enter_repo(const char *path, int strict);
1251 static inline int is_absolute_path(const char *path)
1252 {
config.c
+4 -4
@@ -137,7 +137,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
137 if (!path)
138 return config_error_nonbool("include.path");
139
140 - expanded = expand_user_path(path, 0);
140 + expanded = interpolate_path(path, 0);
141 if (!expanded)
142 return error(_("could not expand include path '%s'"), path);
143 path = expanded;
@@ -185,7 +185,7 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
185 char *expanded;
186 int prefix = 0;
187
188 - expanded = expand_user_path(pat->buf, 1);
188 + expanded = interpolate_path(pat->buf, 1);
189 if (expanded) {
190 strbuf_reset(pat);
191 strbuf_addstr(pat, expanded);
@@ -1270,7 +1270,7 @@ int git_config_pathname(const char **dest, const char *var, const char *value)
1270 {
1271 if (!value)
1272 return config_error_nonbool(var);
1273 - *dest = expand_user_path(value, 0);
1273 + *dest = interpolate_path(value, 0);
1274 if (!*dest)
1275 die(_("failed to expand user dir in: '%s'"), value);
1276 return 0;
@@ -1844,7 +1844,7 @@ void git_global_config(char **user_out, char **xdg_out)
1844 char *xdg_config = NULL;
1845
1846 if (!user_config) {
1847 - user_config = expand_user_path("~/.gitconfig", 0);
1847 + user_config = interpolate_path("~/.gitconfig", 0);
1848 xdg_config = xdg_config_home("config");
1849 }
1850
path.c
+2 -2
@@ -724,7 +724,7 @@ static struct passwd *getpw_str(const char *username, size_t len)
724 *
725 * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion.
726 */
727 -char *expand_user_path(const char *path, int real_home)
727 +char *interpolate_path(const char *path, int real_home)
728 {
729 struct strbuf user_path = STRBUF_INIT;
730 const char *to_copy = path;
@@ -811,7 +811,7 @@ const char *enter_repo(const char *path, int strict)
811 strbuf_add(&validated_path, path, len);
812
813 if (used_path.buf[0] == '~') {
814 - char *newpath = expand_user_path(used_path.buf, 0);
814 + char *newpath = interpolate_path(used_path.buf, 0);
815 if (!newpath)
816 return NULL;
817 strbuf_attach(&used_path, newpath, strlen(newpath),
sequencer.c
+1 -1
@@ -1241,7 +1241,7 @@ N_("Your name and email address were configured automatically based\n"
1241
1242 static const char *implicit_ident_advice(void)
1243 {
1244 - char *user_config = expand_user_path("~/.gitconfig", 0);
1244 + char *user_config = interpolate_path("~/.gitconfig", 0);
1245 char *xdg_config = xdg_config_home("config");
1246 int config_exists = file_exists(user_config) || file_exists(xdg_config);
1247