Merge branch 'master' of https://Governor-Tarkin@bitbucket.org/Governor-Tarkin/swg...
[swg-src.git] / tools / p4consistency.pl
blobb577afeff2bdc82b905757ee9dca09402843e86d
1 #! /usr/bin/perl
3 use strict;
4 use warnings;
6 # ======================================================================
8 sub usage
10 die "usage: $0 [--fast] [--quiet] directory ...\n" .
11 "\t--fast = do not compare file contents\n" .
12 "\t--quiet = do not display identical files\n";
15 # ----------------------------------------------------------------------
17 sub findFiles
19 local $_;
21 my @paths = @_;
22 my @localfiles;
24 while (@paths)
26 my $path = shift(@paths);
27 opendir(DIR, $path) || die "could not open dir $path";
28 while ($_ = readdir(DIR))
30 next if ($_ eq "." || $_ eq "..");
32 my $new = $path . "/" . $_;
33 $new =~ s%\\%/%g;
34 $new =~ s%//%/%g;
36 if (-d $new)
38 push(@paths, $new);
40 else
42 push (@localfiles, $new);
45 closedir(DIR);
48 return @localfiles;
51 # ======================================================================
53 my $quiet = 0;
54 my $fast = 0;
56 # ======================================================================
58 # process command line
59 while (@ARGV && $ARGV[0] =~ /^-/)
61 my $arg = shift;
63 if ($arg eq "--quiet")
65 $quiet = 1;
67 elsif ($arg eq "--fast")
69 $fast = 1;
71 else
73 usage();
76 usage() if (@ARGV == 0);
78 while (@ARGV)
80 my %files;
82 # get the perforce locations for what was specified
83 open(P4, "p4 where " . (shift @ARGV) . " |");
84 $_ = <P4>;
85 chomp;
86 my ($depot, $client, $local) = split(/ /, $_, 3);
87 close(P4);
89 # find all the local files
90 $local =~ s%\\%\/%g;
91 $local =~ s%\/\.\.\.$%%;
92 foreach (findFiles($local))
94 $files{$_} = "extra";
97 if ($fast)
99 # fast mode doesn't compare the contentes
100 open(P4, "p4 fstat $client#have |") || die "$0: Can't open p4: $!\n";
102 my $file;
103 my $action;
105 while (<P4>)
107 chomp;
108 if (/^\s*$/)
110 if (defined($file) && defined($action))
112 if ($action ne "delete")
114 if (defined $files{$file})
116 # if we already knew about the file, then mark it as being in both places
117 $files{$file} = "both";
119 else
121 # if we didn't know about the file, then it's missing
122 $files{$file} = "missing";
126 undef $file;
127 undef $action;
130 else
132 if (s%^\.\.\. clientFile %%)
134 s%\\%\/%g;
135 $file = $_;
137 elsif (s%^\.\.\. headAction %%)
139 $action = $_;
143 close(P4)
145 else
147 # diff is more authoritative than the file search, but we'll still keep the extra files
148 open(P4, "p4 diff -sl $client |") || die "$0: Can't open p4: $!\n";
149 while (<P4>)
151 chomp;
152 my ($status, $file) = split(/ /, $_, 2);
153 $file =~ s%\\%/%g;
154 $files{$file} = $status;
156 close(P4);
159 foreach (sort keys %files)
161 my $status = $files{$_};
162 print "$status $_\n" if (!$quiet || ($status ne "same" && $status ne "both"));