1 #!/usr/local/bin/perl5.8.4
2 ################################################################################
6 # Author: Andrew@DeFaria.com
7 # Description: This script will read CVS commit information searching for Issue
8 # IDs and formulate a "change set" including the files committed
10 # Created: Fri Dec 9 15:10:56 PST 2005
11 # Modified: 2007/05/17 07:45:48
14 # (c) Copyright 2005, Andrew@DeFaria.com, all rights reserved
16 ################################################################################
26 my $lib_path = $^O =~ /MSWin/ ? "\\\\brcm-irv\\dfs\\projects\\ccase\\SCM\\lib"
27 : "/projects/ccase/SCM/lib";
29 # Extract relative path and basename from script name.
30 $0 =~ /(.*)[\/\\](.*)/;
32 my $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
33 $me = (!defined $2) ? $0 : $2;
36 # Add the appropriate path to our modules to @INC array.
37 unshift @INC, $ENV {SITE_PERL_LIBPATH} if defined $ENV {SITE_PERL_LIBPATH};
38 unshift @INC, "$lib_path";
39 unshift @INC, "$abs_path";
48 display "ERROR: $msg\n" if defined $msg;
50 display "Usage: $me\t[-u] [-v] [-d] [-passthru]
51 \t\t[{-pre -logfile <filename>} |
52 \t\t {-post -repository <repository> -path <path>
53 \t\t <file> <rev> {<file> <rev>...}}]
58 -v: Turn on verbose mode
59 -d: Turn on debug mode
60 -passthru: Passthru stdin to stdout
63 -pre: Perform pre commit checking.
64 -logfile Path to logfile containing commit message
67 -post: Perform post commit updating
68 -repository: Repository (path portion of \$CVSROOT)
69 -path: Path relative to repository
70 <file> <rev>: Files and revisions commited (Format: \"file rev file rev ...\")
77 my $repository = shift;
83 foreach (sort (keys (%filerevs))) {
84 $change_set .= "${filerevs {$_}}\t$repository/$path/$_\n";
87 my $error = AddToChangeSet ($issueid, $change_set);
95 my $sentinal = "csp: ";
98 # Issue id information in the input must have the following format:
101 foreach my $line (@input) {
102 if ($line =~ /^$sentinal/i) {
104 $line = substr $line, length ($sentinal);
107 @issue_ids = split /\s+/, $line;
112 # Eliminate duplicates on return
113 return grep (!$issue_ids {$_}++, @issue_ids);
118 my $passthru = shift;
125 print $_ if $passthru;
128 push @cleansed_lines, $_ if !/^#/; # Discard comment lines
131 return @cleansed_lines;
142 if ($ARGV [0] eq "-v") {
143 Display::set_verbose;
144 } elsif ($ARGV [0] eq "-d") {
146 } elsif ($ARGV [0] eq "-passthru") {
148 } elsif ($ARGV [0] eq "-repository") {
151 Usage "Must specify repository after -repository";
153 $repository = $ARGV [0];
155 } elsif ($ARGV [0] eq "-path") {
158 Usage "Must specify path after -path";
162 } elsif ($ARGV [0] eq "-pre") {
164 } elsif ($ARGV [0] eq "-logfile") {
167 Usage "Must specify log filename after -logfile";
169 $logfile = $ARGV [0];
171 } elsif ($ARGV [0] eq "-post") {
173 } elsif ($ARGV [0] eq "-u") {
183 Usage "Must specify -pre or -post" if !defined $optkind;
185 if ($optkind eq "pre") {
186 Usage "No logfile to parse" if !defined $logfile;
187 } elsif ($optkind eq "post") {
188 Usage "No files committed" if !%filerevs;
193 if ($optkind eq "pre") {
194 verbose "$me v$version: Checking for Issue ID(s)...";
195 open LOGFILE, $logfile
196 or error "Unable to open logfile $logfile - $!", 4;
198 @issue_ids = ParseInput ReadFile (*LOGFILE);
202 # Special case here. Seems cvs will call this script through loginfo
203 # even though directories are not versioned in cvs. If so then
204 # %filerevs will contain "- New directory" and "NONE". In this case
206 if (defined $filerevs {"- New directory"}) {
210 verbose "$me v$version: Updating Issue ID(s)...";
211 @issue_ids = ParseInput ReadFile (*STDIN, $passthru);
214 if (scalar (@issue_ids) eq 0) {
215 error "No issue ID(s) found", 1;
218 verbose "Verifying Issue IDs";
220 foreach (@issue_ids) {
221 my %issue_info = GetIssue $_;
224 verbose "Issue $_ exists in IMS";
226 error "Issue ID $_ does not exist in IMS", 2 if !%issue_info;
230 if ($optkind eq "post") {
231 foreach my $issue_id (@issue_ids) {
232 verbose "Updating Issue ID ${issue_id}'s Change Set";
234 my $error = UpdateIMS $issue_id, $repository, $path, %filerevs;
239 verbose "Issue ID ${issue_id}'s Change Set updated";