Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

migration - Getting the whole files history with git-p4

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 git-p4 (you have to dig a bit more, since it's not even at the repository pointed by the link. The actual git-p4 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

https://github.com/araqnid/p4utils 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...