Skip to content

Commit 97fbc23

Browse files
committed
Merge branch 'bc/git-p4-for-python-2.4'
With small updates to remove dependency on newer features of Python, keep git-p4 usable with older Python. * bc/git-p4-for-python-2.4: INSTALL: git-p4 does not support Python 3 git-p4.py: support Python 2.4 git-p4.py: support Python 2.5
2 parents a14daf8 + 2e4f04f commit 97fbc23

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

INSTALL

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ Issues of note:
131131
use English. Under autoconf the configure script will do this
132132
automatically if it can't find libintl on the system.
133133

134-
- Python version 2.6 or later is needed to use the git-p4
135-
interface to Perforce.
134+
- Python version 2.4 or later (but not 3.x, which is not
135+
supported by Perforce) is needed to use the git-p4 interface
136+
to Perforce.
136137

137138
- Some platform specific issues are dealt with Makefile rules,
138139
but depending on your specific installation, you may not

git-p4.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
import tempfile, getopt, os.path, time, platform
1919
import re, shutil
2020

21+
try:
22+
from subprocess import CalledProcessError
23+
except ImportError:
24+
# from python2.7:subprocess.py
25+
# Exception classes used by this module.
26+
class CalledProcessError(Exception):
27+
"""This exception is raised when a process run by check_call() returns
28+
a non-zero exit status. The exit status will be stored in the
29+
returncode attribute."""
30+
def __init__(self, returncode, cmd):
31+
self.returncode = returncode
32+
self.cmd = cmd
33+
def __str__(self):
34+
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
35+
2136
verbose = False
2237

2338
# Only labels/tags matching this will be imported/exported
@@ -158,13 +173,17 @@ def system(cmd):
158173
expand = isinstance(cmd,basestring)
159174
if verbose:
160175
sys.stderr.write("executing %s\n" % str(cmd))
161-
subprocess.check_call(cmd, shell=expand)
176+
retcode = subprocess.call(cmd, shell=expand)
177+
if retcode:
178+
raise CalledProcessError(retcode, cmd)
162179

163180
def p4_system(cmd):
164181
"""Specifically invoke p4 as the system command. """
165182
real_cmd = p4_build_cmd(cmd)
166183
expand = isinstance(real_cmd, basestring)
167-
subprocess.check_call(real_cmd, shell=expand)
184+
retcode = subprocess.call(real_cmd, shell=expand)
185+
if retcode:
186+
raise CalledProcessError(retcode, real_cmd)
168187

169188
def p4_integrate(src, dest):
170189
p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)])
@@ -768,7 +787,8 @@ def wildcard_encode(path):
768787
return path
769788

770789
def wildcard_present(path):
771-
return path.translate(None, "*#@%") != path
790+
m = re.search("[*#@%]", path)
791+
return m is not None
772792

773793
class Command:
774794
def __init__(self):
@@ -3173,7 +3193,9 @@ def run(self, args):
31733193
init_cmd = [ "git", "init" ]
31743194
if self.cloneBare:
31753195
init_cmd.append("--bare")
3176-
subprocess.check_call(init_cmd)
3196+
retcode = subprocess.call(init_cmd)
3197+
if retcode:
3198+
raise CalledProcessError(retcode, init_cmd)
31773199

31783200
if not P4Sync.run(self, depotPaths):
31793201
return False

t/t9802-git-p4-filetype.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ build_gendouble() {
105105
cat >gendouble.py <<-\EOF
106106
import sys
107107
import struct
108-
import array
109108
110-
s = array.array("c", '\0' * 26)
111-
struct.pack_into(">L", s, 0, 0x00051607) # AppleDouble
112-
struct.pack_into(">L", s, 4, 0x00020000) # version 2
113-
s.tofile(sys.stdout)
109+
s = struct.pack(">LL18s",
110+
0x00051607, # AppleDouble
111+
0x00020000, # version 2
112+
"" # pad to 26 bytes
113+
)
114+
sys.stdout.write(s)
114115
EOF
115116
}
116117

0 commit comments

Comments
 (0)