How to identify user who created the head revision using fstat? - perforce

I can do this using filelog. A command such as
p4 filelog -m1 -s //path/to/file
Produces output of the following form:
#51 change 196811 edit on 2014/05/06 by user#client-workspace ...
I would prefer not to have parse it. I can't figure out how to do it using p4 fstat. I would have thought it would be actionOwner, but:
$ p4 fstat -T actionOwner //path/to/file
Field actionOwner doesn't exist.

Instead of using 'fstat', you could do 'p4 -ztag filelog -m1 -s //path/to/file'.
It will produce output something like:
C:\Users\Bryan\perforce\client>p4 -ztag filelog -m 1 //depot/a
... depotFile //depot/a
... rev0 1
... change0 1
... action0 add
... type0 text
... time0 1399680148
... user0 Bryan
... client0 Dell660
... fileSize0 10
... digest0 733F328D8CFF7DD89970EC34A70AA14F
... desc0 My super change
And you could look at the "user0" field.
By the way, if you have a recent enough client, you can even combine this with the less-known -F option, as in:
C:\Users\Bryan\perforce\client>p4 -ztag -F "%user0%" filelog -m 1 //depot/a
Bryan
There are lots of ways to skin this cat, but this is definitely one of the ways.

Related

Is it possible to use a P4 command to `Mark for Delete` every file that is "missing"?

