Subversion Repositories DevTools

Rev

Rev 315 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 315 Rev 319
Line 60... Line 60...
60
my @opt_files;
60
my @opt_files;
61
my @opt_dirs;
61
my @opt_dirs;
62
my $opt_comment;
62
my $opt_comment;
63
my $opt_vob;
63
my $opt_vob;
64
my $opt_user;
64
my $opt_user;
-
 
65
my $opt_admin_vob;
65
 
66
 
66
my $label;
67
my $label;
67
my $user_cwd;
68
my $user_cwd;
68
my @error_list;
69
my @error_list;
69
my $last_result;
70
my $last_result;
Line 115... Line 116...
115
                "files=s"       => \@opt_files,             # Multiple strings
116
                "files=s"       => \@opt_files,             # Multiple strings
116
                "dirs=s"        => \@opt_dirs,              # Multiple strings
117
                "dirs=s"        => \@opt_dirs,              # Multiple strings
117
                "comment=s"     => \$opt_comment,           # String
118
                "comment=s"     => \$opt_comment,           # String
118
                "vob=s"         => \$opt_vob,               # String
119
                "vob=s"         => \$opt_vob,               # String
119
                "user=s"        => \$opt_user,              # String
120
                "user=s"        => \$opt_user,              # String
-
 
121
                "admin"         => \$opt_admin_vob,         # String
120
 
122
 
121
                );
123
                );
122
 
124
 
123
                #
125
                #
124
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
126
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
Line 211... Line 213...
211
if ( $opt_create || ( $opt_auto && ! $label_exists    ) )
213
if ( $opt_create || ( $opt_auto && ! $label_exists    ) )
212
{
214
{
213
    Verbose ("Create label");
215
    Verbose ("Create label");
214
    Error ("Label already exists") if ( $label_exists );
216
    Error ("Label already exists") if ( $label_exists );
215
 
217
 
216
    my $opts = '-nc';
218
    my @opts;
217
    $opts = '-c "' . $opt_comment . '"' if ( $opt_comment );
219
    push @opts, $opt_comment ? ( '-c', '"' . $opt_comment . '"' ) : '-nc';
-
 
220
    push @opts, '-global' if ( $opt_admin_vob );
218
 
221
 
219
    ClearCmd ("mklbtype", $opts, "$label$vob_desc" ) unless $opt_test;
222
    ClearCmd ("mklbtype", @opts, "$label$vob_desc" ) unless $opt_test;
220
    Error ("Program Terminated") if ( @error_list );
223
    Error ("Program Terminated") if ( @error_list );
221
    $opr_done = 1;
224
    $opr_done = 1;
222
}
225
}
223
 
226
 
224
#-------------------------------------------------------------------------------
227
#-------------------------------------------------------------------------------
Line 549... Line 552...
549
    #
552
    #
550
    $data->{'dir_list'} = [];
553
    $data->{'dir_list'} = [];
551
    $data->{'checked_out_pdirs'} = [];
554
    $data->{'checked_out_pdirs'} = [];
552
    $data->{'is_symlink'} = 0;
555
    $data->{'is_symlink'} = 0;
553
    $data->{'VobRoot'} = '';
556
    $data->{'VobRoot'} = '';
-
 
557
    $data->{'DirsSeen'} = {};
554
 
558
 
555
    #
559
    #
556
    #   Figure out what to do
560
    #   Figure out what to do
557
    #       Label dirs upwards if requested, or we are not doing files or dirs
561
    #       Label dirs upwards if requested, or we are not doing files or dirs
558
    #       Label the current directory unless asked to do files/dirs or up-only
562
    #       Label the current directory unless asked to do files/dirs or up-only
559
    #
563
    #
560
    my $do_files = scalar @opt_files;
564
    my $do_files = scalar @opt_files;
561
    my $do_dirs  = scalar @opt_dirs;
565
    my $do_dirs  = scalar @opt_dirs;
562
    my $do_up = $opt_up || ( ! $do_files && ! $do_dirs );
566
    my $do_up = $opt_up || ( ! $do_files && ! $do_dirs );
563
    push @opt_dirs, '.' unless ($opt_up || $do_files || $do_dirs);
-
 
564
 
567
 
565
    #
568
    #
566
    #   Build up a list of parent directories up to the root of the VOB
