views:

1692

answers:

2

As I've mentioned in a previous question, I'm looking into migrating our source control from Perforce to git.
Looking around, I've found p4-git (you have to dig a bit more, since it's not even at the repository pointed by the link. The actual p4-git script harder to find).

I'm now running this script, and it imports the current version of the files in a new git repository, but I can't manage to get the history, no matter what I do.

Here's the current command line I use is:

P4CLIENT=my-p4-clientspec git-p4 clone --max-changes=1000 --use-client-spec //p4/path/to/be/imported/...

So, the real question is: if anyone has managed to import a P4 depot, including the history, I'd like to know how you did it.

Thanks!

joce.

A: 

I'm also trying to figure out git-p4. Not much documentation out there, unfortunately. I'd like to get in touch with you as we can probably help each other out.

Hey there Carl. You can reach me at jocelynlegault with gmail.com
Joce
+5  A: 

Try appending "@all" to the file path. For example, this produces a single-revision repo for me:

python /usr/share/doc/git-core/contrib/fast-import/git-p4 clone --destination=master-pom \
    //depot/services/master-pom/trunk/...

This command imported the full history:

python /usr/share/doc/git-core/contrib/fast-import/git-p4 clone --destination=master-pom \
    //depot/services/master-pom/trunk/...@all

I tried using the example git-p4 but gave up for several reasons and wrote my own fast-import pump. It was a while back, so some of the problems may have been fixed now: but git-p4 had trouble with large changelists (such as the initial creation of a branch) (although using the client spec may have helped, I don't think I tried it) and files with the "+S" filetype modifier (which is Bad And Evil, but we used to use it). And my Python-fu wasn't up to letting me fix the issues I had.

EDIT: since someone asked for it, here it is.

http://www.araqnid.plus.com/p4utils.git/ has several p4 things, of which p4-git-xfer is the p4->git (one-way) replicator. It has quite a few issues though, due to being mainly a personal handy-tool rather than a real piece of infrastructure.

Getting started:

p4-git-xfer clone -d $PWD/dictionary.git -n //depot/services/midoffice/dictionary/... \
  trunk 'release/*' 'branch/*' \
  trunk=master release/*=r* branch/*=dev/*

will clone that perforce path to a bare "dictionary.git". The first arguments after the base path are "branch specs" that tell the replicator where to find branches under the base. The later ones (with '=' symbols) are "mirror specs" that tell the replicator how to create local branches from the imported ones. The branch specs cause "refs/remotes/p4/trunk", "refs/remotes/p4/release/1.0" etc. to be created. The mirror specs force "refs/heads/master" to mirror "refs/remotes/p4/trunk", "refs/heads/r1.0" to mirror "refs/remotes/p4/release/1.0" etc. It was intended as a way to allow me to select just particular branches from those that were replicated to get propagated to clones.

It will attempt to detect how a branch is created, but that's a bit of a guess anyway with Perforce. Apart from that, it doesn't try to do any branch tracking at all: even whole-branch merges won't be written out as such, sorry.

After the initial clone, running p4-git-xfer fetch from inside the git replica will do an incremental update. The high-water-mark changelist is taken from marks/p4 within the git repo. This is a marks file that fast-import loads, so if you do any fancy footwork like using filter-branch to rewrite things, beware you may have to update this too.

It's not pretty, and has some medium-to-serious issues; I use it mainly for my own convenience, to isolate myself from Perforce problems, not as a day-to-day criticial infrastructure component. It's one-way: I generally use the p4-am script to apply patches created by git format-patch. That itself only works mostly, with general parsing nastiness, problems with end-of-file newlines, binary changes etc.

araqnid
Is your p4 import script public? If so, would you mind sharing it?
Joce