#!/usr/local/bin/perl -w # # Created by Robert Cowham (robert@vaccaperna.co.uk) # This is totally unsupported - use entirely at your own risk! # # Usage: # # ./version_differ.pl filename # # # The results of the following command gives us the files to process: # p4 diff2 -q //depot/main/... //depot/snap/... | grep '=== content' # #==== //depot/main/www/components/util/ftse.epl#5 (xtext) - //depot/snap/www/components/util/ftse.epl#1 (text) ==== content #==== //depot/main/www/components/util/hidden_elements.epl#2 (text) - //depot/snap/www/components/util/hidden_elements.epl#1 (text) ==== content use strict; #----------------------------------------------------------------------- # get file names while (<>) { if (/^==== ([^#]*)#(\d*)\s+\S* - ([^#]*)#(\d*)/) { my ($main_file, $main_ver, $snap_file, $snap_ver) = ($1, $2, $3, $4); # print "File: $main_file, ver: $main_ver, file2: $snap_file, ver: $snap_ver\n"; &find_same_version($main_file, $main_ver, $snap_file, $snap_ver); } } exit; #----------------------------------------------------------------------- # for each file - do a diff2 on each version # Only prints out summary info for file sub find_same_version() { my ($main_file, $main_ver_param, $snap_file, $snap_ver) = @_; my $main_ver = $main_ver_param; # print "Checking $main_file\n"; my $identical = 0; my ($depot_main, $depot_snap); while ($main_ver > 0 && !$identical) { $depot_main = $main_file . '#' . $main_ver; $depot_snap = $snap_file . '#' . $snap_ver; # print "FROM: $depot_main\n"; # print "TO: $depot_snap\n"; my $cmd = "p4 diff2 -q $depot_main $depot_snap"; # print "Executing: $cmd\n"; open(P4DIFF2, "$cmd |") || die "didn't open p4 diff2"; my @diff2 = ; close(P4DIFF2); if (scalar(@diff2) == 1) { my $report_string = '-- NO INFO FOUND --'; if ($diff2[0] =~ /====\s+([^\s]+)$/) { $report_string = $1; } if ($report_string =~ /^types$/) { $identical = 1; print "$report_string: $depot_main\n"; } elsif ($report_string !~ /^content$/) { print "$report_string: $depot_main\n"; } } elsif (scalar(@diff2) == 0) { $identical = 1; print "Identical: $depot_main\n"; } $main_ver -= 1; } if (!$identical) { my $rev = $main_file; $rev =~ s/#.*//; $rev .= "#" . $main_ver_param; print "No revision: $rev\n"; # &find_same_version_verbose($main_file, $main_ver_param, $snap_file, $snap_ver); } # print "\n"; } #----------------------------------------------------------------------- # for each file - do a diff2 on each version - print out some info # so that these files can be integrated by hand sub find_same_version_verbose() { my ($main_file, $main_ver, $snap_file, $snap_ver) = @_; print "Checking $main_file\n"; my $identical = 0; my ($depot_main, $depot_snap); while ($main_ver > 0 && !$identical) { $depot_main = $main_file . '#' . $main_ver; $depot_snap = $snap_file . '#' . $snap_ver; # print "FROM: $depot_main\n"; # print "TO: $depot_snap\n"; open(P4DIFF2, "p4 diff2 $depot_main $depot_snap |") || die "didn't open p4 diff2"; my @diff2 = ; close(P4DIFF2); if (scalar(@diff2) == 1) { my $report_string = '-- NO INFO FOUND --'; if ($diff2[0] =~ /====\s+([^\s]+)$/) { $report_string = $1; } print $depot_main, "\t", $depot_snap, "\t", "SINGLE LINE DIFF2: $report_string\n"; if ($report_string =~ /^identical$/) { $identical = 1; print "Identical: $depot_main\n"; } else { print "$report_string: $depot_main\n"; } } else { print $depot_main, "\t", $depot_snap, "\t", "DIFF LINES: " , scalar(@diff2), "\n"; my $l; # foreach $l (@diff2) { # print "$l"; # } } $main_ver -= 1; } if (!$identical) { print "No revision: $depot_main\n"; } print "\n"; }