From 598354c0ad4198daff279c34a96f42e4d91fb4e6 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sat, 26 Jan 2013 11:14:32 -0800 Subject: git-p4.py: support Python 2.5 Python 2.5 and older do not accept None as the first argument to translate() and complain with: TypeError: expected a character buffer object As suggested by Pete Wyckoff, let's just replace the call to translate() with a regex search which should be more clear and more portable. This allows git-p4 to be used with Python 2.5. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano diff --git a/INSTALL b/INSTALL index 28f34bd..fc723b3 100644 --- a/INSTALL +++ b/INSTALL @@ -131,7 +131,7 @@ Issues of note: use English. Under autoconf the configure script will do this automatically if it can't find libintl on the system. - - Python version 2.6 or later is needed to use the git-p4 + - Python version 2.5 or later is needed to use the git-p4 interface to Perforce. - Some platform specific issues are dealt with Makefile rules, diff --git a/git-p4.py b/git-p4.py index 551aec9..a041b49 100755 --- a/git-p4.py +++ b/git-p4.py @@ -742,7 +742,8 @@ def wildcard_encode(path): return path def wildcard_present(path): - return path.translate(None, "*#@%") != path + m = re.search("[*#@%]", path) + return m is not None class Command: def __init__(self): -- cgit v0.10.2-6-g49f6 From a235e85cc8bc308a7dbf414f6594a9d309f13289 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sat, 26 Jan 2013 11:14:33 -0800 Subject: 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 Acked-by: Pete Wyckoff Signed-off-by: Junio C Hamano diff --git a/INSTALL b/INSTALL index fc723b3..b96e16d 100644 --- a/INSTALL +++ b/INSTALL @@ -131,7 +131,7 @@ Issues of note: use English. Under autoconf the configure script will do this automatically if it can't find libintl on the system. - - Python version 2.5 or later is needed to use the git-p4 + - Python version 2.4 or later is needed to use the git-p4 interface to Perforce. - Some platform specific issues are dealt with Makefile rules, diff --git a/git-p4.py b/git-p4.py index a041b49..0682e61 100755 --- a/git-p4.py +++ b/git-p4.py @@ -12,6 +12,21 @@ import optparse, sys, os, marshal, subprocess, shelve import tempfile, getopt, os.path, time, platform import re, shutil +try: + from subprocess import CalledProcessError +except ImportError: + # from python2.7:subprocess.py + # Exception classes used by this module. + class CalledProcessError(Exception): + """This exception is raised when a process run by check_call() returns + a non-zero exit status. The exit status will be stored in the + returncode attribute.""" + def __init__(self, returncode, cmd): + self.returncode = returncode + self.cmd = cmd + def __str__(self): + return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) + verbose = False # Only labels/tags matching this will be imported/exported @@ -152,13 +167,17 @@ def system(cmd): expand = isinstance(cmd,basestring) if verbose: sys.stderr.write("executing %s\n" % str(cmd)) - subprocess.check_call(cmd, shell=expand) + retcode = subprocess.call(cmd, shell=expand) + if retcode: + raise CalledProcessError(retcode, cmd) def p4_system(cmd): """Specifically invoke p4 as the system command. """ real_cmd = p4_build_cmd(cmd) expand = isinstance(real_cmd, basestring) - subprocess.check_call(real_cmd, shell=expand) + retcode = subprocess.call(real_cmd, shell=expand) + if retcode: + raise CalledProcessError(retcode, real_cmd) def p4_integrate(src, dest): p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)]) @@ -3104,7 +3123,9 @@ class P4Clone(P4Sync): init_cmd = [ "git", "init" ] if self.cloneBare: init_cmd.append("--bare") - subprocess.check_call(init_cmd) + retcode = subprocess.call(init_cmd) + if retcode: + raise CalledProcessError(retcode, init_cmd) if not P4Sync.run(self, depotPaths): return False diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh index 21924df..aae1a3f 100755 --- a/t/t9802-git-p4-filetype.sh +++ b/t/t9802-git-p4-filetype.sh @@ -105,12 +105,13 @@ build_gendouble() { cat >gendouble.py <<-\EOF import sys import struct - import array - s = array.array("c", '\0' * 26) - struct.pack_into(">L", s, 0, 0x00051607) # AppleDouble - struct.pack_into(">L", s, 4, 0x00020000) # version 2 - s.tofile(sys.stdout) + s = struct.pack(">LL18s", + 0x00051607, # AppleDouble + 0x00020000, # version 2 + "" # pad to 26 bytes + ) + sys.stdout.write(s) EOF } -- cgit v0.10.2-6-g49f6 From 2e4f04fae6810161c17bf456124b364ad927c499 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Jan 2013 11:17:59 -0800 Subject: INSTALL: git-p4 does not support Python 3 Signed-off-by: Junio C Hamano diff --git a/INSTALL b/INSTALL index b96e16d..2dc3b61 100644 --- a/INSTALL +++ b/INSTALL @@ -131,8 +131,9 @@ Issues of note: use English. Under autoconf the configure script will do this automatically if it can't find libintl on the system. - - Python version 2.4 or later is needed to use the git-p4 - interface to Perforce. + - Python version 2.4 or later (but not 3.x, which is not + supported by Perforce) is needed to use the git-p4 interface + to Perforce. - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not -- cgit v0.10.2-6-g49f6