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

Function internal_prefix_pathspec

builtin/mv.c:54–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52#define KEEP_TRAILING_SLASH 2
53
54static 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
82static char *add_slash(const char *path)
83{

Callers 1

cmd_mvFunction · 0.85

Calls 3

xmemdupzFunction · 0.85
prefix_pathFunction · 0.85
strvec_pushFunction · 0.85

Tested by

no test coverage detected