569
    #   Build up a list of parent directories up to the root of the VOB
567
    #   that do not have the desired label
570
    #   that do not have the desired label
568
    #
571
    #
569
    if ( $do_up )
572
    if ( $do_up )
570
    {
573
    {
571
        Verbose ("Examine parent directories");
574
        Verbose ("Examine parent directories");
-
 
575
        examine_directory (getcwd(), $data, 1);
572
 
576
 
-
 
577
        #
-
 
578
        #   If the user has provided a list of directories or files then we should label
-
 
579
        #   the directory components too
-
 
580
        #
573
        my $path = getcwd();
581
        my @dirs_from_files;
574
        while ( 1 )
582
        foreach my $file ( @opt_files )
575
        {
583
        {
576
            my $cmd = QuoteCommand ("cleartool", "describe", $path);
-
 
577
            my $has_label;
-
 
578
            my $is_versioned;
584
            my $dir = $file;
579
            my $start_labels;
585
            $dir =~ tr~\\/~/~s;
580
            my $link;
-
 
581
            my $is_checkedout;
-
 
582
 
-
 
583
            Verbose($cmd);
-
 
584
            my $cmd_handle;
-
 
585
            open($cmd_handle, "$cmd 2>&1 |") || Error( "Can't run command: $!");
-
 
586
            while (<$cmd_handle>)
-
 
587
            {
-
 
588
                #
-
 
589
                #   Filter output from the user
586
            $dir =~ s~/[^/]+$~~ unless ( -d $dir);
590
                #
-
 
591
                chomp;
-
 
592
                Verbose2($_);
587
            push @dirs_from_files, $dir;
593
                push @error_list, $_    if ( m~Error:~ );
-
 
594
                $link = $1              if ( m~^symbolic link.* -> (.*)~ );
-
 
595
                $is_versioned = 1       if ( m~^directory version ~ );
-
 
596
                $start_labels = 1       if ( m~^\s+Labels:$~ );
-
 
597
                $is_checkedout = 1      if ( m~[\\/]CHECKEDOUT"~ );
-
 
598
                next unless ( $start_labels );
-
 
599
                $has_label = 1          if ( m~^\s+$label$~ );
-
 
600
            }
588
        }
601
            close($cmd_handle);
-
 
602
            $data->{'VobRoot'} = $path;
-
 
603
 
589
 
604
            #
-
 
605
            #   Symbolic link located
-
 
606
            #   Resolve the link and continue
-
 
607
            #   The link cannot be labeled. If we can label the resolved link then
-
 
608
            #   all is good, otherwise we have a a problem
590
        foreach my $dir ( @opt_dirs , @dirs_from_files)
609
            #
591
        {
610
            if ( $link )
592
            examine_directory ($dir, $data);
611
            {
593
        }
612
                $data->{'is_symlink'} = 1;
-
 
613
                $path =~ s~[/][^/]*$~~;
-
 
614
                $path = $path . '/' . $link;
-
 
615
                $path =~ s~/[^/]+/\.\./~/~;
-
 
616
                Verbose("Symbolic link: $link, Path: $path" );
-
 
617
                next;
-
 
618
            }
594
    }
-
 
595
}
619
 
596
 
-
 
597
#-------------------------------------------------------------------------------
620
            #
598
# Function        : examine_directory
-
 
599
#
621
            #   Parent directory checked out. Options:
600
# Description     : Examine one directory entry
-
 
601
#
622
            #       0: Don't Label checkedout elements
602
# Inputs          : $path           - Path to examine
623
            #       1: Do Label only checkout elements
603
#                   $data           - Ref to hash to collect info
624
            #       2: Label both (default)
604
#                   $find_root      - Finding root
-
 
605
#
625
            #
606
# Returns         : 
-
 
607
#
626
            if ( $is_checkedout )
608
sub examine_directory
627
            {
609
{
628
                $has_label = 2 if ( $opt_checkout == 0 );
-
 
629
                push @{$data->{'checked_out_pdirs'}}, $_;
610
    my ($path, $data, $find_root) = @_;
630
            }
-
 
631
            else
611
    my $is_symlink;
632
            {
-
 
633
                $has_label = 2 if ( $opt_checkout == 1 );
-
 
634
            }
612
    $path =~ tr~\\/~/~s;
635
 
613
 
-
 
614
    while ( 1 )
-
 
615
    {
636
            last unless ( $is_versioned );
616
        return if ( defined $data->{'DirsSeen'}{$path} );
637
            unshift @{$data->{'dir_list'}}, $path unless ( $has_label );
617
        $data->{'DirsSeen'}{$path} = 1;
638
 
618
 
-
 
619
        my $cmd = QuoteCommand ("cleartool", "describe", $path);
639
            #
620
        my $has_label;
640
            #   Versioned directory seen
621
        my $is_versioned;
641
            #   If the previous one loop was a symlink, then we have labeled
-
 
642
            #   the link correctly
622
        my $start_labels;
643
            #
623
        my $link;
644
            $data->{'is_symlink'} = 0;
624
        my $is_checkedout;
645
 
625
 
-
 
626
        Verbose($cmd);
-
 
627
        my $cmd_handle;
-
 
628
        open($cmd_handle, "$cmd 2>&1 |") || Error( "Can't run command: $!");
-
 
629
        while (<$cmd_handle>)
-
 
630
        {
646
            #
631
            #
647
            #   Calculate the path of the parent directory
632
            #   Filter output from the user
648
            #   Stop when we get to the top ( ie z: is not good )
-
 
649
            #
633
            #
-
 
634
            chomp;
-
 
635
            Verbose2($_);
-
 
636
            push @error_list, $_    if ( m~Error:~ );
-
 
637
            $link = $1              if ( m~^symbolic link.* -> (.*)~ );
-
 
638
            $is_versioned = 1       if ( m~^directory version ~ );
-
 
639
            $start_labels = 1       if ( m~^\s+Labels:$~ );
-
 
640
            $is_checkedout = 1      if ( m~[\\/]CHECKEDOUT"~ );
-
 
641
            next unless ( $start_labels );
-
 
642
            $has_label = 1          if ( m~^\s+$label$~ );
-
 
643
        }
-
 
644
        close($cmd_handle);
-
 
645
        $data->{'VobRoot'} = $path if ( $find_root );
-
 
646
 
-
 
647
        #
-
 
648
        #   Symbolic link located
-
 
649
        #   Resolve the link and continue
-
 
650
        #   The link cannot be labeled. If we can label the resolved link then
-
 
651
        #   all is good, otherwise we have a a problem
-
 
652
        #
-
 
653
        if ( $link )
-
 
654
        {
-
 
655
            $is_symlink = 1;
650
            last unless ( $path =~ s~[/][^/]*$~~);
656
            $path =~ s~[/][^/]*$~~;
651
            last unless ( $path =~ m~/~ );
657
            $path = $path . '/' . $link;
-
 
658
            $path =~ s~/[^/]+/\.\./~/~;
-
 
659
            Verbose("Symbolic link: $link, Path: $path" );
-
 
660
            next;
652
        }
661
        }
-
 
662
 
-
 
663
        #
-
 
664
        #   Parent directory checked out. Options:
-
 
665
        #       0: Don't Label checkedout elements
-
 
666
        #       1: Do Label only checkout elements
-
 
667
        #       2: Label both (default)
-
 
668
        #
-
 
669
        if ( $is_checkedout )
-
 
670
        {
-
 
671
            $has_label = 2 if ( $opt_checkout == 0 );
-
 
672
            push @{$data->{'checked_out_pdirs'}}, $_;
-
 
673
        }
-
 
674
        else
-
 
675
        {
-
 
676
            $has_label = 2 if ( $opt_checkout == 1 );
-
 
677
        }
-
 
678
 
-
 
679
        last unless ( $is_versioned );
-
 
680
        unshift @{$data->{'dir_list'}}, $path unless ( $has_label );
-
 
681
 
-
 
682
        #
-
 
683
        #   Versioned directory seen
-
 
684
        #   If the previous one loop was a symlink, then we have labeled
-
 
685
        #   the link correctly
-
 
686
        #
-
 
687
        $is_symlink = 0;
-
 
688
 
-
 
689
        #
-
 
690
        #   Calculate the path of the parent directory
-
 
691
        #   Stop when we get to the top ( ie z: is not good )
-
 
692
        #
-
 
693
        last unless ( $path =~ s~[/][^/]*$~~);
-
 
694
        last unless ( length $path);
-
 
695
        last if ( $path =~ m~:$~ );
653
    }
696
    }
-
 
697
 
-
 
698
    #
-
 
699
    #   Accumulate bad symlinks
-
 
700
    #
-
 
701
    $data->{'is_symlink'}++
-
 
702
        if ( $is_symlink );
654
}
703
}
655
 
