| 52 | #define KEEP_TRAILING_SLASH 2 |
| 53 | |
| 54 | static void internal_prefix_pathspec(struct strvec *out, |
| 55 | const char *prefix, |
| 56 | const char **pathspec, |
| 57 | int count, unsigned flags) |
| 58 | { |
| 59 | int prefixlen = prefix ? strlen(prefix) : 0; |
| 60 | |
| 61 | /* Create an intermediate copy of the pathspec based on the flags */ |
| 62 | for (int i = 0; i < count; i++) { |
| 63 | size_t length = strlen(pathspec[i]); |
| 64 | size_t to_copy = length; |
| 65 | const char *maybe_basename; |
| 66 | char *trimmed, *prefixed_path; |
| 67 | |
| 68 | while (!(flags & KEEP_TRAILING_SLASH) && |
| 69 | to_copy > 0 && is_dir_sep(pathspec[i][to_copy - 1])) |
| 70 | to_copy--; |
| 71 | |
| 72 | trimmed = xmemdupz(pathspec[i], to_copy); |
| 73 | maybe_basename = (flags & DUP_BASENAME) ? basename(trimmed) : trimmed; |
| 74 | prefixed_path = prefix_path(the_repository, prefix, prefixlen, maybe_basename); |
| 75 | strvec_push(out, prefixed_path); |
| 76 | |
| 77 | free(prefixed_path); |
| 78 | free(trimmed); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static char *add_slash(const char *path) |
| 83 | { |
no test coverage detected