Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 38 lines (34 sloc) 1.32 KB
#!/usr/bin/python
# only implements --verify
import subprocess
import sys
# sha1_name.c:get_sha1
def get_sha1(name):
if name[-2] == '~': # for ~
name = name[:-2] + '^' * int(name[-1])
if name[-1] == '^': # for ^
sha1 = get_sha1(name[:-1])
contents = subprocess.check_output(['cat-file', 'commit', sha1])
parent = next(line for line in contents.splitlines()
if line.startswith('parent '))
return parent.split(' ')[1]
if '^{' in name: # for ^{type}
name, requested_type = name.rsplit('^{', 1)
assert requested_type[-1] == '}'
requested_type = requested_type[:-1]
while True:
sha1 = get_sha1(name)
actual_type = subprocess.check_output(['cat-file', '-t', sha1]).strip()
if actual_type == requested_type:
return sha1
elif actual_type == 'commit':
contents = subprocess.check_output(['cat-file', 'commit', sha1])
tree = next(line for line in contents.splitlines()
if line.startswith('tree '))
name = tree.split(' ')[1]
else:
raise Exception('wrong type')
else:
return subprocess.check_output(['get-sha1-basic', name]).strip()
_, name = sys.argv
print get_sha1(name)
You can’t perform that action at this time.