1#ifndef PATH_H 2#define PATH_H 3 4struct repository; 5 6/* 7 * The result to all functions which return statically allocated memory may be 8 * overwritten by another call to _any_ one of these functions. Consider using 9 * the safer variants which operate on strbufs or return allocated memory. 10 */ 11 12/* 13 * Return a statically allocated path. 14 */ 15externconst char*mkpath(const char*fmt, ...) 16__attribute__((format(printf,1,2))); 17 18/* 19 * Return a path. 20 */ 21externchar*mkpathdup(const char*fmt, ...) 22__attribute__((format(printf,1,2))); 23 24/* 25 * Construct a path and place the result in the provided buffer `buf`. 26 */ 27externchar*mksnpath(char*buf,size_t n,const char*fmt, ...) 28__attribute__((format(printf,3,4))); 29 30/* 31 * The `git_common_path` family of functions will construct a path into a 32 * repository's common git directory, which is shared by all worktrees. 33 */ 34 35/* 36 * Constructs a path into the common git directory of repository `repo` and 37 * append it in the provided buffer `sb`. 38 */ 39externvoidstrbuf_git_common_path(struct strbuf *sb, 40const struct repository *repo, 41const char*fmt, ...) 42__attribute__((format(printf,3,4))); 43 44/* 45 * Return a statically allocated path into the main repository's 46 * (the_repository) common git directory. 47 */ 48externconst char*git_common_path(const char*fmt, ...) 49__attribute__((format(printf,1,2))); 50 51 52/* 53 * The `git_path` family of functions will construct a path into a repository's 54 * git directory. 55 * 56 * These functions will perform adjustments to the resultant path to account 57 * for special paths which are either considered common among worktrees (e.g. 58 * paths into the object directory) or have been explicitly set via an 59 * environment variable or config (e.g. path to the index file). 60 * 61 * For an exhaustive list of the adjustments made look at `common_list` and 62 * `adjust_git_path` in path.c. 63 */ 64 65/* 66 * Return a path into the git directory of repository `repo`. 67 */ 68externchar*repo_git_path(const struct repository *repo, 69const char*fmt, ...) 70__attribute__((format(printf,2,3))); 71 72/* 73 * Construct a path into the git directory of repository `repo` and append it 74 * to the provided buffer `sb`. 75 */ 76externvoidstrbuf_repo_git_path(struct strbuf *sb, 77const struct repository *repo, 78const char*fmt, ...) 79__attribute__((format(printf,3,4))); 80 81/* 82 * Return a statically allocated path into the main repository's 83 * (the_repository) git directory. 84 */ 85externconst char*git_path(const char*fmt, ...) 86__attribute__((format(printf,1,2))); 87 88/* 89 * Return a path into the main repository's (the_repository) git directory. 90 */ 91externchar*git_pathdup(const char*fmt, ...) 92__attribute__((format(printf,1,2))); 93 94/* 95 * Construct a path into the main repository's (the_repository) git directory 96 * and place it in the provided buffer `buf`, the contents of the buffer will 97 * be overridden. 98 */ 99externchar*git_path_buf(struct strbuf *buf,const char*fmt, ...) 100__attribute__((format(printf,2,3))); 101 102/* 103 * Construct a path into the main repository's (the_repository) git directory 104 * and append it to the provided buffer `sb`. 105 */ 106externvoidstrbuf_git_path(struct strbuf *sb,const char*fmt, ...) 107__attribute__((format(printf,2,3))); 108 109/* 110 * Return a path into the worktree of repository `repo`. 111 * 112 * If the repository doesn't have a worktree NULL is returned. 113 */ 114externchar*repo_worktree_path(const struct repository *repo, 115const char*fmt, ...) 116__attribute__((format(printf,2,3))); 117 118/* 119 * Construct a path into the worktree of repository `repo` and append it 120 * to the provided buffer `sb`. 121 * 122 * If the repository doesn't have a worktree nothing will be appended to `sb`. 123 */ 124externvoidstrbuf_repo_worktree_path(struct strbuf *sb, 125const struct repository *repo, 126const char*fmt, ...) 127__attribute__((format(printf,3,4))); 128 129/* 130 * Return a path into a submodule's git directory located at `path`. `path` 131 * must only reference a submodule of the main repository (the_repository). 132 */ 133externchar*git_pathdup_submodule(const char*path,const char*fmt, ...) 134__attribute__((format(printf,2,3))); 135 136/* 137 * Construct a path into a submodule's git directory located at `path` and 138 * append it to the provided buffer `sb`. `path` must only reference a 139 * submodule of the main repository (the_repository). 140 */ 141externintstrbuf_git_path_submodule(struct strbuf *sb,const char*path, 142const char*fmt, ...) 143__attribute__((format(printf,3,4))); 144 145externvoidreport_linked_checkout_garbage(void); 146 147/* 148 * You can define a static memoized git path like: 149 * 150 * static GIT_PATH_FUNC(git_path_foo, "FOO"); 151 * 152 * or use one of the global ones below. 153 */ 154#define GIT_PATH_FUNC(func, filename) \ 155 const char *func(void) \ 156 { \ 157 static char *ret; \ 158 if (!ret) \ 159 ret = git_pathdup(filename); \ 160 return ret; \ 161 } 162 163#define REPO_GIT_PATH_FUNC(var, filename) \ 164 const char *git_path_##var(struct repository *r) \ 165 { \ 166 if (!r->cached_paths.var) \ 167 r->cached_paths.var = git_pathdup(filename); \ 168 return r->cached_paths.var; \ 169 } 170 171struct path_cache { 172const char*cherry_pick_head; 173const char*revert_head; 174const char*squash_msg; 175const char*merge_msg; 176const char*merge_rr; 177const char*merge_mode; 178const char*merge_head; 179const char*fetch_head; 180const char*shallow; 181}; 182 183#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } 184 185const char*git_path_cherry_pick_head(struct repository *r); 186const char*git_path_revert_head(struct repository *r); 187const char*git_path_squash_msg(struct repository *r); 188const char*git_path_merge_msg(struct repository *r); 189const char*git_path_merge_rr(struct repository *r); 190const char*git_path_merge_mode(struct repository *r); 191const char*git_path_merge_head(struct repository *r); 192const char*git_path_fetch_head(struct repository *r); 193const char*git_path_shallow(struct repository *r); 194 195#endif/* PATH_H */