Say I had checked in the files:
a.txt
b.txt
c.txt
I checked them all out so that I could mass edit them by dumping files from another folder:
cp -R folder-one/* folder-two/
The result is:
a.txt (updated)
b.txt (deleted)
c.txt (no changes)
Now I Revert Unchanged Files and intend to submit:
a.txt (updated)
b.txt (deleted)
But I can't because now b.txt is "missing".
Is it possible to use a P4 command to Mark for Delete every file that is "missing"?
Easiest fix is just to revert all of the files that you've opened (with the -k flag so you keep your local changes) and let reconcile figure it out from square one:
p4 revert -k ...
p4 reconcile ...

Search output of p4 command

I am trying to perform an action depending on the output of perforce commands. But it seems that pipping and greping/acking the command doesn't appear to pickup the output
e.g.
p4 sync -n $HOME/... | grep -c up
/homedirectory/... - file(s) up-to-date.
0
p4 sync -n $HOME/... | grep -c nope
/homedirectory/... - file(s) up-to-date.
0
Further example of what i'm trying to do:
if ( `p4 sync -n $HOME/... | grep -c "no such file"` == 0 ) then
if command
else
do else command
endif
Is there anyway to read the output of a perforce command without having to write to a file then read the output? Ideally the command would be a single line.
grep isn't working because the "empty" messages like no such file and up-to-date go to stderr. As #heemayl suggested one way to fix that is to do a redirect.
You can also fix this in a shell-independent way by using the -s or -e flags to p4:
C:\Perforce\test>p4 -s sync
error: File(s) up-to-date.
exit: 0
C:\Perforce\test>p4 -e sync
error: File(s) up-to-date.
code0 554768772 (sub 388 sys 6 gen 17 args 1 sev 2 uniq 6532)
... code0 554768772
... fmt0 [%argc% - file(s)|File(s)] up-to-date.
... argc
exit: 0
Both of these flags redirect all output to stdout and also prepend every message with debugging information about the message itself. If you're trying to grep for a particular message, for example, you can use the -e flag and grep for its unique code rather than the string.
Using the -F flag lets you reformat the output to include particular elements from the message dict that you see with -e, so if you want just the code:
C:\Perforce\test>p4 -F %code0% sync
554768772
If you're trying to capture elements of the actual output, like file names, -F is even more useful:
C:\Perforce\test>p4 -F %localPath% sync -n ...#1
c:\Perforce\test\0.f1
c:\Perforce\test\1.15
c:\Perforce\test\1.18
c:\Perforce\test\2.f1
c:\Perforce\test\2.f2

Get local location for Perforce opened files

I want to write a script to process files that have been edited. p4 opened gives a good list but it is using depot syntax. Is there a way to get the output in local syntax so I can pass the results to my script?
I am running Perforce on Linux.
p4 where will tell you where a depot file is located locally.
You'll need to take the output of p4 opened and use p4 where to translate each depot path to a local path.
This answer might provide some hints.
Edit: Also see if p4 -ztag opened suits your needs. -ztag frequently produces a more verbose, but script-friendly output.
If you just want the client syntax for the file you can use the
'p4 -Ztag opened' command such as either of the following examples:
$ p4 -Ztag opened | grep clientFile
... clientFile //admin14streams/depot/www/dev/Jam.html
... clientFile //admin14streams/depot/www/dev/Jambase.html
... clientFile //admin14streams/depot/www/dev/Jamfile.html
... clientFile //admin14streams/depot/www/dev/Jamlang.html
... clientFile //admin14streams/depot/www/dev/images/jamgraph-jam.gif
... clientFile //admin14streams/depot/www/dev/index.html
$ p4 -Ztag opened | grep clientFile | cut -d ' ' -f3
//admin14streams/depot/www/dev/Jam.html
//admin14streams/depot/www/dev/Jambase.html
//admin14streams/depot/www/dev/Jamfile.html
//admin14streams/depot/www/dev/Jamlang.html
//admin14streams/depot/www/dev/images/jamgraph-jam.gif
//admin14streams/depot/www/dev/index.html
The 'p4 where' command will give you the local file system
location if that is what you want, however.
$ p4 where //depot/www/dev/Jam.html
//depot/www/dev/Jam.html //admin14streams/depot/www/dev/Jam.html /home/bruno/myspaces/admin14streams/depot/www/dev/Jam.html
$ p4 -Ztag where //depot/www/dev/Jam.html
... depotFile //depot/www/dev/Jam.html
... clientFile //admin14streams/depot/www/dev/Jam.html
... path /home/bruno/myspaces/admin14streams/depot/www/dev/Jam.html
Hope this helps.

Is there a way to extract only CL number and username from p4 changes

p4 changes command will give me change list number, date, user by whom submitted, changelist description but how to extract only CL number and user name?
Perhaps not the pretties way to do it, but this works for me:
p4 changes | awk '{print $2" "$6}' | sed "s/\#[^\n]*//"
First, awk extracts the changelist number ($2, i.e. column 2) and the username#workspace ($6, i.e. column 6). Then sed removes the #<workspace>.
You'll need to parse the output from p4 manually, but you might find it easier to do so by using p4 -z tag COMMAND, which generates more parsable output.
For example, p4 -z tag changes changes -s submitted -m 1 will output:
... change 123456
... time 1384458979
... user james
... client james-p4
... status submitted
... changeType public
... path //depot/some/path...
... desc Some truncated description

How do I split a large changelist in P4

I have a very large changelist (~40,000 files) and I need to split it into several smaller changelists so I can view the files contained. I am aware that I can adjust my p4 preferences to show more files in a changelist, but I need to run commands against the files in the changelist, and when I run the command it hangs and doesn't complete after 18 hours.
I'm running the 2012.2 P4 server.
The command I'm running is:
C:>p4 -u some_user -c some_client revert -k -c 155530 //...
Thanks
If you want to move files into a separate changeset, you could do:
p4 reopen -c default //some/subdirectory/...
p4 change
The above would move a portion of the files into the "default" changeset and then create a new changeset from them. Or, if you have another changeset to use already, you could of course do:
p4 reopen -c NEW_CLN //some/subdirectory/...
directly.
If the files you want to split out aren't nicely contained within a subdirectory, a more general approach would be to do:
p4 -ztag opened -c OLD_CLN | grep depotFile | cut -d ' ' -f 3 > files.txt
to get a list of files opened in that changeset. Then edit that file so that only files you want to remove from the changeset are listed, and then do:
p4 -x files.txt reopen -c NEW_CLN
The above calls p4 reopen -c NEW_CLN using each of line from files.txt as an argument.

Resources