704
 
-
 
705
 
656
#-------------------------------------------------------------------------------
706
#-------------------------------------------------------------------------------
657
# Function        : determine_files_to_label
707
# Function        : determine_files_to_label
658
#
708
#
659
# Description     : Determine a list of files that need to be
709
# Description     : Determine a list of files that need to be
660
#                   labeled.
710
#                   labeled.
Line 685... Line 735...
685
    #       Label dirs upwards if requested, or we are not doing files or dirs
735
    #       Label dirs upwards if requested, or we are not doing files or dirs
686
    #       Label the current directory unless asked to do files/dirs or up-only
736
    #       Label the current directory unless asked to do files/dirs or up-only
687
    #
737
    #
688
    my $do_files = scalar @opt_files;
738
    my $do_files = scalar @opt_files;
689
    my $do_dirs  = scalar @opt_dirs;
739
    my $do_dirs  = scalar @opt_dirs;
690
    my $do_up = $opt_up || ( ! $do_files && ! $do_dirs );
-
 
691
    push @opt_dirs, '.' unless ($opt_up || $do_files || $do_dirs);
740
    push @opt_dirs, '.' unless ($opt_up || $do_files || $do_dirs);
692
 
741
 
693
    my @check_these;
742
    my @check_these;
694
 
743
 
