Remove python 2.5'isms
The following python 2.5 features were worked around: * the sha module is used as a fallback when the hashlib module is not available * the 'any' built-in method was replaced with a 'for' loop * a conditional expression was replaced with an 'if' statement * the subprocess.check_call method was replaced by a call to subprocess.Popen followed by a call to subprocess.wait with a check of its return status These changes allow the python infrastructure to be used with python 2.4 which is distributed with RedHat's RHEL 5, for example. t5800 was updated to check for python >= 2.4 to reflect these changes. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Jun 9, 2010 at 19:24 UTC
23b093ee087e99049585487f59e262a0e0662b6e
6 files changed
+39
-13
git-remote-testgit.py
+12
-3
@@ -1,6 +1,12 @@
1
#!/usr/bin/env python
2
3
-import hashlib
3
+# hashlib is only available in python >= 2.5
4
+try:
5
+ import hashlib
6
+ _digest = hashlib.sha1
7
+except ImportError:
8
+ import sha
9
+ _digest = sha.new
10
import sys
11
import os
12
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
@@ -19,7 +25,7 @@ def get_repo(alias, url):
25
repo.get_revs()
26
repo.get_head()
27
22
- hasher = hashlib.sha1()
28
+ hasher = _digest()
29
hasher.update(repo.path)
30
repo.hash = hasher.hexdigest()
31
@@ -133,7 +139,10 @@ def do_export(repo, args):
139
140
path = os.path.join(dirname, 'testgit.marks')
141
print path
136
- print path if os.path.exists(path) else ""
142
+ if os.path.exists(path):
143
+ print path
144
+ else:
145
+ print ""
146
sys.stdout.flush()
147
148
update_local_repo(repo)
git_remote_helpers/git/exporter.py
+3
-1
@@ -48,4 +48,6 @@ class GitExporter(object):
48
49
args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
50
51
- subprocess.check_call(args, stdin=p1.stdout)
51
+ child = subprocess.Popen(args, stdin=p1.stdout)
52
+ if child.wait() != 0:
53
+ raise CalledProcessError
git_remote_helpers/git/importer.py
+3
-1
@@ -35,4 +35,6 @@ class GitImporter(object):
35
if os.path.exists(path):
36
args.append("--import-marks=" + path)
37
38
- subprocess.check_call(args)
38
+ child = subprocess.Popen(args)
39
+ if child.wait() != 0:
40
+ raise CalledProcessError
git_remote_helpers/git/non_local.py
+12
-4
@@ -29,7 +29,9 @@ class NonLocalGit(object):
29
os.makedirs(path)
30
args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
31
32
- subprocess.check_call(args)
32
+ child = subprocess.Popen(args)
33
+ if child.wait() != 0:
34
+ raise CalledProcessError
35
36
return path
37
@@ -43,10 +45,14 @@ class NonLocalGit(object):
45
die("could not find repo at %s", path)
46
47
args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
46
- subprocess.check_call(args)
48
+ child = subprocess.Popen(args)
49
+ if child.wait() != 0:
50
+ raise CalledProcessError
51
52
args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
49
- subprocess.check_call(args)
53
+ child = subprocess.Popen(args)
54
+ if child.wait() != 0:
55
+ raise CalledProcessError
56
57
def push(self, base):
58
"""Pushes from the non-local repo to base.
@@ -58,4 +64,6 @@ class NonLocalGit(object):
64
die("could not find repo at %s", path)
65
66
args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath]
61
- subprocess.check_call(args)
67
+ child = subprocess.Popen(args)
68
+ if child.wait() != 0:
69
+ raise CalledProcessError
git_remote_helpers/git/repo.py
+7
-2
@@ -19,7 +19,10 @@ def is_remote(url):
19
20
prefixes = ["http", "file", "git"]
21
22
- return any(url.startswith(i) for i in prefixes)
22
+ for prefix in prefixes:
23
+ if url.startswith(prefix):
24
+ return True
25
+ return False
26
27
class GitRepo(object):
28
"""Repo object representing a repo.
@@ -50,7 +53,9 @@ class GitRepo(object):
53
path = ".cached_revs"
54
ofile = open(path, "w")
55
53
- subprocess.check_call(args, stdout=ofile)
56
+ child = subprocess.Popen(args, stdout=ofile)
57
+ if child.wait() != 0:
58
+ raise CalledProcessError
59
output = open(path).readlines()
60
self.revmap = dict(sanitize(i) for i in output)
61
if "HEAD" in self.revmap:
t/t5800-remote-helpers.sh
+2
-2
@@ -9,13 +9,13 @@ test_description='Test remote-helper import and export commands'
9
10
if test_have_prereq PYTHON && "$PYTHON_PATH" -c '
11
import sys
12
-if sys.hexversion < 0x02050000:
12
+if sys.hexversion < 0x02040000:
13
sys.exit(1)
14
'
15
then
16
:
17
else
18
- say 'skipping git remote-testgit tests: requires Python 2.5 or newer'
18
+ say 'skipping git remote-testgit tests: requires Python 2.4 or newer'
19
test_done
20
fi
21