
| Current Path : /var/www/web-klick.de/dsh/10_customer2017/1204__intel/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/10_customer2017/1204__intel/scmerge |
#!/usr/bin/perl -w
use Getopt::Long;
use Pod::Usage qw(pod2usage);
use strict;
my $help=0;
my $exec=1;
my $opstr="help";
my $opfnc;
GetOptions('help' => \$help, 'exec' => \$exec, 'dry-run' => sub { $exec=0 } );
# returns true if all elements are contained within the array
# given as first parameter; else false
sub contain {
my $arr=shift;
my $encounterednew=0;
while ($#_>-1 && !$encounterednew) {
my $elem=shift;
$encounterednew=!(grep $_ eq $elem, @$arr);
}
return !$encounterednew;
}
# do a findmerge on the given branch type
sub findmerge {
(my $branch)=@_;
if (!defined($branch)) { $help=2; return; }
my $cccmd="cleartool findmerge";
my $ccopt="-fver .../$branch/LATEST -log /dev/null ".
"-c \"Merge from $branch\"";
my $fin=0;
my @merges;
# repeat findmerge until no new finds are recorded
while (!$fin) {
my @log=`$cccmd -avobs $ccopt -print 2>/dev/null`;
my @merge;
# parse ClearCase output and record to attempt merges to @merge
foreach (@log) {
(my $file)=/Needs Merge "(.+)" \[.*\]/;
push(@merge, $file) if (defined($file));
}
# check whether any new merges have emerged and work on them
my $newelem=!contain(\@merges, @merge);
# found new elem; user told us to merge
if ($newelem && $exec) {
foreach my $file (sort @merge) {
if (!system("$cccmd $file $ccopt -merge -abort 2>/dev/null")) {
# merge successful
push(@merges, $file);
} else {
# merge failed
die "Problem merging file $file";
}
}
# found new elem; user just wants to dry-run
} elsif ($newelem && !$exec) {
push(@merges, sort @merge);
# no new elements found
} else {
$fin=1;
}
@merge=();
}
# run completed: print found merges
print("cleartool findmerge operated on:\n\t".join("\n\t", @merges)."\n");
}
$opstr=shift if ($#ARGV > -1);
if ($opstr eq "1to2") { $opfnc=\&findmerge; }
elsif (!$help) { $help=2; }
if ($help == 1) {
pod2usage(-exitval => 0, -verbose => 3);
} elsif (defined($opfnc)&&!$help) {
&$opfnc(@ARGV);
}
if ($help) {
pod2usage(-verbose => 99,
-sections => "SYNOPSIS|ARGUMENTS",
-exitval => 1);
}
__END__
=head1 NAME
scmerge - merge helper application for ClearCase
=head1 SYNOPSIS
B<scmerge> B<[--options]> B<arguments>
=head1 DESCRIPTION
This program helps with merging branches within ClearCase. The exact
functionality depends on the mode of operation which are described
below.
=head1 ARGUMENTS
=over
=item B<1to2>
The mode "1to2" provides a convenient wrapper for ClearCase's findmerge: With this mode it is easy to merge a SmartCM version 1 branch (legacy branch) with a SmartCM version 2 branch.
Though this mode is the only mode for now, it needs to be given as a command line argument for backwards compatibility during future upgrades of this tool.
This mode requires exactly one additional argument:
=over
=item B<taskbranch-v1>
The taskbranch name in version 1 which needs to be merged to version 2.
=back
=head2 Examples
C<scmerge 1to2 username_20111111-test>
Merges the taskbranch username_20111111-test into the current selected v2 taskbranch.
=back
=head1 OPTIONS
=over
=item B<--help>
Shows the manual.
=item B<--exec>
Default. Actually performs the operation. The very opposite to B<--dry-run>.
=item B<--dry-run>
Only prints what would be done; no operations are actually
performed. The very opposite to B<--exec>.
=back
=head1 SEE ALSO
L<scwa>
=cut