X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-mv.c;h=c07f53b34380200eaba223d2e1f8f977c1f9fd18;hb=ea68b0ce9f8ce8da3e360aed3cbd6720159ffbee;hp=82471869a0b677202fb5585e2fca880d16478af8;hpb=3259ada4c79eb1e8213ab44c7ce3ec6f7775cd33;p=git.git diff --git a/builtin-mv.c b/builtin-mv.c index 82471869a..c07f53b34 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -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); }