p4 list opened files that are shelved - perforce

I don't want the changelists; I want the actual files that are shelved. So the results should look like the results of p4 opened but filtered to show only the files that are shelved.
Anyone know how to do this in a few commands? (Preferably one)

I couldn't find a way to get it down to less than this, but maybe this will help as a starting point:
for cl in `p4 -ztag changes -u your.name -s shelved | \
grep -oP '(?<=^\.{3} change )\d+'`
do
p4 describe -Ss $cl | grep -E '^\.{3}'
done | sort | uniq
This does a p4 describe -S on each of your shelved changelists, but tries to only show the files. It might be a bit fragile. It should look like:
... //depot/yourfile.txt#4 edit
... //depot/otherfile.txt#5 edit

Related

Change Perforce files' recursive permissions

I have multiple directories that have +w (Always writable in workspace).
How do I change all files to keep all permissions as is, and remove the +w if exists. Need the p4 command (I know p4 edit -t is per file type...).
Some files are text, some are binaries...
This'll do it:
p4 -F "%type%#%depotFile%" files ... | grep -e ".*w.*#.*" | sed -e "s/\(.*\)w\(.*\)#\(.*\)/edit -t \1\2 \"\3\"/" | p4 -x - run
Note that you need "grep" and "sed" -- if you're on Windows (like I am) I recommend the versions that come with Cygwin. :)

In Perforce, how to find files with certain filetype+attribute?

Files stored in P4 depot are decorated with file type and optional attributes:
The above example is for <binary+S4>.
How can I search the depot tree for all files which have <binary+S4>?
I want to audit these files and change attributes of some of them to <binary+S10>.
p4 fstat should solve it for you.
So a command like this would show you all of the writable text files.
p4 fstat -F "headType=text+w" //DEPOT/...
From the command line (I'm on Windows using Cygwin's version of "grep" and "cut", should work on Mac/Unix too):
p4 -F %type%:%depotFile% files //... | grep ^binary+S4 | cut -d: -f2- | p4 -x - edit -t +S10

In Perforce, how do I find the local path for files in a pending changelist?

Given a Perforce changelist number, I want to find the local path of all files in that pending changelist.
p4 describe changelist -- gets me the depot path for files in the changelist (method 1)
p4 opened -c changelist -- gets me the depot path for files in the changelist (method 2)
p4 have -- gets me the depot path and local path for all files that have previously been submitted
Using a combination of p4 describe and p4 have, I can find the local paths for all files in the changelist that have previously been submitted to Perforce (and are opened for delete or edit).
But what about files that are opened for add? p4 have does not know anything about files that are opened for add.
Given a pending Perforce changelist, how do I find the local path for files that are about to be added to Perforce?
To output the local path of all pending adds of a changelist you can use:
p4 opened -c changelist | grep -w add | sed 's/#.*//' \
| p4 -x - where | awk '/^\// {print $3}'
This does the same without grep but is a bit more obscure:
p4 opened -c changelist | sed -n 's/\(.*\)#.*- add .*/\1/p' \
| p4 -x - where | awk '/^\// {print $3}'
You could of course also use
p4 -ztag opened -c changelist
This will report both the depotFile and the clientFile for each opened file.
To list only client files:
p4 -ztag opened -c changelist | grep clientFile | awk '{print $3}'
Replacing //client/ with the client's root is left as an exercise for the reader.
Local path for all files in a pending changelist without any external or platform-specific tools:
p4 -F %clientFile% fstat -Ro -F action=add [-e CHANGE] //...
Remove the '-F action=add' if you want to get files opened for all actions.
p4 opened -s -c <changelist#> | awk -F " " '{print $1}' | p4 -x - where | awk -F " " '{print $3}'
Based on Peter G's answer, translated into powershell 2.0:
p4 opened -c changelist
| Where-Object{$_ -match "add"}
| ForEach-Object{p4 where ($_.split('#')[0])}
| ForEach-Object{$_.split()[2]}

P4, How to find changelist user from a given changelist?

Anybody knows how to get the change list user from a given changelist(say, #12345)?
p4 describe -s #12345
will give output like this:
Change #12345 by user#user_clientspec on 2010/07/26 10:26:29
affected files...
.......
Is there any command to give only the user name. Not with client spec as it shows user#user_clientspec.
Appreciate your help.
Thanks,
Tom
p4 change -o 12345 | grep ^User:
Or, if you're on a fairly recent version of the 'p4' command line:
p4 -F "%User%" -ztag change -o 12345
I think you'll just have to parse the output.
This ungainly bit of powershell will get you the user:
p4 describe -s 12345 | select-object -first 1 | %{ $_.Split()[3].Split('#')[0] }
to get only the user, and not other "User:" strings, trailing spaces, etc. try:
bash -c "p4 change -o 12345 | grep -oP '(?<=^User:).*' | xargs"

In Perforce, list all changesets by user

In Perforce, how do I list all changesets for a given user?
Can that be done via a single "p4" command?
Yes.
p4 changes -u <username>
In Powershell 2.0:
p4 users
| select-string "^\w+(.\w+)?" | %{$_.Matches} | %{$_.Value}
| %{p4 changes -u $_}
The first line shows all users, the second line parses out the username from the output, adn the third line sends that input to p4 changes.
EDIT: The regex assumes your usernames are either a single word or a firstname.lastname format. You may need to edit it for different formats.
EDIT2: Ooooh for a given user. Arse.
EDIT3: Shorter powershell:
p4 users
| select-string "^\w+(.\w+)?" | %{$_.Matches}
| %{p4 changes -u $_.Value }
EDIT4: even shorter powershell:
p4 users | % { p4 changes -u $_.Split()[0] }
For details of the changes for each changelist use:
p4 changes -u <user_name> | %{p4 describe $_.Split()[1]}
Use -s option for describe if you don't need the file diff.
p4 changes -m 1 -L -t -u

Resources