* 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. */
| 696 | * relative to where Git is installed, and expanded to the absolute path. |
| 697 | */ |
| 698 | char *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); |
| 734 | return_null: |
| 735 | strbuf_release(&user_path); |
| 736 | return NULL; |
| 737 | } |
| 738 | |
| 739 | int calc_shared_perm(struct repository *repo, |
| 740 | int mode) |
no test coverage detected