Merge with http://hannibal.lr-s.tudelft.nl/~vincent/fcgi/mercurial/fcgi/
authorThomas Arendsen Hein <thomas@intevation.de>
Wed, 31 Aug 2005 21:07:36 +0200
changeset 1182 24d553b598e8
parent 1179 8acf62f579d8 (diff)
parent 1181 4f5001f5b4c3 (current diff)
child 1183 d9e85a75dbda
child 1185 2ae9c319e6fe
Merge with http://hannibal.lr-s.tudelft.nl/~vincent/fcgi/mercurial/fcgi/
mercurial/hgweb.py
--- a/contrib/mercurial.el
+++ b/contrib/mercurial.el
@@ -283,13 +283,13 @@ XEmacs and GNU Emacs."
     (replace-regexp-in-string regexp newtext str nil literal)))
 
 (defsubst hg-strip (str)
-  "Strip leading and trailing white space from a string."
-  (hg-replace-in-string (hg-replace-in-string str "[ \t\r\n]+$" "")
-			"^[ \t\r\n]+" ""))
+  "Strip leading and trailing blank lines from a string."
+  (hg-replace-in-string (hg-replace-in-string str "[\r\n][ \t\r\n]*\\'" "")
+			"\\`[ \t\r\n]*[\r\n]" ""))
 
 (defsubst hg-chomp (str)
   "Strip trailing newlines from a string."
-  (hg-replace-in-string str "[\r\n]+$" ""))
+  (hg-replace-in-string str "[\r\n]+\'" ""))
 
 (defun hg-run-command (command &rest args)
   "Run the shell command COMMAND, returning (EXIT-CODE . COMMAND-OUTPUT).
@@ -469,12 +469,11 @@ directory names from the file system.  W
       (set-buffer hg-prev-buffer))
     (let ((rev (or default "tip")))
       (if current-prefix-arg
-	  (let ((revs (split-string (hg-chomp
-				     (hg-run0 "-q" "log" "-r"
-					      (format "-%d"
-						      hg-rev-completion-limit)
-					      "-r" "tip"))
-				    "[\n:]")))
+	  (let ((revs (split-string
+		       (hg-chomp
+			(hg-run0 "-q" "log" "-r"
+				 (format "-%d:tip" hg-rev-completion-limit)))
+		       "[\n:]")))
 	    (dolist (line (split-string (hg-chomp (hg-run0 "tags")) "\n"))
 	      (setq revs (cons (car (split-string line "\\s-")) revs)))
 	    (completing-read (format "Revision%s (%s): "
@@ -650,7 +649,7 @@ SCM Task                              G/
 Help overview (what you are reading)  G    C-c h h      hg-help-overview
 
 Tell Mercurial to manage a file       G    C-c h a      hg-add
-Commit changes to current file only   L    C-x v n      hg-commit
+Commit changes to current file only   L    C-x v n      hg-commit-start
 Undo changes to file since commit     L    C-x v u      hg-revert-buffer
 
 Diff file vs last checkin             L    C-x v =      hg-diff
@@ -660,10 +659,10 @@ View annotated file                   L 
 
 Diff repo vs last checkin             G    C-c h =      hg-diff-repo
 View status of files in repo          G    C-c h s      hg-status
-Commit all changes                    G    C-c h c      hg-commit
+Commit all changes                    G    C-c h c      hg-commit-start
 
 Undo all changes since last commit    G    C-c h U      hg-revert
-View repo change history              G    C-c h l      hg-log
+View repo change history              G    C-c h l      hg-log-repo
 
 See changes that can be pulled        G    C-c h ,      hg-incoming
 Pull changes                          G    C-c h <      hg-pull
@@ -966,9 +965,10 @@ With a prefix argument, prompt for each 
 			 (format "Mercurial: Log of rev %s of %s" rev1 a-path)
 		       (format "Mercurial: Log from rev %s to %s of %s"
 			       r1 r2 a-path)))
-      (if (> (length path) (length (hg-root path)))
-	  (call-process (hg-binary) nil t nil "log" "-r" r1 "-r" r2 path)
-	(call-process (hg-binary) nil t nil "log" "-r" r1 "-r" r2))
+      (let ((revs (format "%s:%s" r1 r2)))
+	(if (> (length path) (length (hg-root path)))
+	    (call-process (hg-binary) nil t nil "log" "-r" revs path)
+	  (call-process (hg-binary) nil t nil "log" "-r" revs)))
       (hg-log-mode))))
 
 (defun hg-log-repo (path &optional rev1 rev2)
new file mode 100644
--- /dev/null
+++ b/contrib/tcsh_completion
@@ -0,0 +1,40 @@
+#
+# tcsh completion for Mercurial
+#
+# This file has been auto-generated by tcsh_completion_build.sh for
+# Mercurial Distributed SCM (version a33a7a543803) 
+#
+# Copyright (C) 2005 TK Soh.
+#
+# This is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version. 
+#
+
+complete hg \
+  'n/--cwd/d/' 'n/-R/d/' 'n/--repository/d/' \
+  'C/-/( -R --repository \
+    --cwd \
+    -y --noninteractive \
+    -q --quiet \
+    -v --verbose \
+    --debug \
+    --traceback \
+    --time \
+    --profile \
+    --version \
+    -h --help)/' \
+  'p/1/(add addremove annotate cat clone \
+    commit ci copy debugcheckstate debugconfig \
+    debugdata debugindex debugindexdot debugrename debugstate \
+    debugwalk diff export forget grep \
+    heads help identify id import \
+    patch incoming in init locate \
+    log history manifest outgoing out \
+    parents paths pull push rawcommit \
+    recover remove rm revert root \
+    serve status tag tags tip \
+    undo update up checkout co \
+    verify version)/'
+
new file mode 100644
--- /dev/null
+++ b/contrib/tcsh_completion_build.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+#
+# tcsh_completion_build.sh - script to generate tcsh completion
+#
+#
+# Copyright (C) 2005 TK Soh.
+#
+# This is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version. 
+#
+#
+# Description
+# -----------
+# This script generates a tcsh source file to support completion
+# of Mercurial commands and options.
+#
+# Instruction:
+# -----------
+# Run this script to generate the tcsh source file, and source
+# the file to add command completion support for Mercurial.
+#
+#    tcsh% tcsh_completion.sh FILE
+#    tcsh% source FILE
+#
+# If FILE is not specified, tcsh_completion will be generated.
+#
+# Bugs:
+# ----
+# 1. command specific options are not supported
+# 2. hg commands must be specified immediately after 'hg'.
+#
+
+tcsh_file=${1-tcsh_completion}
+
+hg_commands=`hg --debug help | \
+        sed -e '1,/^list of commands:/d' \
+            -e '/^global options:/,$d' \
+            -e '/^ [^ ]/!d; s/[,:]//g;' | \
+        xargs -n5 | \
+        sed -e '$!s/$/ \\\\/g; 2,$s/^ */    /g'`
+
+hg_global_options=`hg -v help | \
+        sed -e '1,/global/d;/^ *-/!d; s/ [^- ].*//' | \
+        sed -e 's/ *$//; $!s/$/ \\\\/g; 2,$s/^ */    /g'`
+
+hg_version=`hg version | sed -e '1q'`
+
+script_name=`basename $0`
+
+cat > $tcsh_file <<END
+#
+# tcsh completion for Mercurial
+#
+# This file has been auto-generated by $script_name for
+# $hg_version 
+#
+# Copyright (C) 2005 TK Soh.
+#
+# This is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version. 
+#
+
+complete hg \\
+  'n/--cwd/d/' 'n/-R/d/' 'n/--repository/d/' \\
+  'C/-/($hg_global_options)/' \\
+  'p/1/($hg_commands)/'
+
+END
--- a/doc/hgrc.5.txt
+++ b/doc/hgrc.5.txt
@@ -64,14 +64,14 @@ keys, and their possible values.
 hooks::
   Commands that get automatically executed by various actions such as
   starting or finishing a commit.
+  changegroup;;
+    Run after a changegroup has been added via push or pull.
+  commit;;
+    Run after a changeset has been created. Passed the ID of the newly
+    created changeset.
   precommit;;
     Run before starting a commit.  Exit status 0 allows the commit to
     proceed.  Non-zero status will cause the commit to fail.
-  commit;;
-    Run after a changeset has been created. Passed the ID of the newly
-    created changeset.
-  changegroup;;
-    Run after a changegroup has been added via push or pull.
 
 http_proxy::
   Used to access web-based Mercurial repositories through a HTTP
@@ -79,13 +79,13 @@ http_proxy::
   host;;
     Host name and (optional) port of the proxy server, for example
     "myproxy:8000".
-  user;;
-    Optional.  User name to authenticate with at the proxy server.
-  passwd;;
-    Optional.  Password to authenticate with at the proxy server.
   no;;
     Optional.  Comma-separated list of host names that should bypass
     the proxy.
+  passwd;;
+    Optional.  Password to authenticate with at the proxy server.
+  user;;
+    Optional.  User name to authenticate with at the proxy server.
 
 paths::
   Assigns symbolic names to repositories.  The left side is the
@@ -105,50 +105,53 @@ ui::
     Default is "hgmerge".
   quiet;;
     Reduce the amount of output printed.  True or False.  Default is False.
+  remotecmd;;
+    remote command to use for clone/push/pull operations. Default is 'hg'.
+  ssh;;
+    command to use for SSH connections. Default is 'ssh'.
   username;;
     The committer of a changeset created when running "commit".
     Typically a person's name and email address, e.g. "Fred Widget
     <fred@example.com>".  Default is $EMAIL or username@hostname.
   verbose;;
     Increase the amount of output printed.  True or False.  Default is False.
-  ssh;;
-    command to use for SSH connections. Default is 'ssh'.
-  remotecmd;;
-    remote command to use for clone/push/pull operations. Default is 'hg'.
 
 
 web::
   Web interface configuration.
-  name;;
-    Repository name to use in the web interface. Default is current
-    working directory.
-  address;;
-    Interface address to bind to. Default is all.
-  port;;
-    Port to listen on. Default is 8000.
-  ipv6;;
-    Whether to use IPv6. Default is false.
   accesslog;;
     Where to output the access log. Default is stdout.
-  errorlog;;
-    Where to output the error log. Default is stderr.
-  templates;;
-    Where to find the HTML templates. Default is install path.
-  style;;
-    Which template map style to use.
-  maxchanges;;
-    Maximum number of changes to list on the changelog. Default is 10.
-  maxfiles;;
-    Maximum number of files to list per changeset. Default is 10.
+  address;;
+    Interface address to bind to. Default is all.
+  allowbz2;;
+    Whether to allow .tar.bz2 downloading of repo revisions. Default is false.
+  allowgz;;
+    Whether to allow .tar.gz downloading of repo revisions. Default is false.
   allowpull;;
     Whether to allow pulling from the repository. Default is true.
   allowzip;;
     Whether to allow .zip downloading of repo revisions. Default is false.
     This feature creates temporary files.
-  allowgz;;
-    Whether to allow .tar.gz downloading of repo revisions. Default is false.
-  allowbz2;;
-    Whether to allow .tar.bz2 downloading of repo revisions. Default is false.
+  description;;
+    Textual description of the repository's purpose or contents.
+    Default is "unknown".
+  errorlog;;
+    Where to output the error log. Default is stderr.
+  ipv6;;
+    Whether to use IPv6. Default is false.
+  name;;
+    Repository name to use in the web interface. Default is current
+    working directory.
+  maxchanges;;
+    Maximum number of changes to list on the changelog. Default is 10.
+  maxfiles;;
+    Maximum number of files to list per changeset. Default is 10.
+  port;;
+    Port to listen on. Default is 8000.
+  style;;
+    Which template map style to use.
+  templates;;
+    Where to find the HTML templates. Default is install path.
 
 
 AUTHOR
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1386,7 +1386,10 @@ def serve(ui, repo, **opts):
         if opts[o]:
             ui.setconfig("web", o, opts[o])
 
-    httpd = hgweb.create_server(repo)
+    try:
+        httpd = hgweb.create_server(repo)
+    except socket.error, inst:
+        raise util.Abort('cannot start server: ' + inst.args[1])
 
     if ui.verbose:
         addr, port = httpd.socket.getsockname()
--- a/mercurial/hgweb.py
+++ b/mercurial/hgweb.py
@@ -6,7 +6,7 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-import os, cgi, time, re, socket, sys, zlib
+import os, cgi, time, re, socket, sys, zlib, errno
 import mdiff
 from hg import *
 from ui import *
@@ -77,8 +77,8 @@ class hgrequest:
                     self.out.write(thing)
                 except TypeError:
                     self.out.write(str(thing))
-                except socket.error, x:
-                    if x[0] != errno.ECONNRESET:
+                except socket.error, inst:
+                    if inst[0] != errno.ECONNRESET:
                         raise
 
     def header(self, headers=[('Content-type','text/html')]):
@@ -178,8 +178,7 @@ class hgweb:
             self.repo = repo
 
         self.mtime = -1
-        self.reponame = name or self.repo.ui.config("web", "name",
-                                                    self.repo.root)
+        self.reponame = name
         self.archives = 'zip', 'gz', 'bz2'
 
     def refresh(self):
@@ -663,10 +662,10 @@ class hgweb:
         files.sort()
 
         if type == 'zip':
-            import zipfile
+            import zipfile, tempfile
 
+            tmp = tempfile.mkstemp()[1]
             try:
-                tmp = tempfile.mkstemp()[1]
                 zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED)
 
                 for f in files:
@@ -730,6 +729,9 @@ class hgweb:
         if "?" in uri:
             uri = uri.split("?")[0]
         url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri)
