Subversion Repositories DevTools

Rev

Rev 7213 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
383 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
383 dpurdie 3
#
4
# Module name   : jats_vcsdiff.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Create two views and DIFF them
10
#                 The views can be any type understood by JATS
11
#                 Can:
12
#                   - Compare with MD5SUms
13
#                   - Invoke BeyondCompare
14
#
15
#......................................................................#
16
 
17
require 5.008_002;
18
use strict;
19
use warnings;
20
 
21
use Pod::Usage;
22
use Getopt::Long;
23
 
24
use JatsError;
25
use JatsSystem;
7213 dpurdie 26
use JatsRmApi;
27
use DBI;
383 dpurdie 28
use FileUtils;
29
use Cwd;
30
 
31
my $VERSION = "1.0.0";                      # Update this
32
 
33
#
34
#   Options
35
#
36
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
37
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
38
my $opt_help = 0;
39
my $opt_new_label;
40
my $opt_old_label;
41
my $opt_md5check;
42
my $opt_mode;
2931 dpurdie 43
my $opt_diff;
7213 dpurdie 44
my $opt_rtag_id;
45
my $opt_package_name;
6085 dpurdie 46
my @opt_options;
7214 dpurdie 47
my $opt_patch;
383 dpurdie 48
 
49
#
50
#   Globals - Provided by the JATS environment
51
#
52
my $USER            = $ENV{'USER'};
53
my $UNIX            = $ENV{'GBE_UNIX'};
54
my $TMP             = $UNIX ? "/tmp" : $ENV{'TMP'};
55
my $MACHINENAME     = $ENV{'GBE_HOSTNAME'};
56
 
57
#
58
#   Globals
59
#
2931 dpurdie 60
my $Name            = 'BeyondCompare';
3967 dpurdie 61
my $DiffProg;
2931 dpurdie 62
my @DiffArgs;
63
my $DiffWait;
383 dpurdie 64
my @view_tags;
65
my @view_commands;
66
my @cleanFiles;
67
 
7213 dpurdie 68
my $RM_DB;                      # Database interface
69
my $package_name;               # Selected package name.
70
my $package_ver;                # Selected package version.
71
my $package_vcs;                # Selected package VCS tag.
72
my $package_vcs_base;           # Selected package base path.
73
my $package_release_branch;     # Selected package release branch or nul if released on trunk.
383 dpurdie 74
 
7213 dpurdie 75
 
383 dpurdie 76
#-------------------------------------------------------------------------------
77
# Function        : Mainline Entry Point
78
#
79
# Description     :
80
#
81
# Inputs          :
82
#
83
 
84
#
85
#   Parse the user options
86
#
87
my $result = GetOptions (
7213 dpurdie 88
                'help|h:+'          => \$opt_help,              # Help Level
89
                'manual:3'          => \$opt_help,              # Help Level
90
                "verbose:+"         => \$opt_verbose,           # Verbosity
91
                "debug:+"           => \$opt_debug,             # Debug Verbosity
92
                "new=s"             => \$opt_new_label,         # Path1
93
                "old=s"             => \$opt_old_label,         # Path2
94
                'check'             => \$opt_md5check,          # Force MD5 Check
95
                'diff!'             => \$opt_diff,              # Force use of diff
96
                "rtagid|rtag_id=s"  => \$opt_rtag_id,           # Release tag needed for release extractions
97
                "package=s"         => \$opt_package_name,      # Name of the package to query
98
                'option=s'          => \@opt_options,           # User options
7214 dpurdie 99
                'patch:s'           => \$opt_patch,             # Generate a patch file ( for FeCru )
383 dpurdie 100
                );
101
 
102
                #
103
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
104
                #
105
 
106
#
107
#   Process help and manual options
108
#
109
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result );
110
pod2usage(-verbose => 1)  if ($opt_help == 2 );
7213 dpurdie 111
pod2usage(-verbose => 2)  if ($opt_help > 2 );
383 dpurdie 112
 
113
InitFileUtils();
114
 
115
#
116
#   Configure the error reporting process now that we have the user options
117
#
118
ErrorConfig( 'name'    => 'VCSDIFF',
119
             'verbose' => $opt_verbose,
120
             'debug'   => $opt_debug );
121
 
