After a large merge between project branches in CVS we often end up with a bunch of fairly nasty conflicts. We have found that the best way to deal with them is to open two diff windows so that the differences between the common ancestor and the current target are shown in one view, and the differences between the current target and the merged result are shown in another.
This tool is designed so that it can be set up as a desktop shortcut that the merge result file can be dropped onto. It will then open the two diff views.
use warnings; use strict; use Win32::Process; use File::Find; use File::Path; use Tk; my $cvs = '"C:\Program Files\GNU\WinCvs 1.3\CVSNT\cvs"'; my $diffTool; my $confictFile; my $listOnly = 0; while ($_ = shift) { ShowHelp (-3, "Too many parameters provided.\n\n") if defined $con +fictFile; $confictFile = $_ if defined $diffTool; $diffTool = $_ if ! defined $diffTool; } ShowHelp () if ! $diffTool; ErrorBox ("Missing Conflict File", "Can't find $confictFile\n\n") if ! + -e $confictFile; (my $path = $confictFile) =~ s/^(.*)[\/\\](.*?)$/$1/; my $fileName = $2; find (\&setHeadFile, ($path)); my $headFile; # Set in setHeadFile @ARGV = ($confictFile); while (<>) { next if ! />>>>>>>\s+((?:\d+\.){2})/; my $commonRev = substr $1, 0, -1 + length $1; my $commonRevSrc = `$cvs update -P -p -r $commonRev $confictFile`; ErrorBox ("cvs failed", $commonRevSrc) if $?; my $tempFileName = "${confictFile}.$commonRev"; open tempFile, ">", $tempFileName; print tempFile $commonRevSrc; close tempFile; my $proc2; Win32::Process::Create ( $proc2, "$diffTool", "\"$diffTool\" $headFile $confictFile", 0, NORMAL_PRIORITY_CLASS, "." ) || ErrorBox ("Create failed", Win32::FormatMessage (Win32::GetLa +stError ())); my $proc1; Win32::Process::Create ( $proc1, "$diffTool", "\"$diffTool\" $tempFileName $headFile", 0, NORMAL_PRIORITY_CLASS, "." ) || ErrorBox ("Create failed", Win32::FormatMessage (Win32::GetLa +stError ())); exit (0); } ErrorBox ("No conflicts", "No conficts found in $confictFile"); sub ShowHelp { my $exitValue = 0; $exitValue = shift if defined $_[0] and $_[0] =~ /^[-+]?\d+$/; print $_ while $_ = shift; print "ConflictCompare opens two diff tool apps to compare the HEAD me +rged result\n"; print "against the common ancestor and the branch version that was mer +ged.\n"; print "\n"; print "Usage:\n\n"; print "ConflictCompare [-n] <tool cmd line> <.# conflict file>\n"; print "\n"; print " -n: show progress information.\n"; print "\n"; exit ($exitValue || -1); } sub ErrorBox { my $main = MainWindow->new (); my $title = shift; my $message = shift; $main->withdraw (); $main->messageBox(-icon => 'error', -message => $message, -title => $t +itle, -type => 'Ok'); exit (-2); } sub setHeadFile { return if $File::Find::name =~ /^\.\.?/; return if $File::Find::name !~ /$fileName(?:\.\d+)+/; return if $headFile and -M $headFile >= -M $File::Find::name; $headFile = $File::Find::name; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Open diff windows looking at CVS file merge conflicts
by cLive ;-) (Prior) on Sep 02, 2005 at 19:40 UTC | |
by GrandFather (Saint) on Sep 02, 2005 at 20:00 UTC |