Skip to content

Commit 23b093e

Browse files
drafnelgitster
authored andcommitted
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>
1 parent ae45732 commit 23b093e

File tree

6 files changed

+39
-13
lines changed

6 files changed

+39
-13
lines changed

git-remote-testgit.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env python
22

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
410
import sys
511
import os
612
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
@@ -19,7 +25,7 @@ def get_repo(alias, url):
1925
repo.get_revs()
2026
repo.get_head()
2127

22-
hasher = hashlib.sha1()
28+
hasher = _digest()
2329
hasher.update(repo.path)
2430
repo.hash = hasher.hexdigest()
2531

@@ -133,7 +139,10 @@ def do_export(repo, args):
133139

134140
path = os.path.join(dirname, 'testgit.marks')
135141
print path
136-
print path if os.path.exists(path) else ""
142+
if os.path.exists(path):
143+
print path
144+
else:
145+
print ""
137146
sys.stdout.flush()
138147

139148
update_local_repo(repo)

git_remote_helpers/git/exporter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ def export_repo(self, base):
4848

4949
args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
5050

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ def do_import(self, base):
3535
if os.path.exists(path):
3636
args.append("--import-marks=" + path)
3737

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def clone(self, base):
2929
os.makedirs(path)
3030
args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
3131

32-
subprocess.check_call(args)
32+
child = subprocess.Popen(args)
33+
if child.wait() != 0:
34+
raise CalledProcessError
3335

3436
return path
3537

@@ -43,10 +45,14 @@ def update(self, base):
4345
die("could not find repo at %s", path)
4446

4547
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
4751

4852
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
5056

5157
def push(self, base):
5258
"""Pushes from the non-local repo to base.
@@ -58,4 +64,6 @@ def push(self, base):
5864
die("could not find repo at %s", path)
5965

6066
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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def is_remote(url):
1919

2020
prefixes = ["http", "file", "git"]
2121

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
2326

2427
class GitRepo(object):
2528
"""Repo object representing a repo.
@@ -50,7 +53,9 @@ def get_revs(self):
5053
path = ".cached_revs"
5154
ofile = open(path, "w")
5255

53-
subprocess.check_call(args, stdout=ofile)
56+
child = subprocess.Popen(args, stdout=ofile)
57+
if child.wait() != 0:
58+
raise CalledProcessError
5459
output = open(path).readlines()
5560
self.revmap = dict(sanitize(i) for i in output)
5661
if "HEAD" in self.revmap:

t/t5800-remote-helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ test_description='Test remote-helper import and export commands'
99

1010
if test_have_prereq PYTHON && "$PYTHON_PATH" -c '
1111
import sys
12-
if sys.hexversion < 0x02050000:
12+
if sys.hexversion < 0x02040000:
1313
sys.exit(1)
1414
'
1515
then
1616
:
1717
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'
1919
test_done
2020
fi
2121

0 commit comments

Comments
 (0)