7214 dpurdie 122
#
123
#   Sanity testing of user options
124
#   
2931 dpurdie 125
Error ("Options -check and -diff cannot be combined")
126
    if ( $opt_md5check && $opt_diff );
7214 dpurdie 127
Error ("Options -check and -patch cannot be combined")
128
    if ( $opt_md5check && defined($opt_patch) );
129
Error ("Options -diff and -patch cannot be combined")
130
    if ( $opt_diff && defined($opt_patch) );
2931 dpurdie 131
 
383 dpurdie 132
#
133
#   Determine mode
134
#   Not all modes work on all machines
135
#
136
Verbose ("Machine Type: UNIX=$UNIX");
137
if ( $opt_md5check )
138
{
139
    $opt_mode = 'md5';
140
}
7214 dpurdie 141
elsif ( $UNIX || $opt_diff || defined($opt_patch))
2931 dpurdie 142
{
143
    $opt_mode = 'diff';
144
    $Name = 'diff';
145
    push @DiffArgs, '-r';
146
    $Name = 'gdiff';
147
    $DiffProg = LocateProgInPath( $Name, '--All');
148
    unless ( $DiffProg =~ m~/~ )
149
    {
150
        $Name = 'diff';
151
        $DiffProg = LocateProgInPath( $Name, '--All');
7214 dpurdie 152
 
2931 dpurdie 153
    }
154
 
155
    Error ("Cannot locate a 'diff' utility in the users PATH")
156
        unless ( $DiffProg =~ m~/~ );
7214 dpurdie 157
    $DiffProg =~ tr~\\~/~;
2931 dpurdie 158
}
383 dpurdie 159
else
160
{
161
    $opt_mode = 'bc2';
2931 dpurdie 162
    $DiffWait = 1;
383 dpurdie 163
 
164
    #
3967 dpurdie 165
    #   Determine the path to Beyond Compare Exe
166
    #       It may not be installed in the default place, but the Windows
167
    #       registry will know where it is
383 dpurdie 168
    #
3967 dpurdie 169
    GetBeyondCompareExePath();
383 dpurdie 170
}
171
 
