MCPcopy Create free account
hub / github.com/git/git / prefix_path_gently

Function prefix_path_gently

setup.c:119–147  ·  view source on GitHub ↗

* Normalize "path", prepending the "prefix" for relative paths. If * remaining_prefix is not NULL, return the actual prefix still * remains in the path. For example, prefix = sub1/sub2/ and path is * * foo -> sub1/sub2/foo (full prefix) * ../foo -> sub1/foo (remaining prefix is sub1/) * ../../bar -> bar (no remaining prefix) * ../../sub1/sub2/foo -> s

Source from the content-addressed store, hash-verified

117 * `pwd`/../bar -> sub1/bar (no remaining prefix)
118 */
119char *prefix_path_gently(struct repository *repo,
120 const char *prefix, int len,
121 int *remaining_prefix, const char *path)
122{
123 const char *orig = path;
124 char *sanitized;
125 if (is_absolute_path(orig)) {
126 sanitized = xmallocz(strlen(path));
127 if (remaining_prefix)
128 *remaining_prefix = 0;
129 if (normalize_path_copy_len(sanitized, path, remaining_prefix)) {
130 free(sanitized);
131 return NULL;
132 }
133 if (abspath_part_inside_repo(repo, sanitized)) {
134 free(sanitized);
135 return NULL;
136 }
137 } else {
138 sanitized = xstrfmt("%.*s%s", len, len ? prefix : "", path);
139 if (remaining_prefix)
140 *remaining_prefix = len;
141 if (normalize_path_copy_len(sanitized, sanitized, remaining_prefix)) {
142 free(sanitized);
143 return NULL;
144 }
145 }
146 return sanitized;
147}
148
149char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path)
150{

Callers 3

prefix_pathFunction · 0.85
path_inside_repoFunction · 0.85
init_pathspec_itemFunction · 0.85

Calls 5

is_absolute_pathFunction · 0.85
xmalloczFunction · 0.85
normalize_path_copy_lenFunction · 0.85
abspath_part_inside_repoFunction · 0.85
xstrfmtFunction · 0.85

Tested by 1

init_pathspec_itemFunction · 0.68