git-p4.py: support Python 2.4

Python 2.4 lacks the following features: subprocess.check_call struct.pack_into Take a cue from 460d1026 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 <bcasey@nvidia.com> Acked-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Jan 26, 2013 at 11:14 UTC a235e85cc8bc308a7dbf414f6594a9d309f13289
3 files changed +31 -9
INSTALL
+1 -1
@@ -131,7 +131,7 @@ Issues of note:
131 use English. Under autoconf the configure script will do this
132 automatically if it can't find libintl on the system.
133
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
135 interface to Perforce.
136
137 - Some platform specific issues are dealt with Makefile rules,
git-p4.py
+24 -3
@@ -12,6 +12,21 @@ import optparse, sys, os, marshal, subprocess, shelve
12 import tempfile, getopt, os.path, time, platform
13 import re, shutil
14
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 +
30 verbose = False
31
32 # Only labels/tags matching this will be imported/exported
@@ -152,13 +167,17 @@ def system(cmd):
167 expand = isinstance(cmd,basestring)
168 if verbose:
169 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)
173
174 def p4_system(cmd):
175 """Specifically invoke p4 as the system command. """
176 real_cmd = p4_build_cmd(cmd)
177 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)
181
182 def p4_integrate(src, dest):
183 p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)])
@@ -3104,7 +3123,9 @@ class P4Clone(P4Sync):
3123 init_cmd = [ "git", "init" ]
3124 if self.cloneBare:
3125 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)
3129
3130 if not P4Sync.run(self, depotPaths):
3131 return False
t/t9802-git-p4-filetype.sh
+6 -5
@@ -105,12 +105,13 @@ build_gendouble() {
105 cat >gendouble.py <<-\EOF
106 import sys
107 import struct
108 - import array
108
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)
115 EOF
116 }
117