# # # RM_EMPTY_BRANCH.pl # # When cleartool uncheckout, rmbranch or rmver are performed # remove the parent branch if the parent branch has no # checkouts, sub-branches or labeled versions associated # with it IFF (IF AND ONLY IF) the uncheckout file is # the 0th element or removing the branch causes the parent # branch to also be "empty". # # NOTE: Also submitted as ftp.atria.com/contrib/T0031 in cshell form. # # Author: Charles W. Clarke III (ABS) # email: charles@abs-consulting.com # URL: http://www.abs-consulting.com # Date: Nov. 04, 1997 ############################################################################## # History: 11/04/97 : Created for A Better Solution, Inc. # : 03/26/98 : Changed Perl version to work for UNIX and NT # : 07/06/98 : Moved OS check to outside of if ($OP ..) # : 12/28/98 : Added quotes to allow for filenames with spaces # : 01/23/02 : Changed "Windows_NT" to "Windows*" # : 02/08/03 : Made change for snapshot and shapshot web views. ############################################################################## $OP="$ENV{'CLEARCASE_OP_KIND'}"; $OS="$ENV{'OS'}"; if ($OP eq uncheckout) { $TEMP_ID="$ENV{'CLEARCASE_ID_STR'}"; @PARTS = split (/[\\\/]/, $TEMP_ID); $ZERO_TEST = $PARTS[$#PARTS]; if ($ZERO_TEST != 0) { ################################### # This is not the place holder so # # the branch must not be empty # # so do not remove the branch. # ################################### exit 0; } } $TEMP_ID="$ENV{'CLEARCASE_XPN'}"; if ($OS =~ /Windows*/ ) { $I = rindex ($TEMP_ID, "\\"); } else { $I = rindex ($TEMP_ID, "\/"); } $BRANCH_DIR = substr ($TEMP_ID, 0, $I); @VERSION_NAMES = `cleartool ls "$BRANCH_DIR"`; if ($#VERSION_NAMES != 1) { ######################################################## # There are either checked-out versions of the file or # # other branches created off of this branch or labeled # # versions. # ######################################################## exit 0; } else { $MAIN_TEST="$ENV{'CLEARCASE_ID_STR'}"; @PARTS = split (/[\\\/]/, $TEMP_ID); $MAIN_TEST = $PARTS[$#PARTS-1]; if ($MAIN_TEST eq "main") { ######################################## # Don't attempt to delete /main branch # ######################################## exit 0; } else { ################################## # Delete the empty parent branch # ################################## $comment="\"Automatic removal of empty branch via trigger...\""; system("cleartool rmbranch -force -c $comment \"$BRANCH_DIR\""); $VIEWKIND = "$ENV{'CLEARCASE_VIEW_KIND'}"; $PN="$ENV{'CLEARCASE_PN'}"; if ($VIEWKIND =~ /snapshot/ ) { system("cleartool update \"$PN\" "); } exit 0; } } exit 1;