Re: [PATCH] git-mv: Fix error with multiple sources.
- From
- David Rydh <dary@math.berkeley.edu>
- Date
- Jan 22, 2010, 17:30 UTC
- Message-ID
- <CB7104C1-EB96-426F-8280-E33105378B18@math.berkeley.edu>
- In-Reply-To
- <7vr5pi8x6z.fsf@alter.siamese.dyndns.org>
On Jan 21, 2010, at 10:34 PM, Junio C Hamano wrote:
Show 19 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Given that basename(3) is allowed to modify its parameter, I think the
>> above code is still not portable. casting constness away and feeding
>> result[i], especially when we didn't obtain our own copy by calling
>> xmemdupz(), is especially problematic.
>>
>> Perhaps something ugly like this?
>>
>> for (i = 0; i < count; i++) {
>> int length = strlen(result[i]);
>> int to_copy = length;
>> while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
>> to_copy--;
>> if (to_copy != length || basename) {
>> char *it = xmemdupz(result[i], to_copy);
>> result[i] = base_name ? strdup(basename(it)) : it;
>> }
>> }This looks fine. Currently we have the odd behavior
> git mv -n dir/ new-dir
Checking rename of 'dir' to 'new-dir' Checking rename of 'dir/a.txt' to 'new-dir/a.txt' Checking rename of 'dir/b.txt' to 'new-dir/b.txt'
> git mv -n dir// new-dir
Checking rename of 'dir/' to 'new-dir' fatal: source directory is empty, source=dir/, destination=new-dir
Note that at the end of copy_pathspec we call get_pathspec which squashes multiple slashes (even if prefix=NULL) but does not remove a trailing slash so it is necessary to squash them all as above.