[p4] Branch Names

Weintraub, David david.weintraub at bofasecurities.com
Thu Oct 26 10:24:40 PDT 2006


In ClearCase, a branch instance is saved as an OID, and the branch name
simply points to it. This allows you to actually rename the branch
instance since the new name points to the same OID, and thus all
branches would be instantly renamed. It's very much like the inode file
system used in Unix.

Perforce is really a lot more tricky. First of all, branches in Perforce
are really just directories with an integration record attached to it.
Second of all, directories themselves are just part of the file name and
not objects in Perforce. Files in Perforce are keyed to their file name.
To Perforce, //Foo/MAIN/myfile.cpp and //Foo/REL_1.0/myfile.cpp are two
distinct files. If you did this:

   $ p4 integrate //Foo/MAIN/myfile.cpp //Foo/REL_1.0/myfile.cpp

Then, Perforce would know there's a relationship between these two files
for merging purposes. Perforce also institutes a lazy copy scheme so in
your physical depot, //Foo/REL_1.0/myfile.cpp isn't created until it
actually differs from //Foo/MAIN/myfile.cpp. Still, if you look in the
physical depot, you'll see these two files are stored as separate RCS
files.

To "rename" a branch, you "branch" all files from the old branch to the
new branch, then delete all of the files located on the old branch. If
you look in the depot history, you'll still see references to the old
branch, and if you sync to the older revision, you get the old branch
name back. In ClearCase, the branch name itself would have been changed
even in older revisions.

You could recreate a new branch with the old, name, but if you create a
"new file" with the same name as a file in the same directory as the old
branch, you'll simply be creating a new revision of that file:

 [1]$ p4 add //Foo/OLD_NAME/bar.cpp
 [2]$ p4 submit
 [3]$ p4 integrate //Foo/OLD_NAME/... //Foo/NEW_NAME/...
 [4]$ p4 delete //Foo/OLD_NAME/...
 [5]$ p4 submit
 [6]$ p4 add //Foo/OLD_NAME/bar.cpp

In the above example, in line #1 creates a file called "bar.cpp" in the
branch "OLD_NAME". In steps 3 to 5, I rename my branch OLD_NAME to
NEW_NAME. In line #6, I am not creating a new file called "bar.cpp", but
a new revision of the old "bar.cpp" that use to be in //Foo/OLD_NAME.

Also, a "branch specification" (created by the "p4 branch" command) is
NOT a branch. It merely is an OPTIONAL guide that can be used when you
create a branch or do a merge between two branches. Most of the time, we
don't create a branch spec until we have to. Creating 100 branch
specifications does not create 100 different branches, just 100 guides
that can be used when you do "p4 integrate". You can have branches
without a branch specification, a branch specification without a branch,
and even a branch that completely ignores what the branch specification
says.

I would not recommend having a general policy where branches are renamed
on a regular basis. For example, you rename branches with an "_OLD"
suffix when they are obsolete. Or, you have a policy where you develop
on a DEV branch, rename that branch to DEV_OLD, and then create a new
DEV branch.

Remember that ClearCase isn't Perforce and Perforce isn't ClearCase. It
isn't that one is necessarily better than the other. They are different.
You shouldn't try to impose the type of development model used for
ClearCase upon Perforce, nor should you impose the development model
you'd use for Perforce onto ClearCase.

You should get Laura Wingerd's book, "Practical Perforce". You should
also look through the various technotes
<http://perforce.com/perforce/technical.html#technicalnotes> located on
Perforce's website. I was a ClearCase administrator for almost 15 years,
and the way development takes place in ClearCase is completely different
from the way development takes place in Perforce. If you are use to
development in ClearCase, it may take you quite a while to switch your
view on how development should take place. This is especially true if
you've never used another version control system except for ClearCase.

-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Vineet
Venugopal
Sent: Thursday, October 26, 2006 10:44 AM
To: perforce-user at perforce.com
Subject: [p4] Branch Names

Hi ,
 
A simple question 
 
1. Can the perforce - rename strategy as mentioned in the cmd ref guide
be used to rename a branch from say oldbranch to newbranch?
 
2. Also once the branch is renamed to newbranch can I recreate oldbranch
using a totally different branch spec?
 
Coming from a clearcase background , I was able to do these operations
easily, so if these are operations that are shunned by the perforce
world , please let me know.
 
Thanks
vineet
_______________________________________________
perforce-user mailing list  -  perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user


More information about the perforce-user mailing list