comparison mercurial/subrepo.py @ 34968:cabc840ffdee stable 4.4.1

stable: merge with security patches
author Augie Fackler <augie@google.com>
date Tue, 07 Nov 2017 11:22:24 -0500
parents 1a314176da9c
children 5c6b96b832c2 3da4bd50103d
comparison
equal deleted inserted replaced
34960:0f5521e56b77 34968:cabc840ffdee
357 if f.lower() == 'hgrc': 357 if f.lower() == 'hgrc':
358 ui.warn(_("warning: removing potentially hostile 'hgrc' " 358 ui.warn(_("warning: removing potentially hostile 'hgrc' "
359 "in '%s'\n") % vfs.join(dirname)) 359 "in '%s'\n") % vfs.join(dirname))
360 vfs.unlink(vfs.reljoin(dirname, f)) 360 vfs.unlink(vfs.reljoin(dirname, f))
361 361
362 def _auditsubrepopath(repo, path):
363 # auditor doesn't check if the path itself is a symlink
364 pathutil.pathauditor(repo.root)(path)
365 if repo.wvfs.islink(path):
366 raise error.Abort(_("subrepo '%s' traverses symbolic link") % path)
367
368 SUBREPO_ALLOWED_DEFAULTS = {
369 'hg': True,
370 'git': False,
371 'svn': False,
372 }
373
374 def _checktype(ui, kind):
375 # subrepos.allowed is a master kill switch. If disabled, subrepos are
376 # disabled period.
377 if not ui.configbool('subrepos', 'allowed', True):
378 raise error.Abort(_('subrepos not enabled'),
379 hint=_("see 'hg help config.subrepos' for details"))
380
381 default = SUBREPO_ALLOWED_DEFAULTS.get(kind, False)
382 if not ui.configbool('subrepos', '%s:allowed' % kind, default):
383 raise error.Abort(_('%s subrepos not allowed') % kind,
384 hint=_("see 'hg help config.subrepos' for details"))
385
386 if kind not in types:
387 raise error.Abort(_('unknown subrepo type %s') % kind)
388
362 def subrepo(ctx, path, allowwdir=False, allowcreate=True): 389 def subrepo(ctx, path, allowwdir=False, allowcreate=True):
363 """return instance of the right subrepo class for subrepo in path""" 390 """return instance of the right subrepo class for subrepo in path"""
364 # subrepo inherently violates our import layering rules 391 # subrepo inherently violates our import layering rules
365 # because it wants to make repo objects from deep inside the stack 392 # because it wants to make repo objects from deep inside the stack
366 # so we manually delay the circular imports to not break 393 # so we manually delay the circular imports to not break
367 # scripts that don't use our demand-loading 394 # scripts that don't use our demand-loading
368 global hg 395 global hg
369 from . import hg as h 396 from . import hg as h
370 hg = h 397 hg = h
371 398
372 pathutil.pathauditor(ctx.repo().root)(path) 399 repo = ctx.repo()
400 _auditsubrepopath(repo, path)
373 state = ctx.substate[path] 401 state = ctx.substate[path]
374 if state[2] not in types: 402 _checktype(repo.ui, state[2])
375 raise error.Abort(_('unknown subrepo type %s') % state[2])
376 if allowwdir: 403 if allowwdir:
377 state = (state[0], ctx.subrev(path), state[2]) 404 state = (state[0], ctx.subrev(path), state[2])
378 return types[state[2]](ctx, path, state[:2], allowcreate) 405 return types[state[2]](ctx, path, state[:2], allowcreate)
379 406
380 def nullsubrepo(ctx, path, pctx): 407 def nullsubrepo(ctx, path, pctx):
385 # scripts that don't use our demand-loading 412 # scripts that don't use our demand-loading
386 global hg 413 global hg
387 from . import hg as h 414 from . import hg as h
388 hg = h 415 hg = h
389 416
390 pathutil.pathauditor(ctx.repo().root)(path) 417 repo = ctx.repo()
418 _auditsubrepopath(repo, path)
391 state = ctx.substate[path] 419 state = ctx.substate[path]
392 if state[2] not in types: 420 _checktype(repo.ui, state[2])
393 raise error.Abort(_('unknown subrepo type %s') % state[2])
394 subrev = '' 421 subrev = ''
395 if state[2] == 'hg': 422 if state[2] == 'hg':
396 subrev = "0" * 40 423 subrev = "0" * 40
397 return types[state[2]](pctx, path, (state[0], subrev), True) 424 return types[state[2]](pctx, path, (state[0], subrev), True)
398 425