Wish: using diff for inteligent patching
Brought to you by:
blais
Hi!
Here's what would make xxdiff usefull to me. (You asked
on linux kernel, that's why you are getting this comment).
Task is updating to next version by linux, when you already
have some changes in your tree. You can probably assume
that each developer also stores official source without
changes somewhere.
So task is to apply patch-2.4.19 over linux directory
with local changes, when you have clean directory
[where you know patch applies without rejects for sure].
As much as possible should be done automatically -- if
it does not conflict within 3 lines, automerge it.
I do not think this is easily done with xxdiff, currently,
and it would be very usefull.
Pavel
Logged In: YES
user_id=15179
Have you ever recieved a patch against xxdiff Martin? Today
I had to slump through a whole pile of patches and I wished
xxdiff had that feature. That is:
xxdiff file.c hackers_delight.diff
xxdiff takes file.c, copies it to some /tmp, applies
hackers_delight.diff and shows you the diff.
Erm, wait - that could be done through some script... I'll have a
try.
Greets,
*t
Logged In: YES
user_id=15179
So here we go. Martin, Pavel, let me know whether you like it.
*t
#!/usr/bin/perl
#
# (gpl) by tomas pospisek <tpo_deb@sourcepole.ch>
use strict;
use warnings;
use English;
sub main();
main();
sub usage() {
print "xxpatch file|dir diff [diff] [...]\n";
print "\tPatch file or directory with diff[s] and display the
diff\n";
print "\twith xxdiff. The original file or directory is left
unaltered\n";
print "\tThe diff has to be in a format that print lets patch
guess the\n";
print "\tfilename to patch, like f.ex. the \&quot;diff -u\&quot; format.\n";
exit 1;
}
sub main() {
my $fileOrDir = shift (@ARGV);
my $tempdir = `mktemp -t -d xxdiff.XXXXXXXXXX`;
$? == 0 or die;
chop $tempdir;
my $curdir = `pwd`;
my $copy = `basename $fileOrDir`; chop $copy;
print "file: $fileOrDir\n";
usage() unless (defined($fileOrDir) and defined($ARGV[0])) ;
# make a copy of the file|dir to patch
system("cp -a $fileOrDir $tempdir") == 0 or die;
chdir $tempdir or die "Couldn't change into $tempdir\n";
# change into $tempdir and maybe into copy-dir
if ( -d $fileOrDir ) {
print "xxpatching directory $fileOrDir\n";
chdir $copy or die "Couldn't change into
$tempdir/$copy\n";
} else {
print "xxpatching file $fileOrDir\n";
}
# apply patches
while( $_ = shift(@ARGV) ) {
system("patch < $_"); $? == 0 or die;
}
# exec xxdiff an patched copy
chdir $tempdir or die "Couldn't change into $tempdir\n";
system("xxdiff $fileOrDir $copy");
# don't like this, but is there a better way?
system("rm -r $tempdir");
}
Logged In: YES
user_id=15179
I'm slowly fixing my little script some more. Up to date versions of
it can be found here:
http://sourcepole.ch/sources/software/xxdiff/
*t