MCPcopy Index your code
hub / github.com/git/git / interpolate_path

Function interpolate_path

path.c:698–737  ·  view source on GitHub ↗

* Return a string with ~ and ~user expanded via getpw*. Returns NULL on getpw * failure or if path is NULL. * * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion. * * If the path starts with `%(prefix)/`, the remainder is interpreted as * relative to where Git is installed, and expanded to the absolute path. */

Source from the content-addressed store, hash-verified

696 * relative to where Git is installed, and expanded to the absolute path.
697 */
698char *interpolate_path(const char *path, int real_home)
699{
700 struct strbuf user_path = STRBUF_INIT;
701 const char *to_copy = path;
702
703 if (!path)
704 goto return_null;
705
706 if (skip_prefix(path, "%(prefix)/", &path))
707 return system_path(path);
708
709 if (path[0] == '~') {
710 const char *first_slash = strchrnul(path, '/');
711 const char *username = path + 1;
712 size_t username_len = first_slash - username;
713 if (username_len == 0) {
714 const char *home = getenv("HOME");
715 if (!home)
716 goto return_null;
717 if (real_home)
718 strbuf_add_real_path(&user_path, home);
719 else
720 strbuf_addstr(&user_path, home);
721#ifdef GIT_WINDOWS_NATIVE
722 convert_slashes(user_path.buf);
723#endif
724 } else {
725 struct passwd *pw = getpw_str(username, username_len);
726 if (!pw)
727 goto return_null;
728 strbuf_addstr(&user_path, pw->pw_dir);
729 }
730 to_copy = first_slash;
731 }
732 strbuf_addstr(&user_path, to_copy);
733 return strbuf_detach(&user_path, NULL);
734return_null:
735 strbuf_release(&user_path);
736 return NULL;
737}
738
739int calc_shared_perm(struct repository *repo,
740 int mode)

Callers 12

handle_path_includeFunction · 0.85
git_config_pathnameFunction · 0.85
git_global_config_pathsFunction · 0.85
enter_repoFunction · 0.85
implicit_ident_adviceFunction · 0.85
sign_buffer_sshFunction · 0.85
fsmonitor_ipc__get_pathFunction · 0.85
run_command_on_repoFunction · 0.85
cmd_credential_storeFunction · 0.85
get_socket_pathFunction · 0.85

Calls 7

system_pathFunction · 0.85
strbuf_add_real_pathFunction · 0.85
strbuf_addstrFunction · 0.85
convert_slashesFunction · 0.85
getpw_strFunction · 0.85
strbuf_detachFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected