Get local location for Perforce opened files - linux

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.

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 ...

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

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.

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 get a count of files in a folder in Perforce?

I would like to know how many files are in any given folder/directory/branch of a Perforce depot, but I don't see a way to do this. The p4 fstat command was my first thought, but it doesn't appear to have options to return file counts. Is there a simple way to get a count of files in a folder using either the graphical or command-line client?
While the p4 fstat doesn't offer a way to obtain file counts per se, you can easily parse its output to obtain this information. Note, this works in Windows, but I would imagine it is easily modified for other OSes. Here's how you do it:
p4 fstat -T depotFile //depot/some/folder/... | find /c "... depotFile"
It can also be done with the p4 files command as thusly:
p4 files //depot/some/folder/... | find /c "//"
Use the p4 sizes -s command.
C:\test>p4 sizes -s ...
... 5 files 342 bytes
or if you want just the count:
C:\test>p4 -F %fileCount% sizes -s ...
5
(obviously the file argument can be anything else in place of ... which is the current directory)
Try this command:
p4 files //depot/dir1/dir2/... | wc -l
Explanation:
p4 files //depot/dir1/dir2/... is the command that recursively prints the files under dir2 to screen.
Pipe that through wordcount lines (| wc -l) to count the number of output lines.
This works in Linux/Unix systems, and in Windows if you're using cygwin (or some other Linux-like terminal).
Powershell method:
To count the files in a specific directory:
p4 files //depot/dir1/dir2/... | Measure-Object
Alternatively:
(p4 files //depot/dir1/dir2/...).Count
The following will give you a list of all child directories and their file counts in an object that you can view as a table, sort, export to csv, etc:
p4 dirs //depot/dir1/* | Select-Object -Property #{Name="Path";Expression={$PSItem}},#{Name="FileCounts";Expression={(p4 files $PSItem/...).Count}}

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