Possible bug in bzr diff
Wayne Davison
wayned at samba.org
Fri Mar 24 00:36:38 GMT 2006
On Tue, Mar 21, 2006 at 08:46:54PM GMT, Aaron Bentley wrote:
> Diff cannot detect renames. So it emits a file move as a
> delete/create pair.
[...]
> Since the primary target of bzr diff is the standard patch command, I
> think we should emulate the standard diff's rename-insensitive behavour.
Isn't the primary target of bzr diff a human who wishes to see what has
changed? If so, then your suggestion to dumb-down bzr diff to the level
of what patch expects would make it harder to see what (if anything)
changed in a moved file.
I much prefer bzr diff working the way it does now. It already mentions
when a rename is occurring via the "=== renamed ..." line, and given
that information, I find it entirely appropriate that the difference
output is then based on the renamed version of the file.
> But if you apply a rename patch, patch doesn't honour the rename.
Correct, but if the rename(s) mentioned in the patch are first done,
then the diff will apply via patch. It's not _too_ hard to automate
this via a script, though renamed directories do cause some problems
due to how bzr continues to refer to old directory names.
Here's a perl script that should handle the task:
#!/usr/bin/perl
my %renamed_dir;
while (<>) {
next unless my($type, $from, $to) = m{
^ === \s renamed \s (file|directory) \s
'([^']+)' \s => \s '([^']+)' $ }x;
my @before = split(/\//, $from);
my $name = pop @before;
$from = '';
foreach (@before) {
$from .= $_;
if (defined $renamed_dir{$from}) {
$from = $renamed_dir{$from};
}
$from .= '/';
}
$from .= $name;
rename($from, $to) or warn "Unable to rename $from to $to: $!\n";
if ($type eq 'directory') {
$renamed_dir{$from} = $to;
}
}
..wayne..
More information about the bazaar
mailing list