Geeks With Blogs

News
Elton Stoneman (@EltonStoneman) IT Consultant, integration specialist, @Microsoft MVP and @Pluralsight author.

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.

Posted on Friday, April 4, 2008 9:27 AM Perforce | Back to top


Comments on this post: Branching with Perforce

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Elton on Dec 04, 2008 11:39 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Peter on Dec 15, 2008 6:23 PM

# re: Branching with Perforce
Requesting Gravatar...
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
Left by Elton on Dec 16, 2008 4:29 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Brian on Feb 25, 2009 10:25 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Branch creation and timestamps on Mar 17, 2009 5:14 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Marion on May 20, 2009 4:38 PM

# re: Branching with Perforce
Requesting Gravatar...
hi,The Motif of your blog is very good to me, I hope more exchanges with you .
Left by bridesmaid dresses on Jun 11, 2010 4:11 AM

# re: Branching with Perforce
Requesting Gravatar...
I love this site and all the neopets cheats on it !
Left by Neopets Cheats on Aug 02, 2010 9:23 AM

# re: Branching with Perforce
Requesting Gravatar...
I do appreciate this thread. Thanks for putting it up.
Left by lose baby weight on Sep 14, 2010 2:27 AM

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

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

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by firewall security assessment on Nov 02, 2010 4:34 AM

# re: Branching with Perforce
Requesting Gravatar...
I can't able to clearly understand. Can anybody help me...
Left by Chicken Coop Plans on Nov 12, 2010 9:59 AM

# re: Branching with Perforce
Requesting Gravatar...
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"?
Left by mensagens para orkut on Dec 07, 2010 5:39 PM

# re: Branching with Perforce
Requesting Gravatar...
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!
Left by Ford Windshield on Jan 10, 2011 6:57 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by hair restoration for women on Mar 03, 2011 12:24 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by home laser hair removal on Mar 04, 2011 6:34 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by windows registry cleaner on Mar 04, 2011 10:23 AM

# re: Branching with Perforce
Requesting Gravatar...
Want to delete a branch in perforce.any suggestion with syntax?
Left by Vel on Mar 10, 2011 8:57 AM

# re: Branching with Perforce
Requesting Gravatar...
شكرا
موضوع جميل
Left by منتدى عام on Mar 10, 2011 12:19 PM

# re: Branching with Perforce
Requesting Gravatar...
Left by الخرج on Mar 11, 2011 12:32 AM

# re: Branching with Perforce
Requesting Gravatar...
Why the depot won't have an R3 branch populated since you can now see the new master in the P4V view?
Left by business credit on Apr 14, 2011 12:46 AM

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

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Running on May 03, 2011 5:04 PM

# re: Branching with Perforce
Requesting Gravatar...
Simplified structure of perforce make me can understand this topic more easily. Examples you provide add more understanding to me.
Left by online nursing programs on May 12, 2011 7:10 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by patio furniture clearance on Jun 02, 2011 2:35 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by mosquito nets on Jun 03, 2011 9:00 AM

# re: Branching with Perforce
Requesting Gravatar...
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
Left by Indian Escorts London on Jun 04, 2011 11:36 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by injections acide hyaluronique on Jun 09, 2011 12:09 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by car title loan on Jun 14, 2011 8:15 PM

# re: Branching with Perforce
Requesting Gravatar...
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?
Left by cheap rhe color purple tickets on Jun 16, 2011 4:59 AM

# re: Branching with Perforce
Requesting Gravatar...
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
Left by emma on Jun 22, 2011 8:19 AM

# re: Branching with Perforce
Requesting Gravatar...
I found so many interesting stuff in your blog especially its discussion.
Left by Web design Newcastle upon Tyne on Jun 25, 2011 6:18 PM

# re: Branching with Perforce
Requesting Gravatar...
Such a nice post. It gives us many informative things. Dont stop blogging. Keep it up.
Left by cheap motorbike clothing on Jun 26, 2011 9:28 AM

# re: Branching with Perforce
Requesting Gravatar...
Good points in your post, you have a great blog here. Thanks for this information.
Left by home textile inspection on Jun 26, 2011 9:50 AM

# Happy Christmas
Requesting Gravatar...
very nice
Left by elizbith on Jul 13, 2011 10:52 AM

# Mr
Requesting Gravatar...
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.
Left by emergency server support on Jul 15, 2011 5:47 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by catatonic schizophrenia on Jul 22, 2011 1:01 PM

# re: Branching with Perforce
Requesting Gravatar...
This was an helpful post for me.

socialmediamarketing
Left by darrekbreckan on Jul 26, 2011 9:27 AM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by Web Designer Qatar on Aug 11, 2011 8:26 AM

# re: Branching with Perforce
Requesting Gravatar...
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
Left by m20 on Sep 11, 2011 6:17 PM

# re: Branching with Perforce
Requesting Gravatar...
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
Left by florida bass fishing on Oct 08, 2011 7:59 AM

# re: Branching with Perforce
Requesting Gravatar...
yeah.. I think I am going to be just like it.. Thanks much for sharing this great information. pmp dictionary free pmp questions
Left by Edwin on Oct 31, 2011 1:41 AM

# re: Branching with Perforce
Requesting Gravatar...
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!
Left by annuity cash now on Nov 30, 2011 8:11 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by buy annuity payments on Nov 30, 2011 8:15 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by cash for structured settlement on Nov 30, 2011 8:18 PM

# re: Branching with Perforce
Requesting Gravatar...
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.
Left by jogos de carros on Dec 28, 2011 7:09 PM

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

# re: Branching with Perforce
Requesting Gravatar...
Simple yet impressive. Great source of information keep it up.
Left by Lendio on Jan 25, 2012 6:27 AM

# re: Branching with Perforce
Requesting Gravatar...
Most dedicated blog dear.You worked hard.Point are those is fantastic.This coding will help me so much
Left by Zahnarzt düsseldorf pempelfort on Apr 08, 2012 10:09 AM

# re: Branching with Perforce
Requesting Gravatar...
Thanks a lot , it has saved many hours of our work.Hats off
Left by Devesh on Jun 21, 2012 4:19 PM

# re: Branching with Perforce
Requesting Gravatar...
Computer coding is very important subject of this post. The blog is specifically designed for the the computer based information. Thanks for it
Left by kijiji kingston on Sep 27, 2012 2:37 PM

# re: Branching with Perforce
Requesting Gravatar...
improvement. Fine lines also weaknesses are often melted, dryness eliminated, pigmentation lightened, scarred tissues in addition over-crowding lessen.
Left by Lululemon Outlet on Apr 09, 2013 4:17 PM

Your comment:
 (will show your gravatar)


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net | Join free