profile-p4 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_impl() {
  51. local tmpfile=$(mktemp)
  52. trap "rm -f ${tmpfile}" EXIT
  53. p4 client -o > "${tmpfile}"
  54. local client=$(grep -E "^Client:" "${tmpfile}" | awk '{ print $2 }')
  55. # Initialize the client if necessary (a client with no files in view will not always have a View header)
  56. local has_view=$(grep -c -E "^View:" "${tmpfile}")
  57. if [[ $has_view -eq 0 ]]
  58. then
  59. echo "View:" >> "${tmpfile}"
  60. fi
  61. for file in "${files[@]}"
  62. do
  63. local mapping="//${client}/${file##*/}"
  64. echo -e "\t${file} ${mapping}" >> "${tmpfile}"
  65. done
  66. p4 client -i < "${tmpfile}"
  67. }
  68. p4_import_client() {
  69. local other_client="${1}"
  70. local files=($(IFS=$'\n'; p4 client -o "${other_client}" | sed -n '/^View:$/ { :a; n; p; ba; }' | cut -d' ' -f1 | tr -d $'\t'))
  71. _p4_import_impl
  72. }
  73. p4_import_changelist() {
  74. local changelist="${1}"
  75. local files=($(IFS=$'\n'; p4 describe -s "${changelist}" | grep -E "^\.\.\." | cut -d' ' -f2- | cut -d'#' -f1))
  76. _p4_import_impl
  77. }
  78. p4finish() {
  79. local rmdir=0 force=0 good=1
  80. if [[ ${1} == "-d" ]]; then rmdir=1; shift; fi
  81. if [[ ${1} == "-f" ]]; then force=1; shift; fi
  82. local tar="${1}" cwd="${PWD}"
  83. if [[ -z ${tar} ]] || [[ ! -d ${tar} ]]; then
  84. echo "Directory does not exist: '${tar}'"
  85. return 1
  86. fi
  87. cd "${tar}"
  88. if [[ $(p4 client -o | grep ^Root | sed 's/Root:\s*//g') != "${PWD}" ]]; then
  89. echo "This directory is not a perforce client"
  90. elif [[ $(p4 opened 2>/dev/null) == "" ]]; then
  91. p4 sync ...#0
  92. elif [[ ${force} -eq 1 ]]; then
  93. echo "Perforce client has open files, but forcing the issue"
  94. p4 revert ...
  95. p4 sync ...#0
  96. else
  97. echo "Perforce client has open files"
  98. good=0
  99. fi
  100. cd "${cwd}"
  101. if [[ ${good} -eq 1 ]]; then
  102. [[ ${rmdir} -eq 1 ]] && rm -rf "${tar}"
  103. else
  104. return 1
  105. fi
  106. }
  107. . ${HOME}/.complete-p4