import re
-import hashlib
+try:
+ import hashlib
+ sha1_hash = hashlib.sha1
+except ImportError:
+ import sha
+ sha1_hash = sha.sha
_hunk_re = re.compile('^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@')
_filename_re = re.compile('^(---|\+\+\+) (\S+)')
lines = str.split('\n')
prefixes = ['-', '+', ' ']
- hash = hashlib.sha1()
+ hash = sha1_hash()
for line in str.split('\n'):
if len(line) <= 0:
continue
- hunk_match = _hunk_re.match(line)
- filename_match = _filename_re.match(line)
+ hunk_match = _hunk_re.match(line)
+ filename_match = _filename_re.match(line)
if filename_match:
# normalise -p1 top-directories
line = filename_match.group(1) + ' ' + filename
- elif hunk_match:
+ elif hunk_match:
# remove line numbers
def fn(x):
if not x: