profile-p4 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. local lastchange=$((changenum-1))
  39. p4 sync @$lastchange
  40. p4 edit ...
  41. p4 sync @$changenum
  42. p4 resolve -ay
  43. if [[ ${target_stage} == "@HEAD" ]]; then
  44. p4 sync
  45. else
  46. p4 sync $target_stage
  47. fi
  48. p4 resolve -am
  49. }
  50. p4_import_changelist() {
  51. local changelist="${1}"
  52. local tmpfile=$(mktemp)
  53. trap "rm -f ${tmpfile}" EXIT
  54. p4 client -o > "${tmpfile}"
  55. local client=$(grep -E "^Client:" "${tmpfile}" | awk '{ print $2 }')
  56. local files=($(IFS=$'\n'; p4 describe -s "${changelist}" | grep -E "^\.\.\." | cut -d' ' -f2- | cut -d'#' -f1))
  57. # Initialize the client if necessary (a client with no files in view will not always have a View header)
  58. local has_view=$(grep -c -E "^View:" "${tmpfile}")
  59. if [[ $has_view -eq 0 ]]
  60. then
  61. echo "View:" >> "${tmpfile}"
  62. fi
  63. for file in "${files[@]}"
  64. do
  65. local mapping="//${client}/${file##*/}"
  66. echo -e "\t${file} ${mapping}" >> "${tmpfile}"
  67. done
  68. p4 client -i < "${tmpfile}"
  69. }
  70. p4finish() {
  71. local cwd="${PWD}"
  72. local rmdir=0
  73. if [[ ${1} == "-d" ]]; then rmdir=1; shift; fi
  74. local tar="${1}"
  75. if [[ -z ${tar} ]] || [[ ! -d ${tar} ]]; then
  76. echo "Directory does not exist: '${tar}'"
  77. return 1
  78. fi
  79. cd "${tar}"
  80. if [[ $(p4 opened 2>/dev/null) == "" ]]; then
  81. p4 sync ...#0
  82. cd "${cwd}"
  83. [[ ${rmdir} -eq 1 ]] && rm -rf "${tar}"
  84. else
  85. echo "Perforce client has open files"
  86. cd "${cwd}"
  87. return 1
  88. fi
  89. }
  90. . ${HOME}/.complete-p4