remote-helpers: add extra safety checks

Suggested-by: Roman Ovchinnikov <coolthecold@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Felipe Contreras 2013-12-07 07:09:41 -06:00 committed by Junio C Hamano
parent 257ec841b8
commit 0c0ebc1fdf
2 changed files with 20 additions and 8 deletions

View File

@ -883,6 +883,16 @@ def main(args):
global branches, peers global branches, peers
global transports global transports
marks = None
is_tmp = False
gitdir = os.environ.get('GIT_DIR', None)
if len(args) < 3:
die('Not enough arguments.')
if not gitdir:
die('GIT_DIR not set')
alias = args[1] alias = args[1]
url = args[2] url = args[2]
@ -891,7 +901,6 @@ def main(args):
blob_marks = {} blob_marks = {}
parsed_refs = {} parsed_refs = {}
files_cache = {} files_cache = {}
marks = None
branches = {} branches = {}
peers = {} peers = {}
transports = [] transports = []
@ -899,11 +908,8 @@ def main(args):
if alias[5:] == url: if alias[5:] == url:
is_tmp = True is_tmp = True
alias = hashlib.sha1(alias).hexdigest() alias = hashlib.sha1(alias).hexdigest()
else:
is_tmp = False
prefix = 'refs/bzr/%s' % alias prefix = 'refs/bzr/%s' % alias
gitdir = os.environ['GIT_DIR']
dirname = os.path.join(gitdir, 'bzr', alias) dirname = os.path.join(gitdir, 'bzr', alias)
if not is_tmp: if not is_tmp:

View File

@ -1164,6 +1164,16 @@ def main(args):
global dry_run global dry_run
global notes, alias global notes, alias
marks = None
is_tmp = False
gitdir = os.environ.get('GIT_DIR', None)
if len(args) < 3:
die('Not enough arguments.')
if not gitdir:
die('GIT_DIR not set')
alias = args[1] alias = args[1]
url = args[2] url = args[2]
peer = None peer = None
@ -1184,16 +1194,12 @@ def main(args):
if alias[4:] == url: if alias[4:] == url:
is_tmp = True is_tmp = True
alias = hashlib.sha1(alias).hexdigest() alias = hashlib.sha1(alias).hexdigest()
else:
is_tmp = False
gitdir = os.environ['GIT_DIR']
dirname = os.path.join(gitdir, 'hg', alias) dirname = os.path.join(gitdir, 'hg', alias)
branches = {} branches = {}
bmarks = {} bmarks = {}
blob_marks = {} blob_marks = {}
parsed_refs = {} parsed_refs = {}
marks = None
parsed_tags = {} parsed_tags = {}
filenodes = {} filenodes = {}
fake_bmark = None fake_bmark = None