Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
1356 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : svn2svn_updaterm.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats#
8
# Description   : Update RM with Subversion Conversion information
9
#                 Convert OLD svn format into New SVN format
10
#                 Requires access to SVN repos
11
# Usage:
12
#
13
# Version   Who      Date        Description
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 JatsRmApi;
26
use JatsSvn;
27
use ConfigurationFile;
28
 
29
#
30
#   Globals
31
#
32
my $RM_DB;
33
my $VERSION = "1.0.0";                      # Update this
34
my %packageVcs;
35
my %packages;
36
our %SvnCache;
37
 
38
#
39
#   Options
40
#
41
my $opt_verbose = 0;
42
my $opt_help = 0;
43
my $opt_package;
44
my $opt_rm = 'RELMANU1';
45
my $opt_test = 1;
46
my $opt_force;
47
my $opt_checkOperation;
48
my $opt_report = 0;
49
my $opt_live;
50
 
51
#-------------------------------------------------------------------------------
52
# Function        : Main Entry
53
#
54
# Description     :
55
#
56
# Inputs          :
57
#
58
# Returns         :
59
#
60
my $result = GetOptions (
61
                "help+"         => \$opt_help,          # flag, multiple use allowed
62
                "manual:3"      => \$opt_help,
63
                "verbose:+"     => \$opt_verbose,       # flag
64
                'package:s'     => \$opt_package,
65
                'database:s'    => \$opt_rm,
66
                'test!'         => \$opt_test,
67
                'force!'        => \$opt_force,
68
                'check:s'       => \$opt_checkOperation,
69
                'report:+'      => \$opt_report,
70
                'live'          => \$opt_live,
71
                );
72
 
73
#
74
#   Process help and manual options
75
#
76
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
77
pod2usage(-verbose => 1)  if ($opt_help == 2);
78
pod2usage(-verbose => 2)  if ($opt_help > 2);
79
 
80
ErrorConfig( 'name'    =>'SVN2SVN_UPDATERM',
81
             'verbose' => $opt_verbose,
82
              );
83
 
84
#
85
#   Configure RM database to use
86
#   Default is the TEST(RELMANU1) database
87
#
88
 
89
$opt_rm = 'RELEASEM' if ( $opt_live );
90
$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaprm01:1521:' . $opt_rm;
91
unless ( $opt_rm eq 'RELEASEM' )
92
{
93
    Warning ("Using internal user/passowrd");
94
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
95
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
96
    $ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07.vix.local:1521:' . $opt_rm;
97
}
98
else
99
{
100
    $ENV{GBE_RM_USERNAME} = 'RM_READONLY';
101
    $ENV{GBE_RM_PASSWORD} = 'RM_READONLY';
102
}
103
 
104
loadCache();
105
findSvnPackages();
106
#DebugDumpData('%packages)', \%packages);
107
processEntry($_) foreach  ( sort sortData keys %packages);
108
saveCache();
109
exit 0;
110
 
111
#-------------------------------------------------------------------------------
112
# Function        : sortData
113
#
114
# Description     : 
115
#
116
# Inputs          : 
117
#
118
# Returns         : 
119
#
120
sub sortData
121
{
122
    return ( $packages{$a}{version} cmp $packages{$b}{version}  ) if ( $packages{$a}{name} eq $packages{$b}{name} );
123
    return ( $packages{$a}{name} cmp $packages{$b}{name} );
124
}
125
 
