#!/usr/local/bin/perl -w # # This script maps files that have been integrated into their destinations. # It is primarily useful for finding files that have been renamed. # # This tool works as follows: # 1. Expand the argument filespecs into files. # 2. For each file, find everywhere it has been branched into. # 3. Iteratively follow branches from those files, until leaves are # reached. # 4. Filter that list (including the original file) for not being deleted, # and being in the same tree as the current directory. # # Script assumes Perforce is already set up. $Usage = < 1); # Prevent loops while($f = shift @candidates) { if(($PrintDeleted || &stillExists($f)) && ($PrintAll || $f =~ m{^$Root})) { &inform(" Result: $f"); push @outputFiles, $f; } foreach $child (&findChildren($f)) { if(!defined($checkedFiles{$child})) { &inform(" Found child $child"); push @candidates, $child; $checkedFiles{$child} = 1 } } } print "$file -> ", join(" ", sort @outputFiles), "\n"; } sub findChildren { my ($file) = @_; my @results = (); open P4, "p4 filelog $file | grep '^\.\.\. \.\.\. branch into' | cut -f5 -d' ' | cut -f1 -d# |" || die "Can't call p4 filelog $file"; while() { chomp; push @results, $_; } close P4; return @results; } sub stillExists { my ($file) = @_; my $status = qx/p4 files $file/; return $status !~ / - delete /; } sub expandFilespec { my($filespec) = @_; my @results; open P4, "p4 files $filespec | cut -f1 -d# |" || die "Can't call p4 files $filespec"; while() { chomp; push @results, $_; } close P4; return @results; } sub error { my($message) = @_; print STDERR "ERROR: $message\n\n$Usage"; exit 1; } sub inform { my($message) = @_; if($Verbose) { print STDERR "> $message\n"; } }