2 ################################################################################
5 # Description: This script will produce listing of the delta between two
7 # Author: Andrew@DeFaria.com
8 # Created: Wed Apr 2 15:21:21 PST 2003
12 # (c) Copyright 2003, Salira Optical Network Systems, all rights reserved.
14 ################################################################################
17 my $me = substr ($0, rindex ($0, "/") + 1);
18 my (@view1out, @view2out);
20 my ($view1_tag, $view2_tag);
25 print "Usage: $me: [-g] <view 1> <view 2>\n";
27 print "\n\t-g\t\tGenerate lists - otherwise <view 1>.list and\n";
28 print "\t\t\t<view 2>.list files in the current directory are\n";
29 print "\t\t\tsearched. If the file is not found then a list file\n";
30 print "\t\t\tis generated.\n";
31 print "\t<view 1>\tClearcase view to compare from\n";
32 print "\t<view 2>\tClearcase view to compare to\n";
37 # This subroutine will simply produce a file listing all Clearcase elements
38 # elements into a file.
42 chdir $view or die "Unable to change directory to $view\n";
44 # Produce listing into array
45 print "Producing a list of elements in view $view_tag...\n";
46 `cleartool ls -recurse -short -visible -vob_only salira > $cwd/$view_tag.list`;
50 # This subroutine merely prints the array passed to it.
57 # This subroutine checks to see if the view passed is a Clearcase view.
71 # This subrourtine produces a list of all elements in the view. These
72 # lists are placed into arrays and saved as files for future runs.
74 ProduceListFile $view1, $view1_tag;
75 ProduceListFile $view2, $view2_tag;
77 if (! -f "$cwd/$view1_tag.list") {
78 ProduceListFile $view1, $view1_tag;
80 if (! -f "$cwd/$view2_tag.list") {
81 ProduceListFile $view2, $view2_tag;
85 # Load up arrays from listing files
86 open (VIEW1OUT, "<$cwd/$view1_tag.list") || die "Unable to open $cwd/$view1_tag.list\n";
87 open (VIEW2OUT, "<$cwd/$view2_tag.list") || die "Unable to open $cwd/$view2_tag.list\n";
88 @view1out = <VIEW1OUT>;
89 @view2out = <VIEW2OUT>;
91 # Now ensure their in sorted order
92 @view1out = sort (@view1out);
93 @view2out = sort (@view2out);
97 # This subroutine will process the two list arrays producing the report.
98 # Now enter a loop comparing items
99 my $view1line = shift (@view1out);
100 my $view2line = shift (@view2out);
102 my (@diffs, @view1only, @view2only);
105 if (!$view1line && !$view2line) {
106 print "$me: Warning: No elements found for either view $view1_tag nor $view2_tag\n";
107 print "Nothing to compare!\n";
112 print "$me: Warning: No elements found for view $view1_tag\n";
117 print "$me: Warning: No elements found for view $view2_tag\n";
121 while ($view1line && $view2line) {
122 # Extract versions and elements
123 my $version_start = rindex ($view1line, "@") + 1;
124 my $version1 = substr ($view1line, $version_start);
125 my $element1 = substr ($view1line, 0, $version_start - 2);
126 my $version_start = rindex ($view2line, "@") + 1;
127 my $version2 = substr ($view2line, $version_start);
128 my $element2 = substr ($view2line, 0, $version_start - 2);
130 # Change "\"'s to "/"'s
131 $element1 =~ s/\\/\//g;
132 $version1 =~ s/\\/\//g;
133 $element2 =~ s/\\/\//g;
134 $version2 =~ s/\\/\//g;
136 # Remove leading vob pathname
137 #$element1 =~ s/$vob\///;
138 #$element2 =~ s/$vob\///;
140 # Remove trailing carriage return and linefeed
141 chop ($version1); chop ($version1);
142 chop ($version2); chop ($version2);
144 # Compare element names
145 if ($element1 eq $element2) {
146 # Element is the same
147 if ($version1 ne $version2) {
148 # Element has different version
149 push (@diffs, "$element1 $version1 -> $version2");
152 # Get next element/version
153 $view1line = shift (@view1out);
154 $view2line = shift (@view2out);
156 # Elements names are different
158 # Element 1 is blank indicating there are no items in view1out array
159 # Push all of element 2
160 push (@view2only, $element2 . " " . $version2);
161 $view2line = shift (@view2out);
162 } elsif (!$element2) {
163 # Element 2 is blank indicating there are no items in view1out array
164 # Push all of element 1
165 push (@view1only, $element1 . " " . $version1);
166 $view1line = shift (@view1out);
167 } elsif ($element1 lt $element2) {
168 # Element 1 is less so get next element 1
169 push (@view1only, $element1 . " " . $version1);
170 $view1line = shift (@view1out);
172 # Element 2 is less so get next element 2
173 push (@view2only, $element2 . " " . $version2);
174 $view2line = shift (@view2out);
179 # Output comparison listing
180 print "Comparison of $view1_tag -> $view2_tag\n";
183 $nbrelements = $#diffs + 1;
184 if ($nbrelements eq 1) {
185 print "\nThe following $nbrelements element appears in only one view:\n\n";
187 print "\nThe following $nbrelements elements appear in both views:\n\n";
192 if ($#view1only ne -1) {
193 $nbrelements = $#view1only + 1;
194 if ($nbrelements eq 1) {
195 print "\nThe following element only appears in the view $view1_tag:\n\n";
197 print "\nThe following $nbrelements elements only appear in the view $view1_tag:\n\n";
199 PrintArray (@view1only);
202 if ($#view2only ne -1) {
203 $nbrelements = $#view2only + 1;
204 if ($nbrelements eq 1) {
205 print "\nThe following element only appear in the view $view2_tag:\n\n";
207 print "\nThe following $nbrelements elements only appear in the view $view2_tag:\n\n";
209 PrintArray (@view2only);
214 if ($ARGV[0] eq "-g") {
221 usage if $ARGV [0] eq "" || $ARGV [1] eq "";;
226 $view1_tag = substr ($view1, rindex ($view1, "/") + 1);
227 $view2_tag = substr ($view2, rindex ($view2, "/") + 1);
229 if (CheckView ($view1)) {
230 print "$me: Error: $view1 is not a view\n";
234 if (CheckView ($view2)) {
235 print "$me: Error: $view2 is not a view\n";
239 ProduceLists $view1, $view2;