Merge branch 'np/compress-loose-object-memsave' into maint
[gitweb.git] / builtin-mv.c
index 82471869a0b677202fb5585e2fca880d16478af8..c07f53b34380200eaba223d2e1f8f977c1f9fd18 100644 (file)
@@ -24,10 +24,13 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
        result[count] = NULL;
        for (i = 0; i < count; i++) {
                int length = strlen(result[i]);
-               if (length > 0 && is_dir_sep(result[i][length - 1]))
-                       result[i] = xmemdupz(result[i], length - 1);
-               if (base_name)
-                       result[i] = basename((char *)result[i]);
+               int to_copy = length;
+               while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
+                       to_copy--;
+               if (to_copy != length || base_name) {
+                       char *it = xmemdupz(result[i], to_copy);
+                       result[i] = base_name ? strdup(basename(it)) : it;
+               }
        }
        return get_pathspec(prefix, result);
 }