Removed /usr/local from CDPATH
[clearscm.git] / cc / diffbl.pl
1 #!ccperl
2
3 =pod
4
5 =head1 NAME $RCSfile: diffbl.pl,v $
6
7 GUI DiffBL
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.7 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/08/31 21:57:06 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage cqperl diffbl.pl: [-u|sage] [-v|erbose] [-d|ebug]
34                          [-[baseline1|bl1] <bl1>]
35                          [-[baseline2|bl2] <bl2>]
36                          [-p|vob <pvob>]
37
38  Where:
39    -u|sage:      Displays usage
40    -ve|rbose:    Be verbose
41    -d|ebug:      Output debug messages
42    -bl1 <bl1>    Full baseline 1 to use in the comparison
43    -bl2 <bl2>    Full baseline 2 to use in the comparison
44    -p|vob <pvob> Pvob to use
45
46 =head2 DESCRIPTION
47
48 This script provides a Perl/Tk GUI application to compare baselines. It provides
49 several benefits over IBM/Rational's graphical diffbl (cleartool diffbl -g ...).
50 First, it assists you in finding baselines to compare whereas diffbl -g requires
51 that you find the baselines yourself. When diffbl.pl is run you are presented
52 with a GUI that you can use to find baselines by either using the dropdown to
53 select pvobs, streams and ultimately baselines. You can also simply type part
54 the name and diffbl.pl will narrow down the list of pvobs, streams or baselines
55 in the drop down. This allows you to easily find the baselines you wish to
56 compare.
57
58 Additionally, IBM/Rational's diffbl -g -version often shows extremely long, but
59 technically accurate version extended pathnames where the user thinks more along
60 the lines of "path to element in a vob" only. diffbl.pl shows shorter, more
61 easily comprehenable pathnames. diffbl.pl also shows only the latest version of
62 the element. Thus if foo.c changed with version 3, 4 and 5 then you see just
63 foo.c and it represents foo.c version 5.
64
65 Finally, diffbl.pl provides a way to save the list of elements that have changed
66 in a file.
67
68 diffbl.pl also provides right click menu options to easily show the elements
69 properties, compare to previous, show the version tree and history of the
70 element.
71
72 =cut
73
74 use strict;
75 use warnings;
76
77 use FindBin;
78 use Cwd;
79 use Getopt::Long;
80
81 use lib "$FindBin::Bin/../CCDB/lib", "$FindBin::Bin/../lib";
82
83 use DiffBLUI;
84 use Display;
85 use Utils;
86 use OSDep;
87
88 use Clearcase;
89 use Clearcase::View;
90
91 $DiffBLUI::SELECTED{pvob} = $ENV{pvob} 
92                           ? Clearcase::vobname ($ENV{pvob})
93                           : '8800_projects';
94
95 our $view;
96 my $currentStream;
97
98 my ($bl1, $bl2);
99
100 END {
101   $view->remove
102     if $view;
103 } # END
104
105 # Should this be moved to Clearcase.pm?
106 sub ccerror ($$@) {
107   my ($msg, $status, @output) = @_;
108
109   Tkerror join ("\n", "$msg (Status: $status)", "\n", @output);
110
111   exit $status;
112 } # ccerror
113
114 sub mkview () {
115   my $user  = $ARCH eq 'windows' ? $ENV{USERNAME} : $ENV{USER};
116
117   my $viewname = "${user}_$FindBin::Script";
118
119   Tkmsg "Creating a view to work in", -1;
120
121   my $newView = Clearcase::View->new ($viewname);
122
123   # If the streams have changed then we need to recreate the view.
124   $currentStream ||= $DiffBLUI::SELECTED{stream};
125
126   if ($currentStream ne $DiffBLUI::SELECTED{stream}) {
127     $newView->remove;
128     $currentStream = $DiffBLUI::SELECTED{stream};
129   } # if
130
131   # The create method needs to support additional parameters such as -stream so
132   # we have to do this by hand right now...
133   my ($status, @output) = 
134     $Clearcase::CC->execute (
135       "mkview -tag $viewname -stream $DiffBLUI::SELECTED{stream}\@" .
136       "$Clearcase::VOBTAG_PREFIX$DiffBLUI::SELECTED{pvob} -stgloc -auto"
137     );
138
139   unless (grep {/already exists/} @output) {
140     if ($status) {
141       ccerror ("Unable to create view $viewname", $status, @output);
142     } # if
143   } # unless
144
145   $newView->updateViewInfo;
146
147   # Start the view
148   ($status, @output) = $newView->start;
149
150   ccerror ('Unable startview ' . $newView->tag, $status, @output)
151     if $status;
152
153   Tkmsg 'Done';
154
155   return $newView;
156 } # mkview
157
158 sub compareBaselines () {
159   unless ($DiffBLUI::SELECTED{pvob}) {
160     Tkerror 'Project Vob must be selected';
161     return;
162   } # unless
163
164   unless ($DiffBLUI::SELECTED{fromBaseline}) {
165     Tkerror 'From baseline must be selected';
166     return;
167   } # unless
168
169   unless ($DiffBLUI::SELECTED{toBaseline}) {
170     Tkerror 'To baseline must be selected';
171     return;
172   } # unless
173
174   DiffBLUI::busy;
175   
176   if ($DiffBLUI::MODE eq 'versions') {
177     $DiffBLUI::integrationActivitiesCheck->configure (-state => 'disable');
178   } else {
179     $DiffBLUI::integrationActivitiesCheck->configure (-state => 'normal');
180   }
181   
182   # Create a view to work in.
183   $view = mkview;
184
185   # Get into the view context 
186   my $view_context = $Clearcase::VIEWTAG_PREFIX . '/' . $view->tag;
187   my $cwd          = getcwd;
188
189   # For my Cygwin environment - translate that path back into a Windows path
190   if ($ARCH eq 'cygwin') {
191     my @cwd = `cygpath -w $cwd`;
192     chomp @cwd;
193
194     $cwd = $cwd[0];
195   } # if
196
197   my ($status, @output) = $Clearcase::CC->execute ("cd \"$view_context\"");
198
199   ccerror "Unable to set view context to $view_context", $status, @output
200     if $status;
201
202   Tkmsg 'Comparing baselines (This may take a while)', -1;
203   
204   %DiffBLUI::LINES= ();
205
206   my $cmd  = "diffbl -$DiffBLUI::MODE ";
207      $cmd .= $DiffBLUI::SELECTED{fromBaseline};
208      $cmd .= "\@$Clearcase::VOBTAG_PREFIX$DiffBLUI::SELECTED{pvob} "; 
209      $cmd .= $DiffBLUI::SELECTED{toBaseline};
210      $cmd .= "\@$Clearcase::VOBTAG_PREFIX$DiffBLUI::SELECTED{pvob}";
211
212   ($status, @output) = $Clearcase::CC->execute ($cmd);
213
214   ccerror "Unable to perform command $cmd", $status, @output
215     if $status;
216
217   Tkmsg 'Done';
218   
219   my $viewtag = $Clearcase::VIEWTAG_PREFIX . '/' . $view->tag;
220
221   foreach (@output) {
222     # Skip lines that don't have either <<, >>, <- or -> at the beginning
223     next unless /^(\<\-|\>\>|\<\<|\-\>)\s/;
224
225     if ($DiffBLUI::MODE eq 'activities') {
226       if (/\W+\s+(.*)\@/) {
227         $DiffBLUI::LINES{$1} = $1;
228       } # if
229     } else {
230       # Change those silly '\'s -> '/'s 
231       s/\\/\//g;
232   
233       # Extract the pathname and strip off the version. Note we use a hash here
234       # to get uniqueness based on the element name and only store the last 
235       # version checked in. It is very possible, for example, that there is foo
236       # versions 1, 2 and 3 but we want to more simply just report that foo 
237       # changed - not that foo changed 3 times.
238       if (/\W+\s+(.*)$Clearcase::SFX/) {
239         my $elementName = $1;
240
241         # Remove view path and tagname from $elementName
242         $elementName =~ s/$viewtag//;
243
244         $DiffBLUI::LINES{$elementName} = $elementName;
245       } # if
246     } # if
247   } # foreach
248
249   ($status, @output) = $Clearcase::CC->execute ("cd \"$cwd\"");
250
251   ccerror "Unable to set view context to $cwd", $status, @output
252     if $status;
253
254   displayLines;
255   
256   DiffBLUI::unbusy;
257
258   Tkmsg 'Done', 1;
259   
260   return;
261 } # compareBaselines
262
263 # Main
264 GetOptions (
265   'usage'           => sub { Usage },
266   'verbose'         => sub { set_verbose },
267   'debug'           => sub { set_debug },
268   'baseline1|bl1=s' => \$bl1,
269   'baseline2|bl2=s' => \$bl2,
270   'pvob=s'          => \$DiffBLUI::SELECTED{pvob},
271 ) or Usage "Invalid parameter";
272
273 createUI;
274
275 =pod
276
277 =head1 CONFIGURATION AND ENVIRONMENT
278
279 DEBUG: If set then $debug is set to this level.
280
281 VERBOSE: If set then $verbose is set to this level.
282
283 TRACE: If set then $trace is set to this level.
284
285 =head1 DEPENDENCIES
286
287 =head2 Perl Modules
288
289 L<Cwd>
290
291 L<FindBin>
292
293 L<Getopt::Long|Getopt::Long>
294
295 =head2 ClearSCM Perl Modules
296
297 =begin man 
298
299  Clearcase
300  Clearcase::View
301  DiffBLUI
302  Display
303  OSDep
304  Utils
305
306 =end man
307
308 =begin html
309
310 <blockquote>
311 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a><br>
312 <a href="http://clearscm.com/php/scm_man.php?file=lib/Clearcase/View.pm">Clearcase::View</a><br>
313 <a href="http://clearscm.com/php/scm_man.php?file=cc/DiffBLUI.pm">DiffBLUI</a><br>
314 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
315 <a href="http://clearscm.com/php/scm_man.php?file=lib/OSDep.pm">OSDep</a><br>
316 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
317 </blockquote>
318
319 =end html
320
321 =head1 BUGS AND LIMITATIONS
322
323 There are no known bugs in this script
324
325 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
326
327 =head1 LICENSE AND COPYRIGHT
328
329 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
330
331 =cut