X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-mv.c;h=c07f53b34380200eaba223d2e1f8f977c1f9fd18;hb=55f638bdc6507b3a2ce03290741f592934afaee7;hp=f633d81424f5e41cb85ac660dbdc9f4913852673;hpb=b30ccd757354ea09b41e4359b0a5ab429d12f02e;p=git.git diff --git a/builtin-mv.c b/builtin-mv.c index f633d8142..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); } @@ -169,9 +172,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) * check both source and destination */ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { - fprintf(stderr, "Warning: %s;" - " will overwrite!\n", - bad); + warning("%s; will overwrite!", bad); bad = NULL; } else bad = "Cannot overwrite";