profile-p4 2.5 KB

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