##// END OF EJS Templates
copies: move from a copy on branchpoint to a copy on write approach...
copies: move from a copy on branchpoint to a copy on write approach Before this changes, any branch points results in a copy of the dictionary containing the copy information. This can be very costly for branchy history with few rename information. Instead, we take a "copy on write" approach. Copying the input data only when we are about to update them. In practice we where already doing the copying in half of these case (because `_chain` makes a copy), so we don't add a significant cost here even in the linear case. However the speed up in branchy case is very significant. Here are some timing on the pypy repository. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 1.399863 comb 1.400000 user 1.370000 sys 0.030000 (median of 10) after: ! wall 0.766453 comb 0.770000 user 0.750000 sys 0.020000 (median of 11) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 1.876748 comb 1.890000 user 1.870000 sys 0.020000 (median of 10) after: ! wall 1.167223 comb 1.170000 user 1.150000 sys 0.020000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.242457 comb 0.240000 user 0.240000 sys 0.000000 (median of 39) after: ! wall 0.211476 comb 0.210000 user 0.210000 sys 0.000000 (median of 45) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013193 comb 0.020000 user 0.020000 sys 0.000000 (median of 224) after: ! wall 0.013290 comb 0.010000 user 0.010000 sys 0.000000 (median of 222) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.001673 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) after: ! wall 0.001677 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000119 comb 0.000000 user 0.000000 sys 0.000000 (median of 8023) after: ! wall 0.000119 comb 0.000000 user 0.000000 sys 0.000000 (median of 7997) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.201898 comb 0.210000 user 0.200000 sys 0.010000 (median of 48) after: ! wall 0.167415 comb 0.170000 user 0.160000 sys 0.010000 (median of 58) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.036820 comb 0.040000 user 0.040000 sys 0.000000 (median of 100) after: ! wall 0.035797 comb 0.040000 user 0.040000 sys 0.000000 (median of 100) The extra cost in the linear case can be reclaimed later with some extra logic. Differential Revision: https://phab.mercurial-scm.org/D7124

File last commit:

r38121:666d90ac default
r43594:ffd04bc9 default
Show More
hg-ssh
97 lines | 3.2 KiB | text/plain | TextLexer
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537 #!/usr/bin/env python
#
Thomas Arendsen Hein
Adjust contrib/hg-ssh for moved dispatch() function.
r5191 # Copyright 2005-2007 by Intevation GmbH <intevation@intevation.de>
Martin Geisler
add blank line after copyright notices and after header
r8228 #
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537 # Author(s):
# Thomas Arendsen Hein <thomas@intevation.de>
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
"""
hg-ssh - a wrapper for ssh access to a limited set of mercurial repos
To be used in ~/.ssh/authorized_keys with the "command" option, see sshd(8):
command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ...
(probably together with these other useful options:
no-port-forwarding,no-X11-forwarding,no-agent-forwarding)
Andreas Freimuth
hg-ssh: fix duplicate word in docstring
r13996 This allows pull/push over ssh from/to the repositories given as arguments.
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
If all your repositories are subdirectories of a common directory, you can
allow shorter paths with:
command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2"
Thomas Arendsen Hein
Added hint to hg-ssh that you can use shell pattern matching.
r1640
You can use pattern matching of your normal shell, e.g.:
command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}"
David Schleimer
hg-ssh: read-only flag...
r16836
You can also add a --read-only flag to allow read-only access to a key, e.g.:
command="hg-ssh --read-only repos/*"
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537 """
Augie Fackler
contrib: update hg-ssh to conform with import style checks
r33892 from __future__ import absolute_import
import os
import shlex
import sys
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
Thomas Arendsen Hein
Enable demandimport only in scripts, not in importable modules (issue605)...
r5197 # enable importing on demand to reduce startup time
Augie Fackler
contrib: update hg-ssh to conform with import style checks
r33892 import hgdemandimport ; hgdemandimport.enable()
Thomas Arendsen Hein
Enable demandimport only in scripts, not in importable modules (issue605)...
r5197
Augie Fackler
contrib: update hg-ssh to conform with import style checks
r33892 from mercurial import (
dispatch,
Pulkit Goyal
py3: use pycompat.fsencode to convert path to bytes...
r38121 pycompat,
Augie Fackler
contrib: update hg-ssh to conform with import style checks
r33892 ui as uimod,
)
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
David Schleimer
hg-ssh: refactor to have main() method...
r16779 def main():
Yuya Nishihara
sshserver: do setbinary() by caller (API)...
r37963 # Prevent insertion/deletion of CRs
dispatch.initstdio()
David Schleimer
hg-ssh: refactor to have main() method...
r16779 cwd = os.getcwd()
David Schleimer
hg-ssh: read-only flag...
r16836 readonly = False
args = sys.argv[1:]
while len(args):
if args[0] == '--read-only':
readonly = True
args.pop(0)
else:
break
David Schleimer
hg-ssh: refactor to have main() method...
r16779 allowed_paths = [os.path.normpath(os.path.join(cwd,
os.path.expanduser(path)))
David Schleimer
hg-ssh: read-only flag...
r16836 for path in args]
David Schleimer
hg-ssh: refactor to have main() method...
r16779 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
try:
cmdargv = shlex.split(orig_cmd)
FUJIWARA Katsunori
misc: use modern exception syntax...
r28047 except ValueError as e:
David Schleimer
hg-ssh: refactor to have main() method...
r16779 sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
sys.exit(255)
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
David Schleimer
hg-ssh: refactor to have main() method...
r16779 if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
path = cmdargv[2]
repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
if repo in allowed_paths:
Pulkit Goyal
py3: use pycompat.fsencode to convert path to bytes...
r38121 cmd = [b'-R', pycompat.fsencode(repo), b'serve', b'--stdio']
Augie Fackler
dispatch: protect against malicious 'hg serve --stdio' invocations (sec)...
r32050 req = dispatch.request(cmd)
David Schleimer
hg-ssh: read-only flag...
r16836 if readonly:
Augie Fackler
dispatch: protect against malicious 'hg serve --stdio' invocations (sec)...
r32050 if not req.ui:
req.ui = uimod.ui.load()
Pulkit Goyal
py3: add b'' prefixes in contrib/hg-ssh...
r38119 req.ui.setconfig(b'hooks', b'pretxnopen.hg-ssh',
b'python:__main__.rejectpush', b'hg-ssh')
req.ui.setconfig(b'hooks', b'prepushkey.hg-ssh',
b'python:__main__.rejectpush', b'hg-ssh')
Augie Fackler
dispatch: protect against malicious 'hg serve --stdio' invocations (sec)...
r32050 dispatch.dispatch(req)
David Schleimer
hg-ssh: refactor to have main() method...
r16779 else:
sys.stderr.write('Illegal repository "%s"\n' % repo)
sys.exit(255)
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537 else:
David Schleimer
hg-ssh: refactor to have main() method...
r16779 sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
Mads Kiilerich
hg-ssh: exit with 255 instead of -1 on error...
r16607 sys.exit(255)
Thomas Arendsen Hein
Added hg-ssh - a wrapper for ssh access to a limited set of mercurial repos...
r1537
David Schleimer
hg-ssh: read-only flag...
r16836 def rejectpush(ui, **kwargs):
Pulkit Goyal
py3: add b'' prefixes in contrib/hg-ssh...
r38119 ui.warn((b"Permission denied\n"))
David Schleimer
hg-ssh: read-only flag...
r16836 # mercurial hooks use unix process conventions for hook return values
# so a truthy return means failure
return True
David Schleimer
hg-ssh: refactor to have main() method...
r16779 if __name__ == '__main__':
main()