profile-p4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. alias p4pending="p4 changes -c \$(. .p4rc; echo \$P4CLIENT) -s pending | awk '{print \$2}'"
  18. p4whose() {
  19. if [[ $# -ne 1 ]]; then return 1; fi
  20. local file="${1}"
  21. if [[ ${file:0:2} != "//" ]]; then local file="${P4_MAIN_ROOT}${file}"; fi
  22. # Get only lines with a change source (no integrate/branch)
  23. # Pull the name of each submitter
  24. # Uniqueify without losing order
  25. # Attach a number to them
  26. p4 filelog "${file}" | \
  27. grep -E "^\.\.\. #" | \
  28. awk '{ print $9 }' | cut -d'@' -f1 | \
  29. perl -ne 'if (!defined $x{$_}) { print $_; $x{$_} = 1; }' | \
  30. awk 'BEGIN { idx=1 } { print idx,$0; idx += 1 }'
  31. }
  32. p4backout() {
  33. if [[ $# -lt 2 ]]; then
  34. echo "usage: p4backout backout# parent#" >&2
  35. return 1
  36. fi
  37. local changenum="$1"
  38. local target_stage="@${2}"
  39. local lastchange=$((changenum-1))
  40. p4 sync @$lastchange
  41. p4 edit ...
  42. p4 sync @$changenum
  43. p4 resolve -ay
  44. if [[ ${target_stage} == "@HEAD" ]]; then
  45. p4 sync
  46. else
  47. p4 sync $target_stage
  48. fi
  49. p4 resolve -am
  50. }
  51. _p4_import_impl() {
  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. # Initialize the client if necessary (a client with no files in view will not always have a View header)
  57. local has_view=$(grep -c -E "^View:" "${tmpfile}")
  58. if [[ $has_view -eq 0 ]]
  59. then
  60. echo "View:" >> "${tmpfile}"
  61. fi
  62. for file in "${files[@]}"
  63. do
  64. local mapping="//${client}/${file##*/}"
  65. echo -e "\t${file} ${mapping}" >> "${tmpfile}"
  66. done
  67. p4 client -i < "${tmpfile}"
  68. }
  69. p4_import_client() {
  70. local other_client="${1}"
  71. local files=($(IFS=$'\n'; p4 client -o "${other_client}" | sed -n '/^View:$/ { :a; n; p; ba; }' | cut -d' ' -f1 | tr -d $'\t'))
  72. _p4_import_impl
  73. }
  74. p4_import_changelist() {
  75. local changelist="${1}"
  76. local files=($(IFS=$'\n'; p4 describe -s "${changelist}" | grep -E "^\.\.\." | cut -d' ' -f2- | cut -d'#' -f1))
  77. _p4_import_impl
  78. }
  79. p4finish() {
  80. local rmdir=0 force=0 good=1
  81. if [[ ${1} == "-d" ]]; then rmdir=1; shift; fi
  82. if [[ ${1} == "-f" ]]; then force=1; shift; fi
  83. local tar="${1}" cwd="${PWD}"
  84. if [[ -z ${tar} ]] || [[ ! -d ${tar} ]]; then
  85. echo "Directory does not exist: '${tar}'"
  86. return 1
  87. fi
  88. cd "${tar}"
  89. if [[ $(p4 client -o | grep ^Root | sed 's/Root:\s*//g') != "${PWD}" ]]; then
  90. echo "This directory is not a perforce client"
  91. elif [[ $(p4 opened 2>/dev/null) == "" ]]; then
  92. p4 sync ...#0
  93. elif [[ ${force} -eq 1 ]]; then
  94. echo "Perforce client has open files, but forcing the issue"
  95. p4 revert ...
  96. p4 sync ...#0
  97. else
  98. echo "Perforce client has open files"
  99. good=0
  100. fi
  101. cd "${cwd}"
  102. if [[ ${good} -eq 1 ]]; then
  103. [[ ${rmdir} -eq 1 ]] && rm -rf "${tar}"
  104. else
  105. return 1
  106. fi
  107. }
  108. . ${HOME}/.complete-p4