autolabel.sh #2

  • //
  • guest/
  • amo/
  • scripts/
  • autolabel.sh
  • View
  • Commits
  • Open Download .zip Download (1 KB)
#!/bin/bash
# ==========
# $File: //guest/amo/scripts/autolabel.sh $
# $Revision: #2 $
# $Change: 24538 $
#
# $Author: amo $
# $DateTimeTZ: 2018/09/03 03:57:55 -0700 PDT $
# ----------
# PURPOSE
# obtaining a list of automatic labels that would be encompassed by the scope of an automatic label. 
#
# Potential improvements: 
# * performance. This script is doing loops through potentially large chunks of data, and probably not terribly efficiently. 
# * verification. Checking that the parameters passed to the script are valid; improved error-handling; etc. 
# 
# ==========
# get a list of automatic labels
# doing this by checking for 'Revision' in the tagged-output of label spec

autolabels=`p4 -F "%label% Rev:%Revision%" -ztag labels | grep -v "Rev:$" | sed -e "s/ Rev:.*//g"`

# loop through the parameters passed to script (should be depot paths)
# assuming (but not really testing for) file patterns

while [ $# -ne 0 ]
do
	depotpath=$1

	# does 'depotpath' contain at least one file? (a low-quality check)
	# if so, get list of automatic labels, check to see if any file revision
	# in depotpath is encompassed by the automatic label.
	# Finally, if it does, print the output of 'p4 labels' for that label.

	filesExist=`p4 files -m1 $depotpath 2> /dev/null | wc -l`

	if [ "$filesExist" -eq "1" ] 
		then
		for l in $autolabels; do

			labcount=`p4 files $depotpath#1,@$l 2> /dev/null | wc -l`
			
			if [ "$labcount" -gt "0" ]
					then p4 labels -e "$l"
			fi
		done
	fi
	shift
done
# Change User Description Committed
#2 24538 Adam Morriss Improvements to script, plus adding keywords
#1 24537 Adam Morriss name-change for script
//guest/amo/scripts/working-autolabel.sh
#1 24203 Adam Morriss Moving files to 'amo'
//guest/adam_morriss/scripts/working-autolabel.sh
#1 18478 Adam Morriss A couple of bash scripts to carry out basic checks.

Both are functional, though need further checks and measures, and neither have been tested to destruction.

'working-autolabel' attempts to produce a list of automatic labels corresponding to a (currently hard-coded) depot path.
'findchange' searches the description of changes related to a specified path for a provided string, and lists the change number for those that match. This needs further error checking, and the ability to search pending changes (which won't work if you provide a path). Would be good to check that the depot path exists too.