aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-08-16 14:00:12 -0700
committerJunio C Hamano <junkio@cox.net>2006-08-16 14:00:12 -0700
commit500a99935dc157a6625b4decae0b97e896061c2c (patch)
tree40875ece9927038974fbbee2dfc2d6f1455fbb95
parent6493cc09c2aa626ffbe6024dd705e1495c2d87e4 (diff)
parentd78b0f3d6aa04510dd0c22c3853d3954c5f5b531 (diff)
downloadgit-500a99935dc157a6625b4decae0b97e896061c2c.tar.gz
git-500a99935dc157a6625b4decae0b97e896061c2c.tar.xz
Merge branch 'maint'
* maint: [PATCH] git-mv: add more path normalization
-rw-r--r--builtin-mv.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/builtin-mv.c b/builtin-mv.c
index e7b5eb708..c0c8764f7 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -17,12 +17,19 @@ static const char builtin_mv_usage[] =
static const char **copy_pathspec(const char *prefix, const char **pathspec,
int count, int base_name)
{
+ int i;
const char **result = xmalloc((count + 1) * sizeof(const char *));
memcpy(result, pathspec, count * sizeof(const char *));
result[count] = NULL;
- if (base_name) {
- int i;
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count; i++) {
+ int length = strlen(result[i]);
+ if (length > 0 && result[i][length - 1] == '/') {
+ char *without_slash = xmalloc(length);
+ memcpy(without_slash, result[i], length - 1);
+ without_slash[length] = '\0';
+ result[i] = without_slash;
+ }
+ if (base_name) {
const char *last_slash = strrchr(result[i], '/');
if (last_slash)
result[i] = last_slash + 1;
@@ -129,6 +136,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
if (lstat(source[i], &st) < 0)
bad = "bad source";
+ if (!bad &&
+ (length = strlen(source[i])) >= 0 &&
+ !strncmp(destination[i], source[i], length) &&
+ (destination[i][length] == 0 || destination[i][length] == '/'))
+ bad = "can not move directory into itself";
+
if (S_ISDIR(st.st_mode)) {
const char *dir = source[i], *dest_dir = destination[i];
int first, last, len = strlen(dir);
@@ -204,12 +217,6 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
}
}
- if (!bad &&
- (length = strlen(source[i])) >= 0 &&
- !strncmp(destination[i], source[i], length) &&
- (destination[i][length] == 0 || destination[i][length] == '/'))
- bad = "can not move directory into itself";
-
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
bad = "not under version control";