695
    #
744
    #
Line 700... Line 749...
700
    #   Use the cleartool find command as it will allow us to determine
749
    #   Use the cleartool find command as it will allow us to determine
701
    #   if the element has already been labled.
750
    #   if the element has already been labled.
702
    #
751
    #
703
    #   Note: cleartool find works on files and directories
752
    #   Note: cleartool find works on files and directories
704
    #
753
    #
-
 
754
    my $doing_files = 0;
705
    foreach my $dir (@opt_files, @opt_dirs )
755
    foreach my $dir (@opt_dirs ,undef, @opt_files )
706
    {
756
    {
-
 
757
        if ( ! defined $dir )
-
 
758
        {
-
 
759
            $doing_files = 1;
-
 
760
            next;
-
 
761
        }
-
 
762
 
-
 
763
        #
-
 
764
        #   If this element is from the files option and its not a file
-
 
765
        #   this skip it - the path will have been processed
-
 
766
        #
-
 
767
        next if ($doing_files  && -d $dir );
-
 
768
 
707
        #
769
        #
708
        #   Remove possible trailing / from user specified directory as
770
        #   Remove possible trailing / from user specified directory as
709
        #   clearcase doesn't handle these too well.
771
        #   clearcase doesn't handle these too well.
710
        #
772
        #
711
        $dir =~ tr~\\/~/~s;
773
        $dir =~ tr~\\/~/~s;
712
        $dir =~ s~/+$~~;
774
        $dir =~ s~/+$~~;
713
        $dir = '/' unless ( $dir );
775
        $dir = '/' unless ( $dir );
714
 
776
 
715
        Verbose ("Examine subdirectory: $dir");
777
        Verbose ("Examine subdirectory: $dir");
716
        my $find_arg = $opt_recurse ? '' : '-nrecurse';
778
        my $find_arg = $opt_recurse && !$doing_files ? '' : '-nrecurse';
717
        my $cmd = QuoteCommand ("cleartool", "find", "$dir", "-cview", $find_arg, "-version", "{!lbtype($label)}", "-print");
779
        my $cmd = QuoteCommand ("cleartool", "find", "$dir", "-cview", $find_arg, "-version", "{!lbtype($label)}", "-print");
718
        Verbose2($cmd);
780
        Verbose2($cmd);
719
 
781
 
720
        my $cmd_handle;
782
        my $cmd_handle;
721
        open($cmd_handle, "$cmd 2>&1 |") || Error( "can't run command: $!");
783
        open($cmd_handle, "$cmd 2>&1 |") || Error( "can't run command: $!");
Line 921... Line 983...
921
    -[no]mine          - Set label owner to user.
983
    -[no]mine          - Set label owner to user.
922
    -info              - Provide label information
984
    -info              - Provide label information
923
    -smartlock         - Unlock and Relock label, if it was locked
985
    -smartlock         - Unlock and Relock label, if it was locked
924
 
986
 
925
 Modifiers
987
 Modifiers
-
 
988
    -admin             - Modifies label creation to create global label
926
    -all               - Process all the VOB. Use with -show and -remove.
989
    -all               - Process all the VOB. Use with -show and -remove.
927
    -replace           - Replace existing labels. Use with -label
990
    -replace           - Replace existing labels. Use with -label
928
    -exclude=n1,n2     - Exclude files and directories from the -label process.
991
    -exclude=n1,n2     - Exclude files and directories from the -label process.
929
    -files=f1,f2,...   - Label only the named files.
992
    -files=f1,f2,...   - Label only the named files.
930
    -dirs=d1,d2,...    - Label only the named dirs.
993
    -dirs=d1,d2,...    - Label only the named dirs.
Line 1019... Line 1082...
1019
 
1082
 
1020
Wildcards are not supported.
1083
Wildcards are not supported.
1021
 
1084
 
1022
Directories will not be recursed, but may be labeled.
1085
Directories will not be recursed, but may be labeled.
1023
 
1086
 
-
 
1087
The component paths of the named path will also be labeled, when the B<-up> is
-
 
1088
used.
-
 
1089
 
1024
=item B<-dirs=name>
1090
=item B<-dirs=name>
1025
 
1091
 
1026
Label only the specified directories. The names may be comma separated, or the
1092
Label only the specified directories. The names may be comma separated, or the
1027
option may be specified multiple times.
1093
option may be specified multiple times.
1028
 
1094
 
Line 1030... Line 1096...
1030
and the entire file tree will not be scanned. Only the specified directories
1096
and the entire file tree will not be scanned. Only the specified directories
1031
will be labeled.
1097
will be labeled.
1032
 
1098
 
1033
Wildcards are not supported.
1099
Wildcards are not supported.
1034
 
1100
 
-
 
1101
The component paths of the named path will also be labeled, when the B<-up> is
-
 
1102
used.
-
 
1103
 
1035
=item B<-label>
1104
=item B<-label>
1036
 
1105
 
1037
This option will label all the files in, and below, the current directory and
1106
This option will label all the files in, and below, the current directory and
1038
all the parent directories.
1107
all the parent directories.
1039
 
1108
 
Line 1109... Line 1178...
1109
operation is performed automatically when a -rename operation occurs. The
1178
operation is performed automatically when a -rename operation occurs. The
1110
"no" option allows this behaviour to be modified.
1179
"no" option allows this behaviour to be modified.
1111
 
1180
 
1112
=item B<-up>
1181
=item B<-up>
1113
 
1182
 
1114
This option will prevent the utility for labeling files and directories below
1183
This option will prevent the utility from labeling files and directories below
1115
the current directory. Only directories above the current directory will be
1184
the current directory. Only directories above the current directory will be
1116
labeled.
1185
labeled.
1117
 
1186
 
1118
This option may be specifically used with -dirs and -files to label the named
1187
This option may be specifically used with -dirs and -files to label the named
1119
directories and files as well as the directoires up, from the current directory.
1188
directories and files as well as the directoires up, from the current directory.
Line 1147... Line 1216...
1147
 
1216
 
1148
This option is used by commands that do not acutally place labels on files to
1217
This option is used by commands that do not acutally place labels on files to
1149
manipulate when the user's current directry is not within a view. This allows lables to be created,
1218
manipulate when the user's current directry is not within a view. This allows lables to be created,
1150
locked and unlocked without having a view present.
1219
locked and unlocked without having a view present.
1151
 
1220
 
-
 
1221
=item B<-admin>
-
 
1222
 
-
 
1223
This option modifies the label creation process to create a global label. This
-
 
1224
may be used in an admin vob.
-
 
1225
 
1152
=back
1226
=back
1153
 
1227
 
1154
=head1 DESCRIPTION
1228
=head1 DESCRIPTION
1155
 
1229
 
1156
This program provides a number of useful ClearCase labeling operations. These
1230
This program provides a number of useful ClearCase labeling operations. These