Perforce NotesRuss Bateman |
Table of Contents
|
Install PerforceThis is a commercial, proprietary source code management system. You can use a visual GUI or command-line client to manage source code check-outs, updates and commits.
|
To change what you've got from Perforce, simply modify the client specification via
p4 client
To switch branches, for instance, you have only to...
If you're excluding files like .png, .gif and .jpg from templates then you're removing most of the grief caused by the templates. The best solution is to prepare a shared directory for accessing templates, per office. At present, there is no working implementation of this.
This is a simple matter; you can update everything you've told Perforce is a concern to you (via p4 client) by just
p4 sync
If you're in a specific subdirectory, do this:
p4 sync ...
When encountering build errors because of missing directories or files in the Snapfish sources, as long as local.properties is accurate, you may find the need to force synchronization.
Every time you perform synchronization, Perforce keeps track of what files (and versions of files) it thinks you have in your hos filesystem. The next time you synchronize, it compares what it thinks you have with what it has that's new and only sends down the items for which there is a delta. It does not examine your local filesytem to ascertain the truth.
This is calculated to lessen traffic on the wire and pressure on Perforce itself. You should not over-use this option with Perforce.
For this reason, some things will get out of sync, if rarely. If you're changing product branches frequently, this is likely to happen less rarely and you'll have to resort to forcing things.
The use of the -f option says, in effect, "Disregard what you think I have and give me everything my client specification says to give me."
To force resynchronization of everything, ...
p4 sync -f
If you're reacting to a build error and you understand where the disconnect is occurring, force resynchronization only of that portion that's necessary by going to the top of the filesystem you wish to resynchronize. This does just your current working directory and everything under it (assuming all these are under Perforce control).
p4 sync -f ...
Okay, now that you've just read how to force synchronization, try never to use it. Daniel says he never has to (but then, he's just the little wizard, isn't he?). Here are some work-arounds to try first:
p4 diff -se # show unopened files that differ from the depot revision p4 diff -se | p4 -x- edit # fix files modified without being formally opened for edit p4 diff -sd # show missing files p4 diff -sd | p4 -x- sync -f # force-sync missing files
Assuming you have synchronized files from a Perforce repository, you must tell Perforce that you wish to edit the file in order, later, to commit changes.
p4 edit filepath //depot/somewhere/snapfish-core/blah/filepath - opened for edit
To commit a file you've edited, ...
p4 submit filepath
This will launch vi just as other source code-control software permitting you to explain the reason for committing the change.
These depend on the repository owner, i.e.: your company. In the illustrations below you'll see my company's policy in the form of VID, PID, FF, etc.
Organizational policy can disallow a submission. This cannot be described here.
To add a file you've created, use
p4 add filepath //depot/somewhere/snapfish-core/blah/filepath - opened for add
As soon as you like, you may commit it using p4 submit.
To delete a file currently under Perforce control, do
p4 delete //depot/<path>/foo.txt
When you "check out" a file for editing, Perforce creates a changelist that only it knows about. This is use to later commit changes (see Committing files above).
If you opened a file for editing and no longer wish to make changes, whether or not you modified the file, use p4 revert <filename> to "drop your check-out".
p4 revert only backs out changes from an unsubmitted (uncommitted) changelist. If you kept track of Perforce's echoed change number, that number can be very useful in backing out changes. If the change you want to back out was very recent, you can also get a list of such changes (-m 5 limits the list to 5 here):
p4 changes -m 5 -u jay.johnson Change 414336 on 2011/04/08 by [email protected] ' VID: PID: BID: FF: Added this to xxxx.java file...' Change 414334 on 2011/04/08 by [email protected] ' VID: PID: BID: FF: Added a' Change 414333 on 2011/04/08 by [email protected] ' VID: PID: BID: FF: Added a ' Change 414330 on 2011/04/08 by [email protected] ' VID: PID: BID: FF: '
To begin the process, you must have the change number. Subtract 1 from it to produce the number of the change just prior to the one you wish unapply. Synchronize your subdirectory to that change. Understand that if, for a given change, you checked in more than one file, every file (or subdirectory) that was part of that change will be back-rev'd.
After back-rev'ing, "open" the file(s) for editing. Without making changes to the file(s), re-synchronize, then resolve, then re-submit. This sequence accomplishes erasing the change you made. Here are the steps illustrated. Notice that 414335 is 1 less than 414336 above.
p4 sync @414335 p4 edit xxxx.java [yyyy.java etc.] p4 sync p4 resolve -ay p4 submit
There is even a trick to backing out a change made subsequent to which many other changes were made. The trick is to re-synchronize to the change number after backing out that change. Let's assume that the change number to be erased is 1000. The major differences between this operation and the simpler one already described are in bold below:
p4 sync @999 p4 edit xxxx.java [yyyy.java etc.] p4 sync @1000 p4 resolve -ay p4 sync p4 resolve p4 submit
(Yes, it's unclear why one synchronizes to 1000 instead of 1001, but that's what the example says. I'll update once I have to do this case myself.)
There is no p4 status command, but this works for finding untracked files from the current working directory down:
find -type f ! -name '*~' -print0| xargs -0 p4 fstat 2>&1|awk '/no such file/{print $1}'
There is no p4 status command as in cvs, svn and git. However, there are some commands that will show somewhat similar things about your filesystem copy to put you at ease. The responses shown demonstrates there is nothing to worry about.
p4 opened (Show all files opened for editing) p4 diff -sa (Show opened files that are different from the depot, or missing) File(s) not opened on this client. p4 diff -sb (Show files opened for integration that have been resolved, but later modified) File(s) not opened on this client. p4 resolve -n (Show files in need of resolving) No file(s) to resolve.
To find files you've failed to add (p4 add), use this. What comes out is a list of files that aren't tracked by Perforce—there will be many and many that should not.
find . -type f -print0 | xargs -0 p4 fstat > dev/null ./rsync/rsyncd.global.conf.bak - file(s) not in client view.
When you open a file for editing using p4 edit, Perforce tells you who else has that file open via the format <user>@<workspace>. However, you likely will not know who this really is. The following command will dump the first few lines of his Perforce client configuration:
p4 user -o <user>
...where <user> is the first string before '@' in what Perforce echoed back.
You can have as many Perforce clients as you like. Normally your p4 client comes from the P4CLIENT environment variable. Those using multiple clients do the following.
Set P4CONFIG in your .bashrc to something like .p4config.
If you set this environment variable then instead of consulting environment for the Perforce client, user, password and port, Perforce will search your current working directory (and every directory above this) for a file named the same as the value of ${P4CONFIG}. If it finds such a file, it'll read that file for its configuration.
By way of example, to maintain two different clients you create two clients (make sure their root directories are different), then put a .p4config in the root of the client with the content
P4CLIENT=client-name
Create a separate client for every branch you wish to maintain or work with. When you're done with a branch, delete your client. Keep a separate client for shared resources, like modules, templates, dna_binaries, etc.
Daniel Rogers' .p4config files look like:
P4CLIENT=dsrogers-creamy
or
P4CLIENT=dsrogers-environment
Here are some brief notes on additional Perforce topics that might later be integrated into the article above. Most of these are from a session with Ravi (Vanga Palli Ravinder Kumar).
Steps for merging. These are from the Snapfish wiki. This is interactive as you must pick your way through the merge.
Do this to see if a file or files (or all files—no argument) is (are) under Perforce control and what version you have:
p4 have filename]
p4 opened lists the file on which p4 edit has been done.
Removing lines from client spec (p4 client) will result in erasing these from the database. It takes time to do this on the development host—why so many developers don't take time to do it. Ravi has a script for managing branches that solves this problem without spending time.
p4 users. To see details about self, do p4 users | russ.
To see what's been happening to a file use the following command. Adding option -s shortens what's listed dramatically.
p4 filelog [-s] filename
p4 change creates a new one; be sure to record the number for later reference.
Display the differences between two versions of a file. Yields the expected, Unix-style format.
$ p4 diff file.ext{#24,#25}
I don't advise you to integrate Perforce into Eclipse unless you're willing to endure considerable slowness on start-up—about 30 seconds in my case. (What's slow is the required Eclipse Mylyn software.) You don't really need it and can do everything from the command line.
Download the Perforce-Eclipse integration plug-in the usual way: Help
-> Install New Software... -> Add
and name it "Perforce plug-in"
with this URL, which supports Helios (3.6):
http://www.perforce.com/downloads/http/p4-eclipse/install/3.6
Click the associated bits of functionality as desired. Mylyn comes free with Helios and you may find yourself using it down the road. It's a task manager and is required for integration with Rally as well. (So, if it's there, if Rally is using it, maybe the Perforce integration will be useful too. It will not take up memory or anything but diskspace as long as you don't actually use it.)
This isn't greatly difficult. Mostly, be careful not to check the box to copy the sources into the workspace. (I haven't modified code yet, so I'm unsure of all the "read-only" versus "not read-only" states here.)
There are two ways to get projects into Eclipse using Perforce integration. In this case, the projects imported are not read-only, i.e.: the sources are ready for modification.
In this case the project will go to the Perforce workspace and will also be visible in the Eclipse Package Explorer view. The project gets imported into the Eclipse workspace associated with IDE (but it won't get copied there; the project will still reside in the Perforce workspace).
This is an illustration of creating a new file and editing three others in an active code base.
russ@russ-elite-book:~/snapcat/> p4 add 2011/8/javasrc/com/snapfish/be/rest/server/handlers/CLookupByEmailHandler.java //depot/Snapfish/2011/8/javasrc/com/snapfish/be/rest/server/handlers/CLookupByEmailHandler.java#1 - opened for add russ@russ-elite-book:~/snapcat> ll 2011/8/components/snapfish-beapi/be_api*.xsd 2011/8/javasrc/resources/beapiconfig.properties.in -rw------- 1 russ russ 172717 2011-04-20 15:13 2011/8/components/snapfish-beapi/be_api_types.xsd -rw------- 1 russ russ 43220 2011-04-20 15:13 2011/8/components/snapfish-beapi/be_api.xsd -rw------- 1 russ russ 14319 2011-04-18 15:27 2011/8/javasrc/resources/beapiconfig.properties.in russ@russ-elite-book:~/snapcat> p4 edit 2011/8/components/snapfish-beapi/be_api*.xsd 2011/8/javasrc/resources/beapiconfig.properties.in //depot/Snapfish/2011/8/components/snapfish-beapi/be_api_types.xsd#8 - opened for edit ... //depot/Snapfish/2011/8/components/snapfish-beapi/be_api_types.xsd - must sync/resolve #9 before submitting //depot/Snapfish/2011/8/components/snapfish-beapi/be_api.xsd#5 - opened for edit ... //depot/Snapfish/2011/8/components/snapfish-beapi/be_api.xsd - must sync/resolve #6,#7 before submitting ... //depot/Snapfish/2011/8/components/snapfish-beapi/be_api.xsd - also opened by srinivas.manda@smanda_ubuntu //depot/Snapfish/2011/8/javasrc/resources/beapiconfig.properties.in#5 - opened for edit ... //depot/Snapfish/2011/8/javasrc/resources/beapiconfig.properties.in - must sync/resolve #6 before submitting
I must use p4 resolve to combine the contents of the three files I marked for edit because if, for example, Kate Middleton marked be_api.xsd for edit, then added something to it followed by me doing the same thing, committing my copy would wipe her changes out.
What if my copy dates back two weeks and there are yet other changes before Kate's that weren't in mine since mine is so old? Can I simply do p4 resolve be_api.csd and Perforce will not see in my files what's old (and now changed) besides my additions as changes I want to make?
Here are random notes on this fairy-boy tool that I don't use much, but it's really effective at doing visual merges.
See P4V File Icons for the details as to what the icons in this tool mean: it's very important to understand them as they tell you immediately what state a file's in (you've modified it, someone else has already committed modifications since you opened it for edit, etc.).
These notes were offered in response to a question in a forum.
Consider the following:
If you're cloudy on this point, the following comments, though made for Git,
are relevant:
http://www.javahotchocolate.com/tutorials/git-eclipse.html
p4 client
p4 sync
File -> Import -> General
-> Existing Projects into Workspace
Next
When I say command line, note that you can also use p4v if you like. I rarely do, but sometimes I do when I want to explore the rather humongous amount of code there is—only a tiny part of which I actually have to work on.