Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3607 Comments | 0 Trackbacks

News

Archives

Post Categories


My preferred structure is for each project to have a root in the depot, then each branch to have a root within the project. So as the codebase matures you end up with:

\\depot
    \ProjectX
       \MAIN
          \source
       \R1
          \source
        \R2
          \source

    \ProjectY
       \MAIN
          \source
etc.

Nothing revolutionary there, but it gives some context for the examples.

Branching the Codeline

There are  four steps to creating and populating a branch from the main codeline:
  1. Create a branch view
  2. Create a master workspace (client view) for the branch
  3. Flag files to be branched (integrated in Perforce terminology)
  4. Submit the change list from 3) to the depot
(there are other approaches but this is straightforward and recommended. See Practical Perforce - Google Book Search
 and Perforce Branching for more details).

Walkthrough

I'll follow this through with the example that ProjectX has just been released to version 3.0. The build applied a label of 3.0.4.86 to the code which has gone into release, and work has been checked into the main branch since, so we want to create a new R3 branch and populate it from the MAIN branch at label 3.0.4.86.

The example will use the command line tool p4.exe, so when we look at automating this in a script the commands will be familiar. Note that in Perforce most command lines take a small number of arguments, then launch a text editor with a pre-populated specification form. After editing and saving the form, the command will complete.

1. Create the branch view
   
We start by creating a branch with a view that links it back to the main codeline. Following best practice guidelines, the branch name reflects the project and the views it links: ProjectX_MAIN-R3. Creating it is as simple as issuing:

    p4 branch ProjectX_MAIN-R3

- and setting the view in the specification form to map the existing MAIN branch to the new R3 branch:

//depot/ProjectX/MAIN/... //depot/ProjectX/R3/...


This creates the branch view which you will see listed in the Branches tab of P4V, but the new branch is not yet in the depot.

2. Create the master workspace

We'll create a workspace for the branch which will be the master - by integrating the R3 master workspace with the main branch, we'll populate the depot with the desired source. Using the p4 client command, we'll create the workspace ProjectX_R3-MASTER:

    p4 client ProjectX_R3-MASTER

- and in the specifcation form, set the view to map the R3 master to the R3 branch:

//depot/ProjectX/R3/... //ProjectX_R3-MASTER/...


You should now see the new master in the P4V Workspaces view, but the depot won't have an R3 branch populated yet.

3. Flag files to be branched

Using p4 integrate, we create a changelist which will populate the R3 master from MAIN, via the R3 branch:

p4 -cProjectX_R3-MASTER integrate -b ProjectX_MAIN-R3 @3.0.4.86

There is no specification form for this command. Note that we tell P4 to use the R3 master workspace with the -c global option before issuing integrate. This will flag all the files from the R3 branch with the 3.0.4.86 label in the R3 master's default changelist as new additions. To populate the branch in the depot we just need to submit the changelist.

4. Submit the change list

p4 -cProjectX_R3-MASTER submit

The specification form here shows you all the files that will be added and requires you to give the changelist a description - you must change it from the default <enter description here>.

Assuming there were no errors, we'll now have the populated R3 branch under ProjectX, without the changes made in MAIN after the 3.0.4.86 build. You may well have errors as the views you enter in the spec forms are not validated against what's in the depot. This is a brittle operation which is likely to be needed repeatedly, so in the next post we look at scripting the whole branch creation.

Developing Against Branches

You can create your dev workspaces with a view over the whole project (e.g. \\depot\\ProjectX\... \\a.developer\ProjectX\...), so when the new branch is added it will be automatically brought into the developers' workspaces when they Get Latest.

I'd prefer to set workspaces up to a specific branch (\\depot\\ProjectX\MAIN\... \\a.developer\ProjectX\MAIN\...). This means you only have people working in the branch they need. When a new branch is made the people who need to work on it can edit their workspace to add the new view (\\depot\\ProjectX\R3\... \\a.developer\ProjectX\R3\...). The main dev team continue as they are and don't end up having to synchronize to branches they never use.