+        if not self.reponame:
+            self.reponame = (self.repo.ui.config("web", "name")
+                             or uri.strip('/') or self.repo.root)
 
         self.t = templater(m, common_filters,
                            {"url": url,
@@ -867,7 +869,7 @@ def create_server(repo):
             try:
                 self.do_hgweb()
             except socket.error, inst:
-                if inst.args[0] != 32:
+                if inst[0] != errno.EPIPE:
                     raise
 
         def do_GET(self):
@@ -956,7 +958,10 @@ class hgwebdir:
             parity = 0
             for name, path in self.repos:
                 u = ui()
-                u.readconfig(file(os.path.join(path, '.hg', 'hgrc')))
+                try:
+                    u.readconfig(file(os.path.join(path, '.hg', 'hgrc')))
+                except IOError:
+                    pass
                 get = u.config
 
                 url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name])
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -342,8 +342,6 @@ else:
 
     def explain_exit(code):
         """return a 2-tuple (desc, code) describing a process's status"""
-        if os.name == 'nt': # os.WIFxx is not supported on windows
-            return "aborted with error." , -1
         if os.WIFEXITED(code):
             val = os.WEXITSTATUS(code)
             return "exited with status %d" % val, val
new file mode 100755
--- /dev/null
+++ b/tests/test-archive
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+mkdir test
+cd test
+hg init
+echo foo>foo
+hg addremove
+hg commit -m 1
+echo bar>bar
+hg addremove
+hg commit -m 2
+mkdir baz
+echo bletch>baz/bletch
+hg addremove
+hg commit -m 3
+echo "name = test-archive" >> .hg/hgrc
+echo "allowzip = true" >> .hg/hgrc
+echo "allowgz = true" >> .hg/hgrc
+echo "allowbz2 = true" >> .hg/hgrc
+hg serve -p 20059 > /dev/null &
+sleep 1 # wait for server to be started
+
+TIP=`hg id -v | cut -f1 -d' '`
+QTIP=`hg id -q`
+cat > getarchive.py <<EOF
+import sys, urllib2
+node, archive = sys.argv[1:]
+f = urllib2.urlopen('http://127.0.0.1:20059/?cmd=archive;node=%s;type=%s'
+                    % (node, archive))
+sys.stdout.write(f.read())
+EOF
+http_proxy= python getarchive.py "$TIP" gz | tar tzf - | sed "s/$QTIP/TIP/"
+http_proxy= python getarchive.py "$TIP" bz2 | tar tjf - | sed "s/$QTIP/TIP/"
+http_proxy= python getarchive.py "$TIP" zip > archive.zip
+unzip -t archive.zip | sed "s/$QTIP/TIP/"
+
+kill $!
new file mode 100644
--- /dev/null
+++ b/tests/test-archive.out
@@ -0,0 +1,15 @@
+adding foo
+adding bar
+adding baz/bletch
+test-archive-TIP/bar
+test-archive-TIP/baz/bletch
+test-archive-TIP/foo
+test-archive-TIP/bar
+test-archive-TIP/baz/bletch
+test-archive-TIP/foo
+Archive:  archive.zip
+    testing: test-archive-TIP/bar   OK
+    testing: test-archive-TIP/baz/bletch   OK
+    testing: test-archive-TIP/foo   OK
+No errors detected in compressed data of archive.zip.
+killed!
--- a/tests/test-copy2
+++ b/tests/test-copy2
@@ -8,11 +8,11 @@ hg commit -m1 -d"0 0"
 echo "# should show copy"
 cp foo bar
 hg copy foo bar
