contrib/hg-ssh
branchstable
changeset 32050 77eaf9539499
parent 28047 863075fd4cd0
child 33891 42bc7f39376b
equal deleted inserted replaced
31760:68f263f52d2e 32050:77eaf9539499
    30 """
    30 """
    31 
    31 
    32 # enable importing on demand to reduce startup time
    32 # enable importing on demand to reduce startup time
    33 from mercurial import demandimport; demandimport.enable()
    33 from mercurial import demandimport; demandimport.enable()
    34 
    34 
    35 from mercurial import dispatch
    35 from mercurial import dispatch, ui as uimod
    36 
    36 
    37 import sys, os, shlex
    37 import sys, os, shlex
    38 
    38 
    39 def main():
    39 def main():
    40     cwd = os.getcwd()
    40     cwd = os.getcwd()
    59     if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
    59     if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
    60         path = cmdargv[2]
    60         path = cmdargv[2]
    61         repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
    61         repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
    62         if repo in allowed_paths:
    62         if repo in allowed_paths:
    63             cmd = ['-R', repo, 'serve', '--stdio']
    63             cmd = ['-R', repo, 'serve', '--stdio']
       
    64             req = dispatch.request(cmd)
    64             if readonly:
    65             if readonly:
    65                 cmd += [
    66                 if not req.ui:
    66                     '--config',
    67                     req.ui = uimod.ui.load()
    67                     'hooks.pretxnopen.hg-ssh=python:__main__.rejectpush',
    68                 req.ui.setconfig('hooks', 'pretxnopen.hg-ssh',
    68                     '--config',
    69                                  'python:__main__.rejectpush', 'hg-ssh')
    69                     'hooks.prepushkey.hg-ssh=python:__main__.rejectpush'
    70                 req.ui.setconfig('hooks', 'prepushkey.hg-ssh',
    70                     ]
    71                                  'python:__main__.rejectpush', 'hg-ssh')
    71             dispatch.dispatch(dispatch.request(cmd))
    72             dispatch.dispatch(req)
    72         else:
    73         else:
    73             sys.stderr.write('Illegal repository "%s"\n' % repo)
    74             sys.stderr.write('Illegal repository "%s"\n' % repo)
    74             sys.exit(255)
    75             sys.exit(255)
    75     else:
    76     else:
    76         sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
    77         sys.stderr.write('Illegal command "%s"\n' % orig_cmd)