126
#-------------------------------------------------------------------------------
127
# Function        : findSvnPackages
128
#
129
# Description     : Locate ALL package versions with an SVN VCS
130
#                   Bit of a Kludge as it assumes the vcs_type
131
#
132
# Inputs          : 
133
#
134
# Returns         : 
135
#
136
sub findSvnPackages
137
{
138
    my (@row);
139
    my $pv_id;
140
    my $pkg_id;
141
 
142
    #
143
    #   Establish a connection to Release Manager
144
    #
145
    connectRM(\$RM_DB) unless ( $RM_DB );
146
 
147
    #
148
    #   Extract data from Release Manager
149
    #
150
    my $m_sqlstr = "select pv.PV_ID, p.PKG_NAME, pv.PKG_VERSION, pv.PKG_LABEL, pv.SRC_PATH" .
151
                   " from RELEASE_MANAGER.PACKAGE_VERSIONS pv," .
152
                   "      RELEASE_MANAGER.PACKAGES p" .
153
                   " WHERE pv.VCS_TYPE_ID=23" .
154
                   " AND pv.PKG_ID = p.PKG_ID";
155
 
156
    my $sth = $RM_DB->prepare($m_sqlstr);
157
    if ( defined($sth) )
158
    {
159
        if ( $sth->execute( ) )
160
        {
161
            if ( $sth->rows )
162
            {
163
                while ( @row = $sth->fetchrow_array )
164
                {
165
                    Verbose3( "DATA: " . join(',', @row) );
166
 
167
                    my %data;
168
                    $data{pv_id} = $row[0];
169
                    $data{name} = $row[1];
170
                    $data{version} = $row[2];
1451 dpurdie 171
                    $data{label} = $row[3] || '';
1356 dpurdie 172
                    $data{path} = $row[4];
173
 
174
                    $packages{$row[0]} = \%data;
175
                }
176
            }
177
            else
178
            {
179
                Error ("findSvnPackages:No Data");
180
            }
181
            $sth->finish();
182
        }
183
    }
184
    else
185
    {
186
        Error("findSvnPackages:Prepare failure" );
187
    }
188
}
189
 
190
#-------------------------------------------------------------------------------
191
# Function        : processEntry
192
#
193
# Description     : Process on PVID entry
194
#
195
# Inputs          : $pvid               - pvid to process
196
#
197
# Returns         : 
198
#
199
sub processEntry
200
{
201
    my ($pvid) = @_;
202
    return unless ( exists $packages{$pvid} );
203
    my $entry = $packages{$pvid};
204
    my $name = $entry->{name} . ' ' . $entry->{version};
205
    my $pname = $entry->{name};
206
    my $baseurl = $entry->{path};
207
#    return if ( $entry->{path} =~ m~^FRBESA~ );
208
 
1451 dpurdie 209
    if ( ($entry->{label} ne 'N/A') and ($entry->{label} ne '') )
1356 dpurdie 210
    {
211
        Verbose2("Already processed: $name");
212
        return;
213
    }
214
    Verbose ("Processing: $name, $baseurl");
215
 
2764 dpurdie 216
Debug0('Path:', $entry->{path});
1356 dpurdie 217
 
218
    #
219
    #   Backtrack from entry
220
    #
221
    if ( $entry->{path} =~ m~/?(.*)/((tags|branches|trunk)(/|$|@)(.*))$~ )
222
    {
223
        my $tgt = $2;
224
        my $ttb = $3;
225
        my $root = $1;
226
        my $tag = $5 if ( $ttb eq 'tags');
227
        my $peg = $1 if ( $tag && $tag =~ m~\@(\d+)$~ );
228
        my $devBranch;
229
        my $label;
230
        my $bt = '-';
231
 
232
        #
233
        #   If the existing source path is a 'tag' then we need to backtrack
234
        #   Other wise we can calulate it
235
        #
236
        if ( $ttb ne 'tags' )
237
        {
238
            #
239
            #   Not a TAG
240
            #   Expecting ..../trunk@nnnn or /branches/xxxxx@xxxx
241
            #
242
            if ( $entry->{path} =~ m~(.*)\@(\d+)$~ )
243
            {
244
                $devBranch = $1;
245
                $label = $2;
246
            }
247
        }
248
        else
249
        {
250
            my $found = 0;
251
            my $error = 0;
252
            until ( $found || $error )
253
            {
254
                if ( exists $SvnCache{$pname}{$tgt} )
255
                {
256
                    Verbose ("Cached result for $tgt");
257
                    $bt = $SvnCache{$pname}{$tgt};
258
                }
259
                else
260
                {
261
                    my $svnSession = NewSessionByUrl ( $baseurl, 1 );
262
 
263
            #Debug0('base:', $baseurl, $tgt );
264
                    my $data;
265
                    $bt = $svnSession->backTrackSvnLabel($tgt, 'data' => \$data);
2764 dpurdie 266
 
267
Error ("The return value from backTrackSvnLabel has changed since the code was written",
268
       "The result is now a path relative to the base of the Repo",
269
       "Result: $bt");
270
 
271
 
1356 dpurdie 272
#            Debug0( 'Back:' , $bt );
273
#            DebugDumpData('$data', $data );
274
 
275
                    if ( ! exists $data->{isaBranch}  ) {
276
                        Warning ("Cannot backtrack: $name");
277
                        $error = 1;
278
                        next;
279
 
280
                    } elsif ( $data->{changeSets} > 1 ) {
281
                        Warning ("Package: $name has changes on branch: " . $data->{changeSets});
282
            DebugDumpData('$data', $data );
283
                        $error = 1;
284
                        next;
285
                    }
286
 
287
                    #
288
                    #   Save for other lookup attempts
289
                    #   Processing order has been sorted to assist
290
                    #
291
                    $SvnCache{$pname}{$tgt} = $bt;
292
                    saveCache();
293
                }
294
 
295
                if ( $bt =~ m~^tags/~ )
296
                {
297
                    $tgt = $bt;
298
                    Verbose ("Backtracked to another TAG: $bt");
299
                }
300
                else
301
                {
302
                    $found = 1;
303
                }
304
 
305
            }
306
 
307
 
308
            if ( $bt =~ m~^(.*)(/|\@)(.*)$~ )
309
            {
310
                if ( $bt =~ m~^tags/~ )
311
                {
312
                    Warning ("Backtracked to another TAG");
313
                }
314
                else
315
                {
316
                    $devBranch = $root . '/' .$1;
317
                    if ( $tag ) {
318
                        $label = $tag;
319
                    } else {
320
                        $label = $peg;
321
                    }
322
                    $label = $tag || $3;
323
                }
324
            }
325
        }
326
 
327
        if ( ! $devBranch || ! $label )
328
        {
329
            Warning("Cannot parse: $name", $entry->{path}, $entry->{label}, $bt, $devBranch, $label );
330
        }
331
        else
332
        {
333
            Verbose ("Process results: $name, $bt");
334
            my $tag =  join( '::', 'SVN', $devBranch, $label);
335
            Message ("Processed: $pvid, $name, $tag");
336
            intoReleaseManager( $pvid, $tag)
337
        }
338
    }
339
    else
340
    {
341
        Warning ("Package does not conatin TTB");
342
    }
343
}
344
 
