export P4EDITOR="${EDITOR}" export P4DIFF="${EDITOR} -d" export P4MERGE="${EDITOR} -d" # May be overridden in ~/.profile-local or other such file : ${P4_MAIN_ROOT:="//depot/"} export P4_MAIN_ROOT alias p4a="p4 add" alias p4e="p4 edit" alias p4r="p4 revert" alias p4s="p4 sync" alias p4d="p4 delete" alias p4o="p4 opened" alias p4c="p4 client" alias p4i="p4 integrate" alias p4grab="p4 diff -se | p4 -x - edit" alias p4reset="p4 diff -sr | p4 -x - revert" alias p4pending="p4 changes -c \$(. .p4rc; echo \$P4CLIENT) -s pending | awk '{print \$2}'" p4whose() { if [[ $# -ne 1 ]]; then return 1; fi local file="${1}" if [[ ${file:0:2} != "//" ]]; then local file="${P4_MAIN_ROOT}${file}"; fi # Get only lines with a change source (no integrate/branch) # Pull the name of each submitter # Uniqueify without losing order # Attach a number to them p4 filelog "${file}" | \ grep -E "^\.\.\. #" | \ awk '{ print $9 }' | cut -d'@' -f1 | \ perl -ne 'if (!defined $x{$_}) { print $_; $x{$_} = 1; }' | \ awk 'BEGIN { idx=1 } { print idx,$0; idx += 1 }' } p4backout() { if [[ $# -lt 2 ]]; then echo "usage: p4backout backout# parent#" >&2 return 1 fi local changenum="$1" local target_stage="@${2}" local lastchange=$((changenum-1)) p4 sync @$lastchange p4 edit ... p4 sync @$changenum p4 resolve -ay if [[ ${target_stage} == "@HEAD" ]]; then p4 sync else p4 sync $target_stage fi p4 resolve -am } _p4_import_impl() { local tmpfile=$(mktemp) trap "rm -f ${tmpfile}" EXIT p4 client -o > "${tmpfile}" local client=$(grep -E "^Client:" "${tmpfile}" | awk '{ print $2 }') # Initialize the client if necessary (a client with no files in view will not always have a View header) local has_view=$(grep -c -E "^View:" "${tmpfile}") if [[ $has_view -eq 0 ]] then echo "View:" >> "${tmpfile}" fi for file in "${files[@]}" do local mapping="//${client}/${file##*/}" echo -e "\t${file} ${mapping}" >> "${tmpfile}" done p4 client -i < "${tmpfile}" } p4_import_client() { local other_client="${1}" local files=($(IFS=$'\n'; p4 client -o "${other_client}" | sed -n '/^View:$/ { :a; n; p; ba; }' | cut -d' ' -f1 | tr -d $'\t')) _p4_import_impl } p4_import_changelist() { local changelist="${1}" local files=($(IFS=$'\n'; p4 describe -s "${changelist}" | grep -E "^\.\.\." | cut -d' ' -f2- | cut -d'#' -f1)) _p4_import_impl } p4finish() { local rmdir=0 force=0 good=1 if [[ ${1} == "-d" ]]; then rmdir=1; shift; fi if [[ ${1} == "-f" ]]; then force=1; shift; fi local tar="${1}" cwd="${PWD}" if [[ -z ${tar} ]] || [[ ! -d ${tar} ]]; then echo "Directory does not exist: '${tar}'" return 1 fi cd "${tar}" if [[ $(p4 client -o | grep ^Root | sed 's/Root:\s*//g') != "${PWD}" ]]; then echo "This directory is not a perforce client" elif [[ $(p4 opened 2>/dev/null) == "" ]]; then p4 sync ...#0 elif [[ ${force} -eq 1 ]]; then echo "Perforce client has open files, but forcing the issue" p4 revert ... p4 sync ...#0 else echo "Perforce client has open files" good=0 fi cd "${cwd}" if [[ ${good} -eq 1 ]]; then [[ ${rmdir} -eq 1 ]] && rm -rf "${tar}" else return 1 fi } . ${HOME}/.complete-p4