#!/usr/bin/perl -w # #******************************************************************************* # #Copyright (c) 2009, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #******************************************************************************* # #Author: Stephen Moon # #Date: August 5, 2010 #Program: Generate an archive file using a file's p4 filelog with empty file # content. # #******************************************************************************* # use warnings; use strict; use FileHandle; sub headRevision() { my $fh = shift; my $cl = shift; my @arrText = qw/head access symbols locks/; printf($fh "%-10s1.%-1s;\n",$arrText[0],$cl); printf($fh "%-10s;\n",$arrText[1]); printf($fh "%-10s;\n",$arrText[2]); printf($fh "%-10s;comment @@;\n\n\n",$arrText[3]); return $cl; } sub subRevision() { my $fh = shift; my $maxCount = shift; my $count = shift; my $regTokenRef = shift; my @arrText = qw/date author p4 state Exp branches next/; if($count >= 2) { printf($fh "%-10s1.%-1s;\n\n",$arrText[6],$regTokenRef->[2]); } printf($fh "1.%-1s\n",$regTokenRef->[2]); printf($fh "%-10s%-1s.%-1s.%-1s.",$arrText[0],$regTokenRef->[4], $regTokenRef->[5],$regTokenRef->[6]); printf($fh "%-1s.%-1s.%-1s %-1s %-1s; %-1s %-1s;\n", $regTokenRef->[7],$regTokenRef->[8],$regTokenRef->[9],$arrText[1], $arrText[2],$arrText[3],$arrText[4]); printf($fh "%-10s;\n",$arrText[5]); if($maxCount == $count) { printf($fh "%-10s;\n",$arrText[6]); } } sub revisionContent() { my $fh = shift; my $maxCount = shift; my $type = shift; my $revRef = shift; printf($fh "\n\ndesc\n@@\n\n"); for(0..$maxCount-1) { printf($fh "1.%-1s;\nlog\n@@\n%-1s\n@@\n\n",$revRef->[$_], $type); } } sub main() { my $argc = @ARGV; if($argc != 1) { die "Usage: genLibrFile.pl <fileName>\n"; } my $p4 = "p4 -u smoon -p localhost:20101 -c smoon_ws"; # For example: # ... #5 change 1017 edit on 2010/08/04 by smoon@smoon_ws (text) 'fifth revision' my $prefix = qr/^\.\.\. \#(\d+) change (\d+) (\w+) on/; my $date = qr/(\d{4})\/(\d{2})\/(\d{2})/; my $time = qr/(\d{2}):(\d{2}):(\d{2})/; my $cluser = qr/(\w+)\@(\w+)/; my $ftype = qr/\((\w+)\)/; my $description = qr/'(.*)'/; my @regTokens = (); my @revArray = (); my $count = 0; my $prevRev = 0; my $maxCount = 0; my $fh = new FileHandle; $fh->open(">$ARGV[0],v") or die "Unable to open $ARGV[0],v\n"; foreach my $eachRev (`$p4 filelog -t $ARGV[0]`) { if($eachRev =~ /$prefix $date $time by $cluser $ftype $description.*$/) { $count += 1; for(1..13) { $regTokens[$_] = eval("\$$_"); #converts $1..$13 to matched tokens } push(@revArray,$regTokens[2]); if($count == 1) { &headRevision($fh,$regTokens[2]); &subRevision($fh,$maxCount,$count,\@regTokens); $maxCount = $regTokens[1]; } else{ &subRevision($fh,$maxCount,$count,\@regTokens); } } } &revisionContent($fh,$maxCount,$regTokens[12],\@revArray); close($fh); } #end of main &main();
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 8645 | Stephen Moon | removing not up-to-date scripts | ||
#11 | 7768 | Stephen Moon | changed $filename to $ARGV[0] when invoking perforce commands since there are cases where there are no archived files and depot spec has to be used for p4 command | ||
#10 | 7767 | Stephen Moon | now works for depot name as well as local name | ||
#9 | 7766 | Stephen Moon | p4 changed to '' for getFstatInfo() | ||
#8 | 7759 | Stephen Moon | The script corrected to account for lazy copies; the correct location of librarian file is determined by using p4 fstat -Oc in conjunction with p4 filelog -t | ||
#7 | 7750 | Stephen Moon | description updated | ||
#6 | 7749 | Stephen Moon |
Wrong version submitted in the previous submit. Corrected |
||
#5 | 7748 | Stephen Moon | made another bug fix: added semicolon before 'author' | ||
#4 | 7747 | Stephen Moon | made some modifications to match the actual RCS file | ||
#3 | 7736 | Stephen Moon | removed unused variable | ||
#2 | 7735 | Stephen Moon | Make regex for client user and client more permissive | ||
#1 | 7734 | Stephen Moon | a script which generates an archive file using a p4 filelog output with empty file content |