#!/usr/local/bin/perl
#----------------------------------------------------------------------#
# /Copyright 1999 Cimatron Ltd. #
# #
# Perl name : rep.pl #
# Programmers : Eli Ofek & Yael Stern #
# #
# Description: New SCM Reports System for cimatron #
# #
# Invocation: #
# See Help sub Below... #
# #
# Notice: * This script creates an error log called: RErrors.log #
# When the file becomes big - you should manualy DELETE it. #
# #
# #
#----------------------------------------------------------------------#
#----------------------------------------------------------------------#
# Set general parameters: #
#----------------------------------------------------------------------#
sub GetCfg($,$) # This sub reads values from a cfg file
{ # Input: <Name of file to read from> , <Name of variable to return>
# OutPut: Returns the value of the requested variable read from the file.
my $FileName = shift; # Get file name to read from.
my $VarName = shift; # Get Var name to look for.
my $Value=""; # Holds the returned value.
my $FoundName;
my $FoundVal;
my @AllFile; # Holds the configuration file.
my @Vars; # Holds the configuration file without comments.
my $path;
# Get path To //p4ctrl/pcfs/cfg/
$path=`p4 sync //p4ctrl/pcfs/cfg/... 2> null`;
if ($?!=0) {&ErrorDie("Cannot run : p4 sync //p4ctrl/pcfs/cfg/... 2> null . Failed in sub GetCfg.");}
$path=`p4 where //p4ctrl/pcfs/cfg/...`;
if ($?!=0) {&ErrorDie("Cannot run : p4 where //p4ctrl/pcfs/cfg/... . Failed in sub GetCfg.");}
$path=~/\S*\s\S*\s(\S*)\.\.\./;
$path = $1;
my $cmd = join('',"type ",'"',"$path\\$FileName",'"');
@AllFile=`$cmd`; # Read the file
if ($?!=0) {&ErrorDie("Cannot run : $cmd . Failed in sub GetCfg.");}
@Vars = grep ((!/^#/ and !/^\n/),@AllFile); # Eliminate comments.
foreach $Vars (@Vars)
{
# chomp($Vars);
$Vars=~/(\S*)\s*:=\s*(.*)\n/;
$FoundName = $1;
$FoundVal = $2;
if ($FoundName eq $VarName)
{
$Value = $FoundVal; last;
}
}
if (length($Value)<1) { &ErrorDie("Cannot Find Variable $VarName in file $FileName ! . Failed in sub GetCfg.");}
return $Value;
}
my $timestmp = 0; # Scalars for time stamp.
my $sec = 0;
my $min = 0;
my $hour = 0;
my $mday = 0;
my $mon = 0;
my $year = 0;
my $wday = 0;
my $yday = 0;
my $isdst = 0;
my @Versions=""; # An array to keep versions of project configuration.
my $PREver=0; # Current project PRE version number.
my $DEVver=0; # Current project DEV version number.
my $INTver=0; # Current project INT version number.
my $QATver=0; # Current project QAT version number.
my $PRDver=0; # Current project PRD version number.
my $NewVer=0; # New version Num.
my $SCLver=""; # SCL version.
my $TempFile=&GetCfg("nscm.cfg","TempFile"); # Name of temporary file.
@TempArr=""; # A temporary array.
@TempArr2=""; # A temporary array.
my $TempVar=""; # A temporary var.
my $LabelName=""; # A var to keep Label Name.
my $LabelName2=""; # A var to keep Label Name.
my $LabelFile=&GetCfg("nscm.cfg","LabelFile"); # A var for filename of label properties.
my $Root=""; # Path to user's Root directory of Perforce.
my $User=""; # UserName from p4 info
my $PROJ=""; # A var for project name.
my $CONF=""; # A var for configuration name.
my $OrgCONF=""; # A var for configuration name.
my $Counter=0; # A simple counter.
my $ArgNum=""; # A var to keep the number of arguments passed to the script.
my @Users=""; # A var to keep names of users passes to the script.
my $UserNum=""; # A var to keep number of users passed to the script.
my @Groups=""; # A var to keep names of groups passes to the script or keep perforce Groups.
my $GroupNum=""; # A var to keep number of groups passed to the script.
my @Labels=""; # A var to keep names of labels passes to the script.
my $LabelNum=""; # A var to keep number of labels passed to the script.
my $DateF=""; # Avar to keep date to search from.
my $DateT=""; # Avar to keep date to search to.
my @MGrepOut=""; # An Array to keep MultiGrepCut output.
my @GrepOut=""; # An Array to keep GrepCut output.
my @Buffer=""; # An Array to keep source buffer.
my @Buffer2=""; # An Array to keep source buffer.
my @OutPut=""; # An Array to output.
my @FinOutPut=""; # An Array to output.
my @TempOutPutDates=""; # An Array for a temporary cut output of Dates.
my $Users=""; # A var to keep a list of perforce users.
my $Labels=""; # A var to keep a list of perforce labels.
my $Changes=""; # A var to keep a list of perforce changes.
my @Changes=""; # A var to keep a list of perforce changes.
my $ArgPlace=1; # A var to index how many Args were read from STDIN.
my $Data=""; # A Var to keep temporary data to transfer between subrutines.
my $Mix=""; # A Var to specify kind of report.
my $Mode=""; # A var to specify a mode of action.
my $IsPending=0; # A flag to know if we want alist of pending changelist (to know if to add "deafult by").
# Declaring subroutines #
#----------------------------------------------------------------------#
# Help Sub:
#############################
sub Help
{
print "\n\n Invocation: \n\n";
print " Use: \n";
print " \n";
print " perl rep.pl <primary switch> <seconedry switch> <<cut switch> <data>> ... \n";
print " \n";
print " <primary switch> = \n";
print " -ul : Print Perforce User List. (No cut) \n";
print " -gl : Print Perforce Group List. (No cut) \n";
print " -gul : Print Perforce Group & User List. (No cut) \n";
print " -ll : Print Perforce Labels List.(No cut) \n";
print " -pc <project>: show all configurations for a specified Project. \n";
print " -pc2 <project>: show all configurations for a specified Project,if the project is IT-show the Elite's configurations also. \n";
print " -pcall : show all configurations for all Projects (uniq). \n";
print " -fdsc <change#>: Show a full description of a given change# \n";
print " -gdsc <groupname>: Show a full description of a given group \n";
print " -diff <labelname> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> \n";
print " Show the different files between the Label and the Head revision. \n";
print " -diff2 <labelname1> <labelname2> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the different files between two Labels. \n";
print " -diff3 <tree branch 1> <tree branch 2> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the different files between two trees. \n";
print " -diffoneh <labelname> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the files that present on Head revision but not on label specified. \n";
print " -diffonel <labelname> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the files that present on label specified but not on Head revision. \n";
print " -diffone2 <labelname1> <labelname2> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the files that are in Label 1 but not in LAbel 2. \n";
print " -diffone3 <tree branch 1> <tree branch 2> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the files that are in Tree 1 but not in Tree 2. \n";
print " -eql <labelname> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show equal files between the Label and the Head revision. \n";
print " -eql2 <labelname1> <labelname2> <(optional)-full for :sort by files -fullu <optional: -u <data> or -g <data> > for :sort by user> : \n";
print " Show the equal files between two Labels. \n";
print " -eql3 <tree branch 1> <tree branch 2> <(optional)-full for :sort by files -fullu for :sort by user> : \n";
print " Show equal files between two trees. \n";
print " -arstochs < -dt to include Changes details -ndt to omit or -ndtnt to omit titles too> <ars numbers> :\n";
print " Create Submitted changes report for each Ars given. \n";
print " -arstochp < -dt to include Changes details -ndt to omit or -ndtnt to omit titles too> <ars numbers> : \n";
print " Create Pending changes report for each Ars given. \n";
print " -abytochs < -u <logins> > or <-g <groups> >:\n";
print " Create Submitted changes report for each ABY login given. \n";
print " -abytochp < -u <logins> > or <-g <groups> >: \n";
print " Create Pending changes report for each ABY login given. \n";
print " -chtoars <change numbers> : \n";
print " Create Ars report for each change # given.(including associated changes. \n";
print " -schp <change numbers> : \n";
print " Show changelist details for each pending chnagelist given. \n";
print " -schs <change numbers> : \n";
print " Show changelist details for each submitted chnagelist given. \n";
print " -msynch <changes #>: Sync to a list of changes(takes last revision if files are duplicated). \n";
print " -unsynch <change #>: UnSync to a specified change(sync to X-1 revision) - only if revision>1. \n";
print " -mintegch < -r to resolve -nr not to reslove > <project> <original branch> <destination branch> <changes #>: Integrate a list of changelists from the same branch, or from IT to Elite/.../OFF202, to a destination branch. \n";
print " -mintegchcheck <project> <original branch> <destination branch> <changes #> : Check if integrate will clobber files in the private work. \n";
print " -rdf <change #> revert all the files in the changelists that where check out for delete. \n";
print " -res <change #> resolve all the files in the changelists. \n";
print " -unsub <changes #> unsubmitting a changelist, (the version before the one in the changelist will be head revision. \n";
print " -autointg <changelist number> a new changelists will be created to all the target of the configuration \n";
print " -lf < -dt to include Labels details -ndt to omit> <label names>: \n";
print " Create label's files Report. \n";
print " -cfs < -dt to include changes details -ndt to omit -ldt to include less changes details(date&desc.)> <change numbers or 'all'>: \n";
print " Create submitted changelist's files Report. \n";
print " -cf < ARS #'s> -c < change #'s>: \n";
print " Create changelist's files Report according to given ARS's. \n";
print " -cfp < -dt to include changes details -ndt to omit> <change numbers or 'all'>: \n";
print " Create pending changelist's files Report (including default). \n";
print " -cd : Create default changelist's files Report. \n";
print " -fa < -dt to include changes details -ndt to omit> <cuts on changes> -sc <cuts on files> \n";
print " This option creates a files report according to a changes report. \n";
print " -cp : Create Pending Changelist Report. \n";
print " -cs : Create Submitted Changelist Report. \n";
print " -l : Create Labels Report. \n\n";
print " <secondery switch> = ( used only after -l switch ) \n";
print " -wb : Report only on weekly build Labels (Sorted by Date) \n";
print " -wbps : Report only on weekly build Labels (Sorted by Pass number) \n";
print " -sl : Report only on SCM standard Labels \n";
print " -all : Report on all kinds of Labels \n";
print " -vtree : Report on files labels , what revision in which label \n\n";
print " \n";
print " <cut switch> = \n";
print " -p <data>: For searching by specified project/s. \n";
print " -pp <project><configuration>: For searching by specified project & conf. . \n";
print " -c <data>: For searching by specified configuration/s. \n";
print " -m <data>: For searching by specified module/s. \n";
print " -u <data>: For searching by specified user@. \n";
print " -uu <data>: For searching by specified user.. \n";
print " -g <data>: For searching by specified group/s. \n";
print " -gu <data>: For searching by specified group/s and User/s. \n";
print " -s <data>: For searching by specified string/s. \n";
print " -ns <data>: For searching by specified string/s in Names. \n";
print " -ds <data>: For searching by specified string/s in Descriptions. \n";
print " -nds <data>: For searching by specified string/s that are NOT in Descriptions. \n";
print " -d <date from> <date to> : For searching by specified Dates/s. \n\n";
print " <date from>= day to search from. Format: yyyymmdd \n";
print " <date to> = day to search to. Format: yyyymmdd \n";
print " \n";
print " <data> = X1 X2 X3 .... \n";
print " Where Xn is a name of user, group,label etc.(According to the switch). \n";
print " \n\n";
print " You Can search with multipule switches. \n";
print " For example: perl rep.pl -l -all -d 19980924 19981024 -u elio michaln -g softinfra ...\n";
print " \n";
print " Notice: * This script creates an error log called: RErrors.log \n";
print " When the file becomes big - you should manualy DELETE it. \n\n\n";
}
# Error Subs:
#######################
sub ErrorDie ($) # This Function notifys the user of an Error , create a record of it
{ # In The log file RErrors.log , and exit the script.
my $Msg = shift; # Get message
print "Error !!!\n$Msg !\n" ;
print Err "Perforce Returned:\n" , "$!";
if (open(Err, ">>RErrors.log")!=1) {
print "Error !!!\nCannot create or update Error Log File\n" ;
}
else { select(Err); }
print Err "\nTime of Error: $timestmp \n$Msg !\n ";
print Err "Perforce Returned:\n" , "$!";
print Err "\n----------------------------------------------------------\n";
close(Err);
select(STDOUT);
exit(0);
}
sub ArgError($) # This Function notifys the user of an Argument Error , create a record of it
{ # In The log file RErrors.log , and exit the script.
my $Msg = shift; # Get message
print "\n Error !!!\n Wrong Arguments !!!\n$Msg !\n" ;
if (open(Err, ">>RErrors.log")!=1) {
print "Error !!!\nCannot create or update Error Log File\n" ;
}
else { select(Err); }
print Err "\nTime of Error: $timestmp \n Error !!!\n Wrong Arguments !!!\n$Msg !\n ";
print Err "Perforce Returned:\n" , "$!";
print Err "\n----------------------------------------------------------\n";
close(Err);
select(STDOUT);
&Help();
print "\n Please try again.\n\n\n";
exit(0);
}
# Tool Subs:
#############################
sub create_change_list($) # This subroutine Creates a Changlist and return it's #.
{ # Input: Description for the changelist.
my $description=shift; # Get description.
my $DescFile="desc.$$";
if (open(DF,">$DescFile")!=1)
{
&ErrorDie("Cannot open $DescFile $DescFile");
}
else
{ print DF "\nChange: new\n\nClient: \n\nUser: $User\n\nStatus:\n\nDescription:\n $description";
close(DF);
}
@TempArr="";
@TempArr=`p4 change -i < $DescFile`;
if ($?!=0) {&ErrorDie("Cannot run : p4 change -i < $DescFile in sub create_change_list");}
$change_list_number =substr($TempArr[0],7,index($TempArr[0],'cre',0)-8);
unlink "$DescFile";
return $change_list_number;
}
sub MultiGrepCut($,@) # Grep multiple strings of Arg1 from source Arg2 into @MGrepOut Var (Array).
{
my $Strs=shift;
my @StrsAr="";
my @Source=@_;
my $Place=0;
@MGrepOut="";
@StrsAr=split("~~",$Strs);
shift(@StrsAr);
foreach $Source (@Source)
{
foreach $StrsAr (@StrsAr)
{
if (index($Source,$StrsAr)!=-1)
{
$MGrepOut[$Place]=$Source;
$Place=$Place+1;
}
}
}
if ($IsPending==1)
{
foreach $StrsAr (@StrsAr)
{
$StrsAr=~s/by (.*)\@/$1/;
}
$Temp=`echo @StrsAr > $ENV{SCMTool}\\TempTxt\\UsersForDefault.txt`; # Create approvement file.
die "Error !\n Can't run:echo @StrsAr > $ENV{SCMTool}\\TempTxt\\UsersForDefault.txt in sub MultiGrepCut.\n" if ($?!=0);
}
}
sub MultiGrepCutOnName($,@) # Grep multiple strings in Names of Arg1 from source Arg2 into @MGrepOut Var (Array).
{
my $Strs=shift;
my @StrsAr="";
my @Source=@_;
my $Place=0;
@MGrepOut="";
@StrsAr=split("~~",$Strs);
foreach $Source (@Source)
{
foreach $StrsAr (@StrsAr)
{
if (rindex($Source,$StrsAr,index($Source," ",2))!=-1) # Limit search to Name of Label only.
{
$MGrepOut[$Place]=$Source;
$Place=$Place+1;
}
}
}
}
sub MultiGrepCutOnDesc($,@) # Grep multiple strings in Descriptions of Arg1 from source Arg2 into @MGrepOut Var (Array).
{
my $Strs=shift;
my @StrsAr="";
my @Source=@_;
my $Place=0;
@MGrepOut="";
@StrsAr=split("~~",$Strs);
foreach $Source (@Source)
{
foreach $StrsAr (@StrsAr)
{
if (index($Source,$StrsAr,index($Source," '",2))!=-1) # Limit search to description only.
{
$MGrepOut[$Place]=$Source;
$Place=$Place+1;
}
}
}
}
sub MultiGrepCutOnDescNOT($,@) # UNGrep multiple strings in Descriptions of Arg1 from source Arg2 into @MGrepOut Var (Array).
{
my $Strs=shift;
my @StrsAr="";
my @Source=@_;
my $Place=0;
my $Insert=1;
@MGrepOut="";
@StrsAr=split("~~",$Strs);
foreach $Source (@Source)
{
$Insert=1;
foreach $StrsAr (@StrsAr)
{
if (index($Source,$StrsAr,index($Source," '",2))!=-1) # Limit search to description only.
{ $Insert=0; } # Mark not to insert.
}
if ($Insert)
{
$MGrepOut[$Place]=$Source;
$Place=$Place+1;
}
}
}
sub SortAscending # This is a sorting sub for the sort Function
{ # to sort numbers in ascending order.
$a<=>$b;
}
sub SortByDate($,@) # This sub accepts an array and sort it by Date value ( If present)
{ # Input: Mode("a" for ascending, "d" for descending),Unsorted Array with dates( every line must end with \n
# Output: returns a sorted Array.
my $Mode=shift; # Get Mode.
if (not($Mode=~/[a|d]/)) { die "Error !\n Unknown Sorting Mode in Sub SortByDate ( Illegal call)\n";}
my @Unsorted=@_; # Get array to sort.
my @Sorted;
my @SortedDates;
my %hash; # Hash table.
my $date;
foreach $Unsorted (@Unsorted)
{
$Unsorted=~m|.\s(\d\d\d\d/\d\d/\d\d)\s.|; # Look for date in line.
$date=$1;
$date=~s|/||g; # eliminate / from date.
$hash{$date}="$hash{$date}$Unsorted"; # Insert to Hash.
}
if ($Mode eq "a") {@SortedDates= sort {$a <=> $b} keys %hash; }# return the sorted KEYS (Ascending)
if ($Mode eq "d") {@SortedDates= sort {$b <=> $a} keys %hash; }# return the sorted KEYS (Descending)
foreach $SortedDates (@SortedDates) # Build new array according to sorted keys.
{
push(@Sorted,$hash{$SortedDates});
}
return @Sorted; #return the sorted Array. (Each cell contains all values for the same date !)
}
sub SortByPass($,@) # This sub accepts an array and sort it by Pass Number ( If present)
{ # Input: Mode("a" for ascending, "d" for descending),Unsorted Array with dates( every line must end with \n
# Output: returns a sorted Array.
my $Mode=shift; # Get Mode.
if (not($Mode=~/[a|d]/)) { die "Error !\n Unknown Sorting Mode in Sub SortByDate ( Illegal call)\n";}
my @Unsorted=@_; # Get array to sort.
my @Sorted;
my @SortedPasses;
my %hash; # Hash table.
my $passA; # We need to saporate them in order to give diffrent weight to them as the kength of
my $passB; # the numbers is not always the same ...
my $passC; # the format will be: A.B.C.D
my $passD;
my $pass; # Concat passes ABCD
# Weights:
#===========
# A X 10^15 ( ^ means power)
# B X 10^10
# C X 10^5
# D X 10^0
#
foreach $Unsorted (@Unsorted)
{
$Unsorted=~m|._(\d+)\.(\d+)\.(\d+)\.(\d+)\D|; # Look for pass in line.
# exp(x*log(Y)) -- means x^Y
$passA=$1*exp(10*log(15));
$passB=$2*exp(10*log(10));
$passC=$3*exp(10*log(5));
$passD=$4*1;
# Make total sort weight:
$pass=$passA+$passB+$passC+$passD;
#$pass=~s|\.||g; # eliminate . from pass.
$hash{$pass}="$hash{$pass}$Unsorted"; # Insert to Hash.
}
if ($Mode eq "a") {@SortedPasses= sort {$a <=> $b} keys %hash; }# return the sorted KEYS (Ascending)
if ($Mode eq "d") {@SortedPasses= sort {$b <=> $a} keys %hash; }# return the sorted KEYS (Descending)
foreach $SortedPasses (@SortedPasses) # Build new array according to sorted keys.
{
push(@Sorted,$hash{$SortedPasses});
}
return @Sorted; #return the sorted Array. (Each cell contains all values for the same pass !)
}
# List Subs:
##############################
sub UserList # Create the Array $Users containing List of Perforce Users:
{
@TempArr=`p4 users`;
if ($?!=0) {&ErrorDie("Cannot create Userlist from p4 users\nFailed in sub UserList.");}
else
{ foreach $TempArr (@TempArr)
{
$TempVar=substr($TempArr,0,index($TempArr," "));
$Users=join('',$Users,$TempVar,"\n"); # Grep Login name only.
}
}
}
sub GroupList # Create the Array $Groups containing List of Perforce Groups:
{
@Groups=`p4 groups`;
if ($?!=0) {&ErrorDie("Cannot create Userlist from p4 groups\nFailed in sub GroupList.");}
$Groups[0]=" $Groups[0]";
}
sub ProjectConfig #This sub finds all configuration exist in specified project.
{
my $Sign="\\";
push(@OutPut,"dev\n"); # dev always exists.
$PROJ=lc($PROJ);
my @Buff=`p4 branches`;
if ($?!=0) {&ErrorDie("Cannot create configuration list from p4 branches.\nFailed in sub ProjectConfig.");}
@TempArr=grep(/Branch $PROJ/i,@Buff);
foreach $TempArr (@TempArr)
{
$TempArr=~/Branch $PROJ(\S*)(\s)/i;
$TempVar=$1;
$TempVar=~s|_|$Sign|g;
$TempVar=substr($TempVar,1);
push(@OutPut,"$TempVar\n");
}
}
sub ProjectConfig_off202 #This sub finds all configuration exist in specified project.and if the project is IT it gives also the elite conf.
{ #we use it when we want to integrate from IT to OFF202.
#input:project.
my $Sign="\\";
push(@OutPut,"dev\n"); # dev always exists.
$PROJ=lc($PROJ);
@Buffer=`p4 branches`;
if ($?!=0) {&ErrorDie("Cannot create configuration list from p4 branches.\nFailed in sub ProjectConfig.");}
@TempArr=grep(/Branch $PROJ/i,@Buffer);
foreach $TempArr (@TempArr)
{
$TempArr=~/Branch $PROJ(\S*)(\s)/i;
$TempVar=$1;
$TempVar=~s|_|$Sign|g;
$TempVar=substr($TempVar,1);
push(@OutPut,"$TempVar\n");
}
if ($PROJ =~/^IT/i) #if the project is IT give the Elite configurations also.
{
push(@OutPut,"Elite\\dev\n");
@TempArr=grep(/Branch Elite/i,@Buffer);
foreach $TempArr (@TempArr)
{
$TempArr=~/Branch (\w*)(\s)/i;
$TempVar=$1;
$TempVar=~s|_|$Sign|g;
push(@OutPut,"$TempVar\n");
}
}
}
sub Configs #This sub finds all configuration exist.
{
my $Sign="\\";
push(@OutPut,"dev\n"); # dev always exists.
$PROJ=lc($PROJ);
@Buffer=`p4 branches`;
if ($?!=0) {&ErrorDie("Cannot create configuration list from p4 branches.\nFailed in sub Configs.");}
@TempArr=grep(/Branch /,@Buffer);
foreach $TempArr (@TempArr)
{
$TempVar=substr($TempArr,index($TempArr,"_")+1,index($TempArr," ",7)-index($TempArr,"_"));
$TempVar=~s|_|$Sign|g;
push(@OutPut,"$TempVar\n");
}
%temp = map {$_ => 1} @OutPut; # Sort Uniq
@OutPut = sort {$a <=> $b} keys %temp;
}
sub FullDesc($) # Show a full description of a change.
{
my $ChangeNum=shift; # get change Number
@Buffer=`p4 change -o $ARGV[1]`;
@OutPut=grep !/^#/, @Buffer;
if ($?!=0) {&ErrorDie("Cannot run p4 change -o $ARGV[1] in sub FullDesc.");}
}
sub GroupDesc($) # Show a full description of a Group.
{
my $GroupName=shift; # get change Number
@Buffer=`p4 group -o $ARGV[1]`;
@OutPut=grep /^ /, @Buffer;
if ($?!=0) {&ErrorDie("Cannot run group -o $ARGV[1] in sub GroupDesc.");}
foreach $OutPut (@OutPut) # del Tab
{
$OutPut=~s/ //; # Del tab
# $OutPut=~s/(\s)//; # del whitespace
# $OutPut="$OutPut\n";
}
$OutPut[0]=" $OutPut[0]"; # fix space
#chomp($OutPut[$#OutPut]); # trim last \n
}
sub LabelList # Create the Array $Labels containing List of Perforce Labels:
{
@TempArr=`p4 labels`;
if ($?!=0) {&ErrorDie("Cannot create Labellist from p4 labels.\nFailed in sub LabelList.");}
foreach $TempArr (@TempArr)
{
$TempVar=substr($TempArr,index($TempArr," "));
$Labels=join('',$Labels,$TempVar); # Grep Label name only.
}
}
sub Vtree($,$,$) #create a report on a file : what revisions belong to which labels
{
my $File = shift; #Reciving the file name
my $FromDate = shift;
my $ToDate = shift ;
$FromDate =~ s/\///g;
$ToDate =~ s/\///g;
my $Temp = `p4 files $File`;
if ($?!=0) { print "Cannot run p4 files to $File"; }
$Temp =~ /#(\d+)/;
my $Version = $1;
$File =~ /^\/\/(\w+)\//;
my $Conf ; #reciving the project and the configuration
my $Project;
$Project = $1;
if ($File =~ /\/dev\//)
{
$Conf = "dev";
}
else
{
$File =~ /\/\/$Project\/(\S+)\/$Project/;
$Conf = $1;
$Conf =~ s/prd//;
$Conf =~ s/\///g;
}
@FileRevision ;
my $Vers ;
my $date ;
my @TempArr=`p4 labels`;
if ($?!=0) { print"Cannot create Labellist from p4 labels"; }
foreach $TempArr (@TempArr) #checking each label in the label list
{
$TempVar=substr($TempArr,index($TempArr,' '));
$TempVar =~ s/\s//;
$TempVar =~ /\s(\S+).*/;
$date = $1;
$date =~ s/\///g;
$TempVar =~ s/\s.*//;
if ($date >= $FromDate && $date <= $ToDate )
{
if($TempVar =~ /^$Project/)
{
if($Conf eq "dev")
{
if($TempVar =~ /\_dev\_/||$TempVar =~ /\_DEV\_/)
{
chomp ($TempVar);
$Temp = `p4 files $File\@$TempVar 2>null`;
if($Temp)
{
if ( $Temp !~ /file(s) not in label/ )
{
$Temp =~ /#(\d+)/;
$Vers = $1;
@FileRevision[$Vers] .= " " . $TempVar ; #making an array of the maching label
}
}
}
}
else
{
if($TempVar !~ /\_dev\_/ && $TempVar !~ /\_DEV\_/)
{
chomp ($TempVar);
if ($TempVar =~ /\_$Conf\_/)
{
$Temp = `p4 files $File\@$TempVar 2>null`;
if($Temp)
{
if ( $Temp !~ /file(s) not in label/ )
{
$Temp =~ /#(\d+)/;
$Vers = $1;
@FileRevision[$Vers] .= " " . $TempVar ; #making an array of the maching label
}
}
}
}
}
}
}
}
for ($i = 1 ; $i <= $Version ; $i++ ) #print all the label of the file according to the file revision
{
if ( defined @FileRevision[$i] )
{
@Temp = split( " " ,@FileRevision[$i] );
print "Revision $i:\n";
foreach $temp(@Temp)
{
print $temp ."\n";
}
}
}
unlink (null);
}
# Making Buffer Source Subs:
##################################
sub ConcatChanges(@) # Gets an array of changes & descriptions
{ # and puts every change with its description in one line.
# Input: Array of changes& full description.
# Returns: The concutted array.
my @OldArr=@_; # get old array.
my @NewArr="";
my $String="";
foreach $OldArr (@OldArr)
{
if ($OldArr=~/^Change/)
{
if ($String=~/^Change/)
{
$String=~s/[\t|\n|\r]/ /g; # eliminate tabs,newlines,CR.
$String="$String '\n";
$String=substr($String,index($String,' '));
push(@NewArr,$String);# Add full line to new array.
}
$String="$OldArr '";
}
elsif ($OldArr=~/^\t/) {chomp($OldArr); $String=join ('',$String,$OldArr);} # Add description line.
}
if ($String=~/^Change/)
{
$String=~s/[\t|\n|\r]/ /g; # eliminate tabs,newlines,CR.
$String="$String '\n";
$String=substr($String,index($String,' '));
push(@NewArr,$String);# Add full line to new array.
}
return @NewArr;
}
sub PendingChanges # Make a Buffer with all Pending Changelists:
{
@TempArr=`p4 changes -l -s pending`;
if ($?!=0) {&ErrorDie("Cannot create PendingChangesList from p4 changes -l -s pending.\nFailed in sub PendingChanges.");}
# foreach $TempArr (@TempArr)
# {
# if ($TempArr=~/^Change/) {
# # Get only number.
# $TempVar=substr($TempArr,index($TempArr,' '));}
# push(@Changes,$TempVar);
# }
# insert data into BufferArray:
@Buffer=&ConcatChanges(@TempArr);
}
sub SubmittedChangesbydate # Make a Buffer with all Submitted Changelists:
{
#input:dates <from> <to>.
$from=shift;
$to=shift;
$to++;
if ($to=~/(\d{4})1232/)
{
$to=$to+10000-1100-31;
}
if ($to=~/\d{4}(\d{2})32/)
{
$to=$to+100-31;
}
$from=~s/(\d{4})(\d{2})(\d{2})/\1\/\2\/\3/;
$to=~s/(\d{4})(\d{2})(\d{2})/\1\/\2\/\3/;
$from=~s/(\S{10})/\@\1,$to/;
@TempArr=`p4 changes -l -s submitted $from`;
if ($?!=0) {&ErrorDie("Cannot create SubmittedChangesList from p4 changes -l -s submitted $from.\nFailed in sub SubmittedChangesbydate.");}
@Buffer=&ConcatChanges(@TempArr);
}
sub SubmittedChanges # Make a Buffer with all Submitted Changelists:
{
@TempArr=`p4 changes -l -s submitted`;
if ($?!=0) {&ErrorDie("Cannot create SubmittedChangesList from p4 changes -l -s submitted.\nFailed in sub SubmittedChanges.");}
# foreach $TempArr(@TempArr)
# {
# if ($TempArr=~/^Change/) {
# $TempVar=substr($TempArr,index($TempArr,' '));}
# push(@Changes,$TempVar); # Get only number.
#
# }
# insert data into BufferArray:
@Buffer=&ConcatChanges(@TempArr);
}
sub LabelsAll # Make a Buffer with all Labels:
{
@TempArr=`p4 labels`;
if ($?!=0) {&ErrorDie("Cannot create Labellist from p4 labels.\nFailed in sub LabelsAll.");}
foreach $TempArr (@TempArr)
{
$TempVar=substr($TempArr,index($TempArr,' '));
push(@Labels,$TempVar); # grep only name.
}
# insert data into BufferArray:
@Buffer=@Labels;
}
sub LabelsWB # Make a Buffer only with Weekly build Labels:
{
@TempArr=`p4 labels`;
if ($?!=0) {&ErrorDie("Cannot create Labellist from p4 labels.\nFailed in sub LabelsWB.");}
foreach $TempArr (@TempArr)
{
if (index($TempArr,"_ob_")!=-1) # Grep only if it's a build label.
{
$TempVar=substr($TempArr,index($TempArr,' '));
push(@Labels,$TempVar); # Grep Label name only & insert cut mark.
}
}
# insert data into BufferArray:
@Buffer=@Labels;
}
sub LabelsSL # Make a Buffer with all Labels:
{
@TempArr=`p4 labels`;
if ($?!=0) {&ErrorDie("Cannot create Labellist from p4 labels.\nFailed in sub LabelsSL.");}
foreach $TempArr (@TempArr)
{
if ((index($TempArr,"_ns_")!=-1)||(index($TempArr,"_s_")!=-1)) # Grep only if it's a SCM standard label.
{
$TempVar=substr($TempArr,index($TempArr,' '));
push(@Labels,$TempVar); # Grep Label name only & insert cut mark.
}
}
# insert data into BufferArray:
@Buffer=@Labels;
}
sub ListLabelsFiles # Make a Buffer with files of specified Labels:
{
my $TempLabel="";
my @Data="";
my @TempBuffer="";
my $KeepArgPlace="";
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$TempLabel=join('',"@",$ARGV[$ArgPlace]);
push(@Data,$TempLabel); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
$KeepArgPlace=$ArgPlace;
foreach $Data (@Data)
{
if (length($Data)==0) { next;}
@Buffer=`p4 files $Data`;
if ($?!=0) { &ErrorDie(" can't run p4 files $Data .\n Failed in sub ListLabelsFiles.\n");}
$ArgPlace=$KeepArgPlace; # return to start of STDIN args & Cut on change files according to STDIN:
&GetArgs(); # Cut
@Buffer=@OutPut;
if (length($Buffer[0])>1) # If output not empty:
{
if ($Mix eq "-dt") # If asked to insert label details in report :
{
$Data=substr($Data,1); # trunc @ sign.
push(@TempBuffer,"\nFiles from Label: $Data\n\n");
}
}
push(@TempBuffer,@Buffer);
@Buffer="";
}
@OutPut=@TempBuffer;
}
sub ListSubmittedChangesFiles # Make a Buffer with files of specified changes:
{
my @Data="";
my $expr1="... //";
my $expr2="===";
my $expr3=">";
my $expr4="<";
my @TempBuffer="";
my $KeepArgPlace="";
my $UserName="";
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
if ($ARGV[$ArgPlace] eq "all") # If choose to report for all submitted changes.
{
&SubmittedChanges(); # Find all submitted changes.
foreach $Buffer (@Buffer)
{
$Buffer=~/(\s)(\d*) on(\w*) by (\w*)@(\w*)/; # get only numbers.
push(@Data,$2);
}
if (length($Data)==0) { next;}
last;
}
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
$KeepArgPlace=$ArgPlace;
foreach $Data (@Data)
{
if (length($Data)==0) { next;}
@TempArr=`p4 describe $Data`;
if ($?!=0) {&ErrorDie("Cannot create Submitted Changes Files list from p4 describe $Data\nFailed in sub ListSubmittedChangesFiles.");}
$TempArr[0]=~/Change (\d*) by (\w*)@(\S*) on (\S* \S*)/; # Get owner of this chngelist
$UserName=$2;
$Date= $4;
@Description=grep(/^\t/,@TempArr);
@Buffer=grep(/$expr1/,@TempArr);
@Buffer=grep(!/$expr2/,@Buffer);
@Buffer=grep(!/$expr3(\w*)/,@Buffer);
@Buffer=grep(!/$expr4(\w*)/,@Buffer);
map(s|... //|//|, @Buffer);
$ArgPlace=$KeepArgPlace; # return to start of STDIN args & Cut on change files according to STDIN:
&GetArgs(); # Cut
@Buffer=@OutPut;
if (length($Buffer[0])>1) # If output not empty:
{
if ($Mix eq "-ldt") # If asked to insert change details in report :
{
push(@TempBuffer,"\nFiles from Submitted Change: $Data ($UserName)\n\n");
}
if ($Mix eq "-dt") # If asked to insert more change details in report :
{
push(@TempBuffer,"\nSubmitted Change: $Data \n");
push(@TempBuffer,"User: $UserName \n");
push(@TempBuffer,"Date: $Date \n");
push(@TempBuffer,"Description: \n@Description\n\n");
push(@TempBuffer,"Files:\n\n");
}
}
push(@TempBuffer,@Buffer);
push(@TempBuffer,"========================================================================\n\n");
@Buffer="";
}
@OutPut=@TempBuffer;
}
sub ListPendingChangesFiles # Make a Buffer with files of specified changes:
{
my $expr="";
my @Data="";
my @TempBuffer="";
my $KeepArgPlace="";
my $UserName="";
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
if ($ARGV[$ArgPlace] eq "all") # If choose to report for all Pending changes.
{
&PendingChanges(); # Find all pending changes.
foreach $Buffer (@Buffer)
{
$Buffer=~/(\s)(\d*) on(\w*)/; # get only numbers.
push(@Data,$2);
}
push(@Data,"default");
$ArgPlace=$ArgPlace+1; # skip to cut Args
last;
}
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
$KeepArgPlace=$ArgPlace;
@TempArr=`p4 opened -a`;
if ($?!=0) {&ErrorDie("Cannot create Pending Changes Files list from p4 opened -a\nFailed in sub ListPendingChangesFiles.");}
foreach $Data (@Data)
{
if (length($Data)==0) { next;}
@Buffer="";
@Buffer=grep(/ (change|edit|add|delete) $Data /,@TempArr);
$ArgPlace=$KeepArgPlace; # return to start of STIN args & Cut on change files according to STDIN:
&GetArgs(); # Cut
@Buffer=@OutPut;
# omit unsuseful info and find out username of change:
$Buffer[0]=~/ by (\w*)@/; # Find Name.
$UserName=$1;
foreach $Buffer (@Buffer)
{
$Buffer=substr($Buffer,0,index($Buffer," by "));
$Buffer="$Buffer\n";
}
if (length($Buffer[0])>1) # If output not empty:
{
if ($Mix eq "-dt") # If asked to insert change details in report :
{
push(@TempBuffer,"\nFiles from Pending Change: $Data ($UserName)\n\n");
}
}
push(@TempBuffer,@Buffer);
}
@OutPut=@TempBuffer;
}
sub ListDefaultChangesFiles # Make a Buffer with files of specified changes:
{
$Data="";
@TempArr=`p4 opened -a`;
if ($?!=0) {&ErrorDie("Cannot create Default Changes Files list from p4 opened -a\nFailed in sub ListDeaultChangesFiles.");}
@Buffer=grep(/ (change|edit|add|delete) default/,@TempArr);
}
sub OpenChanges
{
my $Change="";
my $Cnum="";
my $KeepArgPlace=$ArgPlace;
my $expr1="... //";
my $expr2="===";
my $expr3=">";
my $expr4="<";
my @Files="";
@FinOutPut="";
@Changes=@OutPut;
foreach $Change (@Changes) # For each change selected:
{
@Buffer="";
@Files="";
if (length($Change)<1) {next;}
$Change=~/(\s)(\d*)(\s)on(\w*)/; # Get change num.
$Cnum=$2;
@TempArr=`p4 describe $Cnum`;
if ($?!=0) {&ErrorDie("Cannot create Changes Files list from p4 describe $Cnum.\nFailed in sub OpenChanges.");}
# grep only files data.
@Files=grep(/$expr1/,@TempArr);
@Files=grep(!/$expr2/,@Files);
@Files=grep(!/$expr3(\w*)/,@Files);
@Files=grep(!/$expr4(\w*)/,@Files);
map(s|... //|//|, @Files);
@Buffer=@Files;
@OutPut="";
$ArgPlace=$KeepArgPlace; # return to start of STIN args & Cut on change files according to STDIN:
&GetArgs();
if (length($OutPut[0])>1) # If output not empty:
{
if ($Mix eq "-dt") # If asked to insert change details in report :
{
push(@FinOutPut,$Change,"\n",@OutPut,"\n\n");
}
else # If asked to create only files report:
{
push(@FinOutPut,@OutPut);
}
}
}
}
sub DiffLabel() # Find the diffrent files between the label and the head revision.
{
my $item;
my $Command=join('',"p4 diff2 //...@",$LabelName," //... ");
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command.\nFailed in sub DiffLabel.");}
foreach $TempArr (@TempArr) # Grep only diffrent files.
{
chomp;
if ($TempArr=~/^===/)
{
$item = $TempArr;
}
else
{
$NLines{$item}++;
}
}
# Put Headline:
push(@OutPut,"The different files between:\n\n Label: $LabelName Vs. Head revision : \n\n\n");
foreach $l (sort keys %NLines)
{
push(@OutPut,"$l");
}
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The different files between:\n\n Label: $LabelName Vs. Head revision : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,length($OutPut)-10),"\n");
}
}
sub DiffonehLabel() # Find the files only in the head revision.
{
my $Command="";
my $item;
my @Views="";
@TempArr="";
@Views=`p4 label -o $LabelName`;
if ($?!=0) {&ErrorDie("Cannot run p4 label -o .\nFailed in sub DiffonehLabel.");}
@Views=grep m| //|,@Views;
foreach $View (@Views) # Check all views in Label
{
chomp($View);
$Command=join('',"p4 diff2 -dc $View@",$LabelName," $View ");
@TempArr2=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command.\nFailed in sub DiffonehLabel.");}
push(@TempArr,@TempArr2);
}
@TempArr2="";
@TempArr2=grep (m|^====|,@TempArr); # Grep only lines with "====".
@TempArr="";
@TempArr=grep (m|==== < none > - //|,@TempArr2); # Grep only lines with "none".
# Put Headline:
push(@OutPut,"The files only in Head revision but not in Label : $LabelName : \n\n\n");
push(@OutPut,@TempArr);
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The files only in Head revision but not in Label : $LabelName : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,index($OutPut,"> - ")+4,rindex($OutPut," ====")-index($OutPut,"> - ")-4),"\n");
}
}
sub DiffonelLabel() # Find the files only in the label.
{
my $Command="";
my $item;
my @Views="";
@TempArr="";
@Views=`p4 label -o $LabelName`;
if ($?!=0) {&ErrorDie("Cannot run p4 label -o .\nFailed in sub DiffonelLabel.");}
@Views=grep m| //|,@Views;
foreach $View (@Views) # Check all views in Label
{
chomp($View);
$Command=join('',"p4 diff2 -dc $View@",$LabelName," $View ");
@TempArr2=`$Command`;
if ($?!=0){&ErrorDie("Cannot create diff file list from $Command\nFailed in sub DiffonelLabel.");}
push(@TempArr,@TempArr2);
}
@TempArr2="";
@TempArr2=grep (m|^====|,@TempArr); # Grep only lines with "====".
@TempArr="";
@TempArr=grep (m|- <none> ==|,@TempArr2); # Grep only lines with "none".
# Put Headline:
push(@OutPut,"The files only in Label : $LabelName but not in Head revision : \n\n\n");
push(@OutPut,@TempArr);
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The files only in Label : $LabelName but not in Head revision : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,rindex($OutPut," - <")-4),"\n");
}
}
sub DiffLabel2() # Find the diffrent files between two Labels.
{
$CONF=lc($CONF); # Compare files:
my $item;
my $Command=join('',"p4 diff2 -dc //...@",$LabelName," //...@",$LabelName2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub DiffLabel2.");}
foreach $TempArr (@TempArr) # Grep only diffrent files.
{
chomp;
if ($TempArr=~/^===/)
{
$item = $TempArr;
}
else
{
$NLines{$item}++;
}
}
# Put Headline:
push(@OutPut,"The different files between:\n\n Label: $LabelName & Label: $LabelName2 : \n\n\n");
foreach $l (sort keys %NLines)
{
push(@OutPut,"$l");
}
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The different files between:\n\n Label: $LabelName & Label: $LabelName2 : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,length($OutPut)-10),"\n");
}
}
sub DiffoneLabel2() # Find the files only in the First label.
{
my $Command="";
my $item;
$Command=join('',"p4 diff2 -dc //...@",$LabelName," //...@",$LabelName2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub DiffoneLabel2.");}
@TempArr2=grep (m|^====|,@TempArr); # Grep only lines with "====".
@TempArr="";
@TempArr=grep (m|- <none> ==|,@TempArr2); # Grep only lines with "none".
# Put Headline:
push(@OutPut,"The files only in Label : $LabelName but not in Label : $LabelName2 : \n\n\n");
push(@OutPut,@TempArr);
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The files only in Label : $LabelName but not in Label : $LabelName2 : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,rindex($OutPut," - <")-4),"\n");
}
}
sub DiffLabel3($,$) # Find the diffrent files between two branch trees.
{
my $Tree1=shift;
my $Tree2=shift;
my $item;
my $Command=join('',"p4 diff2 -dc ",$Tree1," ",$Tree2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub DiffLabel3.");}
foreach $TempArr (@TempArr) # Grep only diffrent files.
{
chomp;
if ($TempArr=~/^===/)
{
$item = $TempArr;
}
else
{
$NLines{$item}++;
}
}
# Put Headline:
push(@OutPut,"The different files between $Tree1 Vs. $Tree2 : \n\n");
foreach $l (sort keys %NLines)
{
push(@OutPut,"$l");
}
$Tree1=substr($Tree1,0,length($Tree1)-3);
$Tree2=substr($Tree2,0,length($Tree2)-3);
my $pos1=index($OutPut,"$Tree1")+length($Tree1)+5;
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut=~/The different files between/) { next;}
$OutPut=join('',substr($OutPut,$pos1,index($OutPut," - //")-$pos1+3),
substr($OutPut,index($OutPut,"$Tree2",$pos1)+length($Tree2)-1,
index($OutPut," ====")-index($OutPut,"$Tree2",$pos1)-length($Tree2)+1),"\n");
}
}
sub DiffoneLabel3() # Find the files only in the First tree.
{
my $Command="";
my $item;
my $Tree1=shift;
my $Tree2=shift;
$Command=join('',"p4 diff2 -dc ",$Tree1," ",$Tree2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub DiffoneLabel3.");}
@TempArr2=grep (m|^====|,@TempArr); # Grep only lines with "====".
@TempArr="";
@TempArr=grep (m|- <none> ==|,@TempArr2); # Grep only lines with "none".
# Put Headline:
push(@OutPut,"The files that are only in $Tree1 but not in $Tree2 : \n\n\n");
push(@OutPut,@TempArr);
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The files that are only in $Tree1 but not in $Tree2 : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,rindex($OutPut," - <")-4),"\n");
}
}
sub EqlLabel() # Find the files equal in both label & Head revision.
{
my $Command="";
my $item;
my @Views="";
@TempArr="";
@Views=`p4 label -o $LabelName`;
if ($?!=0) {&ErrorDie("Cannot run p4 label -o \nFailed in sub EqlLabel.");}
@Views=grep m| //|,@Views;
foreach $View (@Views) # Check all views in Label
{
chomp($View);
$Command=join('',"p4 diff2 -dc $View@",$LabelName," $View ");
@TempArr2=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub EqlLabel.");}
push(@TempArr,@TempArr2);
}
@TempArr2="";
@TempArr2=grep (m|^====|,@TempArr); # Grep only lines with "====".
@TempArr="";
@TempArr=grep (m| = //|,@TempArr2); # Grep only lines with "none".
# Put Headline:
push(@OutPut,"The files both in Label : $LabelName and in Head revision : \n\n\n");
push(@OutPut,@TempArr);
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut eq "The files both in Label : $LabelName and in Head revision : \n\n\n")
{ next;}
$OutPut=join('',substr($OutPut,5,rindex($OutPut," = //")-4),"\n");
}
}
sub EqlLabel2() # Find the files equal in both labels.
{
my $Command="";
my $item;
$Command=join('',"p4 diff2 -dc //...@",$LabelName," //...@",$LabelName2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub EqlLabel2.");}
foreach $TempArr (@TempArr) # Grep only diffrent files.
{
chomp;
if ($TempArr=~/^===/)
{
$item = $TempArr;
if ($TempArr=~/none/) {next;} else {$NLines{$item}=0};
}
else
{
$NLines{$item}++;
}
}
# Put Headline:
push(@OutPut,"The files both in Label : $LabelName and in Label : $LabelName2 : \n\n\n");
foreach $l (sort keys %NLines) # Get only equal files.
{
if ($NLines{$1}==0) {push(@OutPut,"$l");}
}
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut=~/The files both in/) { next;}
if ($OutPut=~/ - /)
{$OutPut=join('',substr($OutPut,5,rindex($OutPut," - //")-7),"\n");}
if ($OutPut=~/ = /)
{$OutPut=join('',substr($OutPut,5,rindex($OutPut," = //")-7),"\n");}
}
}
sub EqlLabel3() # Find the files equal in both trees.
{
my $Command="";
my $item;
my $Tree1=shift;
my $Tree2=shift;
$Command=join('',"p4 diff2 -dc ",$Tree1," ",$Tree2);
@TempArr=`$Command`;
if ($?!=0) {&ErrorDie("Cannot create diff file list from $Command\nFailed in sub EqlLabel3.");}
foreach $TempArr (@TempArr) # Grep only diffrent files.
{
chomp;
if ($TempArr=~/^===/)
{
$item = $TempArr;
if ($TempArr=~/none/) {next;} else {$NLines{$item}=0};
}
else
{
$NLines{$item}++;
}
}
# Put Headline:
push(@OutPut,"The files both in : $Tree1 and in $Tree2 : \n\n\n");
foreach $l (sort keys %NLines) # Get only equal files.
{
if ($NLines{$1}==0) {push(@OutPut,"$l");}
}
$Tree1=substr($Tree1,0,length($Tree1)-3);
my $pos1=index($OutPut,"$Tree1")+length($Tree1)+5;
foreach $OutPut (@OutPut) # filename.
{
if ($OutPut=~/The files both in/) { next;}
if ($OutPut=~/ - /)
{$OutPut=join('',substr($OutPut,$pos1,index($OutPut," - ")-$pos1-2),"\n");}
if ($OutPut=~/ = /)
{$OutPut=join('',substr($OutPut,$pos1,index($OutPut," = ")-$pos1-2),"\n");}
}
}
sub MakeFull
{
my @Buffer2="";
my $revision1="";
my $revision2="";
my $Command="";
my $FileName="";
@Buffer=@OutPut;
@OutPut="";
$OutPut[0]=$Buffer[1]; # Copy headline.
$Buffer[0]="";
$Buffer[1]="";
foreach $Buffer (@Buffer)
{
if (length($Buffer)<1) {next;}
push(@OutPut,"\n$Buffer"); # Put file headline
$revision1=substr($Buffer,index($Buffer,"#")+1,index($Buffer," - ")); # get old revision.
$revision2=substr($Buffer,rindex($Buffer,"#")+1);# get new revision.
$FileName=substr($Buffer,0,index($Buffer,"#"));
# $FileName=~s|/(\w)(\w*)(\s)(\s*)(\w)(\w*)/|/"$1$2$3$4$5$6"/|; # Fix directories with spaces in names.
# $Command=join('',"p4 filelog ",'"',$FileName); #Get filename only.
$Command=join('','p4 filelog "',$FileName,'"'); #Get filename only.
@Buffer2=`$Command`; # Get log.
if ($?!=0) { &ErrorDie("Cannot run $Command in sub MakeFull");}
@Buffer2=grep {(/... #(\d*) change/) && ($1<=$revision2) && ($1>$revision1)} @Buffer2; # get only revisions in range.
push(@OutPut,@Buffer2);
@Buffer2="";
}
}
sub MakeFullU
{
my @Buffer2="";
my @Buffer3="";
my @Buffer4="";
my $revision1="";
my $revision2="";
my $Command="";
my $FileName="";
my $SelectedUsers="";
my @SelectedGroups="";
my $CutKind="";
&UserList(); # Get Names of users.
my @UserNames=split('\n',$Users);
@Buffer=@OutPut;
@OutPut="";
$OutPut[0]=$Buffer[1]; # Copy headline.
$Buffer[0]="";
$Buffer[1]="";
$ArgPlace++; # Get users and groups to show
if ($ARGV[$ArgPlace] eq "-u") { $CutKind="u";}
elsif ($ARGV[$ArgPlace] eq "-g") { $CutKind="g";}
else {$CutKind="All";}
$ArgPlace++;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
if ($CutKind eq "u")
{ $SelectedUsers=join('',$SelectedUsers," $ARGV[$ArgPlace] ");} # Add item to list.
if ($CutKind eq "g")
{ push(@SelectedGroups,$ARGV[$ArgPlace]);} # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
# Open groups to users.
if ($CutKind eq "g")
{
foreach $SelectedGroups (@SelectedGroups)
{
if (length($SelectedGroups)<1) {next;}
@TempArr=`p4 group -o $SelectedGroups`; # open group
@TempArr=grep /^ /, @TempArr; # get user names.
foreach $TempArr (@TempArr)
{ chomp($TempArr);
$TempArr=substr($TempArr,1);
if ($SelectedUsers=~/~$TempArr~/) {next} # If exist already - skip
$SelectedUsers=join('',$SelectedUsers," $TempArr "); # Add user to list.
}
}
}
foreach $Buffer (@Buffer)
{
if (length($Buffer)<1) {next;}
$revision1=substr($Buffer,index($Buffer,"#")+1,index($Buffer," - ")); # get old revision.
$revision2=substr($Buffer,rindex($Buffer,"#")+1);# get new revision.
$FileName=substr($Buffer,0,index($Buffer,"#"));
# $FileName=~s|/(\w)(\w*)(\s)(\s*)(\w)(\w*)/|/"$1$2$3$4$5$6"/|; # Fix directories with spaces in names.
# $Command=join('',"p4 filelog ",'"',$FileName); #Get filename only.
$Command=join('','p4 filelog "',$FileName,'"'); #Get filename only.
@Buffer2=`$Command`; # Get log.
if ($?!=0) { &ErrorDie("Cannot run $Command in sub MakeFullU");}
@Buffer2=grep {(/... #(\d*) change/) && ($1<=$revision2) && ($1>$revision1)} @Buffer2; # get only revisions in range that belong to the user.
foreach $Buffer2 (@Buffer2)
{ $Buffer2="$Buffer2~~~~~$FileName"; } # Put file index for every change.
push(@Buffer3,@Buffer2);
@Buffer2="";
}
foreach $UserNames (@UserNames)
{
if (($CutKind ne "All") && (index($SelectedUsers," $UserNames ")==-1)){ next;} # if user wasn't selected - skip.
foreach $Buffer (@Buffer)
{
if (length($Buffer)<1) {next;}
$FileName=substr($Buffer,0,index($Buffer,"#"));
# $FileName=~s|/(\w)(\w*)(\s)(\s*)(\w)(\w*)/|/"$1$2$3$4$5$6"/|; # Fix directories with spaces in names.
@Buffer2=grep {(/~~~~~$FileName/) && (/ by $UserNames@/)} @Buffer3; # get only revisions in range that belong to the user.
if ((length($Buffer2[0])>0) || (length($Buffer2[1])>0))
{
push(@Buffer4,"\n$Buffer\n"); # Put file headline
}
foreach $Buffer2 (@Buffer2)
{
$Buffer2=substr($Buffer2,0,index($Buffer2,"~~~~~")); # Clean file index.
}
push(@Buffer4,@Buffer2);
@Buffer2="";
}
if ((length($Buffer4[0])>0) || (length($Buffer4[1])>0))
{
push(@OutPut,"\n\nFiles And Changes from user: $UserNames\n\n");
push(@OutPut,@Buffer4);
@Buffer4="";
}
}
}
sub ArsToSubmittedChanges() # This sub Gets a list of ARS # and show their associated Submitted changes with or without details.
{
my @Data="";
my @ArsN="";
my $Place=0;
my $ArsTitle=0;
&SubmittedChanges();
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
@ArsN=@Data;
foreach $ArsN (@ArsN)
{
if (length($ArsN)<1) {next;}
$ArsTitle=0;
foreach $Buffer (@Buffer)
{
# if (($Buffer=~/[Aa][Rr][Ss](\s*)(\d*)/) and ($ArsN==$2)) # Find ARS# that much $ArsN.
if ($Buffer=~/[Aa][Rr][Ss](\s*)$ArsN[\W]/) # Find ARS# that much $ArsN.
{
if($ArsTitle==0)
{
if ($Mix eq "-ndtnt")
{
$OutPut[$Place]="$ArsN\n"; # Insert ARS Title if not inserted yet And only number required.
$Place=$Place+1;
$ArsTitle=1;
}
else
{
#$OutPut[$Place]="ARS $ArsN :\n"; # Insert ARS Title if not inserted yet.
$Place=$Place+1;
$ArsTitle=1;
}
}
if ($Mix eq "-ndt") # If asked to omit changes details:
{
$Buffer=substr($Buffer,0,index($Buffer,"on")-1);
$OutPut[$Place]=" $Buffer";
$Place=$Place+1;
}
elsif ($Mix eq "-ndtnt") # If asked to omit changes details and Titles details:
{
$Buffer=substr($Buffer,0,index($Buffer,"on")-1);
$OutPut[$Place]="$Buffer\n";
$Place=$Place+1;
}
else
{
$OutPut[$Place]="$Buffer ";
$Place=$Place+1;
}
}
}
}
}
sub ArsToPendingChanges() # This sub Gets a list of ARS # and show their associated Pending changes with or without details.
{
my @Data="";
my @ArsN="";
my $Place=0;
my $ArsTitle=0;
&PendingChanges();
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
@ArsN=@Data;
foreach $ArsN (@ArsN)
{
if (length($ArsN)<1) {next;}
$ArsTitle=0;
foreach $Buffer (@Buffer)
{
# if (($Buffer=~/[Aa][Rr][Ss](\s*)(\d*)/) and ($ArsN==$2)) # Find ARS# that much $ArsN.
if ($Buffer=~/[Aa][Rr][Ss](\s*)$ArsN[\W]/) # Find ARS# that much $ArsN.
{
if($ArsTitle==0)
{
if ($Mix eq "-ndtnt")
{
$OutPut[$Place]="$ArsN\n"; # Insert ARS Title if not inserted yet And only number required.
$Place=$Place+1;
$ArsTitle=1;
}
else
{
#$OutPut[$Place]="ARS $ArsN :\n"; # Insert ARS Title if not inserted yet.
$Place=$Place+1;
$ArsTitle=1;
}
}
if ($Mix eq "-ndt") # If asked to omit changes details:
{
$Buffer=substr($Buffer,0,index($Buffer,"on")-1);
$OutPut[$Place]=" $Buffer";
$Place=$Place+1;
}
elsif ($Mix eq "-ndtnt") # If asked to omit changes details and Titles details:
{
$Buffer=substr($Buffer,0,index($Buffer,"on")-1);
$OutPut[$Place]="$Buffer\n";
$Place=$Place+1;
}
else
{
$OutPut[$Place]="$Buffer ";
$Place=$Place+1;
}
}
}
}
}
sub ABYToSubmittedChanges($) # This sub Gets a list of ABY logins # and show their associated Submitted changes with or without details.
{ # Input: -u for search by users -g for search by groups.
my $Search=shift; # Get search method.
my @Data="";
my @Abyl="";
my $Place=0;
my $Users="";
&SubmittedChanges();
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
if ($Search eq "-u") # If users method:
{
@Abyl=@Data;
}
elsif ($Search eq "-g") # If groups method:
{
foreach $Data (@Data)
{
if (length($Data)<1) {next;}
@TempArr=`p4 group -o $Data`; # open group
if ($?!=0) { &ErrorDie("can't run: p4 group -o $Data.\n Failed in sub ABYToSubmittedChanges.");}
@TempArr=grep /^ /, @TempArr; # get user names.
foreach $TempArr (@TempArr)
{ chomp($TempArr);
$TempArr=substr($TempArr,1);
if ($Users=~/ $TempArr /) {next} # If exist already - skip
$Users=join("",$Users," ",$TempArr," "); # Add user to list.
}
}
@Abyl=split(" ",$Users);
}# If Unknown (Error):
else {&ErrorDie("Illegal parameter was sent to sub ABYToSubmittedChanges.\nFailed in sub ABYToSubmittedChanges.");}
foreach $Abyl (@Abyl)
{
if (length($Abyl)<1) {next;}
$AbyTitle=0;
foreach $Buffer (@Buffer)
{
# if (($Buffer=~/[Aa][Bb][Yy]:(\s*)(\d*)/) and ($Abyl==$2)) # Find ABY:<login> that much $Abyl.
if ($Buffer=~/[Aa][Bb][Yy]:(\s*)$Abyl[\W]/) # Find ABY:<login> that much $Abyl.
{
push(@OutPut,"$Buffer ");
}
}
}
}
sub ABYToPendingChanges() # This sub Gets a list of ABY logins and show their associated Pending changes with or without details.
{ # Input: -u for search by users -g for search by groups.
my $Search=shift; # Get search method.
my @Data="";
my @Abyl="";
my $Place=0;
my $Users="";
&PendingChanges();
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
if ($Search eq "-u") # If users method:
{
@Abyl=@Data;
}
elsif ($Search eq "-g") # If groups method:
{
foreach $Data (@Data)
{
if (length($Data)<1) {next;}
@TempArr=`p4 group -o $Data`; # open group
if ($?!=0) { &ErrorDie("can't run: p4 group -o $Data.\n Failed in sub ABYToPendingChanges.");}
@TempArr=grep /^ /, @TempArr; # get user names.
foreach $TempArr (@TempArr)
{ chomp($TempArr);
$TempArr=substr($TempArr,1);
if ($Users=~/ $TempArr /) {next} # If exist already - skip
$Users=join("",$Users," ",$TempArr," "); # Add user to list.
}
}
@Abyl=split(" ",$Users);
}# If Unknown (Error):
else {&ErrorDie("Illegal parameter was sent to sub ABYToPendingChanges.\nFailed in sub ABYToPendingChanges.");}
foreach $Abyl (@Abyl)
{
if (length($Abyl)<1) {next;}
$AbyTitle=0;
foreach $Buffer (@Buffer)
{
# if (($Buffer=~/[Aa][Bb][Yy]:(\s*)(\d*)/) and ($Abyl==$2)) # Find ABY:<login> that much $Abyl.
if ($Buffer=~/[Aa][Bb][Yy]:(\s*)$Abyl[\W]/) # Find ABY:<login> that much $Abyl.
{
push(@OutPut,"$Buffer ");
}
}
}
}
sub ShowSubmittedChangelists(@) # This sub showes a list of submitted changelists requested as parameter.
{
$Changes=join (' ' ,' ',@_,' '); # Get List of changes to show.
&SubmittedChanges(); # Get both Submitted & Pending Changes.
foreach $Buffer (@Buffer)
{
if (($Buffer=~/(\d*) on/) && ($Changes=~/ $1 /)) # If found changelist:
{ push (@OutPut,$Buffer);} # Add change to output.
}
}
sub ShowPendingChangelists(@) # This sub showes a list of pending changelists requested as parameter.
{
$Changes=join (' ' ,' ',@_,' '); # Get List of chnges to show.
&PendingChanges(); # Get both Submitted & Pending Changes.
foreach $Buffer (@Buffer)
{
if (($Buffer=~/(\d*) on/) && ($Changes=~/ $1 /)) # If found hcnagelist:
{ push (@OutPut,$Buffer);} # Add change to output.
}
}
sub ArsToChangesAndFiles() # This sub Gets a list of ARS # and show their associated changes that were requested and files with or without details.
{
my $Changes="";
my $ChangeNum="";
my $Data="";
my @ArsN="";
my $ArsTitle=0;
my @TempBuffer="";
my @Files="";
my @SaveSubmitted="";
my $expr1="... //";
my $expr2="===";
my $expr3=">";
my $expr4="<";
&SubmittedChanges(); # Get both Submitted & Pending Changes.
@SaveSubmitted=@Buffer;
&PendingChanges();
push(@Buffer,@SaveSubmitted);
@Changes="";
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-c")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add ARS item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
$ArgPlace=$ArgPlace+1; # Move to next Arg.
while ($ArgPlace <= $ArgNum) # While not passes a switch or end.
{
push(@Changes,$ARGV[$ArgPlace]); # Add ARS item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
$Changes=join(" ",@Changes);
@ArsN=@Data;
foreach $ArsN (@ArsN)
{
if (length($ArsN)<1) {next;}
$TempVar=substr($ArsN,length($ArsN)-1,1);
while ((ord($TempVar)>57) || (ord($TempVar)<48))
{ chomp($ArsN);}
$ArsTitle=0;
@TempArr2="";
#@TempArr2=grep {(/[Aa][Rr][Ss](\s*)(\d*)/)&&($ArsN==$2); } @Buffer;
@TempArr2=grep {(/[Aa][Rr][Ss](\s*)$ArsN[\W]/)} @Buffer;
foreach $TempArr2 (@TempArr2)
{
$TempArr2=~/ (\d*) on/;
$ChangeNum=$1;
# Check if the change is required. else - skip
if (index($Changes,$ChangeNum)==-1) {next;}
if($ArsTitle==0)
{
push(@OutPut,"\n\nFrom ARS $ArsN:\n\n"); # Insert ARS Title if not inserted yet.
$ArsTitle=1;
}
push(@OutPut,"\n$TempArr2 "); # Insert change specification.
if (index($TempArr2,"*pending*")!=-1) # if it's a pending change:
{
@TempArr=`p4 opened -a`;
if ($?!=0) {&ErrorDie("Cannot create Pending Changes Files list from p4 opened -a.\nFailed in sub ArsToChangesAndFiles.");}
# grep only files data.
@Files=grep(/ change $ChangeNum /,@TempArr);
}
else # if it's a submitted change:
{
@TempArr=`p4 describe $ChangeNum `;
if ($?!=0) {&ErrorDie("Cannot create Change Files list from p4 describe $ChangeNum .\nFailed in sub ArsToChangesAndFiles.");}
# grep only files data.
@Files=grep(/$expr1/,@TempArr);
@Files=grep(!/$expr2/,@Files);
@Files=grep(!/$expr3(\w*)/,@Files);
@Files=grep(!/$expr4(\w*)/,@Files);
map(s|... //|//|, @Files);
}
if (length($Files[0])>2){push(@OutPut,"\n@Files");} # Add Files to report.
}
}
}
sub ChangesToArs() # This Sub Gets a list of changes # and show the ARS's associated
{
my @Data="";
my @Change="";
my $Place=0;
my $ArsTitle;
my $ChangeTitle=0;
my $TempBuffer="";
my @ArsList="";
my @SelectedChanges="";
my @Buff1="";
my @Buff2="";
# Get buffer of Submitted & Pending changes.
&PendingChanges();
@Buff1=@Buffer;
&SubmittedChanges();
@Buff2=@Buffer;
@Buffer="";
push(@Buffer,@Buff1,@Buff2);
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
push(@Data,$ARGV[$ArgPlace]); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
@Change=@Data;
foreach $Change (@Change)
{
if (length($Change)<1) {next;}
foreach $Buffer (@Buffer) # Get only Changes details of changes specified and contain ARS's.
{
if (($Buffer=~/$Change on/)&&($Buffer=~/[Aa][Rr][Ss](\s*)(\d*)[\W]/)) # Find Change # that much $Change and contains ARS's.
{
push(@SelectedChanges,$Buffer);
}
}
}
foreach $SelectedChanges (@SelectedChanges)
{
@TempArr=($SelectedChanges=~/[Aa][Rr][Ss](\s*)(\d*)/g); # Get ARS #'s.
if (length($TempArr[1])>0)
{
foreach $TempArr (@TempArr)
{
if (length($TempArr)<1) {next;}
$TempVar=join('~~',@ArsList);
if ($TempVar=~/$TempArr/) {next;}
else { push(@ArsList,$TempArr);}
}
}
}
#$TempVar=join('~~',@ArsList);
#$TempVar=substr($TempVar,4);
#@ArsList=split('~~~~',$TempVar);
foreach $ArsList (@ArsList) # Finds all associated changes.
{
if (length($ArsList)<3) {next;}
$ArsTitle=0;
foreach $Buffer (@Buffer)
{
if (($Buffer=~/[Aa][Rr][Ss](\s*)$ArsList[\W]/g) ) # Find ARS# that much $ArsList.
{
if($ArsTitle==0)
{
push(@OutPut,"\n\nFrom ARS $ArsList:\n\n"); # Insert ARS Title if not inserted yet.
$ArsTitle=1;
}
push(@OutPut," $Buffer");
}
}
}
}
sub CheckSyncToChange($) # Simulate Sync to a specified change.
{ # and Return 1 if OK 0 If Failed.
# Also print message to the STDOUT.
my $ChangeNum=shift;
my $Error=0;
@Buffer="";
@TempArr=`p4 describe -s $ChangeNum`;
if ($?!=0) { &ErrorDie("Can't run p4 describe -s $ChangeNum in sub CheckSyncTOChange.");}
@TempArr2=grep /#/, @TempArr;
foreach $TempArr2 (@TempArr2) # Get only file names in change.
{
$TempArr2=~s|... ||;
$TempArr2=~s/( edit\n| add\n| delete\n)//;
chomp($TempArr2);
$TempArr2=join('','"',$TempArr2,'"'); # Overcome directories with space in name.
push(@Buffer,$TempArr2);
}
foreach $Buffer (@Buffer) # Force Sync on each file from the list.
{
if (length($Buffer)<1) {next;}
@TempArr=`p4 sync -n -f $Buffer 2>$TempFile & type $TempFile`; # Run Simulation & get STDERR output.
if ($?!=0) { print "Error !\nCannot Simulate Sync to $Buffer in sub CheckSyncToChange.\n ";}
if ($TempArr[0]=~/(- must refer to|- no such|error)/) {$Error=1;} # Look for Errors.
}
unlink "$TempFile";
# Notify User of Simulation Outcome.
if (not($Error)) { print "Sync to Changelist : $ChangeNum Succeeded.\n"; return 1;}
else { print "Sync to Changelist : $ChangeNum Failed !\n"; return 0;}
}
sub MultiSyncToChange(@) # Sync to a list of changes - if diles duplicated takes last revision.
{
my @ChangeNums=@_;
my @NewList="";
my $FileName="";
my $Duplicate=0;
my @TempArr3="";
@ChangeNums=sort SortAscending @ChangeNums; # Sort list of changes in ascending order.
foreach $ChangeNums (@ChangeNums)
{
if (not (&CheckSyncToChange($ChangeNums))) { next;} # Simulate sync to change - If failed skip it.
@TempArr="";
@NewList="";
@TempArr=`p4 describe -s $ChangeNums`;
if ($?!=0) { &ErrorDie("Can't run p4 describe -s $ChangeNums in sub MultiSyncTOChange.");}
@NewList=grep /#/, @TempArr;
push(@TempArr3,@NewList); # Add Change to main list.
}
@NewList="";
@Buffer="";
foreach $TempArr3 (@TempArr3) # Get only file names in change.
{
if (not($TempArr3=~m|//|) or (length($TempArr3)<2)) {next;} # skip empty lines.
$TempArr3=~s|... ||;
$TempArr3=~s/( edit\n| add\n| delete\n)//;
chomp($TempArr3);
$TempArr3=join('','"',$TempArr3,'"'); # Overcome directories with space in name.
push(@Buffer,$TempArr3);
}
# Prevent duplicates:
#foreach $NewList (@NewList)
#{
# $Duplicate=0;
# $NewList=~m|(\S*)#\d*\w*|;
# $FileName=$1; # Get only filename.
# foreach $Buffer (@Buffer) # Check If duplicated.
# {
# if ($Buffer=~/$FileName/) { $Duplicate=1; } # If found - mark as duplicated.
# }
# if (not($Duplicate)) { push(@Buffer,$NewList);} # If not duplicated - add file to list.
#}
#shift(@Buffer); # delete empty line.
foreach $Buffer (@Buffer) # Force Sync on each file from the list.
{
if (length($Buffer)<1) {next;}
@TempArr=`p4 sync -f $Buffer`;
if ($?!=0) { print "Error !\nCannot Sync to $Buffer in sub MultiSyncToChange.\n ";}
}
# push (@OutPut,"Client was succesfully synced to changes : \n@ChangeNums \n");
}
sub UnSyncToChange($) # UnSync to a specified change(Revision -1).
{
my $ChangeNum=shift;
my $Revision="";
my $DestFile="";
@TempArr=`p4 describe -s $ChangeNum`;
if ($?!=0) { &ErrorDie("Can't run p4 describe -s $ChangeNum in sub UnSyncTOChange.");}
@TempArr2=grep /#/, @TempArr;
foreach $TempArr2 (@TempArr2) # Get only file names in change.
{
$TempArr2=~s|... ||;
$TempArr2=~s/( edit\n| add\n| delete\n)//;
chomp($TempArr2);
$TempArr2=~/#(\d*)/;
$Revision=$1;
if ($Revision!=1) {$Revision--}; # decrement revision only if greater then 1.
$TempArr2=~s/#(\d*)/#$Revision/; # Down 1 revision.
$TempArr2=join('','"',$TempArr2,'"'); # Overcome directories with space in name.
push(@Buffer,$TempArr2);
}
foreach $Buffer (@Buffer) # Force Sync on each file from the list.
{
if (length($Buffer)<1) {next;}
@TempArr=`p4 sync -f $Buffer`;
if ($?!=0) { print "Error !\nCannot Sync to $Buffer in sub UnSyncToChange.\n ";}
}
push (@OutPut,"Client was succesfully Unsynced to change : $ChangeNum \n");
}
sub MultiIntegToChanges($,$,$,@) # Integrate a list of changes to a specified branch.
{ # Input: Project, Original Branch name (configuration) ,Destination Branch name (configuration) , Array of change numbers.
my $project=shift;
my $orgconf=shift;
my $conf=shift;
my @ChangeNums=@_;
my @NewList="";
my @Description="";
my $FileName="";
my $Duplicate=0;
my @TempArr3="";
my @TempArr4="";
my $FileSum=0;
#@ChangeNums=sort SortAscending @ChangeNums; # Sort list of changes in ascending order.
# Create changelist:
#my $ChangeNum=&create_change_list("Integrating Change Lists from Configuration $orgconf to $conf in Project $project using Changelist/s:\n\t@ChangeNums\n");
# Sort Uniq changelists.
%temp = map {$_ => 1} @ChangeNums;
@ChangeNums = sort {$a <=> $b} keys %temp;
foreach $ChangeNums (@ChangeNums) # Get a List of files to integrate.
{
@TempArr="";
@NewList="";
@TempArr=`p4 describe -s $ChangeNums`;
if ($?!=0) { &ErrorDie("Can't run p4 describe -s $ChangeNums in sub MultiIntegToChanges.");}
@NewList=grep /#/, @TempArr;
@Description=grep (/^\t/,@TempArr);#find the description.
push(@TempArr4,"\n chg $ChangeNums:\n@Description");#add the description to the list.
push(@TempArr3,@NewList); # Add Change to main list.
}
# Create changelist:
my $ChangeNum=&create_change_list("Integrating Change Lists from Configuration $orgconf to $conf in Project $project using Changelist/s:\n\t@ChangeNums\n@TempArr4\n");
shift(@TempArr3); # Teminate space line.
foreach $TempArr3 (@TempArr3) # Make sure all files are from the same branch:
{
if (not($TempArr3=~m|//$project/$orgconf/|i)) { print "\nNotice: There are File/s in changelist/s which are NOT from Project $project and Configuration $orgconf - they will be ignored.\n\n";last;}
}
@NewList="";
@Buffer="";
foreach $TempArr3 (@TempArr3) # Get only file names + revision in change.
{
if (not($TempArr3=~m|//|) or (length($TempArr3)<2)) {next;} # skip empty lines.
$TempArr3=~s|... ||;
$TempArr3=~s/( edit\n| add\n| delete\n| integrate\n| branch\n)//;
chomp($TempArr3);
$TempArr3=join('','"',$TempArr3,'"'); # Overcome directories with space in name.
push(@Buffer,$TempArr3);
}
foreach $Buffer (@Buffer) # Integrate each file from the list.
{
if (length($Buffer)<1) {next;}
if (not ($Buffer=~m|//$project/$orgconf/|i)) { next;} # Skip File if it's not matches parameters.
$DestFile=$Buffer;
if ($conf=~/^Elite/i) #check if the destination Branch is //Elite/.../Off202,when the source: IT.
{
my $Temp=`p4 dirs //$conf/OFF202`;
if (Temp=~/no such file/i)
{
&ErrorDie("there is no such dir: //$conf/OFF202!!! failed in sub MultiIntegToChangesCheck.");
}
$DestFile=~s|//(\w*)/$orgconf/IT|//$conf/OFF202|i; # Change Configuration.
}
else
{
$DestFile=~s|//(\w*)/$orgconf/|//$1/$conf/|i; # Change Configuration.
}
$DestFile=~s|#(\d*)||; # Chop Revision specification.
# $DestFile=lc($DestFile); # Switch to lower case all path + filename.
$Buffer=lc($Buffer);
# Itegrate the file:
# @TempArr=`p4 integrate -v -c $ChangeNum $Buffer $DestFile 2>$TempFile & type $TempFile`;
# Took of the -v option because it can't clobber a file.
@TempArr=`p4 integrate -f -i -c $ChangeNum $Buffer $DestFile 2>$TempFile & type $TempFile`;
if ($TempArr[0]=~/no permission for operation on file/) # Notify User of an Error if NO Permissions.
{
unlink "$TempFile";
@TempArr=`p4 change -d $ChangeNum`; # Delete Empty changelist.
&ErrorDie("Can't run:p4 change -d $ChangeNum ( While aborting operation due to *no permission* Error.)\n Failed in sub MultiIntegToChanges.") if ($?!=0);
&ErrorDie("You do NOT have permission for this operation ");
}
if ($TempArr[0]=~/no mappings in client view/) # Notify User of an Error if Client view is not good.
{
unlink "$TempFile";
@TempArr=`p4 change -d $ChangeNum`; # Delete Empty changelist.
&ErrorDie("Can't run:p4 change -d $ChangeNum ( While aborting operation due to *no mappings* Error.)\n Failed in sub MultiIntegToChanges.") if ($?!=0);
&ErrorDie("Your Client View is not suitable for this operation ");
}
if ($TempArr[0]=~/not in client view/) # Notify User of an Error if Client view is not good.
{
unlink "$TempFile";
@TempArr=`p4 change -d $ChangeNum`; # Delete Empty changelist.
&ErrorDie("Can't run:p4 change -d $ChangeNum ( While aborting operation due to *not in client view* Error.)\n Failed in sub MultiIntegToChanges.") if ($?!=0);
&ErrorDie("Your Client View is not suitable for this operation (not in client)");
}
if ($TempArr[0]=~/already integrated/) # Notify User if File already integrated.
{
unlink "$TempFile";
print "File: $Buffer Already Integrated !(File Ignored)\n";
}
unlink "$TempFile";
$FileSum++; # Count integrated files.
#print "Running: p4 integrate -v -c $ChangeNum $Buffer $DestFile \n\n"; #********************* Remove !!!!
if ($?!=0) { print "Error !\nCannot run: p4 integrate -v -c $ChangeNum $Buffer $DestFile 2>$TempFile & type $TempFile in sub MultiIntegToChanges.\n
It is possible that you do not have write permissions in branch $conf ! Please contact
Perforce Administrator ! ";}
# Resolve File as "Theirs": ( if asked to )
if ($Mode eq '-r') # If asked to resolve.
{
@TempArr=`p4 resolve -at -af $DestFile 2>$TempFile & type $TempFile`;
if ($?!=0) { print "Error !\nCannot run: p4 resolve -at -af $DestFile 2>$TempFile & type $TempFile in sub MultiIntegToChanges.\n";}
}
}
# Check if any files where integrated:
@TempArr=`p4 opened -c $ChangeNum 2>$TempFile & type $TempFile`;
if ($TempArr[0]=~/not opened on this client/) # Notify User if File already integrated.
{
unlink "$TempFile";
print "\n NO Files were Integrated !\n\n";
@TempArr=`p4 change -d $ChangeNum`; # Delete Empty changelist.
&ErrorDie("Can't run:p4 change -d $ChangeNum ( While aborting operation due to *no files were integrated* .)\n Failed in sub MultiIntegToChanges.") if ($?!=0);
}
else
{ if ($Mode eq '-r'){ print "\n Files were integrated and resolved into changelist : $ChangeNum .\n\n";}
else { print "\n Files were integrated into changelist : $ChangeNum .\n\n";}
}
unlink "$TempFile";
}
sub MultiIntegToChangesCheck($,$,$,@) # Check if integrate will clobber any files in the private work.
{ # Input: Project, Original Branch name (configuration) ,Destination Branch name (configuration) , Array of change numbers.
my $project=shift;
my $orgconf=shift;
my $conf=shift;
my @ChangeNums=@_;
my @NewList="";
my $FileName="";
my @TempArr3="";
my @UpdatedFiles;
# Sort Uniq changelists.
%temp = map {$_ => 1} @ChangeNums;
@ChangeNums = sort {$a <=> $b} keys %temp;
foreach $ChangeNums (@ChangeNums) # Get a List of files to integrate.
{
@TempArr="";
@NewList="";
@TempArr=`p4 describe -s $ChangeNums`;
if ($?!=0) { &ErrorDie("Can't run p4 describe -s $ChangeNums in sub MultiIntegToChanges.");}
@NewList=grep /#/, @TempArr;
push(@TempArr3,@NewList); # Add Change to main list.
}
shift(@TempArr3); # Teminate space line.
foreach $TempArr3 (@TempArr3) # Make sure all files are from the same branch:
{
if (not($TempArr3=~m|//$project/$orgconf/|i)) { print "\nNotice: There are File/s in changelist/s which are NOT from Project $project and Configuration $orgconf - they will be ignored.\n\n";last;}
}
@NewList="";
@Buffer="";
foreach $TempArr3 (@TempArr3) # Get only file names + revision in change.
{
if (not($TempArr3=~m|//|) or (length($TempArr3)<2)) {next;} # skip empty lines.
$TempArr3=~s|... ||;
$TempArr3=~s/( edit\n| add\n| delete\n| integrate\n| branch\n)//;
chomp($TempArr3);
$TempArr3=join('','"',$TempArr3,'"'); # Overcome directories with space in name.
push(@Buffer,$TempArr3);
}
foreach $Buffer (@Buffer) # Integrate each file from the list.
{
if (length($Buffer)<1) {next;}
if (not ($Buffer=~m|//$project/$orgconf/|i)) { next;} # Skip File if it's not matches parameters.
$DestFile=$Buffer;
if ($conf=~/Elite/i) #check if the destination Branch is //Elite/.../Off202,when the source: IT.
{
my $Temp=`p4 dirs //$conf/OFF202`;
if (Temp=~/no such file/i)
{
&ErrorDie("there is no such dir: //$conf/OFF202!!! failed in sub MultiIntegToChangesCheck.");
}
$DestFile=~s|//(\w*)/$orgconf/IT|//$conf/OFF202|i; # Change Configuration.
}
else
{
$DestFile=~s|//(\w*)/$orgconf/|//$1/$conf/|i; # Change Configuration.
}
$DestFile=~s|#(\d*)||; # Chop Revision specification.
# $DestFile=lc($DestFile); # Switch to lower case all path + filename.
$Buffer=lc($Buffer);
# Preview a sync of the file - if it was to be updated - worn the user that the
# file will be overwritten if he will integrate.
@TempArr=`p4 sync -n $DestFile 2>$TempFile & type $TempFile`;
if ($TempArr[0]=~/- updating/) # Check if file was updated, if yes - keep a record of it.
{
push(@UpdatedFiles,"$DestFile\n");
}
}
# If everything was OK:
if ($#UpdatedFiles <0)
{
print "OK, No files will be overwritten.\n";
unlink "$TempFile";
exit(0);
}
else
{
print "Warning !, Files will be overwritten :\n\n";
print "@UpdatedFiles\n";
unlink "$TempFile";
exit(0);
}
}
sub RevertDeletedFiles (@) #do revert to all the files in the changelists that were check out for delete.
#input: the changelists.
{
my @ChangeNums=@_;
my @delfiles="";
my @Files="";
my @rev="";
foreach $ChangeNums (@ChangeNums)
{
@Files=`p4 opened -c $ChangeNums 2>$TempFile & type $TempFile`;
if ($?!=0) {&ErrorDie("Cannot create Pending Changes Files list from p4 opened -c.\nFailed in sub RevertDeletedFiles.");}
@delfiles=grep (/delete/,@Files);
foreach $delfiles (@delfiles)
{
$delfiles=~s/#.*//;
$rev=`p4 revert $delfiles`;
if (not($rev=~/was delete/i))
{
print "can't revert $delfiles";
}
}
}
print "\nO.K, finished reverting the deleted files!!!\n";
}
sub Resolve (@) #resolve all the files in the changelists.
#input: change #
{
my @ChangeNums=@_;
my @resfiles="";
my @Files="";
my @TempArr="";
my @TempFile="";
foreach $ChangeNums (@ChangeNums)
{
@Files=`p4 opened -c $ChangeNums 2>$TempFile & type $TempFile`;
if ($?!=0) {&ErrorDie("Cannot create Pending Changes Files list from p4 opened -c.\nFailed in sub resolve.");}
foreach $Files (@Files)
{
$Files=~s/#.*//;
@TempArr=`p4 resolve -as $Files 2>$TempFile & type $TempFile`;
#@TempArr=`p4 resolve -as $Files 2>$TempFile`;
if ($?!=0) { print "Error !\nCannot run: p4 resolve -as $Files 2>$TempFile & type $TempFile in sub resolve.\n";}
}
}
print "finished resolving";
}
sub ChangelistsByConfiguration($,$,@)#returns only the changelist that contains files from this project and configuration.
{ # Input: Project, configuration , Array of change numbers.
my $project=shift;
my $conf=shift;
my @Buff=@_;
if ($#Buff==-1) #check the lenght of Buff if it is empty then return.
{
return;
}
my $TempArray="";
my $flag=0;
@ByConf="";
$conf=~s|(\\)|\/|g;
my $configuration="";
foreach $Buff (@Buff)
{
$Buff=~/^\s(\d+)\s/;
$ChangeNum=$1;
my @describe=`p4 describe $ChangeNum`;
if ($?!=0) { print "Error !\nCannot run p4 describe $ChangeNums in sub ChangelistsByConfiguration.\n ";}
if ($conf eq "All")
{
@TempArray=grep (/^\.\.\. \/\/$project\//i , @describe);
if ($#TempArray != -1)
{
push (@ByConf,$Buff);
}
}
else
{
@TempArray=grep (/^\.\.\. \/\/$project\/$conf\//i , @describe);
foreach $TempArray(@TempArray) #check if there is a file from the proj & conf in the changelist.
{
foreach $OutPut (@OutPut) # find the branch of the file.
{
chomp($OutPut);
$OutPut=~s|\\(\S)|\/\1|g;
$crtr="//$project/$OutPut/";
if($TempArray=~/$crtr/i)
{
$configuration=$OutPut;
}
}
if ($conf eq $configuration)
{
$flag =1;
}
$configuration="";
}
if ($flag == 1)
{
push (@ByConf,$Buff);
}
$flag=0;
}
}
}
sub UnSubmit(@) #this sub gets a changelist and sync all the files in the changelist one version before this changelist.
#and then submit it. so the head revision is like one revision before.
{
@changes=@_;
my %hash;
#Sort the change numbers so you'll unsubmit the latest change last.
foreach $changes (@changes)
{
$hash{$changes}="$hash{$changes}$changes"; # Insert to Hash.
}
my @Sortedchanges= sort {$b <=> $a} keys %hash; # return the sorted KEYS (Descending)
#Unsubmit each changelist from the first to the last
foreach $Sortedchanges (@Sortedchanges)
{
my $change=&create_change_list("UnSubmitting changelist $Sortedchanges.");
@describe=`p4 describe -s $Sortedchanges`;
@Files=grep (/\.\.\.\s\/\//,@describe);
foreach $Files (@Files)
{
$Files=~s/\.\.\.\s(.*#)(\d*).*\n/$1/;
$ver=$2;
if ($ver==1)
{
chop($Files);
$tempo=`p4 sync "$Files"`;
if ($?!=0) {die ("can't run p4 sync $Files, in sub UnSubmit"); }
$tempo=`p4 delete -c $change "$Files"`;
if ($?!=0) {die ("can't run p4 delete -c $change $Files, in sub UnSubmit"); }
}
else
{
$ver--;
$tempo=`p4 sync "$Files"$ver`;
if ($?!=0) {die ("can't run p4 sync $Files$ver, in sub UnSubmit"); }
chop($Files);
$tempo=`p4 edit -c $change "$Files"`;
if ($?!=0) {die ("can't run p4 edit -c $change $Files, in sub UnSubmit"); }
$tempo=`p4 sync "$Files" `;
if ($?!=0) {die ("can't run p4 sync $Files , in sub UnSubmit"); }
$tempo=`p4 resolve -ay "$Files" `;
if ($?!=0) {die ("can't run p4 resolve -ay $Files , in sub UnSubmit"); }
}
}
@Files2=`p4 opened -c $change`; #to compare if the new changelist contain the same number of files.
if ($#Files== $#Files2)
{
print STDERR "\nChangelist $change is ready to submit...\n";
}
else
{
foreach $Files2 (@Files2)
{ #if the new changelist contain less files revert all the files
$Files2=~s/(.*)#.*/$1/;
my $tem="p4 revert $Files2";
$tempo=`$tem`;
if ($?!=0) {die ("can't run p4 revert -c $change $Files2 , in sub UnSubmit"); }
}
$tempo=`p4 change -d $change`; #delete the empty changelist
if ($?!=0) {die ("can't run p4 change -d $change , in sub UnSubmit"); }
print STDERR "\nThe unsubmit failed!!\nnot all the files in this changelist can be unsubmitted.\n";#print warning
}
}
}
sub main_autointg ($) #reciving chagelist no. and create a new changelists to all the
# configurations targets
{
$Change_Num = shift;
chomp($Change_Num);
$Slash="/";
$First_Time = 0;
@Describe = `p4 describe -s $Change_Num`;
if (!@Describe) {die("Cannot run : p4 describe to $Change_Num ");}
$details= @Describe[0];
$details=~/\@(\S+)/;
$Client = $1;
$User_Name = $`;
$User_Name =~ s/^.*by\s+//;
$Configuration_exist=0;
foreach $Line(@Describe)
{
if($Line=~ /AUTOMATIC CHANGELIST CREATION/)
{ exit(0); } #prevent from making another chagelist on a changelist that the daemon.pl created
if(($Line=~ /^\.\.\. \/\//)&&($First_Time==0))
{
$Line =~ /\W+(\w+)\W/;
$Project=$1;
@Buffer=`p4 branches`;
if ($?!=0) {print("\nCannot create configuration list from p4 branches.\nFailed in sub EqualBranch.");}
@TempArr=grep(/Branch $Project/i,@Buffer);
push(@OutPut,"dev\n"); # dev always exists.
push(@OutPut,"add-in\n"); # it is not included in p4 branches.
foreach $TempArr (@TempArr) #put in OutPut all the existing branches.
{
$TempArr =~ /Branch $Project(\S*)(\s)/i;
$TempVar=$1;
$TempVar=~s|_|$Slash|g;
$TempVar=substr($TempVar,1);
push(@OutPut,"$TempVar\n");
}
foreach $OutPut (@OutPut) # find the branch of the first file.
{
chomp($OutPut);
$crtr="... //$Project/$OutPut/";
if($Line=~/^$crtr/i)
{
$Configuration=$OutPut;
}
}
$First_Time=1
}
if($Line=~ /^\.\.\. \/\//)
{
$Line =~ s/... \/\/$Project\/$Configuration\///;
@The_files_who_were_changed = (@The_files_who_were_changed,$Line);
}
}
if (!( @Table=`p4 print //p4ctrl/pcfs/$Project/PTF` ))
{
exit(0); # checking if there is a file of description of the target <PTF>
}
($x,@Table) = @Table;
if ( !@Table )
{
exit(0); # checking if the file of description isnt empty
}
foreach $Line(@Table)
{
if( $Line =~ /^$Configuration/)
{ $Configuration_exist=1 }
}
if ( !$Configuration_exist )
{
exit(0);
}
foreach $Line(@Table)
{
if( $Line =~ /^$Configuration/)
{
$Line =~ s/$Configuration\s//;
@List_of_targets=(@List_of_targets,$Line);
}
}
if (@List_of_targets == "")
{
exit(0);
}
foreach $List(@List_of_targets)
{
$List= $Project."/".$List;
}
#&Checking_The_client($Project,@List_of_targets);
foreach $File(@The_files_who_were_changed) #remove the #3 (number of version) and everything that comes after
{
$File =~ s/\#(.*)//;
}
foreach $Target(@List_of_targets)
{
$NewChangeNum = &create_change_list_autointg; #creating new changlists for each target
$NewChange = $NewChangeNum;
chomp ($NewChangeNum); #then integrate and resolve the files
chomp($Target);
foreach $File(@The_files_who_were_changed)
{
chomp($File);
$TargetFile = "//".$Target."/".$File;
$SourceFile = "//".$Project."/".$Configuration."/".$File;
@Temp = `p4 integrate -f -i -c $NewChangeNum $SourceFile $TargetFile `;
@temp = `p4 resolve -at -af $TargetFile`;
}
$Target = $Target."\n"; # For using in the e-mail later on
$NewChangeNum = $NewChangeNum." to: ".$Target;
@Changes = (@Changes,$NewChangeNum);
}
@Describe = `p4 describe -s $NewChange`;
if (!@Describe) {die("Cannot run : p4 describe to $NewChange ");}
$details= @Describe[0];
$details=~/\@(\S+)/;
$Client = $1;
$User = $`;
$User =~ s/^.*by\s+//;
$Subject = "A NEW CHANGELIST HAVE BEEN AUTOMATICLY CREATED";
$Main = "New changelist(s) have automatic created by $User\:\n @Changes The changelist(s) was created according to your submitted changelist: $Change_Num in $Project/$Configuration \.";
&SendMail_autointg($User_Name,$User_Name,$Subject,$Main);
}
sub create_change_list_autointg # This subroutine Creates a Changlist and return it's #.
{ # Input: Description for the changelist. The belong to the autointg.
my $description="AUTOMATIC CHANGELIST CREATION"; # Get description.
my $DescFile="desc.$$";
if (open(DF,">$DescFile")!=1)
{
die("Cannot open $DescFile $DescFile");
}
else
{ print DF "\nChange: new\n\nClient: \n\nUser: \n\nStatus:\n\nDescription:\n $description";
close(DF); }
@TempArr="";
@TempArr=`p4 change -i < $DescFile`;
if ($?!=0) {die("Cannot run : p4 change -i < $DescFile in sub create_change_list_autointg");}
$change_list_number =substr($TempArr[0],7,index($TempArr[0],'cre',0)-8);
unlink "$DescFile";
return $change_list_number;
}
sub SendMail_autointg($,$,$,$) # This sub sends mail to user.
{ # It belong to the autointg
# Get parameters:
my $recepient=shift;
my $sender=shift;
my $subject=shift;
my $MessageBody=shift;
my $ServerName="Ntserv1"; # Define Mail server to use here.
my $Domain="\@cimatron.co.il"; # Define the domain to send to.
my $MessageBodyFile="body.txt";
$recepient=join('',$recepient,$Domain); # Make email address.
$subject=join('','"',$subject,'"');
my $Temp="";
###### Make Message Body ######
if (open(BODY,"+>$MessageBodyFile")!=1)
{ die "\nError!\nCan't create body of message in file: $MessageBodyFile\n\n";}
print BODY "$MessageBody";
close(BODY);
######## Send Messages ##########
$Temp=`blat.exe $MessageBodyFile -t $recepient -s $subject -server $ServerName -f $sender`;
die "Error !\n Can't run:blat.exe $MessageBodyFile -t $recepient -s $subject -server $ServerName -f $sender\n Failed in sub SendMail_autointg.\n" if ($?!=0);
}
# Cutting Buffer Subs:
####################################
# Main cutting sub
##########################
sub GetArgs() # This sub get the Args from ARGV and operate the cutting sub according to the data.
{
while ($ArgPlace <= $ArgNum) # While there are more Args.
{
$Data="";
if ($ARGV[$ArgPlace] eq "-d") # If a date cut was asked:
{
$DateF=$ARGV[$ArgPlace+1]; # Get dates from argv
$DateT=$ARGV[$ArgPlace+2];
&CutByDates($DateF,$DateT); # start sub
@Buffer=@TempOutPutDates;
$ArgPlace=$ArgPlace+3; # move index to next args.
}
elsif ($ARGV[$ArgPlace] eq "-p") # If a project cut was asked on lable:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"_","~~"); # Add item to list(names format).
$Data=join("",$Data,"/",$ARGV[$ArgPlace],"/","~~"); # Add item to list(path format).
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-pp") # If a project cut was asked on changelists:
{
$PROJ=$ARGV[$ArgPlace+1];
my $con=$ARGV[$ArgPlace+2];
&ProjectConfig();
&ChangelistsByConfiguration($PROJ,$con,@Buffer);
@Buffer=@ByConf;
$ArgPlace=$ArgPlace+3;
}
elsif ($ARGV[$ArgPlace] eq "-c") # If a configuration cut was asked:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,"_",lc($ARGV[$ArgPlace]),"_","~~"); # Add item to list(name foemat).
$Data=join("",$Data,"/",lc($ARGV[$ArgPlace]),"/","~~"); # Add item to list(path format).
$Data=join("",$Data,"_",uc($ARGV[$ArgPlace]),"_","~~"); # Add item to list(name foemat).
$Data=join("",$Data,"/",uc($ARGV[$ArgPlace]),"/","~~"); # Add item to list(path format).
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-m") # If a module cut was asked:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,"_",$ARGV[$ArgPlace],"_","~~"); # Add item to list(name format).
$Data=join("",$Data,"/",$ARGV[$ArgPlace],"/","~~"); # Add item to list(path format).
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-uu") # If a user cut was asked:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data," by ",$ARGV[$ArgPlace],".","~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-u") # If a user@ cut was asked:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data," by ",$ARGV[$ArgPlace],"@","~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-g") # If a group cut was asked:
{
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
@TempArr2=split("~~",$Data);
$Data="~~";
foreach $TempArr2 (@TempArr2)
{
@TempArr=`p4 group -o $TempArr2`; # open group
@TempArr=grep /^ /, @TempArr; # get user names.
foreach $TempArr (@TempArr)
{ chomp($TempArr);
$TempArr=substr($TempArr,1);
if ($Data=~/\s$TempArr@~/) {next} # If exist already - skip
$Data=join("",$Data," by ",$TempArr,"@","~~"); # Add user to list.
}
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-gu") # If a group cut was asked:
{
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
@TempArr2=split("~~",$Data);
$Data="~~";
my @groups=`p4 groups`;
foreach $TempArr2 (@TempArr2)
{
my @group=grep /$TempArr2/,@groups;
if (@group=="")
{
@TempArr="";
$TempArr[0]=" $TempArr2";
}
else
{
@TempArr=`p4 group -o $TempArr2`; # open group
@TempArr=grep /^ /, @TempArr; # get user names.
}
foreach $TempArr (@TempArr)
{ chomp($TempArr);
$TempArr=substr($TempArr,1);
if ($Data=~/\s$TempArr@~/) {next} # If exist already - skip
$Data=join("",$Data," by ",$TempArr,"@","~~"); # Add user to list.
}
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-s") # If a string cut was asked:
{
$Data="~~";
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCut($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-ns") # If a string in name cut was asked:
{
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCutOnName($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-ds") # If a string in description cut was asked:
{
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCutOnDesc($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-nds") # If a string in description cut was asked:
{
$ArgPlace=$ArgPlace+1;
while (($ArgPlace <= $ArgNum)&&(index($ARGV[$ArgPlace],"-")==-1)) # While not passes a switch or end.
{
$Data=join("",$Data,$ARGV[$ArgPlace],"~~"); # Add item to list.
$ArgPlace=$ArgPlace+1; # Move to next Arg.
}
&MultiGrepCutOnDescNOT($Data,@Buffer);
@Buffer=@MGrepOut;
}
elsif ($ARGV[$ArgPlace] eq "-sc") # If asked to stop cut on this buffer for now.
{
$ArgPlace=$ArgPlace+1; # Move to next Arg.
last;
}
else
{
&ArgError("Invalid cut Switch: '$ARGV[$ArgPlace]' ");
}
}
@OutPut=@Buffer;
}
# Date cutting sub
##########################
sub CutByDates($,$) # Cut Buffer by a period of time into Array @TempOutPutDates:
{
my $DF=shift; # Get dates.
my $DT=shift;
my $Place=0;
my $D="";
@TempOutPutDates="";
my $YearF=""; # Date From parameters.
my $MonthF="";
my $DayF="";
my $YearT=""; # Date To parameters.
my $MonthT="";
my $DayT="";
my $Year=""; # Date actual parameters.
my $Month="";
my $Day="";
# Get dates parameters.
#$DF=~m|(?=.*)(\d*)/(\d*)/(\d*)(?=.*)|;
#$YearF=$1; # This section was canceled -
#$MonthF=$2; # date arguments will be sent without "/"
#$DayF=$3;
#$DT=~m|(?=.*)(\d*)/(\d*)/(\d*)(?=.*)|;
#$YearT=$1;
#$MonthT=$2;
#$DayT=$3;
#
#$DF="$YearF$MonthF$DayF";
#$DT="$YearT$MonthT$DayT";
foreach $Buffer (@Buffer)
{
$Buffer=~m|(?=.*)(\s)(\d*)/(\d*)/(\d*)(\s)(?=.*)|;
$Year=$2;
$Month=$3;
$Day=$4;
$D="$Year$Month$Day";
# If Date is between the period given then grep this line.
if (($DF<=$D)&&($D<=$DT))
{
$TempOutPutDates[$Place]=$Buffer;
$Place=$Place+1;
}
}
}
# Recorsive report into changes:
# Begin Creating Reports: #
#----------------------------------------------------------------------#
# Print help in case of an "help"-like argument.
if (($ARGV[0] eq 'help') || ($ARGV[0] eq 'HELP') || ($ARGV[0] eq '?')
|| ($ARGV[0] eq '-?') || ($ARGV[0] eq '\?') || ($ARGV[0] eq '-h'))
{
&Help();
exit(0);
}
# Create timestamp:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;
$timestmp = (join ".", "",$year, $mon, $mday, $hour, $min, $sec);
$TempFile="Tmp.$$"; # Create uniq tempfile to avoid colision.
# Check to see if P4 is in path:
@TempArr=`p4 info` ;
if ($?!=0){ die "Error !!!\nCannot run p4 info\n" ;}
if (index($TempArr[0],"The name specified is not recognized")!=-1)
{
print "Error !!!\nCannot Find P4 in your PATH !!!\n" ;
if (open(Err, ">>MErrors.log")!=1) {
print "Error !!!\nCannot create or update Error Log File\n" ;
}
else { select(Err); }
print Err "\nTime of Error: $timestmp \nCannot Find P4 in your PATH !!!\n ";
print Err "Perforce Returned:\n" , "$!";
print Err "\n----------------------------------------------------------\n";
close(Err);
select(STDOUT);
exit(0);
}
# Check the arguments given in STDIN, then choose action.
$ArgNum=$#ARGV; # Get number of total arguments.
if ($ARGV[0] eq "-ul") # Print User List.
{
&UserList(); # Make List.
print "$Users"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-gl") # Print Group List.
{
&GroupList(); # Make List.
print "@Groups"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-gul") # Print Group List.
{
&GroupList(); # Make List.
&UserList(); # Make List.
push (@Groups,$Users);
print "@Groups"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-ll") # Print Labels List.
{
&LabelList(); # Make List.
print "$Labels"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-fdsc") # Print Full description of a change.
{
if (length($ARGV[1])<1)
{&ArgError("Invalid second Argument(Change Num)"); }
&FullDesc($ARGV[1]);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-gdsc") # Print Full description of a group.
{
if (length($ARGV[1])<1)
{&ArgError("Invalid second Argument(Group Name)"); }
&GroupDesc($ARGV[1]);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-msynch") # Sync to a specified changes (only change files without removing other).
{
if (length($ARGV[1])<1)
{&ArgError("Missing Arguments(Change Number/s)"); }
shift(@ARGV); # delete option - leave numbers
&MultiSyncToChange(@ARGV);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-unsynch") # UnSync to a specified change (Sync to revision -1)(only change files without removing other).
{
if (length($ARGV[1])<1)
{&ArgError("Invalid second Argument(Change Num)"); }
&UnSyncToChange($ARGV[1]);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-rdf") # Print Full description of a change.
{
if (length($ARGV[1])<1)
{&ArgError("you didn't send any change num"); }
shift(@ARGV); # delete option
&RevertDeletedFiles(@ARGV);
exit(0);
}
elsif ($ARGV[0] eq "-res") # Print Full description of a change.
{
if (length($ARGV[1])<1)
{&ArgError("you didn't send any change num"); }
shift(@ARGV); # delete option
&Resolve(@ARGV);
exit(0);
}
elsif ($ARGV[0] eq "-unsub") # Print Full description of a change.
{
if (length($ARGV[1])<1)
{&ArgError("you didn't send any change num"); }
shift(@ARGV); # delete option
&UnSubmit(@ARGV);
exit(0);
}
elsif ($ARGV[0] eq "-autointg") # creating a new changelists to the targets of the submited changelist.
{
if (length($ARGV[1])<1)
{&ArgError("you didn't send any change num"); }
shift(@ARGV); # delete option
&main_autointg(@ARGV);
exit(0);
}
elsif ($ARGV[0] eq "-mintegchcheck") # Check if integrate will clobber any files in the private work..
{
if ($#ARGV<4)
{&ArgError("Missing Arguments(Project, Original Branch and/or Branch Destination and/or Change Number/s)"); }
shift(@ARGV); # delete option - leave branch & numbers
$PROJ=shift(@ARGV); # Get Project.
$OrgCONF=shift(@ARGV); # Get Orginal Branch.
$CONF=shift(@ARGV); # Get Branch destination.
$CONF=lc($CONF);
$OrgCONF=lc($OrgCONF);
&MultiIntegToChangesCheck($PROJ,$OrgCONF,$CONF,@ARGV);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-mintegch") # Integrate a list of changes to a specifies branch.
{
if ($#ARGV<5)
{&ArgError("Missing Arguments(Project, Original Branch and/or Branch Destination and/or Change Number/s)"); }
shift(@ARGV); # delete option - leave branch & numbers
$Mode=shift(@ARGV); # check if to resolve or not.
if (($Mode ne '-r') and ($Mode ne '-nr')) { &ArgError("Invalid rosolve argument");}
$PROJ=shift(@ARGV); # Get Project.
$OrgCONF=shift(@ARGV); # Get Orginal Branch.
$CONF=shift(@ARGV); # Get Branch destination.
$CONF=lc($CONF);
$OrgCONF=lc($OrgCONF);
# if (index(" pre dev int qat prd ",$CONF)==-1)
# { &ArgError("Unknown Branch ( Configuration ) "); }
&MultiIntegToChanges($PROJ,$OrgCONF,$CONF,@ARGV);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cbc") # Integrate a list of changes to a specifies branch.
{
if ($#ARGV<3)
{&ArgError("Missing Arguments(Project, configuration and/or Change Number/s)"); }
shift(@ARGV); # delete option - leave branch & numbers
$PROJ=shift(@ARGV); # Get Project.
$CONF=shift(@ARGV); # Get Configuration.
$CONF=lc($CONF);
# if (index(" pre dev int qat prd ",$CONF)==-1)
# { &ArgError("Unknown Branch ( Configuration ) "); }
&ChangelistsByConfiguration($PROJ,$CONF,@ARGV);
print "@OutPut"; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-pc") # Print Configuration List For specified project.
{
if (length($ARGV[1])>1)
{ $PROJ=$ARGV[1];}
else {&ArgError("Invalid second Argument(Project Name)"); }
$ArgPlace=2;
&ProjectConfig(); # Make List.
print @OutPut; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-pc2") # Print Configuration List For specified project.
{
if (length($ARGV[1])>1)
{ $PROJ=$ARGV[1];}
else {&ArgError("Invalid second Argument(Project Name)"); }
$ArgPlace=2;
&ProjectConfig_off202(); # Make List.
print @OutPut; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-pcall") # Print Configuration List for all projects (uniq).
{
&Configs(); # Make List.
print @OutPut; # Print List to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cp") # Create a pending changelist report.
{
$IsPending=1;
&PendingChanges(); # Create buffer to cut on.
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cs") # Create a submitted changelist report.
{
&SubmittedChangesbydate($ARGV[1],$ARGV[2]); # Create buffer to cut on.
$ArgPlace=$ArgPlace+2;
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-arstochs") # Create a submitted changelist report from given ARS.
{
if (($ARGV[1] eq "-dt")||($ARGV[1] eq "-ndt")||($ARGV[1] eq "-ndtnt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ArsToSubmittedChanges(); # Create buffer to cut on.
@Buffer=@OutPut;
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-arstochp") # Create a Pending changelist report from given ARS.
{
if (($ARGV[1] eq "-dt")||($ARGV[1] eq "-ndt")||($ARGV[1] eq "-ndtnt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ArsToPendingChanges(); # Create buffer to cut on.
@Buffer=@OutPut;
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-abytochs") # Create a submitted changelist report from given ARS.
{
if (($ARGV[1] eq "-u")||($ARGV[1] eq "-g"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ABYToSubmittedChanges($ARGV[1]); # Create Report.
@Buffer=@OutPut;
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-abytochp") # Create a Pending changelist report from given ARS.
{
if (($ARGV[1] eq "-u")||($ARGV[1] eq "-g"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ABYToPendingChanges($ARGV[1]); # Create Report.
@Buffer=@OutPut;
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-schp") # Show pending chnagelists by given Change numbers.
{
if ($#ARGV <1) {&ArgError(" Missing parmeter - chnagelist number/s ");}
shift(@ARGV);
&ShowPendingChangelists(@ARGV); # Search for data.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-schs") # Show submitted chnagelists by given Change numbers.
{
if ($#ARGV <1) {&ArgError(" Missing parmeter - chnagelist number/s ");}
shift(@ARGV);
&ShowSubmittedChangelists(@ARGV); # Search for data.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-chtoars") # Create a submitted changelist report.
{
$ArgPlace=1;
&ChangesToArs(); # Create buffer to cut on.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-lf") # Create a labels files report.
{
if (($ARGV[1] eq "-dt") ||($ARGV[1] eq "-ndt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ListLabelsFiles(); # Create buffer to cut on.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cfs") # Create a submitted changelist files report.
{
if (($ARGV[1] eq "-dt")||($ARGV[1] eq "-ndt")||($ARGV[1] eq "-ldt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ListSubmittedChangesFiles(); # Create buffer to cut on.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cfp") # Create a pending changelist files report.
{
if (($ARGV[1] eq "-dt")||($ARGV[1] eq "-ndt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&ListPendingChangesFiles(); # Create buffer to cut on.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-cf") # Create a changelist files report according to Ars's & changes #'s.
{
&ArsToChangesAndFiles(); # Create buffer to cut on.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
# notice : all compairsons return exit(2) if no files were found - else prints and return exit(1)
####################################################################################################
elsif ($ARGV[0] eq "-eql") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(Label Name)"); }
$ArgPlace=2;
&EqlLabel(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[2] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[2] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-eql2") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(First Label Name)"); }
if (length($ARGV[2])>1)
{ $LabelName2=$ARGV[2];}
else {&ArgError("Invalid third Argument(Second Label Name)"); }
$ArgPlace=3;
&EqlLabel2(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-eql3") # Create a diff files report.
{
if (length($ARGV[1])<1)
{&ArgError("Invalid fourth Argument(First branch tree)"); }
if (length($ARGV[2])<1)
{&ArgError("Invalid fifth Argument(Second branch tree)"); }
$ArgPlace=3;
&EqlLabel3($ARGV[1],$ARGV[2]); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diff") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(Label Name)"); }
$ArgPlace=2;
&DiffLabel(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[2] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[2] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diff2") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(First Label Name)"); }
if (length($ARGV[2])>1)
{ $LabelName2=$ARGV[2];}
else {&ArgError("Invalid third Argument(Second Label Name)"); }
$ArgPlace=3;
&DiffLabel2(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diff3") # Create a diff files report.
{
if (length($ARGV[1])<1)
{&ArgError("Invalid fourth Argument(First branch tree)"); }
if (length($ARGV[2])<1)
{&ArgError("Invalid fifth Argument(Second branch tree)"); }
$ArgPlace=3;
&DiffLabel3($ARGV[1],$ARGV[2]); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diffoneh") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(Label Name)"); }
$ArgPlace=2;
&DiffonehLabel(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[2] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[2] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diffonel") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(Label Name)"); }
$ArgPlace=2;
&DiffonelLabel(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[2] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[2] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diffone2") # Create a diff files report.
{
if (length($ARGV[1])>1)
{ $LabelName=$ARGV[1];}
else {&ArgError("Invalid second Argument(First Label Name)"); }
if (length($ARGV[2])>1)
{ $LabelName2=$ARGV[2];}
else {&ArgError("Invalid third Argument(Second Label Name)"); }
$ArgPlace=3;
&DiffoneLabel2(); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
elsif ($ARGV[0] eq "-diffone3") # Create a diff files report.
{
if (length($ARGV[1])<1)
{&ArgError("Invalid fourth Argument(First branch tree)"); }
if (length($ARGV[2])<1)
{&ArgError("Invalid fifth Argument(Second branch tree)"); }
$ArgPlace=3;
&DiffoneLabel3($ARGV[1],$ARGV[2]); # Create buffer to cut on.
if ($#OutPut<1){exit(2);}
if ($ARGV[3] eq "-full") # If asked to convert to Full Report by Files.
{
&MakeFull();
}
if ($ARGV[3] eq "-fullu") # If asked to convert to Full Report By Users.
{
&MakeFullU();
}
exit(1) if ($#OutPut<2); # Don't output if empty.
print @OutPut; # Print the report to STDOUT.
exit(1);
}
################################################################################### End of compairisons.
elsif ($ARGV[0] eq "-cd") # Create a changelist files report.
{
&ListDefaultChangesFiles(); # Create buffer to cut on.
&GetArgs(); # Cut buffer according to Args.
print @OutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-fa") # Create a submitted changelist files report by cutting
{ # on changes then files and create mixed report.
if (($ARGV[1] eq "-dt")||($ARGV[1] eq "-ndt"))
{ $Mix=$ARGV[1];}
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&SubmittedChanges(); # Create buffer to cut on.
&GetArgs(); # Cut changes buffer according to Args.
&OpenChanges();
print @FinOutPut; # Print the report to STDOUT.
exit(0);
}
elsif ($ARGV[0] eq "-l") # Create a labels report.
{ # Create buffer to cut on.
if ($ARGV[1] eq "-all") # All labels buffer.
{ &LabelsAll();}
elsif ($ARGV[1] eq "-wb") # Weekly build labels buffer. ( sorted by dates as default)
{ &LabelsWB(); }
elsif ($ARGV[1] eq "-wbps") # Weekly build labels buffer - Sort by pass #.
{ &LabelsWB(); }
elsif ($ARGV[1] eq "-sl") # Standard labels buffer.
{ &LabelsSL(); }
else {&ArgError("Invalid Secondery Argument"); }
$ArgPlace=2;
&GetArgs(); # Cut buffer according to Args.
if ($ARGV[1] eq "-wbps") {print &SortByPass("a",@OutPut);} # Print sorted by pass #.
else {print &SortByDate("a",@OutPut); } # Print the report to STDOUT (Ascending sort). (Use "d" for decsending)
exit(0);
}
elsif ($ARGV[0] eq "-vtree")
{
if ( @ARGV < 4 )
{ &ArgError("Not enough argument"); }
else
{ &Vtree( $ARGV[1],$ARGV[2],$ARGV[3]); }
}
else
{ &ArgError("Invalid Primary Argument"); }