From 3d1f111d302627f93be619088c9d214d4755119b Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Mon, 22 Oct 2007 09:48:48 +0200 Subject: [PATCH] hg2git.py: Use git-rev-parse to get SHA1s instead of reading files below refs/ directly This should now also properly support packed refs. Signed-off-by: Rocco Rutte --- hg2git.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hg2git.py b/hg2git.py index aa6ad70..c58b4e7 100755 --- a/hg2git.py +++ b/hg2git.py @@ -6,6 +6,7 @@ from mercurial import repo,hg,cmdutil,util,ui,revlog,node import re import os +import sys # git branch for hg's default 'HEAD' branch cfg_master='master' @@ -80,9 +81,13 @@ def save_cache(filename,cache): def get_git_sha1(name,type='heads'): try: - f=open(os.getenv('GIT_DIR','/dev/null')+'/refs/'+type+'/'+name) - sha1=f.readlines()[0].split('\n')[0] - f.close() - return sha1 + # use git-rev-parse to support packed refs + cmd="GIT_DIR='%s' git-rev-parse --verify refs/%s/%s 2>/dev/null" % (os.getenv('GIT_DIR','/dev/null'),type,name) + p=os.popen(cmd) + l=p.readline() + p.close() + if l == None or len(l) == 0: + return None + return l[0:40] except IOError: return None -- 2.11.4.GIT