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; }

Perl is Huffman encoded by design.

In reply to Open diff windows looking at CVS file merge conflicts by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.