Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one run git-p4 in Windows?

It doesn't look like git-p4 is part of the MSys-Git project for Windows. Does anybody know how to get it running through Windows?

like image 358
Michael Brennan Avatar asked Apr 15 '10 14:04

Michael Brennan


People also ask

How to Install git p4?

Installing git p4 If the system complains that git p4 is not installed, download git-p4.py and put it in a folder in your PATH , for example ~/bin (obviously you will need Python to be installed too for it to work). Then run git p4 again and you should get no errors. The tool is installed.

What is git p4?

Generally, git p4 clone is used to create a new Git directory from an existing p4 repository: $ git p4 clone //depot/path/project. This: Creates an empty Git repository in a subdirectory called project.


2 Answers

Update July 2019, the "Git P4 clone broken" question now mentions by Gabriel Morin:

[alias]     p4 = !python.exe 'c:\\program files\\Git\\mingw64\\libexec\\git-core\\git-p4' 

Then using git p4 from the command line worked.


With Git 2.32 (Q2 2021), git p4 learned to find branch points more efficiently.

See commit 6b79818, commit c3ab088 (05 May 2021) by Joachim Kuebart (jkuebart).
(Merged by Junio C Hamano -- gitster -- in commit e289f68, 14 May 2021)

git-p4: speed up search for branch parent

Signed-off-by: Joachim Kuebart
Helped-by: Junio C Hamano
Helped-by: Luke Diamand

For every new branch that git-p4 imports, it needs to find the commit where it branched off its parent branch.
While p4 doesn't record this information explicitly, the first changelist on a branch is usually an identical copy of the parent branch.

The method searchParent() tries to find a commit in the history of the given "parent" branch whose tree exactly matches the initial changelist of the new branch, "target".
The code iterates through the parent commits and compares each of them to this initial changelist using diff-tree.

Since we already know the tree object name we are looking for, spawning diff-tree for each commit is wasteful.

Use the "--format" option of "rev-list" to find out the tree object name of each commit in the history, and find the tree whose name is exactly the same as the tree of the target commit to optimize this.

This results in a considerable speed-up, at least on Windows.
On one Windows machine with a fairly large repository of about 16000 commits in the parent branch, the current code takes over 7 minutes, while the new code only takes just over 10 seconds for the same changelist:

Before:

$ time git p4 sync Importing from/into multiple branches Depot paths: //depot Importing revision 31274 (100.0%) Updated branches: b1  real    7m41.458s user    0m0.000s sys     0m0.077s 

After:

$ time git p4 sync Importing from/into multiple branches Depot paths: //depot Importing revision 31274 (100.0%) Updated branches: b1  real    0m10.235s user    0m0.000s sys     0m0.062s 

Update March 2020

With Git 2.27 (Q2 2020), "git p4" is updated to work with Python 3.

See commit 6bb40ed (23 Jan 2020) by SZEDER Gábor (szeder).
See commit 7575f4f, commit ce425eb, commit 2e2aa8d, commit a6b1306, commit 4294d74, commit 50da1e7, commit 5a5577d, commit d38208a, commit 86dca24, commit 6cec21a, commit 1f8b46d, commit 0b4396f (13 Dec 2019) by Yang Zhao (yangminz).
See commit 484d09c (13 Dec 2019) by Ben Keene (seraphire).
(Merged by Junio C Hamano -- gitster -- in commit 9a0fa17, 25 Mar 2020)

ci: use python3 in linux-gcc and osx-gcc and python2 elsewhere

Signed-off-by: SZEDER Gábor

Python2 reached end of life, and we have been preparing our Python scripts to work with Python3.

'git p4', the main in-tree user of Python, has just received a number of compatibility updates.

This is documented only with Git 2.30 (Q1 2021) in commit 263dc0.


Update July 2018:

Git 2.19 (Q3 2018) will start bringing Python 3 support to git p4.

See commit db2d997, commit f2606b1, commit efdcc99, commit 4d88519, commit dba1c9d, commit fc35c9d (19 Jun 2018) by Luke Diamand (luked99).
(Merged by Junio C Hamano -- gitster -- in commit 6dcd364, 18 Jul 2018)

Code preparation to make "git p4" closer to be usable with Python 3.


Update January 2016:

Since 2010, contrib/fast-import/git-p4.README mentions since April 2012

The git-p4 script moved to the top-level of the git source directory. Note that the top-level git-p4.py script is now the source

Windows users can copy the git-p4.py source script directly, possibly invoking it through a batch file called "git-p4.bat" in the same folder.
It should contain just one line:

@python "%~d0%~p0git-p4.py" %* 

(Although this 2013 article is invoking git-p4.py directly)


Original answer (April 2010)

As mention in "Why Perforce is more scalable than Git", be careful to not import in Git any p4 repo. Git cannot handle the same kind of huge unique repo P4 can manage.

Git-P4 being in Python, it should run on Windows (like in this question)

You can grab git-p4.py here and use this as git-p4.bat

@python "%~d0%~p0git-p4" %* 

It requires a Python 2.x installed.

Don't forget there is another approach as well.

like image 175
VonC Avatar answered Sep 25 '22 17:09

VonC


The simplest answer I found, and seems to work flawlessly so far, was on Timo Geusch's blog:

  • Make sure you have Python 2.X installed, eg in C:\Python27 (dunno if git-p4 supports Python 3, so I didn't risk it git-p4.py does not support Python 3.X, as of March 2014)
  • Get a copy of git-p4.py from anywhere, eg as Eric Lathrop's blog post suggests, from the git repo directly (I got mine from a linux install of git 2.1 that I happened to have already set up)
  • In your MSysGit installation, navigate to libexec\git-core, eg on my Git for Windows 1.9.4-preview20140611 install on windows 7 64-bit that is C:\Program Files (x86)\Git\libexec\git-core
  • Drop your git-p4.py file there
  • At that same location, edit the "git-p4" extensionless file, replacing the dummy echo and exit lines with a single line

    c:/python27/python "c:/program files (x86)/Git/libexec/git-core/git-p4.py" $1 $2 $3 $4 $5 $6 $7 $8 $9

That's it. git-p4 now works on your MSysGit / Git for Windows installation just like it does on any linux box.

(please note, Eric Lathrop's existing answer has a lot of additional information about working with git-p4 and all its limitations; I thought this question could benefit from a simple howto answer to the actual question though, i.e. easily getting it working on Windows, lest more wanderers be discouraged as I was last week)

like image 24
Tao Avatar answered Sep 23 '22 17:09

Tao