2 ################################################################################
5 # Description: This script will produce listing of the delta between two
7 # Author: Andrew@DeFaria.com
8 # Created: Thu May 23 13:41:05 2002
12 # (c) Copyright 2002, Salira Optical Network Systems, all rights reserved.
14 ################################################################################
15 $me = substr ($0, rindex ($0, "/") + 1);
17 # The view and vob to perform the work in.
18 $view='\\\\sons-clearcase\views\official';
22 print "Usage: $me: [-g] <label 1> <label 2>\n";
24 print "\n\t-g\t\tGenerate lists - otherwise <label 1>.list and\n";
25 print "\t\t\t<label 2>.list files in the current directory are\n";
26 print "\t\t\tsearched. If the file is not found then a list file\n";
27 print "\t\t\tis generated.\n";
28 print "\t<label 1>\tClearcase label to compare from\n";
29 print "\t<label 2>\tClearcase label to compare to\n";
34 # This subroutine will simply produce a file listing all Clearcase elements
35 # elements into a file.
38 # Produce listing into array
39 print "Producing a list of elements labeled $label...\n";
40 `cleartool find -all -version "lbtype($label)" -print > $cwd/$label.list`;
44 # This subroutine merely prints the array passed to it.
51 # This subroutine checks to see if the label passed is a Clearcase label.
54 return system ("cleartool lstype lbtype:$label > /dev/null 2>&1");
58 # This subrourtine produces a list of all files labeled by each label. This
59 # lists are placed into arrays and saved as files for future runs.
61 ProduceListFile ($lab1);
62 ProduceListFile ($lab2);
64 if (! -f "$cwd/$lab1.list") {
65 ProduceListFile ($lab1);
67 if (! -f "$cwd/$lab2.list") {
68 ProduceListFile ($lab2);
72 # Load up arrays from listing files
73 open (LAB1OUT, "<$cwd/$lab1.list") || die "Unable to open $cwd/$lab1.list\n";
76 open (LAB2OUT, "<$cwd/$lab2.list") || die "Unable to open $cwd/$lab2.list\n";
79 # Now ensure their in sorted order
80 @lab1out = sort (@lab1out);
81 @lab2out = sort (@lab2out);
85 # This subroutine will process the two list arrays producing the report.
86 # Now enter a loop comparing items
87 $lab1line = shift (@lab1out);
88 $lab2line = shift (@lab2out);
90 if (!$lab1line && !$lab2line) {
91 print "$me: Warning: No elements found for either label $lab1 nor $lab2\n";
92 print "Nothing to compare!\n";
97 print "$me: Warning: No elements found for label $lab1\n";
102 print "$me: Warning: No elements found for label $lab2\n";
106 while ($lab1line && $lab2line) {
107 # Extract versions and elements
108 $version_start = rindex ($lab1line, "@") + 1;
109 $version1 = substr ($lab1line, $version_start);
110 $element1 = substr ($lab1line, 0, $version_start - 2);
111 $version_start = rindex ($lab2line, "@") + 1;
112 $version2 = substr ($lab2line, $version_start);
113 $element2 = substr ($lab2line, 0, $version_start - 2);
115 # Change "\"'s to "/"'s
116 $element1 =~ s/\\/\//g;
117 $version1 =~ s/\\/\//g;
118 $element2 =~ s/\\/\//g;
119 $version2 =~ s/\\/\//g;
121 # Remove leading vob pathname
122 $element1 =~ s/$vob\///;
123 $element2 =~ s/$vob\///;
125 # Remove trailing carriage return and linefeed
126 chop ($version1); chop ($version1);
127 chop ($version2); chop ($version2);
129 # Compare element names
130 if ($element1 eq $element2) {
131 # Element has both labels
132 if ($version1 ne $version2) {
133 # Element has different version
134 push (@diffs, "$element1 $version1 -> $version2");
137 # Get next element/version
138 $lab1line = shift (@lab1out);
139 $lab2line = shift (@lab2out);
141 # Elements names are different
143 # Element 1 is blank indicating there are no items in lab1out array
144 # Push all of element 2
145 push (@lab2only, $element2 . " " . $version2);
146 $lab2line = shift (@lab2out);
147 } elsif (!$element2) {
148 # Element 2 is blank indicating there are no items in lab1out array
149 # Push all of element 1
150 push (@lab1only, $element1 . " " . $version1);
151 $lab1line = shift (@lab1out);
152 } elsif ($element1 lt $element2) {
153 # Element 1 is less so get next element 1
154 push (@lab1only, $element1 . " " . $version1);
155 $lab1line = shift (@lab1out);
157 # Element 2 is less so get next element 2
158 push (@lab2only, $element2 . " " . $version2);
159 $lab2line = shift (@lab2out);
164 # Output comparison listing
165 print "Comparison of $lab1 -> $lab2\n";
168 $nbrelements = $#diffs + 1;
169 if ($nbrelements eq 1) {
170 print "\nThe following $nbrelements element have both labels:\n\n";
172 print "\nThe following $nbrelements elements have both labels:\n\n";
177 if ($#lab1only ne -1) {
178 $nbrelements = $#lab1only + 1;
179 if ($nbrelements eq 1) {
180 print "\nThe following element only has the $lab1 label:\n\n";
182 print "\nThe following $nbrelements elements only have the $lab1 label:\n\n";
184 PrintArray (@lab1only);
187 if ($#lab2only ne -1) {
188 $nbrelements = $#lab2only + 1;
189 if ($nbrelements eq 1) {
190 print "\nThe following element only has the $lab2 label:\n\n";
192 print "\nThe following $nbrelements elements only have the $lab2 label:\n\n";
194 PrintArray (@lab2only);
199 if ($ARGV[0] eq "-g") {
206 usage if $ARGV [0] eq "" || $ARGV [1] eq "";;
213 chdir ($vob) or die "Unable to chdir to $vob\n";
215 if (CheckLabel ($lab1)) {
216 print "$me: Error: $lab1 is not a label\n";
220 if (CheckLabel ($lab2)) {
221 print "$me: Error: $lab2 is not a label\n";
225 # Change backslashes to slashes as perl seems to have oddities with