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
Related
I need to return records where there is an access date older than 60 days along with Perforce UserName, Email & Last Accessed Date in Perforce. I am aware of the perforce command to get the all user list with "%User% %Email% %Access%" in combination with p4 users. However, I'm looking for some script that can be set in a cron job to daily monitor and send the alert through email.
The command that i am using to get all user list is
p4 -ztag -F "%User% %Email% %Access%" users | awk '{$3=strftime("%Y/%m/%d %H:%M:%S",$3)} {print}' | sort -k 2,3 | sed 's/[ \t]/,/g'
Any help would be much appreciated.
On Linux, this'll generate a CSV-style list sorted by username:
p4 -ztag -F "%User% %Email% %Access%" users | awk '$3 < '"$(date -d "60 days ago" +%s)"' {print $1","$2","strftime("%Y/%m/%d %H:%M:%S",$3)}'
If you want to also sort by Access date, you could sort before awk.
p4 -ztag -F "%User% %Email% %Access%" users | sort -k3rn | awk '$3 < '"$(date -d "60 days ago" +%s)"' {print $1","$2","strftime("%Y/%m/%d %H:%M:%S",$3)}'
For OSX, this would look like:
p4 -ztag -F "%User% %Email% %Access%" users | sort -k3rn | awk '$3 < '"$(date -v-60d +%s)"' {print $1","$2","strftime("%Y/%m/%d %H:%M:%S",$3)}'
If you're redirecting any of the above commands to a text file, you could then read said text file back in as a list of users to then delete.
awk -F, '{print $1}' old.users.list | xargs -I{} p4 user -df {}
Note this is a fairly shallow way of doing it. It won't remove their workspaces or pending changelists/shelves. It's possible to incorporate those steps as part of a more thorough cleanup script but various companies have their own policies about what to do with shelved changes, etc.
You will at least be able to quickly free up a license this way.
In Python, using the p4python module:
from datetime import datetime
from P4 import P4
with P4().connect() as p4:
for user in p4.run_users():
access_time = datetime.fromtimestamp(int(user['Access']))
if (datetime.now() - access_time).days > 60:
print(user['User'], user['Email'])
# or do whatever else you want
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. :)
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
I wish to find if a user has modified a file in any of the perforce branches.
Is there a simple command to find it?
input: UserName and FileName
output: changelist or no changelist
p4 changes -u {user} //.../{filename}
You can achieve this with a combination of p4 filelog and grep.
p4 filelog {filename} | grep {username}
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"