profile-p4 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. export P4EDITOR=/home/user/wreed/bin/vim
  2. export P4DIFF="/home/user/wreed/bin/vim -d"
  3. export P4MERGE="/home/user/wreed/bin/vim -d"
  4. alias p4a="p4 add"
  5. alias p4e="p4 edit"
  6. alias p4r="p4 revert"
  7. alias p4s="p4 sync"
  8. alias p4d="p4 delete"
  9. alias p4o="p4 opened"
  10. alias p4c="p4 client"
  11. alias p4i="p4 integrate"
  12. alias p4grab="p4 diff -se | p4 -x - edit"
  13. alias p4reset="p4 diff -sr | p4 -x - revert"
  14. p4whose() {
  15. if [[ $# -ne 1 ]]; then return 1; fi
  16. local file="${1}"
  17. if [[ ${file:0:2} != "//" ]]; then local file="//depot/online/makefds/mainline/${file}"; fi
  18. # Get only lines with a change source (no integrate/branch)
  19. # Pull the name of each submitter
  20. # Uniqueify without losing order
  21. # Attach a number to them
  22. p4 filelog "${file}" | \
  23. grep -E "^\.\.\. #" | \
  24. awk '{ print $9 }' | cut -d'@' -f1 | \
  25. perl -ne 'if (!defined $x{$_}) { print $_; $x{$_} = 1; }' | \
  26. awk 'BEGIN { idx=1 } { print idx,$0; idx += 1 }'
  27. }
  28. p4backout() {
  29. local changenum="$1"
  30. local target_stage="${2:-fdsparent}"
  31. local lastchange=$((changenum-1))
  32. p4 sync @$lastchange
  33. p4 edit ...
  34. p4 sync @$changenum
  35. p4 resolve -ay
  36. p4 sync @$target_stage
  37. p4 resolve -am
  38. }
  39. p4_import_changelist() {
  40. local changelist="${1}"
  41. local tmpfile=$(mktemp)
  42. trap "rm -f ${tmpfile}" EXIT
  43. p4 client -o > "${tmpfile}"
  44. local client=$(grep -E "^Client:" "${tmpfile}" | awk '{ print $2 }')
  45. local files=($(IFS=$'\n'; p4 describe -s "${changelist}" | grep -E "^\.\.\." | cut -d' ' -f2- | cut -d'#' -f1))
  46. local has_view=$(grep -c -E "^View:" "${tmpfile}")
  47. if [[ $has_view -eq 0 ]]
  48. then
  49. echo "View:" >> "${tmpfile}"
  50. fi
  51. for file in "${files[@]}"
  52. do
  53. local mapping="//${client}/${file##*/}"
  54. echo -e "\t${file} ${mapping}" >> "${tmpfile}"
  55. done
  56. p4 client -i < "${tmpfile}"
  57. }
  58. p4finish() {
  59. local cwd="${PWD}"
  60. local rmdir=0
  61. if [[ ${1} == "-d" ]]; then rmdir=1; shift; fi
  62. local tar="${1}"
  63. if [[ -z ${tar} ]] || [[ ! -d ${tar} ]]; then
  64. echo "Directory does not exist: '${tar}'"
  65. return 1
  66. fi
  67. cd "${tar}"
  68. if [[ $(p4 opened 2>/dev/null) == "" ]]; then
  69. p4 sync ...#0
  70. cd "${cwd}"
  71. [[ ${rmdir} -eq 1 ]] && rm -rf "${tar}"
  72. else
  73. echo "Perforce client has open files"
  74. cd "${cwd}"
  75. return 1
  76. fi
  77. }
  78. . ${HOME}/.complete-p4