#!/usr/bin/perl # # Compare.pl # # Given perforce paths as input arguments, this finds all # depot filenames in the paths and reports if files # with the same name have differing contents. # # If the same filename occurs more than once, it is # "diffed" (via p4 diff2) against all other occurances # of that filename (that is all other occurances in # the input path spec, not the entire depot!). # # If such a filename is not identical to others # with the same name, then the first line of the p4 diff2 # report is output. # # This is intended to be used as a plug-in tool with # the 2000.1 GUI - it should be passed the # parameter "%D" and it will then operate on any # selected files or directories in the client view pane. # require 5.0; use strict; my @filelist; my %paths = (); my $filename; my $param; while ($param = shift (@ARGV)) { @filelist = `p4 files $param`; foreach (@filelist) { my ($filespec, $dummy, $changetype, $change) = split; if ($changetype eq "delete") { next; } # find the filename and pathlength of perforce depot path - up to "#" (version mark) my $len = rindex ($filespec, "#"); # find end of name. my $pathend = rindex ($filespec, "\/") + 1; my $filename = substr ($filespec, $pathend, $len-$pathend); my $path = substr ($filespec, 0, $pathend); # store this in a hash of "paths per filename" push ( @{$paths{$filename}}, $path); } } # Long-winded bit. # Diff all files against all other files of the same name. # report the differing files. foreach $filename (sort keys %paths) { while ( $#{$paths{$filename}} > 0) { my $x = $#{$paths{$filename}}; my @results = `p4 diff2 ${$paths{$filename}}[$x]$filename ${$paths{$filename}}[$x-1]$filename\n`; my @line = split (/\s+/,$results[0]); if ($line[$#line] ne "identical") { print $results[0]; } $#{$paths{$filename}} -= 1; } } #print @filelist;