I’ve been assigned recently a task to prepare development process for two teams that are working on separate version control systems (GIT and Perforce in my case). One of important parts of this task is to create effective method of syncing codebases between both storages.
Of course we have git-p4 tool, but my requirements are a bit complicated for this tool:
- Only subset of whole GIT repository will be stored in P4
- GIT repository already exists with some history (the same for P4)
so I decided to write small script that will do at least P4 -> GIT sync.
Perforce is a commercial version control system that seems to share some CVS and SVN features. Besides his shortcomings and weaknesses it has very useful feature: automatic merge tracking.
But sometimes you want to know what commits were already merged and what not. The simplest method to obtain such information is to try merge commits separately (so called cherry-picks) and then check merge results reported by “p4 resolve”. It’s very slow and boring method. Can it be automated?
A typical problem: some work must be done outside the office, but remote services needed are restricted only to office IP address (or some of them are behing VPN). If the service is available under single static port it will be pretty easy to tunnel the connection using SSH.
Tunnel: means you can access the service port as it’s available locally. It’s not a proxy (however ssh can act as HTTP proxy if configured).
I’ll show practical example: Perforce server begind VPN must be accessed outside office. First, configure it using ~/.ssh/config (more elegant solution):
Cherry-picking is a technique of porting only selected commits from one branch to another. It’s directly supported in GIT by special command:
git cherry-pick <SHA-COMMIT-ID>
Also SVN has simple merge mode that supports selecting of single commit:
svn merge -c <REV-NO> <URL>
What about Perforce? After checking Perforce documentation for merging I hit the following syntax for selecting subset of changelists to merge:
Status command is very important part of any VCS (Version Control System) local interface. It allows you to check your workspace state and ensure correct commit will be created.
Perforce is a commercial VCS that is similar to CVS (revisions per file) and SVN (global revisions of whole tree). It’s support for status command is very clumsy. Let’s check how we can emulate status with this tool using small script:
echo === extra files not tracked by Perforce ===
find . '!' -type d '!' -executable | p4 -x - have 2>&1 | grep 'not on client' | \
sed '/\/moc_/d;/\.so/d;/\.o /d;/Makefile /d;/\.a /d'
echo === Current changelist ===
p4 changelist -o
As you can see we implemented “ignore” mechanism in above script (by sed filtering). “Extra files not tracked by Perforce” reflects “?”-status from CVS/SVN. “Current changelist” reflects “A,D,U”-statuses from CVS/SVN.
By using such script you can ensure your commit contains all files from your workspace, thus will be buildable on other developers’ machines.