#!/bin/tcsh -x
#
# Copyright (c) 2005 Photon Research Associates. All rights reserved.
# Author: David Lee Faison
#
################################################################################
#
# Redistribution and use in source form, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notices,
# this list of conditions and the following disclaimer.
#
# 2. The name of Photon Research Associates and/or the author may not be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# This software is provided 'AS-IS' and any warranties, express or
# implied, including, but not limited to, the implied warranties of
# merchantability and fitness for a particular purpose are
# DISCLAIMED. In no event shall Photon Research Associates or the author,
# separately or in combination with one another, 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.
#
#
###############################################################################
#
# Purpose: This script reconciles the status of job tickets associated with
# a given changelist, setting the job status back to open if there are any
# changelists associated with it that are still pending.
#
# This is done to undo Perforce's default behavior of ignoring whether
# other changelists are still opened against a given job. Perforce simply
# closes every job associated with any changelist that is successfully
# submitted.
#
# $1 = changelist number
#
# Note: if $1 is not specified then the existence of a CHANGELIST environment
# variable is required to specify the changelist number
#
# -------------------------------------------------------
if ($#argv == 0) then
set changelist=$CHANGELIST
else
set changelist=$1
endif
# The array of job records generated below is one dimensional, so
# to index through it the number of fields per record must be known.
set numFields=9
# also the offset into the record of the desired field must be known.
set offsetJob=1
set offsetChange=5
# This creates the array of job records being 'fixed' by our changelist
set jobsFixed=(`p4 fixes -c $changelist`)
@ numJobs = $#jobsFixed / $numFields
# -------------------------------------------------------
@ jobIdx = 0
while ( $jobIdx < $numJobs)
# The outer loop cycles through the each job that is associated with
# the changelist whose submission invoked this trigger script.
# reset this for each job that we process
set jobComplete=true
# calculate index to beginning of job record
@ startOfRec = $jobIdx * $numFields
# then find the specific field
@ jobPos = $startOfRec + $offsetJob
set job = $jobsFixed[$jobPos]
# -------------------------------------------------------
# This creates an array reflecting all of the changelists
# that 'fix' the current job.
set changesFixing=(`p4 fixes -j $job`)
@ numChanges = $#changesFixing / $numFields
# --------------------------------------------------
@ changeIdx = 0
while ( $changeIdx < $numChanges)
# The inner loop cycles through all of the changelists associated
# a job. This inner loop will always have at least one entry - the
# changelist whose submission caused this trigger script to be invoked.
# calculate index to beginning of change record
@ startOfRec = $changeIdx * $numFields
# then find the specific field
@ chaPos = $startOfRec + $offsetChange
set change = $changesFixing[$chaPos]
# --------------------------------------------------
# this shell command is what determines whether
# the changelist is still pending
set changeStat=`p4 change -o $change | grep '^Status:'`
# the command output has a linefeed character in it,
# so a simple comparison to the text 'pending' won't
# work
if ( $changeStat[2] =~ pending* ) then
# if it is still pending, then set the flag...
set jobComplete = false
endif
@ changeIdx++
end
# --------------------------------------------------
echo jobComplete: $jobComplete
if ($jobComplete == false ) then
echo JOB ' $job ' IS NOT COMPLETE, REVERTING STATUS TO 'open' > /dev/null
p4 job -o $job | sed -e 's/^Status: closed/Status: open/'| p4 job -i
endif
@ jobIdx++
end