Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Edit: Making this even clearer as the bounty is about to expire: is there a way of importing history (pulling from different SCM) directly into a specific branch with Mercurial?


I'm currently working in a company using Perforce and am making way for distributed version control with Mercurial. I've had success importing Perforce history using the perfarce (quite a suitable name, I laugh every time I see/say it) however, this only works with a single branch at a time.

Here's how my P4 integration setup works:

  • In perforce, create a "client", which is kind of a description of what you will be constantly updating/checking-out. This can only address one branch at a time (trunk or other).
  • Once you do this, run hg clone p4://<server>/<client_name>
  • Go to .hg/hgrc and put the perforce path line: perforce = p4://<server>/<client_name>
  • Work normally with the code under mercurial, do hg pull perforce to sync up, hg push to export a changelist

What I'd like to be able to do is have a perforce path per branch and have everything work in the same repository. Now, pushing is not a problem, however, if I pull the history from another branch it would end up at the default branch.

I'd like to be able to do something like hg pull perforce-R5 and have it land in mercurial's R5 branch. Even if I have no merging history, it would be sweet enough to be able to preserve the branch's history.

There are also other plugins for CVCSs that let you integrate mercurial, but AFAIK the subversion one has the same problem.

I don't think there is a straight-through way of doing this, but as long as I could automate the process with some hooks and scripts in a single Mercurial machine, that would be good enough.


Edit: To make things a little clearer:

  • Perforce trunk is mapped to Mercurial's default branch
  • Perforce R1 branch should be mapped to Mercurial's release-1 branch (same for R2, R3, etc.)
  • When I tell Mercurial to pull from perforce (i.e. hg pull perforce, where "perforce" is the name of the path pointing to the Perforce client) it should pull the Perforce trunk into Mercurial's default.
  • When I tell Mercurial to pull from perforce-R1 (i.e. hg pull perforce-R1, where "perforce-R1" is the path to the R1 client) it should pull the Perforce R1 branch to Mercurial's "release-1" branch. THIS IS THE PART I'M ASKING ABOUT.
share|improve this question
    
I'm pretty sure I can help with this (being a mercurial obsessive, and having migrated from p4 to hg in the past) but it'd be great if you could add a diagram showing the workflow you're intending to use, just to make things a little clearer. –  Ed Woodcock Jun 25 '12 at 12:53
add comment

1 Answer

up vote 0 down vote accepted

I don't believe that this can be done directly.

One option would be to use the rebase tool to move the appropriate parts of the repository to the other branch after the pull using something like the following steps:

  • Create desired branch, e.g. hg branch release-1
  • Commit new branch: hg commit -m "Created branch"
  • Pull the remote repository to the default mercurial branch: hg pull perforce-R1
  • Rebase the new pull to the desired branch: hg rebase -s <first changeset of perforce-R1> -d release-1
share|improve this answer
    
I think t his answer suffices, however, I'm looking for a way to do it in a more automatic way. –  dukeofgaming Jul 18 '12 at 22:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.