-hg debugstate|grep ^copy
+hg debugstate|grep '^copy'
 
 echo "# shouldn't show copy"
 hg commit -m2 -d"0 0"
-hg debugstate|grep ^copy
+hg debugstate|grep '^copy'
 
 echo "# should match"
 hg debugindex .hg/data/foo.i
@@ -28,7 +28,7 @@ hg debugrename bar
 cp foo bar
 hg copy foo bar
 echo "# should show copy"
-hg debugstate|grep ^copy
+hg debugstate|grep '^copy'
 hg commit -m3 -d"0 0"
 
 echo "# should show no parents for tip"
@@ -38,6 +38,6 @@ hg debugindex .hg/data/foo.i
 hg debugrename bar
 
 echo "# should show no copies"
-hg debugstate|grep ^copy
+hg debugstate|grep '^copy'
 
 exit 0
--- a/tests/test-grep
+++ b/tests/test-grep
@@ -18,5 +18,6 @@ head -3 port > port1
 mv port1 port
 hg commit -m 4 -u spam -d '4 0'
 hg grep port port
+echo 'FIXME: history is wrong here'
 hg grep -enu port port
 hg grep import port
--- a/tests/test-ssh
+++ b/tests/test-ssh
@@ -13,7 +13,7 @@ if [ $1 != "user@dummy" ] ; then
 fi
 
 # check that we're in the right directory
-if \! [ -x dummyssh ] ; then
+if [ ! -x dummyssh ] ; then
 	exit -1
 fi
 
--- a/tests/test-ssh.out
+++ b/tests/test-ssh.out
@@ -5,7 +5,6 @@ adding changesets
 adding manifests
 adding file changes
 added 1 changesets with 1 changes to 1 files
-remote: ./dummyssh: line 11: !: command not found
 # verify
 checking changesets
 checking manifests
@@ -16,13 +15,11 @@ 1 files, 1 changesets, 1 total revisions
 default = ssh://user@dummy/remote
 pulling from ssh://user@dummy/remote
 searching for changes
-remote: ../dummyssh: line 11: !: command not found
 no changes found
 # local change
 # updating rc
 # find outgoing
 searching for changes
-remote: ../dummyssh: line 11: !: command not found
 changeset:   1:536411b157b4
 tag:         tip
 user:        test
@@ -31,7 +28,6 @@ summary:     add
 
 # push
 pushing to ssh://user@dummy/remote
-remote: ../dummyssh: line 11: !: command not found
 searching for changes
 remote: adding changesets
 remote: adding manifests