Skip to content

Commit a235e85

Browse files
drafnelgitster
authored andcommitted
git-p4.py: support Python 2.4
Python 2.4 lacks the following features: subprocess.check_call struct.pack_into Take a cue from 460d102 and provide an implementation of the CalledProcessError exception. Then replace the calls to subproccess.check_call with calls to subprocess.call that check the return status and raise a CalledProcessError exception if necessary. The struct.pack_into in t/9802 can be converted into a single struct.pack call which is available in Python 2.4. Signed-off-by: Brandon Casey <[email protected]> Acked-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 598354c commit a235e85

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ 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.5 or later is needed to use the git-p4
134+
- Python version 2.4 or later is needed to use the git-p4
135135
interface to Perforce.
136136

137137
- Some platform specific issues are dealt with Makefile rules,

git-p4.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
import tempfile, getopt, os.path, time, platform
1313
import re, shutil
1414

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

1732
# Only labels/tags matching this will be imported/exported
@@ -152,13 +167,17 @@ def system(cmd):
152167
expand = isinstance(cmd,basestring)
153168
if verbose:
154169
sys.stderr.write("executing %s\n" % str(cmd))
155-
subprocess.check_call(cmd, shell=expand)
170+
retcode = subprocess.call(cmd, shell=expand)
171+
if retcode:
172+
raise CalledProcessError(retcode, cmd)
156173

157174
def p4_system(cmd):
158175
"""Specifically invoke p4 as the system command. """
159176
real_cmd = p4_build_cmd(cmd)
160177
expand = isinstance(real_cmd, basestring)
161-
subprocess.check_call(real_cmd, shell=expand)
178+
retcode = subprocess.call(real_cmd, shell=expand)
179+
if retcode:
180+
raise CalledProcessError(retcode, real_cmd)
162181

163182
def p4_integrate(src, dest):
164183
p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)])
@@ -3104,7 +3123,9 @@ def run(self, args):
31043123
init_cmd = [ "git", "init" ]
31053124
if self.cloneBare:
31063125
init_cmd.append("--bare")
3107-
subprocess.check_call(init_cmd)
3126+
retcode = subprocess.call(init_cmd)
3127+
if retcode:
3128+
raise CalledProcessError(retcode, init_cmd)
31083129

31093130
if not P4Sync.run(self, depotPaths):
31103131
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)