GitP4

From Git SCM Wiki
Jump to: navigation, search

Contents

Git P4

Git includes a built-in mechanism to pull code from perforce, and to submit back from git to p4. This page describes how to get started and how to be a developer or tester.

Resources

Downloading p4 binaries

Perforce is a closed-source version control system that is accessed with the p4 executable.

Chances are that you need git-p4 because you want to talk to an existing p4 repository, in which case you already have access to a p4 binary.

You can get p4 and p4d for free, though, for use in limited environments. This is sufficient to run all the git-p4 tests, though.

  1. Go to Perforce downloads
  2. Choose your Platform (e.g. Linux)
  3. Choose your OS (e.g. Linux kernel 2.6 for 64-bit Intel (x64))
  4. Click "Accept and Download" for
    • P4: Command-Line Client
    • P4D: Server
  5. Put these executables somewhere in your path, like $HOME/bin or /usr/local/bin
  6. Make them executable ("chmod +x p4 p4d")

Building the code

The python script, git-p4.py, is in the top-level directory in the git source tree. Building it very simple; the Makefile copies git-p4.py to git-p4 and modifies the "#!" (shebang) line at the top to reference your python path.

If your python is in /usr/bin/python, this will be used automatically. Otherwise, set PYTHON_PATH in your environment on in config.mak to name an explicit python binary, like:

# config.mak
PYTHON_PATH=/usr/bin/python2.7

Installing

Installing git-p4 happens as part of "make install". It copies "git-p4" to your gitexecdir, which by default is $(prefix)/libexec/git-core.

Invoke git-p4 like any other git command, by typing "git p4 ...".

See Installation for information about installing git, and the INSTALL file in the source.

Adding git-p4 to an existing install

If you already have git on your system, perhaps as was installed along with the OS, you don't have to re-install all of git just to get git-p4. First, check if your OS vendor has a package called "git-p4" or similar. If no luck, you can install it by hand from source.

Grab the latest git-p4.py source file:

and put it somewhere in your path, like $HOME/bin or /usr/local/bin, as `git-p4` (no .py extension). Make it executable with "chmod +x git-p4". Now "git p4" commands will find this script.

You might already have the manual page depending on how your OS vendor packaged git. If not, you can download it:

and put it in your MANPATH, such as /usr/local/man/man1, as a file "git-p4.1". This lets the command "git p4 --help" work.

Running tests

All the git-p4 tests start with t/t98*. They are run as part of the entire test suite, but to run just a single one, try this:

unix$ vi git-p4.py
unix$ make git-p4 ; pkill p4d ; (cd t; ./t9809* -d -v -i)

It is easy to forget that you edit git-p4.py, but the tests run git-p4. The command "make git-p4" ensures that git-p4 is up-to-date.

All of the p4 test scripts start p4d as their first test, and shut it down as the last test. If one of the interemdiate tests fail, nothing kills p4d and future test runs will not be able to start p4d. The command "pkill p4d" tries to kill any stray p4d. Do not do this on your production p4d machine.

The parenthesized bit runs test 9809. Its three arguments specify:

  • -d: debug, leave trash directory
  • -v: verbose, echo tests and their output as they are run
  • -i: immediate, quit as soon as a failure is detected.

You can run all the git-p4 tests with:

unix$ make git-p4 ; pkill p4d ; (cd t; make t98*)

Cygwin

Install Cygwin components

Download setup.exe from cygwin.com, if you haven't already. Keep it around as it will come in handy later for adding more packages in the future.

Answer the dialog windows with mostly the defaults:

Choose A Download Source
Install from Internet
Select Root Install Directory
C:\cygwin
Install for All Users
Select Local Package Directory
The default works: C:\Documents and Settings\Your Username\Desktop or you may prefer C:\cygwin\downloads
Select Your Internet Connection
Direct Connection
Choose A Download Site
(pick one of the http ones that sounds close)
Select Packages
git
python
sshd (convenient, not required)
vim (or some editor)

Setup cygwin components

Start Cygwin Terminal with desktop icon, type this

   $ ssh-host-config -y
   $ cygrunsrv -S sshd

Get your ~/.ssh/id_dsa.pub onto windows somehow, using a CIFS share, NFS, putty scp or email, then:

   $ mkdir ~/.ssh
   $ cp //wherever/id_dsa.pub ~/.ssh/authorized_keys
   

Setup your usual dotfiles in $HOME, including .gitconfig.

Install Perforce client

See the section above, using Platform "Windows" and OS "Windows for 32-bit Intel (x86)", probably. It will download "perforce.exe", an installer.

Run "perforce.exe" to install p4 (and p4d). It offers some options.

Select Features
Just the Command-line Client (P4) is required. But go ahead and install the Server (P4D) too, in case you decide to run the unit tests later.
Defaults for everything else
Don't bother to reboot
It just puts p4 in your path, which you won't need under cygwin.

Disable the p4d server process, from bash. You're hopefully talking to an existing p4d server, otherwise you could just be using git everywhere! The unit tests will start their own p4d. Type this to your Cygwin Bash shell:

$ p4 admin stop
$ sc config Perforce start= disabled
$ sc query Perforce

Wrap p4 client so it works in cygwin

P4 looks at the PWD environment variable, which will have a cygwin-style path. This must be converted on every invocation to p4 so that it is a native Windows path.

Put this script into a location that is in your path. Like:

$ cat >/usr/local/bin/p4
#!/bin/bash
export PWD=$(cygpath --windows --absolute .)
exec "/cygdrive/c/Program Files/Perforce/p4" "$@"
<hit ctrl-d>
$ chmod 755 !$

Install git p4

See above for how to download just git-p4.py, if you do not want the whole git source tree.

Another place to get it is from github.

Move git-p4.py to /usr/local/bin/git-p4 (without the .py). Make sure it is executable (chmod 755).

Test it

If you have an existing p4d server, try something like this:

   $ cd
   $ export P4PORT=server:1666
   $ git p4 clone --destination=proj //depot/path/proj
   $ cd proj
   $ git log

Running tests on Cygwin

You can build git and run the full test suite on Cygwin, too. There are a few steps involved.

Install more Cygwin components

It starts by installing some more Cygwin components, using setup.exe.

Rerun the Cygwin setup.exe installer and add the following packages:

  • make
  • gcc-core
  • zlib-devel
  • libiconv

Download git source

$ cd ~/src
$ git clone git://github.com/git/git
$ cd git

Configure and build git

$ cat >config.mak
NO_CURL = YesPlease
NO_ICONV = YesPlease
NO_OPENSSL = YesPlease
NO_TCLTK = YesPlease
NO_GETTEXT = YesPlease

$ make

Run tests

Just like on unix, but much slower

$ make git-p4 && kill $(cat t/trash*/p4d.pid /dev/null); (cd t; make t98*)

or one at a time

$ make git-p4 && kill $(cat t/trash*/p4d.pid /dev/null); (cd t; ./t9800* -d -v -i)

Sometimes kill will hang when trying to kill p4d. This happens to killall (from psmisc package) and pkill (from procps). You can always use the Task Manager GUI to kill off p4d.

Last timings I took were pretty dismal. Running the Windows tests on XP in a KVM guest inside linux. Time to do all the t98*, around git version 1.7.9.

Version User System Wall-clock time
linux 0m18.30s 0m10.34s 3m14.81s
cygwin 15m33.75s 36m25.96s 50m33.57s
msysgit 1m24.92s 1m33.47s 15m08.27s
Personal tools