345
#-------------------------------------------------------------------------------
346
# Function        : intoReleaseManager
347
#
348
# Description     : Update VCS tags in RM
349
#
350
# Inputs          : $pvid           - PVId
351
#                   $tag            - New Tag
352
#
353
# Returns         : 
354
#
355
sub intoReleaseManager
356
{
357
    my ($pvid, $new_tag ) = @_;
358
    my @row;
359
    my $user = 3768;            # buildadm
360
 
361
    if ( $opt_test )
362
    {
363
        Information ("No RM write: $pvid, $new_tag");
364
        return;
365
    }
366
 
367
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
368
 
369
    my $m_sqlstr =  "begin release_manager.PK_RMAPI.update_vcs_details($pvid, '$new_tag', $user); end;";
370
    my $sth = $RM_DB->prepare($m_sqlstr);
371
    if ( defined($sth) )
372
    {
373
        if ( $sth->execute( ) )
374
        {
375
            if ( $sth->rows )
376
            {
377
                while ( @row = $sth->fetchrow_array )
378
                {
379
                    print "Data: @row\n";
380
                }
381
            }
382
            $sth->finish();
383
        }
384
        else
385
        {
386
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
387
        }
388
    }
389
    else
390
    {
391
        Error("Prepare failure" );
392
    }
393
}
394
 
395
#-------------------------------------------------------------------------------
396
# Function        : loadCache
397
#
398
# Description     : Load cached data
399
#                   Allows the process to be run ahead of time
400
#                   Speeds up the operations
401
#
402
# Inputs          : 
403
#
404
# Returns         : 
405
#
406
sub loadCache
407
{
408
 
409
    my $fname = 'svn2svn_cache.txt';
410
    unless ( -f $fname )
411
    {
412
        Warning "Cannot locate $fname" ;
413
    }
414
    else
415
    {
416
        require $fname;
417
 
418
        Error "Data in $fname is not valid\n"
419
            unless ( keys(%SvnCache) >= 0 );
420
    }
421
 
422
#    DebugDumpData("SvnCache", \%SvnCache );
423
}
424
 