Alternatively, you can set up a workspace for each branch you work on, so developers would have a main workspace and a Release 1 workspace. The new dev workspace can be created using the branch master as a template. I'm disinclined to use this as there's a greater admin/maintenance/licensing overheead, with no benefits above the single-workspace-multiple-views approach.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Friday, April 04, 2008 9:27 AM

Feedback

# re: Branching with Perforce 12/4/2008 11:39 AM Elton
Agreed, it is a bit involved... I have another post where I've scripted the process here:

http://geekswithblogs.net/EltonStoneman/archive/2008/04/04/scripting-branch-creation-in-perforce.aspx

- which gives you a batch file to do the whole thing. That makes it easier, but it would be nice if it was easy in P4 in the first place.

# re: Branching with Perforce 12/15/2008 6:23 PM Peter
A lot of people use perforce because they've joined an existing project and don't really know all the ins and outs of it. Then we're expected to do something like make a branch. While the concept is pretty obvious, the steps are not.

It would be nice to see an example of a project that was set up without branching in mind then introduce branching later. I think a lot of people start to use Perforce this way and then find they need more structure to handle releases and such. Planning ahead is nice and all, but some of us don't read the manuals right away because they don't make sense without first using the product or they are poorly written.

# re: Branching with Perforce 12/16/2008 4:29 PM Elton
The branching process is quite cumbersome - you can do it retrospectively though, as long as you are labelling your project.

If you have a Continuous Integration process applying labels, or if you manually label the whole project at key points then you don't need to create branches as you go, you can create a branch for any previous state by branching from the label.

A sample of that is in the batch file I use for scripting branch creation, here: http://geekswithblogs.net/EltonStoneman/archive/2008/04/04/scripting-branch-creation-in-perforce.aspx


# re: Branching with Perforce 2/25/2009 10:25 PM Brian
I used Perforce over a year ago. I am interested in looking into it again; however, one year prior to that Perforce stated that they would make a Gui that would assist with branching so the path names wouldn't have to be typed like you did above. Did they ever implement this?

In today's world I think it would be a great idea to have drag and drop capabilities to merge and branch.

# re: Branching with Perforce 3/17/2009 5:14 AM Branch creation and timestamps
When you create a branch in perforce from one of the existing branches, it updates the timestamp of files and also resets the version to start with 1. We use the file timestamp to decide whether the sql file should be executed or not. If we create a branch and because the file timestamp gets updated the files are executed again on the database. Is there a way to tell perforce to not update the timestamp or not restart the versioning.

Any help will be greatly appreciated!

Regards,
Ram.

# re: Branching with Perforce 5/20/2009 4:38 PM Marion
Personally, I believe tools should evolve by natural selection. The most efficient solution is to select a different tool. For example, SVN with Tortoise makes branching child's play.

However, sometimes you don't get to choose the tool which is my case, so I do appreciate this thread. Thanks for putting it up.

My rant about software configuration management tools is that I've been using them successfully for 20 years. I'm afraid there's not much new to invent here (except perhaps under the hood). Why does every tool define its own separate and conflicting terminology? since when is check in not the opposite of check out. Since when does integrate mean branch? I thought they were opposites.

# re: Branching with Perforce 6/11/2010 4:11 AM bridesmaid dresses
hi,The Motif of your blog is very good to me, I hope more exchanges with you .

# re: Branching with Perforce 8/2/2010 9:23 AM Neopets Cheats
I love this site and all the neopets cheats on it !

# re: Branching with Perforce 9/14/2010 2:27 AM lose baby weight
I do appreciate this thread. Thanks for putting it up.

# re: Branching with Perforce 10/11/2010 1:15 PM chicago web design
Interesting. I never thought that perforce has limited capabilities in terms of branching. But then again, you proven me wrong :)

# re: Branching with Perforce 10/23/2010 8:38 AM scrapbook pages
This web page gives an introduction to Perforce branching mechanisms and explains some aspects that may not be obvious at first sight.Thanks.

