Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
[PATCH] git-mv: add more path normalization
author
Johannes Schindelin
<Johannes.Schindelin@gmx.de>
Wed, 16 Aug 2006 08:44:02 +0000
(10:44 +0200)
committer
Junio C Hamano
<junkio@cox.net>
Wed, 16 Aug 2006 20:19:06 +0000
(13:19 -0700)
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>
builtin-mv.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
53e1a76
)
diff --git
a/builtin-mv.c
b/builtin-mv.c
index e7b5eb7088dc3d45608a7d9b3ebaf1c66501596e..c0c8764f7fa71ffe459997f03b5158cd7c72209b 100644
(file)
--- 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)
{
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;
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;
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 (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);
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";
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
bad = "not under version control";