remove unnecessary initializations
[gitweb.git] / builtin-mv.c
index e47942c13522b2bc8a83203c61071697c9a03307..e7b5eb7088dc3d45608a7d9b3ebaf1c66501596e 100644 (file)
@@ -48,7 +48,8 @@ static const char *add_slash(const char *path)
        if (path[len - 1] != '/') {
                char *with_slash = xmalloc(len + 2);
                memcpy(with_slash, path, len);
-               strcat(with_slash + len, "/");
+               with_slash[len++] = '/';
+               with_slash[len] = 0;
                return with_slash;
        }
        return path;
@@ -71,10 +72,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file());
-       if (newfd < 0)
-               die("unable to create new index file");
-
+       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
        if (read_cache() < 0)
                die("index file corrupt");
 
@@ -121,6 +119,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
        /* Checking */
        for (i = 0; i < count; i++) {
+               int length;
                const char *bad = NULL;
 
                if (show_only)
@@ -206,7 +205,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                }
 
                if (!bad &&
-                   !strncmp(destination[i], source[i], strlen(source[i])))
+                   (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)