# re: Branching with Perforce 11/2/2010 4:34 AM firewall security assessment
Perforce uses inter-file branching (branching in pathspace) and the standard branching model is to branch ahead of time and branch all the files we need.

# re: Branching with Perforce 11/12/2010 9:59 AM Chicken Coop Plans
I can't able to clearly understand. Can anybody help me...

# re: Branching with Perforce 12/7/2010 5:39 PM mensagens para orkut
When you create a branch in perforce from one of the existing branches, it updates the timestamp of files and also resets the version it seems to me that keeping the "branch" object in Perforce may ... By "branch object", I assume you mean "branch specification"?

# re: Branching with Perforce 1/10/2011 6:57 PM Ford Windshield
His pleasure in understanding their blog.The above items is quite extraordinary, and I really enjoyed reading your blog and the points that you have expressed. I like it to appear again on a typical, after much more within the topic.Thanks to share ... keep writing!

# re: Branching with Perforce 3/3/2011 12:24 PM hair restoration for women
I am pretty much amazed of the article content. I learned a lot from the interesting topics that are being discussed. It’s my pleasure to visit and learned things and facts of this page. I will be visiting this site more often for I am very intrigue with the topic that indeed catches my interest.


# re: Branching with Perforce 3/4/2011 6:34 AM home laser hair removal
Participe! Seus comentários poderão ser importantes para outros participantes interessados no mesmo tema. Todos os comentários serão bem-vindos, mas reservamo-nos o direito de excluir eventuais mensagens com linguagem inadequada ou ofensiva, bem como conteúdo meramente comercial.


# re: Branching with Perforce 3/4/2011 10:23 AM windows registry cleaner
I must say that overall I am really impressed with this blog.It is easy to see that you are impassioned about your writing. I wish I had got your ability to write. I look forward to more updates and will be returning. Well done.

# re: Branching with Perforce 3/10/2011 8:57 AM Vel
Want to delete a branch in perforce.any suggestion with syntax?


# re: Branching with Perforce 3/10/2011 12:19 PM منتدى عام
شكرا
موضوع جميل

# re: Branching with Perforce 3/11/2011 12:32 AM الخرج
i liked :)
منتدى الخرج</p>
منتديات الخرج</p>

good

# re: Branching with Perforce 4/14/2011 12:46 AM business credit
Why the depot won't have an R3 branch populated since you can now see the new master in the P4V view?

# re: Branching with Perforce 4/14/2011 12:50 AM send flowers uk
I think many of users begins to work on Perforces because they find they need complete structures to take those releases.

# re: Branching with Perforce 5/3/2011 5:04 PM Running
Pleasant posts. I have just found the desired information in your blog and wish to say that I am really enjoying reading your blog posts.

# re: Branching with Perforce 5/12/2011 7:10 AM online nursing programs
Simplified structure of perforce make me can understand this topic more easily. Examples you provide add more understanding to me.

# re: Branching with Perforce 6/2/2011 2:35 AM patio furniture clearance
I'm a blog enthusiast and with so many blogs on the internet now, very few stand out. This blog caught my attention and I thought that I would post to let you know that.

# re: Branching with Perforce 6/3/2011 9:00 AM mosquito nets
I just discovered your website on yahoo pellet stove and see that you’ve obtained some wonderful thoughts in this post. I particularly appreciate the way you’ve been capable to stick so really much believed you blog into a relatively short submit (comparitively) which creates it an thoughtful post on your subject.

# re: Branching with Perforce 6/4/2011 11:36 PM Indian Escorts London
This is a good post and with this “worldwide web” it will reach all corners of earth in seconds, technological advancements are making this world a much smaller place and being a small entertainment group that travels worldwide at short notice, yes its surely becoming a smaller place... :-)
If you are ever in London, please call us for London Escorts

# re: Branching with Perforce 6/9/2011 12:09 PM injections acide hyaluronique
Comfortably, the post is really the sweetest topic on this related issue. I harmonize with your conclusions and will thirstily look forward to your approaching updates. Saying thanks will not just be enough, for the tremendous lucidity in your writing.

