2 ################################################################################
4 # File: RemoveEmptyBranch.pl
5 # Description: This trigger script is remove empty branches. If a branch has
6 # no elements (except the 0 element of course) after an uncheckout
7 # or rmver, or the parent of a just-rmbranched branch is now empty,
12 # ct mktrtype -element -global -postop uncheckout,rmver,rmbranch \
13 # -c "Remove empty branches after uncheckout, rmver, or rmbranch" \
14 # -exec T:/Triggers/RemoveEmptyBranch RM_EMPTY_BRANCH
15 # Assumptions: Clearprompt is in the users PATH
16 # Author: Andrew@DeFaria.com
17 # Created: Fri May 23 13:23:47 PDT 2003
21 # (c) Copyright 2003, Andrew@DeFaria.com, all rights reserved
23 ################################################################################
27 # Add the appropriate path to our modules to @INC array. We use ipconfig to
28 # get the current host's IP address then determine whether we are in the US
29 # or China. If neither then we fallback to using T:/Triggers.
30 my @ipconfig = grep (/IP Address/, `ipconfig`);
31 my ($ipaddr) = ($ipconfig[0] =~ /(\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/);
33 # US is in the subnets of 192 and 172 while China is in the subnet of 10
34 if ($ipaddr =~ /^192|^172/) {
35 unshift (@INC, "//sons-clearcase/Views/official/Tools/lib");
36 } elsif ($ipaddr =~ /^10/) {
37 unshift (@INC, "//sons-cc/Views/official/Tools/lib");
39 die "Internal Error: Unable to find our modules!\n"
45 # The following environment variables are set by Clearcase when this
47 my $xname = $ENV{CLEARCASE_XPN};
48 my $opkind = $ENV{CLEARCASE_OP_KIND};
49 my $xn_sfx = $ENV{CLEARCASE_XN_SFX};
51 my $brtype = $ENV{CLEARCASE_BRTYPE};
52 #clearlog "Checking to see if the branch is empty and needs to be removed";
53 #clearlog "xname = $xname";
54 #clearlog "opkind = $opkind";
55 #clearlog "xn_sfx = $xn_sfx";
58 $xname =~ s/\\/\//g if $ENV{OS} eq "Windows_NT";
60 # For uncheckout, if the remaining version is not 0 then we are done;
61 exit 0 if ($opkind eq "uncheckout" && $xname !~ m/\/0$/);
63 #clearlog "Continuing...";
66 ($branch = $xname) =~ s/\/[^\/]*$//;
68 #clearlog "branch = $branch; xname = $xname";
70 # Don't try to remove the /main branch
71 exit 0 if $branch =~ m/\@\@\/main$/;
73 # Check if there are other versions, branches, labels or checked out versions
74 # on this branch. If so don't do anything.
75 if (opendir (D, $branch)) {
76 # This opendir succeeds only in a dynamic view
77 #clearlog "In dynamic view!";
78 my @other_stuff = readdir (D);
81 # In an empty branch there are four things: ".", "..", "0" an d"LATEST".
82 # If there are more then it isn't an empty branch
83 exit if (scalar (@other_stuff) != 4);
86 #clearlog "In snapshot view!";
87 my ($pname, $brpath) = split ($xn_sfx, $branch);
88 #clearlog "pname = $pname; brpath = $brpath";
89 # rmbranch will not reload the element...
90 system "cleartool update -log /dev/null \"$pname\"" if ($opkind eq "rmbranch");
91 my @vtree = `cleartool lsvtree -branch $brpath \"$pname\"`;
93 chomp ($latest = pop (@vtree));
94 $latest =~ tr/\\/\// if $os eq "Windows_NT";
95 #clearlog "latest = $latest";
96 exit 0 unless $latest =~ m/$brpath\/0$/;
100 clearlog "After $opkind branch is empty - removing empty branch $brtype";
101 #clearlog "About to cleartool rmbranch -force -nc \"$branch\"";
102 system "cleartool rmbranch -force -nc \"$branch\"";