425
#-------------------------------------------------------------------------------
426
# Function        : saveCache
427
#
428
# Description     : Write out cached results
429
#
430
# Inputs          : 
431
#
432
# Returns         : 
433
#
434
sub saveCache
435
{
436
    my $file = 'svn2svn_cache.txt';
437
    Message ("Create: $file");
438
    my $fh = ConfigurationFile::New( $file );
439
 
440
    $fh->DumpData(
441
        "\n# Cached Data.\n#\n",
442
        "SvnCache", \%SvnCache );
443
 
444
    #
445
    #   Close out the file
446
    #
447
    $fh->Close();
448
}
449
 
450
#-------------------------------------------------------------------------------
451
#   Documentation
452
#
453
 
454
=pod
455
 
456
=for htmltoc    SYSUTIL::cc2svn::
457
 
458
=head1 NAME
459
 
460
cc2svn_updaterm - Update Release Manager with CC2SVN information
461
 
462
=head1 SYNOPSIS
463
 
464
  jats cc2svn_updaterm [options] [PackageName]*
465
 
466
 Options:
467
    -help              - brief help message
468
    -help -help        - Detailed help message
469
    -man               - Full documentation
470
    -verbose           - Enable verbosity
471
    -[no]test          - Test update. Default: -notest
472
    -package=name      - Specify single package to be processed
473
    -database=name     - Default: RELMANU1 (test db) Live: RELEASEM
474
    -[no]force         - Force update of all entries
475
    -check=string      - Check operation with string
476
    -report            - Report on errors
477
    -report=2          - Report on errors, don't access RM
478
 
479
=head1 OPTIONS
480
 
481
=over 8
482
 
483
=item B<-help>
484
 
485
Print a brief help message and exits.
486
 
487
=item B<-help -help>
488
 
489
Print a detailed help message with an explanation for each option.
490
 
491
=item B<-man>
492
 
493
Prints the manual page and exits.
494
 
495
=item B<-[no]test>
496
 
497
Invoke the program in test mode. This is the default.
498
 
499
In test mode the program will examine each packages 'data' results file
500
and report status and errors.
501
 
502
In 'notest' the program will update the Release Manager database.
503
 
504
=item B<-package=name>
505
 
506
This option will name one package to be processed. Packages to be
507
processed can just be named on the command line.
508
 
509
=item B<-database=name>
510
 
511
This option specifies the target database. The default value is 'RELMANU1'.
512
This is a test database.
513
 
514
The production database is RELEASEM.
515
 
516
The user must specifically specify the database to update the production system.
517
 
518
=item B<-[no]force>
519
 
520
This option will force the Release Manager entries to be updated - even if the
521
current entry matches the desired result.
522
 
523
Useful in testing.
524
 
525
=item B<-check=string>
526
 
527
This option will pass a string directly to the Release Manager updating proceedure.
528
 
529
With this option no packages will be examined or processed.
530
 
531
It is only useful for testing.
532
 
533
=back
534
 
535
=head1 DESCRIPTION
536
 
537
This program is a tool used in the conversion of ClearCase VOBS to subversion.
538
It will:
539
 
540
=over 8
541
 
542
=item *
543
 
544
Process all packages named on the command line or with the -package option.
545
 
546
=item *
547
 
548
Examine the packages '.data' file, whcih is created as the package is inserted
549
into Subversion.
550
 
551
=item *
552
 
553
Report the status of the package import and highlight issues.
554
 
555
=item *
556
 
557
Read the Release Manager entry and ensure that the entry is not the same.
558
If the entry is the same then it will not be updated, unless the '-force'
559
option has been used.
560
 
561
=item *
562
 
563
Insert the new Version Control information into the Release Manager entry.
564
 
565
=back
566
 
567
The default operation of this utility is to test the import process. The
568
user needs to provide specific options in order to update the production
569
database. This is intentional.
570
 
571
=cut
572