# re: Branching with Perforce 6/14/2011 8:15 PM car title loan
Thank you for the sensible critique. Me and my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such great information being shared freely out there.

# re: Branching with Perforce 6/16/2011 4:59 AM cheap rhe color purple tickets
Thanks for pleasing the time to split this, I feel powerfully about it and love analysis more on this topic. If promising, as you gain expertise, would you mind updating your blog with more information?

# re: Branching with Perforce 6/22/2011 8:19 AM emma
Thanks so very much for taking your time to create this very useful and informative site.I have learned a lot from your site.Thanks guys
how to get rid of dark circles under my eyes naturally and fast
how to get rid of dandruff naturally

# re: Branching with Perforce 6/25/2011 6:18 PM Web design Newcastle upon Tyne
I found so many interesting stuff in your blog especially its discussion.

# re: Branching with Perforce 6/26/2011 9:28 AM cheap motorbike clothing
Such a nice post. It gives us many informative things. Dont stop blogging. Keep it up.


# re: Branching with Perforce 6/26/2011 9:50 AM home textile inspection
Good points in your post, you have a great blog here. Thanks for this information.

# Happy Christmas 7/13/2011 10:52 AM elizbith
very nice

# Mr 7/15/2011 5:47 PM emergency server support
Pretty very good submit. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you submit again soon.

# re: Branching with Perforce 7/22/2011 1:01 PM catatonic schizophrenia
I am pretty much amazed of the article content. I learned a lot from the interesting topics that are being discussed. It’s my pleasure to visit and learned things and facts of this page. I will be visiting this site more often for I am very intrigue with the topic that indeed catches my interest.

# re: Branching with Perforce 7/26/2011 9:27 AM darrekbreckan
This was an helpful post for me.

socialmediamarketing

# re: Branching with Perforce 8/11/2011 8:26 AM Web Designer Qatar
I am very much pleased with the contents you have mentioned.I wanted to thank you for this great article. I enjoyed every little bit part of it and I will be waiting for the new updates.Thanks.

# re: Branching with Perforce 9/11/2011 6:17 PM m20
You are awesome! This blog is so great. I really hope more people read this and get what you’re saying, because let me tell you, its important stuff. I never would’ve thought about it this way unless Id run into your blog. Thanks for putting it up. I hope you have great success.dating

# re: Branching with Perforce 10/8/2011 7:59 AM florida bass fishing
Impressive stuff here. The information and the aspect were just wonderful. I think that your viewpoint is deep, it’s just well thought out and truly incredible to see someone who knows how to put these thoughts so well. Good job!florida bass fishing

# re: Branching with Perforce 10/31/2011 1:41 AM Edwin
yeah.. I think I am going to be just like it.. Thanks much for sharing this great information. pmp dictionary free pmp questions

# re: Branching with Perforce 11/30/2011 8:11 PM annuity cash now
This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!

# re: Branching with Perforce 11/30/2011 8:15 PM buy annuity payments
Thanks for the FANTASTIC post! This information is really good and thanks a lot for sharing it. I’m looking forward desperately for the next post of yours.

# re: Branching with Perforce 11/30/2011 8:18 PM cash for structured settlement
Reading is my passion. Browsing through your site gives me a lot of knowledge in so many ways. Thank you for the efforts you made in writing and sharing your points of view. Looking forward to learn some more from you. Keep it up.

# re: Branching with Perforce 12/28/2011 7:09 PM jogos de carros
ve generate a branch (called initialbranch) from there which contains a.txt. I make lots of changes to a.txt, & am happy with it. However, it is not yet prepared for submitting back to mainline. I can basically integrate any changes to a.txt that occur in mainline.

# re: Branching with Perforce 12/28/2011 7:11 PM jogos online
That way, when you integrate using the "secondbranch" branch spec, your changes in secondbranch will get pushed to initialbranch or mainline.

# re: Branching with Perforce 1/25/2012 6:27 AM Lendio
Simple yet impressive. Great source of information keep it up.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: