Helpful Perforce One-liners --------------------------- ### About This Project The page contains a list of handy single-line Perforce scripts. Most of these can easily be converted into custom tools to run from the Perforce GUIs. If you have a favorite that's not listed here, please share it! The "shell command" one-liners will run in most generic shells, including the standard Windows **cmd** prompt, but most require a set of CLI tools that are only standard on Unix. The free [Cygwin toolkit](http://www.cygwin.com) is a popular way to get similar versions of these tools on Windows. The [Powershell](http://en.wikipedia.org/wiki/Windows_PowerShell) one-liners do not require Unix tools. The [px](https://swarm.workshop.perforce.com/files/guest/shawn_hladky/px) commands use an extended command-line client. #### Delete all empty submitted changelists. Shell command: ```p4 changes -s submitted | cut -d " " -f 2 | xargs -n1 p4 change -d -f``` Powershell: ```p4 changes -s submitted | %{p4 change -d -f $_.split()[1]}``` px: ```px -F %change% changes -s submitted | px -X- change -d -f``` Contributors: Sam Stafford, Philip Kania, Shawn Hladky #### Find all files containing a given expression. (Obsoleted by p4 grep.) Shell command : ```p4 print PATH | grep -e EXPR -e "^//" | grep -B1 -e EXPR``` Powershell : ```p4 print PATH | select-string EXPR,^//\w | %{if($_ -match "^//\w"){$f=$_}else{if($f){$f;$f=0};$_}} p4 print PATH | select-string EXPR,^//\w | %{if($_ -match "^//\w"){$f=$_}else{$_}} | select @{n="file";e={$f}},@{n="match";e={$_}} ``` Script : [p4find.bat](https://swarm.workshop.perforce.com/view/guest/sam_stafford/scripts/p4find.bat) Contributors : Sam Stafford, Philip Kania #### List all files opened on any client owned by USER, without using p4 opened -a. Shell command : ```p4 -Ztag clients | grep -B3 "... Owner USER" | grep "... client" | cut -d ' ' -f 3 | xargs -n1 p4 opened -C``` Powershell : ```p4 clients -uUSER | %{p4 opened -C $_.split()[1]}``` px : ```px -F %client% clients -u USER | px -X- opened -C``` Contributors : Sam Stafford, Philip Kania, Shawn Hladky #### List all changelists that contributed via integration to target change CHANGE. Shell command : ```p4 files @CHANGE,@CHANGE | sed s/#.*/@CHANGE/ | p4 -x - filelog -m1 | grep "^\.\.\. \.\.\." | grep -v "into" | grep -v "ignored by" | sed "s/.*\/\//\/\//" | p4 -x - changes``` Powershell : ```p4 files "@CHANGE,@CHANGE" | %{$_ -replace "#.*","@CHANGE"} | p4 -x - filelog -m1 | select-string "^\.\.\. \.\.\." | ?{$_ -notmatch "into" -and $_ -notmatch "ignored by"} | %{$_ -replace ".*//","//"} | p4 -x - changes``` Contributors : Sam Stafford, Philip Kania #### Delete all jobs matching the pattern "job=DELETEME*". Shell command : ```p4 jobs -e "job=DELETEME*" | cut -d " " -f 1 | xargs -n 1 p4 job -d``` Powershell : ```p4 jobs -e "job=DELETEME*" | %{p4 job -d $_.split()[0]}``` px : ```px -F %Job% jobs -e "job=DELETEME*" | px -X- job -d``` Contributors : Sam Stafford, Philip Kania, Shawn Hladky #### Get the latest version only for files you already have a copy of in your workspace Shell command : ```p4 sync #have,head``` Script : [haveSync.pl](https://swarm.workshop.perforce.com/view/guest/matt_attaway/scripts/haveSync.pl) Contributor : Matt Attaway #### Open all the files in a submitted changelist for edit Shell command : ```p4 files ...@, | sed s/\#.*// | p4 -x - edit``` Powershell : ```p4 files ...@, | %{$_.split("#")[0]} | p4 -x - edit``` px : ```px -F %depotPath% files ...@, | px -x - edit``` Script : [editFilesInChange.bat](https://swarm.workshop.perforce.com/view/guest/matt_attaway/scripts/editFilesInChange.bat) Contributors : Matt Attaway, Philip Kania, Shawn Hladky #### Returns output if and only if USER has access to FILE. (Doesn't necessarily work with wildcards.) Shell command : ```p4 protects -u USER FILE | tail -n1 | grep -e " //"``` Powershell : ```p4 protects -u USER FILE | select-string " //" -quiet``` Contributors : Sam Stafford, Philip Kania #### Simple triggers entry to enforce revertunchanged SubmitOption on client specs. Shell command : ``` ru form-in client "sed -i -e s/submitunchanged/revertunchanged/ %formfile%"``` Contributor : Sam Stafford #### List all new files under the current directory not opened for add. Shell command : ```dir /b /s /a-d | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16- find . -type f -print | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16- ``` Powershell : ```gci -recurse | ?{-not $_.PSIsContainer} | %{$_.FullName} | p4 -ztag -x - add -nf | select-string "clientFile" | %{([string]$_).substring(15)}``` px : ```px addr -n ...``` Contributors : Sam Stafford, Philip Kania, Shawn Hladky #### List files modified by USER. Shell command : ```p4 changes -u USER | cut -d" " -f2 | xargs -n1 -iARG p4 files @ARG,ARG``` px : ```px -F "@=%change%" changes -u USER | px -x- files``` Contributor : Sam Stafford #### List all changelists with descriptions that match regexp. /\bfix/i in example below that means "list all fixes" Shell command : ```p4 changes -l //depot/your/path/...@2008/04/25,@now | perl -lne '$a=$_ if /^Change/; print qq|$a\t$_| if /\bfix/i'``` Contributor : Dmytro Gorbunov #### List all changelists that are pending (have not been submitted) by a user yet. Shell command : ```p4 changes -u User_Name -s pending``` Contributor : Richard Schilling