172
#
173
#   Validate user options
174
#
175
#   Be nice to the user
176
#   If we have two options and no labels, then assign them
177
#
178
if ( ! $opt_new_label && ! $opt_old_label )
179
{
180
    Error ("Must provide two labels on command line unless they are provided via -old and -new options")
181
         if ( $#ARGV < 1 );
182
 
183
    $opt_old_label = shift @ARGV;
184
    $opt_new_label = shift @ARGV;
185
}
186
 
187
Error ("Need two labels on the command line, or via options")
188
    unless ( $opt_old_label && $opt_new_label );
189
 
190
Error ("Too many command line arguments" )
191
    unless ( $#ARGV < 0 );
192
 
193
#
194
#   Extract parameters that will be used to create a view that is
195
#   unique. Will use hostname and user name
196
#
197
Error ("Machine Name not determined")
198
    unless ( $MACHINENAME );
199
 
200
Error ("USER name not determined" )
201
    unless ( $USER );
202
 
203
#
204
#   Need a TMP working directory
205
#   Used to create config files
206
#
207
Error ("TMP not found or not a directory")
208
    unless ( $TMP && -d $TMP );
209
$TMP = "$TMP/$$";
210
 
7214 dpurdie 211
#   Validate the users patch directory
212
if (defined($opt_patch))
213
{
214
    # Set deafult patch file name, if none is provided
215
    $opt_patch = 'vcsdiff.patch' if (length $opt_patch == 0);
216
    my $patchDir = StripFileExt($opt_patch);
217
    Error ("Directory does not exist: $patchDir") if length($patchDir) > 0;
218
    RmDirTree ($opt_patch);
219
}
220
 
383 dpurdie 221
#
7213 dpurdie 222
#   Translate special label names.
223
#
224
$opt_old_label = translateSpecialLabelName( "old", $opt_old_label );
225
$opt_new_label = translateSpecialLabelName( "new", $opt_new_label );
226
 
227
#
383 dpurdie 228
#   Create views for the two views
229
#   Verify that the view are present
230
#
231
Message ("Constructing views");
7213 dpurdie 232
Message ("  old = $opt_old_label" );
233
Message ("  new = $opt_new_label" );
383 dpurdie 234
my $path1 = create_view( $opt_old_label, 1 );
235
my $path2 = create_view( $opt_new_label, 2 );
236
 
237
Error ("Cannot locate view directory: $path1" ) unless (-d $path1);
238
Error ("Cannot locate view directory: $path2" ) unless (-d $path2);
239
 
240
#
241
#   If one of the paths is a dynamic view and the other is a local path
242
#   then attempt to locate the common directories
243
#
244
if ( $#view_tags == 0 )
245
{
246
    massage_paths();
247
}
248
 
249
if ( $opt_md5check )
250
{
251
    Verbose ("Performing MD5 Check");
252
    my $checkfile = 'vcsdiff_md5.txt';
253
    my $rv;
254
    push @cleanFiles, $checkfile;
255
    $rv = JatsTool ('jats_manifest', '-quiet',
256
                '-manifest', $checkfile,
257
                '-rootdir', $path1 );
258
 
259
    $rv = JatsTool ('jats_manifest', '-quiet', '-check',
260
                '-manifest', $checkfile,
261
                '-rootdir', $path2 ) unless $rv;
262
 
263
    exit $rv;
264
}
265
 
7214 dpurdie 266
if ( defined($opt_patch))
267
{
268
    Verbose ("Creating a Patch File");
269
    Verbose ("Diff Utility: $DiffProg");
270
    @DiffArgs = qw(-U10000 -uNr -x.svn -x.git);
271
    my $rv = System ( '--Shell', $DiffProg, @DiffArgs, split(/,/, join (',', @opt_options)), $path1, $path2, '>', $opt_patch );
272
 
273
    #
274
    #   Warn if the patch file cannot be found
275
    if ( -f $opt_patch) {
276
        Message("Created patch: $opt_patch");
277
    } else {
278
        Error ("Expected patch file not found : $opt_patch");
279
    }
280
    exit $rv;
281
}
282
 
2931 dpurdie 283
#
284
#   Diffing the paths
285
#   Will use BeyondCompare under Windows
286
#   Will use diff under unix
287
#
288
Message ("Using '$Name' to compare two views",
289
         "Wait for utility to exit so that we can delete the views" ) if ($DiffWait);
383 dpurdie 290
 
2931 dpurdie 291
Verbose ("Diff Utility: $DiffProg");
6085 dpurdie 292
System ( $DiffProg, @DiffArgs, split(/,/, join (',', @opt_options)), $path1, $path2 );
383 dpurdie 293
exit 0;
294
 
295
#-------------------------------------------------------------------------------
296
# Function        : create_view
297
#
298
# Description     : Create dynamic view, based on a Vcs Tag
299
#
300
# Inputs          : $vcstag
301
#
302
# Returns         : Path to the view
303
#
304
sub create_view
305
{
306
    my ($vcstag, $num) = @_;
307
 
308
    #
309
    #   Intercept and treat the special label 'current'
310
    #
311
    return create_path_view( $vcstag )
312
        if ( $vcstag eq 'current'  || $vcstag =~ m~^dir=.+~ || $vcstag =~ m~^current=.+~ );
313
 
314
    my $tag = "${USER}_${MACHINENAME}_vcsdiff_${num}";
315
    push @view_tags, $tag;
316
 
317
    #
318
    #   Use vcsrelease to do the hard work
319
    #
320
    my @command = ( 'jats_vcsrelease',
321
                        '-extractfiles',
322
                        '-root=.' ,
323
                        '-noprefix',
1403 dpurdie 324
                        '-devmode=escrow',
383 dpurdie 325
                        '-view', $tag ,
326
                        '-label', $vcstag,
327
                   );
328
    push @view_commands, \@command;
329
 
330
    if ( $opt_debug && -d $tag )
331
    {
332
        Message ("Using existing view");
333
    }
334
    else
335
    {
336
        JatsTool( @command );
337
    }
338
 
339
    #
340
    #   Minor Kludge
341
    #       Should be in a library
342
    #   Iff CC::, then process path info too
343
    #
344
    if ( $vcstag =~ m~^CC::(.*?)(::(.+))?$~ )
345
    {
346
        my $path = $1;
347
        if ( $path )
348
        {
349
            my $try = $tag . '/' . $path;
350
            if ( -d  $try )
351
            {
352
                $tag = $try;
353
            }
354
        }
355
    }
356
 
357
    return $tag;
358
}
359
 
360
#-------------------------------------------------------------------------------
361
# Function        : create_path_view
362
#
363
# Description     : Not using a view, using a path
364
#                   Return the path as requested
365
#
366
# Inputs          : $label                  - with embedded path
367
#
368
# Returns         : Path to the (dummy) view
369
#
370
sub create_path_view
371
{
372
    my ($label) = @_;
373
    my $path  = '.';
374
 
375
    $path = $1
376
        if ( $label =~ m~.+=(.+)~ );
377
 
378
    Error ("Directory not found: $path" )
379
        unless ( -d $path );
380
 
381
    $path = FullPath( $path );
382
    return $path;
383
}
384
 
385
#-------------------------------------------------------------------------------
386
# Function        : massage_paths
387
#
388
# Description     : Used when one of the paths is a view and the the other
389
#                   is a local directory.
390
#
391
#                   Attempt to locate the common root
392
#
393
# Inputs          : None
394
#
395
# Returns         : Modifies $path1 and $path2
396
#
397
sub massage_paths
398
{
399
    my $view_path = $view_tags[0];
400
    my $user_path = $path1;
401
    $user_path = $path2 if ( $view_path eq $path1 );
402
 
403
    #
404
    #   Split the user path into its component directory entries
405
    #   Start at the top and look for one of these in the view
406
    #
407
    my @user_path = split ('/', $user_path );
7040 dpurdie 408
    shift @user_path if $user_path[0] eq '';
383 dpurdie 409
    my $tpath = '';
410
    foreach my $dir ( @user_path )
411
    {
412
        if ( -d "$view_path/$dir" )
413
        {
414
            #
415
            #   Common directory found
416
            #   Set the user path to the previous directory
417
            #
418
            $user_path = $tpath;
419
            if ( $view_path eq $path1   )
420
            {
421
                $path2 = $user_path;
422
            }
423
            else
424
            {
425
                $path1 = $user_path;
426
            }
427
 
428
            #
429
            #   now add the common part
430
            #
431
            $path1 .= "/$dir";
432
            $path2 .= "/$dir";
433
            Message ("Setting common root path ($dir)", $path1, $path2);
434
            last;
435
        }
436
        $tpath .= '/' if ( $tpath );
437
        $tpath .= $dir;
438
    }
439
}
440
 
441
#-------------------------------------------------------------------------------
3967 dpurdie 442
# Function        : GetBeyondCompareExePath
383 dpurdie 443
#
444
# Description     : Determine the path to the BeyondCompare executable
445
#                   by looking in the Windows Registry
446
#
447
# Inputs          : None
448
#
449
# Returns         : Path to an executable
450
#
451
 
3967 dpurdie 452
sub GetBeyondCompareExePath
383 dpurdie 453
{
454
    eval "require Win32::TieRegistry"
455
        or Error ("Win32::TieRegistry not available");
456
 
5264 dpurdie 457
    Win32::TieRegistry::import(qw( REG_SZ REG_EXPAND_SZ REG_DWORD REG_BINARY REG_MULTI_SZ KEY_READ KEY_WRITE KEY_ALL_ACCESS ));
458
 
459
    my $userKey= Win32::TieRegistry->new("CUser", {Access=>KEY_READ(),Delimiter=>"/"})
383 dpurdie 460
        or  Error( "Can't access HKEY_CURRENT_USER key: $^E" );
461
 
5264 dpurdie 462
    my $localKey= Win32::TieRegistry->new("LMachine", {Access=>KEY_READ(),Delimiter=>"/"})
5240 dpurdie 463
        or  Error( "Can't access HKEY_LOCAL_MACHINE key: $^E" );
464
 
465
    sub checkKeys
466
    {
467
        my ($userKey, $localKey, $key) = @_;
468
        my ($bcKey, $DiffProg);
5264 dpurdie 469
        $bcKey = $userKey->Open( $key );
5240 dpurdie 470
        if ($bcKey && ($DiffProg = $bcKey->GetValue( 'ExePath' )) )
471
        {
472
            return $DiffProg;
473
        }
5264 dpurdie 474
        $bcKey = $localKey->Open( $key );
5240 dpurdie 475
        if ($bcKey && ($DiffProg = $bcKey->GetValue( 'ExePath' )) )
476
        {
477
            return $DiffProg;
478
        }
479
        return undef;
480
    }
481
 
3967 dpurdie 482
    my $bcKey;
5240 dpurdie 483
    if ($DiffProg = checkKeys( $userKey, $localKey,"Software/Scooter Software/Beyond Compare 4" ))
3967 dpurdie 484
    {
5100 dpurdie 485
        Verbose("Using BC4");
486
        push @DiffArgs, '/solo';
487
    }
5240 dpurdie 488
    elsif ($DiffProg = checkKeys( $userKey, $localKey,"Software/Scooter Software/Beyond Compare 3"))
5100 dpurdie 489
    {
3967 dpurdie 490
        Verbose("Using BC3");
491
        push @DiffArgs, '/solo';
492
    }
5240 dpurdie 493
    elsif ($DiffProg = checkKeys( $userKey, $localKey,"Software/Scooter Software/Beyond Compare"))
3967 dpurdie 494
    {
495
        Verbose("Using BC2");
496
    }
497
    else
498
    {
5100 dpurdie 499
        Error "Can't access BC2, BC3 or BC4 Keys: $^E";
3967 dpurdie 500
    }
383 dpurdie 501
 
3967 dpurdie 502
    Error ("BeyondCompare program not found", "Prog: $DiffProg")
503
        unless ( -x $DiffProg );
383 dpurdie 504
}
505
 
506
#-------------------------------------------------------------------------------
7213 dpurdie 507
# Function        : findReleaseManagerPackage
508
#
509
# Description     : Find the package information by looking up its existing in 
510
#                   a given release.
511
#
512
# Inputs          : label_name
513
#                   label_value
514
#                   rtag_id
515
#                   package_name
516
#
517
# Returns         : 
518
#
519
sub findReleaseManagerPackage
520
{
521
    my ($label_name, $label_value) = @_;
522
    my (@row);
523
    my $found=0;
524
 
525
    if ( !$opt_rtag_id || !$opt_package_name )
526
    {
527
        Error( "Must specify -rtagid and -package options when the '$label_name' tag has the value '$label_value'" );
528
    }
529
 
530
    if ( !$package_vcs )
531
    {
532
 
533
        connectRM(\$RM_DB) unless ($RM_DB);
534
 
535
        # First get details from pv_id; split the package version and extension.
536
        my $pkg_ext;
537
        my $pkg_name;
538
        if ( $opt_package_name =~ m/(.*)\.(\w*)$/ )
539
        {
540
            $pkg_name = $1;
541
            $pkg_ext = $2;
542
        }
543
        else
544
        {
545
            $pkg_name = $opt_package_name;
546
        }
547
 
548
        my $m_sqlstr = "SELECT pv.PV_ID, pv.PKG_VERSION, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID)".
549
                       " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
550
                       " WHERE rc.RTAG_ID = $opt_rtag_id AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID AND pkg.PKG_NAME = '$pkg_name'";
551
        if ( $pkg_ext )
552
        {
553
            $m_sqlstr .= " AND pv.V_EXT='.$pkg_ext'";
554
        }
555
        Verbose2( $m_sqlstr );
556
        my $sth = $RM_DB->prepare($m_sqlstr);
557
        if ( defined($sth) )
558
        {
559
            if ( $sth->execute( ) )
560
            {
561
                if ( $sth->rows )
562
                {
563
                    while ( @row = $sth->fetchrow_array )
564
                    {
565
                        my $pv_id = $row[0];
566
                        my $ver = $row[1];
567
                        my $vcs = $row[2];
568
 
569
                        Verbose( "findReleaseManagerPackage: [$opt_rtag_id, $opt_package_name] ==> [ $pv_id, $ver, $vcs]" );
570
 
571
                        $package_name = $opt_package_name;
572
                        $package_ver  = $ver;
573
                        $package_vcs  = $vcs;
574
 
575
                        # Most packages are released of trunk...
576
                        my $match = '^(SVN::.*)\/trunk::.*$';
577
                        if ( $package_vcs =~ m/$match/ )
578
                        {
579
                            $package_vcs_base = $1;
580
                            Verbose( "findReleaseManagerPackage: base on trunk ==> $package_vcs_base" );
581
                        }
582
                        else
583
                        {
584
                            # ...but some are released of branches.
585
                            $match = '^(SVN::.*)\/branches\/([^:]+)::.*$';
586
                            if ( $package_vcs =~ m/$match/ )
587
                            {
588
                                $package_vcs_base = $1;
589
                                $package_release_branch = $2;
590
                                Verbose( "findReleaseManagerPackage: base on branch $package_release_branch ==> $package_vcs_base" );
591
                            }
592
                            else
593
                            {
594
                                Error ( "Unable to determine base path from VCS: $package_vcs" );
595
                            }
596
                        }
597
                        $found++;
598
                    }
599
                }
600
                $sth->finish();
601
            }
602
        }
603
        else
604
        {
605
            Error( "findReleaseManagerPackage:Prepare failure" );
606
        }
607
 
608
        if ( $found == 0 )
609
        {
610
            Error( "No package named $opt_package_name found in the release with rtag ID $opt_rtag_id" );
611
        }
612
        elsif ( $found > 1 )
613
        {
614
            Error( "Multiple packages named $opt_package_name found in the release with rtag ID $opt_rtag_id" );
615
        }
616
    }
617
}
618
 
619
#-------------------------------------------------------------------------------
620
# Function        : translateSpecialLabelName
621
#
622
# Description     : Translates the name of a label (-old or -new argument) 
623
#                   if it is one of the special values.
624
#
625
# Inputs          : label_name
626
#                   label_value
627
#
628
# Returns         : new label_value
629
#
630
sub translateSpecialLabelName
631
{
632
    my ($label_name, $label_value) = @_;
633
 
634
    if ( $label_value eq "released" )
635
    {
636
        #
637
        #   Get the exact version released in Release Manager.
638
        #
639
        findReleaseManagerPackage( $label_name, $label_value );
640
        return $package_vcs;
641
    }
642
    elsif ( $label_value eq "head" )
643
    {
644
        #
645
        #   Get the 'head' of the released branch in release manager; this is the trunk
646
        #   if the package is released off trunk or a branch if the package is getting
647
        #   released from a branch in this release area.
648
        #
649
        findReleaseManagerPackage( $label_name, $label_value );
650
        if ( $package_release_branch )
651
        {
652
            return $package_vcs_base . '/branches/' . $package_release_branch;
653
        }
654
        else
655
        {
656
            return $package_vcs_base . '/trunk'
657
        }
658
    }
659
    elsif ( $label_value =~ m/^branch=(.*)/ )
660
    {
661
        #
662
        #   Get a named branch for this package.
663
        #
664
        my $branch_name = $1;
665
        findReleaseManagerPackage( $label_name, $label_value );
666
        return $package_vcs_base . '/branches/' . $branch_name;
667
    }
668
    elsif ( $label_value eq "trunk" )
669
    {
670
        #
671
        #   Get the true trunk of this package.
672
        #
673
        findReleaseManagerPackage( $label_name, $label_value );
674
        return $package_vcs_base . '/trunk';
675
    }
676
 
677
    return $label_value;
678
}
679
 
680
 
681
#-------------------------------------------------------------------------------
383 dpurdie 682
# Function        : END
683
#
684
# Description     : This function will be called as the program exits
685
#                   It will also be called under error conditions
686
#                   Close down stuff we created
687
#
688
# Inputs          : 
689
#
690
# Returns         : 
691
#
692
 
693
sub END
694
{
695
    my $exitCode = $?;
696
 
697
    if ( $opt_debug )
698
    {
699
        Message ("NOT Cleaning up views");
700
        return;
701
    }
702
 
703
    Message ("Cleaning up views") if @view_tags;
704
    foreach my $cmds ( @view_commands )
705
    {
706
        JatsTool( @{$cmds}, '-delete' );
707
    }
708
 
709
    foreach my $file ( @cleanFiles )
710
    {
711
        unlink $file;
712
    }
713
 
714
    #
715
    #   The exit code may get modified by the JatsTool
716
    #   Preserve any error indication
717
    #
718
    $? = $exitCode;
719
}
720
 
721
#-------------------------------------------------------------------------------
722
#   Documentation
723
#
724
 
725
=pod
726
 
727
=head1 NAME
728
 
729
jats_vcsdiff - Difference two views
730
 
731
=head1 SYNOPSIS
732
 
733
  jats vcsdiff [options] [old_label new_label]
734
 
735
 Options:
6085 dpurdie 736
    -help               - Brief help message
737
    -help -help         - Detailed help message
738
    -man                - Full documentation
739
    -check              - Perform MD5SUM over both views
7214 dpurdie 740
    -patch[=name]       - Create a patch file for the views
6085 dpurdie 741
    -[no]diff           - Force the use of a 'diff' utility
742
    -option=opt1,...    - Add user options to the command line
7213 dpurdie 743
    -old=tag            - Old VcsTag (or path or vcs keyword)
744
    -new=tag            - New VcsTag (or path or vcs keyword)
745
    -rtagid=xxx         - Specify the Release to process
746
    -package=xxx        - Specify the package to query from Release Manager
383 dpurdie 747
 
748
=head1 OPTIONS
749
 
750
=over 8
751
 
752
=item B<-help>
753
 
754
Print a brief help message and exits.
755
 
756
=item B<-help -help>
757
 
758
Print a detailed help message with an explanation for each option.
759
 
760
=item B<-man>
761
 
762
Prints the manual page and exits.
763
 
764
=item B<-check>
765
 
766
This option controls the mode in which the program will operate.
767
 
2931 dpurdie 768
If enabled the program will perform an MD5 Cheksum over the files in the first
383 dpurdie 769
view and compare that with files in the second view.
770
 
2931 dpurdie 771
This option cannot be used in conjunction with the '-diff' option'.
383 dpurdie 772
 
7214 dpurdie 773
=item B<-patch[=name]>
774
 
775
This option controls the mode in which the program will operate. If enabled the program
776
will generate a 'patch' file between the two views.
777
 
778
The patch file can be used to perform a 'Pre-commit' Code Review in tools such as Fisheye/Crucible.
779
 
780
If the name of the patch is not provided, the patch will be written to a faile called vcsdiff.patch otherwise
781
the user specified name will be used. The named patch can be created in a directory that exists.
782
 
783
The patch creation process will exclude directories called '.svn' and '.git'.
784
 
785
If using a development directory then it is recommended that all build files and artifactes be removed before the
786
patch is created. This can often be done with a 'jats clobber'.
787
 
2931 dpurdie 788
=item B<-diff>
789
 
790
This option controls the mode in which the program will operate.
791
 
792
By default the program is Operating System dependent. It will:
793
 
794
=over 4
795
 
796
=item * Windows - Use Beyond Compare
797
 
798
=item * Unix - Use gdiff or diff
799
 
800
=back
801
 
802
This option will force the use of a 'diff' utility on both Windows and
803
Unix.
804
 
805
This option cannot be used in conjunction with the '-check' option'.
806
 
6085 dpurdie 807
=item B<-option=opt1,..>
808
 
809
This option allows the user to modify the operation of the invoked diff program.
810
 
811
The options are passed directly to the diff utility invoved by the program. It is the users
812
responsibility to ensure that the options are valid.
813
 
814
This option may be used mutiple times, or options may be comma-seperated.
815
 
383 dpurdie 816
=item B<-old=tag>
817
 
818
This option specifies the old, or base, VcsTag for the difference report. This
819
tag is mandatory.
820
 
821
The old and new tags may be provided on the command line, or via named
822
options, but not both.
823
 
824
The tag may be of the form dir=path to force the utility to use a local
825
view or path.
826
 
7213 dpurdie 827
Additional tag values are available when generating differences against packages
828
that are released in Release Manager.  In order to do this specific -rtagid and
829
-package to specify the Release Manager package version.  Once
830
these are specified the following tags can be used:
831
 
832
=over 4
833
 
834
=item * released
835
 
836
Use the current released package version in Release Manager.
837
 
838
=item * head
839
 
840
Use the Subversion HEAD of the Release Manager release path.
841
 
842
=item * trunk
843
 
844
Use the HEAD of the Subversion trunk.
845
 
846
=item * branch=xxx
847
 
848
Use the HEAD of the Subversion branch named xxx.
849
 
850
=back
851
 
383 dpurdie 852
=item B<-new=tag>
853
 
854
This option specifies the new, or current, VcsTag for the difference report. This
855
tag is mandatory.
856
 
7213 dpurdie 857
Other than that, it has the same form as the -old tag described above.
383 dpurdie 858
 
7213 dpurdie 859
=item B<-rtagid=xxx>
383 dpurdie 860
 
7213 dpurdie 861
This option specified an RTAG_ID that must be determined from Release Manager.
862
 
863
The RTAG_ID uniquely identifies a Release. The value can be read from the URL
864
used to view the release. ie:
865
 
866
 https://auawsaweb005/ManagerSuite/Release_Manager/dependencies.asp?rtag_id=17223
867
 
868
=item B<-package=xxx>
869
 
870
Specifies the name of the package to query from Release Manager.  This can be
871
in the form of <package_name> or alternatly <package_name>.<ext> where <ext>
872
is the project-specific extension for that package.  The <package_name>.<ext>
873
variant is required when there is more than one package with the same name
874
in the release given by -rtagid.
875
 
383 dpurdie 876
=back
877
 
878
=head1 DESCRIPTION
879
 
880
This program has two modes of operation:
881
 
882
=over 4
883
 
884
=item 1 MD5Sum of the two views
885
 
2931 dpurdie 886
=item 2 Invoke a differencing program.
383 dpurdie 887
 
2931 dpurdie 888
The program that is invoked is, by default, Operating System dependent. It will:
889
 
890
=over 4
891
 
892
=item * Windows - Use Beyond Compare to perform a visual diff.
893
 
383 dpurdie 894
This mode simplifies the process of perform a code review between two
895
VCS Tags by:
896
 
897
=over 8
898
 
899
=item *
900
 
901
Creating a visual difference between two labels
902
 
903
=item *
904
 
905
Creating a visual difference between a label and a directory
906
 
907
=item *
908
 
909
Creating a visual difference between two directories.
910
 
911
=back
912
 
2931 dpurdie 913
=item * Unix - Use gdiff or diff
914
 
383 dpurdie 915
=back
916
 
2931 dpurdie 917
=back
918
 
383 dpurdie 919
The program will:
920
 
921
=over 8
922
 
923
=item *
924
 
925
Create two 'extract only' views based on the VCS Tags provided. The resultant
926
views are not connected to any version control system.
927
 
928
=item *
929
 
2931 dpurdie 930
Perform the desired operation: MD5Sum or Difference.
383 dpurdie 931
 
932
=item *
933
 
934
Delete the created directories the comparison is complete.
935
 
936
=back
937
 
938
If one of the Vcs Tags is of the form:
939
 
940
=over 8
941
 
7213 dpurdie 942
=item * current
383 dpurdie 943
 
7213 dpurdie 944
=item * current=path
383 dpurdie 945
 
7213 dpurdie 946
=item * dir=path
383 dpurdie 947
 
7213 dpurdie 948
=back
383 dpurdie 949
 
7213 dpurdie 950
Then the tag will be treated as a directory and will be used for one side
951
of the comparison.
383 dpurdie 952
 
7213 dpurdie 953
If a Vcs Tag is of the form:
383 dpurdie 954
 
7213 dpurdie 955
=over 8
956
 
957
=item * released
958
 
959
=item * head
960
 
961
=item * trunk
962
 
963
=item * branch=xxx
964
 
383 dpurdie 965
=back
966
 
7213 dpurdie 967
Then the source code is checked out of source control based on a Release Manager
968
rtagid (-rtagid option) and package name (-package) option.
383 dpurdie 969
 
970
Two directories views will be created. These should be deleted by this program,
971
but may remain if the command line program is terminated.
972
 
973
=head1 EXAMPLE
974
 
975
The following command will compare a Subversion view with a ClearCase view.
976
 
7214 dpurdie 977
    jats vcsdiff SVN::AUPERASVN01/COTS/crc/tags/crc_26.4.0007.cr@18587 CC::/MASS_Dev_Infra/crc::crc_26.4.0006.cr -check
383 dpurdie 978
 
979
The following command will compare a Subversion View with a local directory
980
 
7214 dpurdie 981
    jats vcsdiff SVN::AUPERASVN01/COTS/crc/tags/crc_26.4.0000.cr dir=crc
383 dpurdie 982
 
7213 dpurdie 983
The following command will compare the release version of the ct-spa package from Pulse 2.7.0 with the current head of that package
984
 
985
    jats vcsdiff -rtagid=38970 -package=ct-spa released head
986
 
7214 dpurdie 987
The following command will create a 'patch' file between the specified version of the crc package and the version in the 
988
directory named 'crc'.
989
 
990
    ats vcsdiff SVN::AUPERASVN01/COTS/crc/tags/crc_26.4.0000.cr dir=crc -patch
991
 
383 dpurdie 992
=cut
993