@matheusbsbs / matheus-bagliano / commits / d78b0f3d6a
Fork 0

[PATCH] git-mv: add more path normalization

We already use the normalization from get_pathspec(), but now we also remove a trailing slash. So, git mv some_path/ into_some_path/ works now. Also, move the "can not move directory into itself" test before the subdirectory expansion. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Aug 16, 2006 at 10:44 UTC d78b0f3d6aa04510dd0c22c3853d3954c5f5b531
1 file changed +16 -9
builtin-mv.c
+16 -9
@@ -17,12 +17,19 @@ static const char builtin_mv_usage[] =
17 static const char **copy_pathspec(const char *prefix, const char **pathspec,
18 int count, int base_name)
19 {
20 + int i;
21 const char **result = xmalloc((count + 1) * sizeof(const char *));
22 memcpy(result, pathspec, count * sizeof(const char *));
23 result[count] = NULL;
23 - if (base_name) {
24 - int i;
25 - for (i = 0; i < count; i++) {
24 + for (i = 0; i < count; i++) {
25 + int length = strlen(result[i]);
26 + if (length > 0 && result[i][length - 1] == '/') {
27 + char *without_slash = xmalloc(length);
28 + memcpy(without_slash, result[i], length - 1);
29 + without_slash[length] = '\0';
30 + result[i] = without_slash;
31 + }
32 + if (base_name) {
33 const char *last_slash = strrchr(result[i], '/');
34 if (last_slash)
35 result[i] = last_slash + 1;
@@ -129,6 +136,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
136 if (lstat(source[i], &st) < 0)
137 bad = "bad source";
138
139 + if (!bad &&
140 + (length = strlen(source[i])) >= 0 &&
141 + !strncmp(destination[i], source[i], length) &&
142 + (destination[i][length] == 0 || destination[i][length] == '/'))
143 + bad = "can not move directory into itself";
144 +
145 if (S_ISDIR(st.st_mode)) {
146 const char *dir = source[i], *dest_dir = destination[i];
147 int first, last, len = strlen(dir);
@@ -204,12 +217,6 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
217 }
218 }
219
207 - if (!bad &&
208 - (length = strlen(source[i])) >= 0 &&
209 - !strncmp(destination[i], source[i], length) &&
210 - (destination[i][length] == 0 || destination[i][length] == '/'))
211 - bad = "can not move directory into itself";
212 -
220 if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
221 bad = "not under version control";
222