changeset 1549:98398a6ddd75

merged crew branch
author twaldmann@thinkmo.de
date Tue, 15 Nov 2005 23:41:24 +0100
parents 8763ddcaf159 (current diff) 4dea10839201 (diff)
children 2cf2fb2e2d15
files mercurial/commands.py mercurial/hgweb.py
diffstat 6 files changed, 59 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/hg-ssh	Tue Nov 15 23:41:24 2005 +0100
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# Copyright 2005 by Intevation GmbH <intevation@intevation.de>
+# Author(s):
+# Thomas Arendsen Hein <thomas@intevation.de>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+"""
+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)
+
+This allows pull/push over ssh to to the repositories given as arguments.
+
+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"
+"""
+
+from mercurial import commands
+
+import sys, os
+
+cwd = os.getcwd()
+allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
+                 for path in sys.argv[1:]]
+orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
+
+if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'):
+    path = orig_cmd[6:-14]
+    repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
+    if repo in allowed_paths:
+        commands.dispatch(['-R', repo, 'serve', '--stdio'])
+    else:
+        sys.stderr.write("Illegal repository %r\n" % repo)
+        sys.exit(-1)
+else:
+    sys.stderr.write("Illegal command %r\n" % orig_cmd)
+    sys.exit(-1)
+
--- a/contrib/zsh_completion	Wed Nov 16 00:33:20 2005 +0200
+++ b/contrib/zsh_completion	Tue Nov 15 23:41:24 2005 +0100
@@ -116,7 +116,7 @@
         '*:file:_files'
     ;;
 
-    (status)
+    (status|st)
         _arguments $includeExclude \
         '(--no-status)-n[hide status prefix]' \
         '(-n)--no-status[hide status prefix]' \
--- a/mercurial/commands.py	Wed Nov 16 00:33:20 2005 +0200
+++ b/mercurial/commands.py	Tue Nov 15 23:41:24 2005 +0100
@@ -13,7 +13,7 @@
 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
 demandload(globals(), "errno socket version struct atexit sets bz2")
 
-# TODO: commands.py:(misc lines): Local variable (ui) shadows global defined on line (12)
+# XXX TODO: commands.py:(misc lines): Local variable (ui) shadows global defined on line (12)
 
 class UnknownCommand(Exception):
     """Exception raised if command is not in the command table."""
@@ -636,17 +636,18 @@
     %p   root-relative path name of file being printed
     """
     mf = {}
-    if opts['rev']:
-        change = repo.changelog.read(repo.lookup(opts['rev']))
+    rev = opts['rev']
+    if rev:
+        change = repo.changelog.read(repo.lookup(rev))
         mf = repo.manifest.read(change[0])
     for src, abs_, rel, exact in walk(repo, (file1,) + pats, opts):
         r = repo.file(abs_)
-        if opts['rev']:
+        if rev:
             try:
                 n = mf[abs_]
             except (hg.RepoError, KeyError):
                 try:
-                    n = r.lookup(rev) # XXX rev undefined!
+                    n = r.lookup(rev)
                 except KeyError, inst:
                     raise util.Abort(_('cannot find file %s in rev %s'), rel, rev)
         else:
@@ -747,6 +748,7 @@
     f = repo.opener("hgrc", "w", text=True)
     f.write("[paths]\n")
     f.write("default = %s\n" % abspath)
+    f.close()
 
     if not opts['noupdate']:
         update(ui, repo)
@@ -2472,7 +2474,7 @@
 
     external = []
     for x in u.extensions():
-        def on_exception(Exception, inst): # XXX Exception is a builtin name!?
+        def on_exception(exc, inst):
             u.warn(_("*** failed to import extension %s\n") % x[1])
             u.warn("%s\n" % inst)
             if "--traceback" in sys.argv[1:]:
@@ -2635,6 +2637,9 @@
         u.debug(inst, "\n")
         u.warn(_("%s: invalid arguments\n") % cmd)
         help_(u, cmd)
+    except AmbiguousCommand, inst:
+        u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
+        help_(u, 'shortlist')
     except UnknownCommand, inst:
         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
         help_(u, 'shortlist')
--- a/mercurial/hgweb.py	Wed Nov 16 00:33:20 2005 +0200
+++ b/mercurial/hgweb.py	Tue Nov 15 23:41:24 2005 +0100
@@ -951,12 +951,6 @@
     else:
         return BaseHTTPServer.HTTPServer((address, port), hgwebhandler)
 
-def server(path, name, templates, address, port, use_ipv6=False,
-           accesslog=sys.stdout, errorlog=sys.stderr):
-    httpd = create_server(path, name, templates, address, port, use_ipv6,
-                          accesslog, errorlog) # XXX wrong param count
-    httpd.serve_forever()
-
 # This is a stopgap
 class hgwebdir:
     def __init__(self, config):
--- a/mercurial/util.py	Wed Nov 16 00:33:20 2005 +0200
+++ b/mercurial/util.py	Tue Nov 15 23:41:24 2005 +0100
@@ -388,8 +388,8 @@
             file.__init__(self, self.temp, mode)
         def close(self):
             if not self.closed:
+                file.close(self)
                 rename(self.temp, self.__name)
-            file.close(self)
         def __del__(self):
             self.close()
 
--- a/tests/test-grep	Wed Nov 16 00:33:20 2005 +0200
+++ b/tests/test-grep	Tue Nov 15 23:41:24 2005 +0100
@@ -14,7 +14,7 @@
 hg commit -m 2 -u spam -d '2 0'
 echo 'import/export' >> port
 hg commit -m 3 -u eggs -d '3 0'
-head -3 port > port1
+head -n 3 port > port1
 mv port1 port
 hg commit -m 4 -u spam -d '4 0'
 hg grep port port