Script for recursive add-to-source control: How to

2019-07-23 23:21发布

问题:

I have this problem that has been bugging me for quite some time now. It is perhaps best explained by referring to the following (well-known) script:

@rem= 'PERL for Windows NT -- ccperl must be in search path 
@echo off 
ccperl %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 
goto endofperl 
@rem '; 

########################################### 
# Begin of Perl section 


$start_dir = $ARGV[0]; 

# 
# Fixed variable 
# 
$S = "\\"; 
$list_file = "c:".$S."list_file"; 
$list_add = "c:".$S."list_add"; 
$choosed = "c:".$S."choosed"; 


sub clean_file 
{ 
$status = system("del $list_file > NUL 2> NUL"); 
$status = system("del $list_add > NUL 2> NUL"); 
$status = system("del $choosed > NUL 2> NUL"); 
} 

# 
# Start of the script... 
# 

printf("add-to-src-control $start_dir...\n"); 

clean_file(); 
$status = system("cleartool ls -view_only -r -s $start_dir > $list_file"); 
open(LIST_ELEMENT,$list_file); 
while ($element=<LIST_ELEMENT>) 
{ 
chop $element; 
# printf " Processing $element "; 
if ($element =~ /CHECKEDOUT/) 
{ 
# printf(" checkedout file \n"); 
} 
else 
{ 
# printf " view private \n"; 
printf " Processing $element ...\n"; 

# 
# For files with spaces... 
# 
if ($element =~ / /) 
{ 
$status = system("cmd /c echo \"$element\" >> $list_add"); 
} 
else 
{ 
$status = system("cmd /c echo $element >> $list_add"); 
} 
} 
} 
close(LIST_ELEMENT); 

if (-e $list_add) 
{ 
$listelement = `type $list_add`; 
$listelement =~ s/\n/,/g; 
$status = `echo $listelement > $list_add`; 

$status = system("clearprompt list -outfile $choosed -dfile $list_add -choices 
-prompt \"Choose element(s) to put over version control : \" -prefer_gui"); 

if ($status != 0) 
{ 
# printf("\n Aborting ...\n"); 
clean_file(); 
exit $status; 
} 

# 
$listtoadd = `type $choosed`; 
$listtoadd =~ s/\n//g; 
printf("\n cleardlg /addtosrc $listtoadd"); 
$status = system("cleardlg /addtosrc $listtoadd"); 

clean_file(); 
exit $status; 
} 
else 
{ 
# printf("\n No files founded...\n"); 
clean_file(); 
exit $status; 
} 

# End of Perl section 

__END__ 
:endofperl

which can be found on "ClearCase: The ten best scripts".
Now, to avoid any misunderstanding, the script works just fine; I followed the steps (outlined on the above website) to reproduce the recursive add-to-source control functionality.

The question (or questions rather) that I have is this:

How do we exclude here files with certain extensions (*.asv or *.dll, for example) from being added to source control (more precisely, from being added to the list of elements returned; see second question below)?
(And similarly with folders.)

Is the line:

$status = system("cleartool ls -view_only -r -s $start_dir > $list_file");

the one to focus on?

My second question is of a rather "cosmetic" nature.
The input box which is produced once you run the script is (in my case, at least) far too small to accommodate the whole paths of the elements to be added to source control.
Is there a way to make sure that the full paths are always visible?
Would that be a matter of amending

$status = system("clearprompt list -outfile $choosed -dfile $list_add -choices 
-prompt \"Choose element(s) to put over version control : \" -prefer_gui"); 

or am I completely mistaken? That is all for now. Any help will be greatly appreciated!

回答1:

As this old thread illustrates, it is best to have files to ignored put outside the ClearCase view rather than inside ;)

That being said, you need to combine the ct lsview -r (or a more elaborate version of that command, as shown in "How do I determine what files in my ClearCase local view have not yet been added to source control?") with a grep.
That means you would read from the parameters the path of a file containing all the grep regexp of the files you want to ignore, and you would put the result of the ct lsview -r through each "grep -v xxx" (in order to exclude any file that matches that specific pattern)

For Windows, GoW (Gnu on Windows) will provide you with a fully functional grep (along with 130 other Unix commands compiled as native win32 binaries).

The op Mahyar reports:

Since some of the UNIX apps (within Gow) were causing conflicts with other local routines, I had to switch back to using findstr.
So, essentially what I have done is just use

cleartool ls -view_only -r -s | findstr /vi "\.asv" f > $list_file. 

In so doing $list_file is generated, just as it ought to be (that is, including all View Private elements apart from asv-files).
Further, when embedded in the Perl-Script, the script runs smoothly to the end, pointing out only those errors which already existed.


Regarding the second question, I don't know to change the size of clearprompt or cleardlg (and once created, they cannot even be re-sized).