merge.
--- a/.hgignore
+++ b/.hgignore
@@ -21,6 +21,7 @@ doc/*.[0-9].{x,ht}ml
MANIFEST
patches
mercurial/__version__.py
+.DS_Store
syntax: regexp
^\.pc/
--- a/contrib/mercurial.el
+++ b/contrib/mercurial.el
@@ -1,6 +1,6 @@
;;; mercurial.el --- Emacs support for the Mercurial distributed SCM
-;; Copyright (C) 2005 Bryan O'Sullivan
+;; Copyright (C) 2005, 2006 Bryan O'Sullivan
;; Author: Bryan O'Sullivan <bos@serpentine.com>
@@ -289,7 +289,7 @@ XEmacs and GNU Emacs."
(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).
@@ -502,6 +502,43 @@ directory names from the file system. W
(or default "tip")))
rev))))
+(defun hg-parents-for-mode-line (root)
+ "Format the parents of the working directory for the mode line."
+ (let ((parents (split-string (hg-chomp
+ (hg-run0 "--cwd" root "parents" "--template"
+ "{rev}\n")) "\n")))
+ (mapconcat 'identity parents "+")))
+
+(defun hg-buffers-visiting-repo (&optional path)
+ "Return a list of buffers visiting the repository containing PATH."
+ (let ((root-name (hg-root (or path (buffer-file-name))))
+ bufs)
+ (save-excursion
+ (dolist (buf (buffer-list) bufs)
+ (set-buffer buf)
+ (let ((name (buffer-file-name)))
+ (when (and hg-status name (equal (hg-root name) root-name))
+ (setq bufs (cons buf bufs))))))))
+
+(defun hg-update-mode-lines (path)
+ "Update the mode lines of all buffers visiting the same repository as PATH."
+ (let* ((root (hg-root path))
+ (parents (hg-parents-for-mode-line root)))
+ (save-excursion
+ (dolist (info (hg-path-status
+ root
+ (mapcar
+ (function
+ (lambda (buf)
+ (substring (buffer-file-name buf) (length root))))
+ (hg-buffers-visiting-repo root))))
+ (let* ((name (car info))
+ (status (cdr info))
+ (buf (find-buffer-visiting (concat root name))))
+ (when buf
+ (set-buffer buf)
+ (hg-mode-line-internal status parents)))))))
+
(defmacro hg-do-across-repo (path &rest body)
(let ((root-name (gensym "root-"))
(buf-name (gensym "buf-")))
@@ -548,13 +585,31 @@ current frame."
'(("M " . modified)
("A " . added)
("R " . removed)
+ ("! " . deleted)
("? " . nil)))))
(if state
(cdr state)
'normal)))))
-(defun hg-tip ()
- (split-string (hg-chomp (hg-run0 "-q" "tip")) ":"))
+(defun hg-path-status (root paths)
+ "Return status of PATHS in repo ROOT as an alist.
+Each entry is a pair (FILE-NAME . STATUS)."
+ (let ((s (apply 'hg-run "--cwd" root "status" "-marduc" paths))
+ result)
+ (dolist (entry (split-string (hg-chomp (cdr s)) "\n") (nreverse result))
+ (let (state name)
+ (if (equal (substring entry 1 2) " ")
+ (setq state (cdr (assoc (substring entry 0 2)
+ '(("M " . modified)
+ ("A " . added)
+ ("R " . removed)
+ ("! " . deleted)
+ ("C " . normal)
+ ("I " . ignored)
+ ("? " . nil))))
+ name (substring entry 2))
+ (setq name (substring entry 0 (search ": " entry :from-end t))))
+ (setq result (cons (cons name state) result))))))
(defmacro hg-view-output (args &rest body)
"Execute BODY in a clean buffer, then quickly display that buffer.
@@ -589,7 +644,7 @@ being viewed."
(put 'hg-view-output 'lisp-indent-function 1)
-;;; Context save and restore across revert.
+;;; Context save and restore across revert and other operations.
(defun hg-position-context (pos)
"Return information to help find the given position again."
@@ -631,22 +686,28 @@ Always returns a valid, hopefully sane,
;;; Hooks.
+(defun hg-mode-line-internal (status parents)
+ (setq hg-status status
+ hg-mode (and status (concat " Hg:"
+ parents
+ (cdr (assq status
+ '((normal . "")
+ (removed . "r")
+ (added . "a")
+ (deleted . "!")
+ (modified . "m"))))))))
+
(defun hg-mode-line (&optional force)
"Update the modeline with the current status of a file.
An update occurs if optional argument FORCE is non-nil,
hg-update-modeline is non-nil, or we have not yet checked the state of
the file."
- (when (and (hg-root) (or force hg-update-modeline (not hg-mode)))
- (let ((status (hg-file-status buffer-file-name)))
- (setq hg-status status
- hg-mode (and status (concat " Hg:"
- (car (hg-tip))
- (cdr (assq status
- '((normal . "")
- (removed . "r")
- (added . "a")
- (modified . "m")))))))
- status)))
+ (let ((root (hg-root)))
+ (when (and root (or force hg-update-modeline (not hg-mode)))
+ (let ((status (hg-file-status buffer-file-name))
+ (parents (hg-parents-for-mode-line root)))
+ (hg-mode-line-internal status parents)
+ status))))
(defun hg-mode (&optional toggle)
"Minor mode for Mercurial distributed SCM integration.
@@ -724,6 +785,13 @@ code by typing `M-x find-library mercuri
default-directory)
(cd hg-root-dir)))))
+(defun hg-fix-paths ()
+ "Fix paths reported by some Mercurial commands."
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward " \\.\\.." nil t)
+ (replace-match " " nil nil))))
+
(defun hg-add (path)
"Add PATH to the Mercurial repository on the next commit.
With a prefix argument, prompt for the path to add."
@@ -732,9 +800,8 @@ With a prefix argument, prompt for the p
(update (equal buffer-file-name path)))
(hg-view-output (hg-output-buffer-name)
(apply 'call-process (hg-binary) nil t nil (list "add" path))
- ;; "hg add" shows pathes relative NOT TO ROOT BUT TO REPOSITORY
- (replace-regexp " \\.\\.." " " nil 0 (buffer-size))
- (goto-char 0)
+ (hg-fix-paths)
+ (goto-char (point-min))
(cd (hg-root path)))
(when update
(unless vc-make-backup-files
@@ -820,8 +887,7 @@ hg-commit-allow-empty-file-list is nil,
(let ((buf hg-prev-buffer))
(kill-buffer nil)
(switch-to-buffer buf))
- (hg-do-across-repo root
- (hg-mode-line)))))
+ (hg-update-mode-lines root))))
(defun hg-commit-mode ()
"Mode for describing a commit of changes to a Mercurial repository.
@@ -973,8 +1039,8 @@ With a prefix argument, prompt for the p
(hg-view-output (hg-output-buffer-name)
(apply 'call-process (hg-binary) nil t nil (list "forget" path))
;; "hg forget" shows pathes relative NOT TO ROOT BUT TO REPOSITORY
- (replace-regexp " \\.\\.." " " nil 0 (buffer-size))
- (goto-char 0)
+ (hg-fix-paths)
+ (goto-char (point-min))
(cd (hg-root path)))
(when update
(with-current-buffer buf
@@ -1148,6 +1214,21 @@ prompts for a path to check."
root)
hg-root))
+(defun hg-cwd (&optional path)
+ "Return the current directory of PATH within the repository."
+ (do ((stack nil (cons (file-name-nondirectory
+ (directory-file-name dir))
+ stack))
+ (prev nil dir)
+ (dir (file-name-directory (or path buffer-file-name
+ (expand-file-name default-directory)))
+ (file-name-directory (directory-file-name dir))))
+ ((equal prev dir))
+ (when (file-directory-p (concat dir ".hg"))
+ (let ((cwd (mapconcat 'identity stack "/")))
+ (unless (equal cwd "")
+ (return (file-name-as-directory cwd)))))))
+
(defun hg-status (path)
"Print revision control status of a file or directory.
With prefix argument, prompt for the path to give status for.
new file mode 100644
--- /dev/null
+++ b/contrib/mq.el
@@ -0,0 +1,281 @@
+;;; mq.el --- Emacs support for Mercurial Queues
+
+;; Copyright (C) 2006 Bryan O'Sullivan
+
+;; Author: Bryan O'Sullivan <bos@serpentine.com>
+
+;; mq.el is free software; you can redistribute it and/or modify it
+;; under the terms of version 2 of the GNU General Public License as
+;; published by the Free Software Foundation.
+
+;; mq.el is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with mq.el, GNU Emacs, or XEmacs; see the file COPYING (`C-h
+;; C-l'). If not, write to the Free Software Foundation, Inc., 59
+;; Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+(require 'mercurial)
+
+
+(defcustom mq-mode-hook nil
+ "Hook run when a buffer enters mq-mode."
+ :type 'sexp
+ :group 'mercurial)
+
+(defcustom mq-global-prefix "\C-cq"
+ "The global prefix for Mercurial Queues keymap bindings."
+ :type 'sexp
+ :group 'mercurial)
+
+(defcustom mq-edit-mode-hook nil
+ "Hook run after a buffer is populated to edit a patch description."
+ :type 'sexp
+ :group 'mercurial)
+
+
+;;; Internal variables.
+
+(defvar mq-patch-history nil)
+
+(defvar mq-prev-buffer nil)
+(make-variable-buffer-local 'mq-prev-buffer)
+(put 'mq-prev-buffer 'permanent-local t)
+
+
+;;; Global keymap.
+
+(defvar mq-global-map (make-sparse-keymap))
+(fset 'mq-global-map mq-global-map)
+(global-set-key mq-global-prefix 'mq-global-map)
+(define-key mq-global-map "." 'mq-push)
+(define-key mq-global-map ">" 'mq-push-all)
+(define-key mq-global-map "," 'mq-pop)
+(define-key mq-global-map "<" 'mq-pop-all)
+(define-key mq-global-map "r" 'mq-refresh)
+(define-key mq-global-map "e" 'mq-refresh-edit)
+(define-key mq-global-map "n" 'mq-next)
+(define-key mq-global-map "p" 'mq-previous)
+(define-key mq-global-map "t" 'mq-top)
+
+
+;;; Refresh edit mode keymap.
+
+(defvar mq-edit-mode-map (make-sparse-keymap))
+(define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
+(define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
+
+
+;;; Helper functions.
+
+(defun mq-read-patch-name (&optional source prompt)
+ "Read a patch name to use with a command.
+May return nil, meaning \"use the default\"."
+ (let ((patches (split-string
+ (hg-chomp (hg-run0 (or source "qseries"))) "\n")))
+ (when current-prefix-arg
+ (completing-read (format "Patch%s: " (or prompt ""))
+ (map 'list 'cons patches patches)
+ nil
+ nil
+ nil
+ 'mq-patch-history))))
+
+(defun mq-refresh-buffers (root)
+ (save-excursion
+ (dolist (buf (hg-buffers-visiting-repo root))
+ (when (not (verify-visited-file-modtime buf))
+ (set-buffer buf)
+ (let ((ctx (hg-buffer-context)))
+ (message "Refreshing %s..." (buffer-name))
+ (revert-buffer t t t)
+ (hg-restore-context ctx)
+ (message "Refreshing %s...done" (buffer-name))))))
+ (hg-update-mode-lines root))
+
+(defun mq-last-line ()
+ (goto-char (point-max))
+ (beginning-of-line)
+ (when (looking-at "^$")
+ (forward-line -1))
+ (let ((bol (point)))
+ (end-of-line)
+ (let ((line (buffer-substring bol (point))))
+ (when (> (length line) 0)
+ line))))
+
+(defun mq-push (&optional patch)
+ "Push patches until PATCH is reached.
+If PATCH is nil, push at most one patch."
+ (interactive (list (mq-read-patch-name "qunapplied" " to push")))
+ (let ((root (hg-root))
+ (prev-buf (current-buffer))
+ last-line ok)
+ (unless root
+ (error "Cannot push outside a repository!"))
+ (hg-sync-buffers root)
+ (let ((buf-name (format "MQ: Push %s" (or patch "next patch"))))
+ (kill-buffer (get-buffer-create buf-name))
+ (split-window-vertically)
+ (other-window 1)
+ (switch-to-buffer (get-buffer-create buf-name))
+ (cd root)
+ (message "Pushing...")
+ (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpush"
+ (if patch (list patch))))
+ last-line (mq-last-line))
+ (let ((lines (count-lines (point-min) (point-max))))
+ (if (and (equal lines 2) (string-match "Now at:" last-line))
+ (progn
+ (kill-buffer (current-buffer))
+ (delete-window))
+ (hg-view-mode prev-buf))))
+ (mq-refresh-buffers root)
+ (sit-for 0)
+ (when last-line
+ (if ok
+ (message "Pushing... %s" last-line)
+ (error "Pushing... %s" last-line)))))
+
+(defun mq-push-all ()
+ "Push patches until all are applied."
+ (interactive)
+ (mq-push "-a"))
+
+(defun mq-pop (&optional patch)
+ "Pop patches until PATCH is reached.
+If PATCH is nil, pop at most one patch."
+ (interactive (list (mq-read-patch-name "qapplied" " to pop to")))
+ (let ((root (hg-root))
+ last-line ok)
+ (unless root
+ (error "Cannot pop outside a repository!"))
+ (hg-sync-buffers root)
+ (set-buffer (generate-new-buffer "qpop"))
+ (cd root)
+ (message "Popping...")
+ (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpop"
+ (if patch (list patch))))
+ last-line (mq-last-line))
+ (kill-buffer (current-buffer))
+ (mq-refresh-buffers root)
+ (sit-for 0)
+ (when last-line
+ (if ok
+ (message "Popping... %s" last-line)
+ (error "Popping... %s" last-line)))))
+
+(defun mq-pop-all ()
+ "Push patches until none are applied."
+ (interactive)
+ (mq-pop "-a"))
+
+(defun mq-refresh-internal (root &rest args)
+ (hg-sync-buffers root)
+ (let ((patch (mq-patch-info "qtop")))
+ (message "Refreshing %s..." patch)
+ (let ((ret (apply 'hg-run "qrefresh" args)))
+ (if (equal (car ret) 0)
+ (message "Refreshing %s... done." patch)
+ (error "Refreshing %s... %s" patch (hg-chomp (cdr ret)))))))
+
+(defun mq-refresh ()
+ "Refresh the topmost applied patch."
+ (interactive)
+ (let ((root (hg-root)))
+ (unless root
+ (error "Cannot refresh outside of a repository!"))
+ (mq-refresh-internal root)))
+
+(defun mq-patch-info (cmd &optional msg)
+ (let* ((ret (hg-run cmd))
+ (info (hg-chomp (cdr ret))))
+ (if (equal (car ret) 0)
+ (if msg
+ (message "%s patch: %s" msg info)
+ info)
+ (error "%s" info))))
+
+(defun mq-top ()
+ "Print the name of the topmost applied patch."
+ (interactive)
+ (mq-patch-info "qtop" "Top"))
+
+(defun mq-next ()
+ "Print the name of the next patch to be pushed."
+ (interactive)
+ (mq-patch-info "qnext" "Next"))
+
+(defun mq-previous ()
+ "Print the name of the first patch below the topmost applied patch.
+This would become the active patch if popped to."
+ (interactive)
+ (mq-patch-info "qprev" "Previous"))
+
+(defun mq-edit-finish ()
+ "Finish editing the description of this patch, and refresh the patch."
+ (interactive)
+ (unless (equal (mq-patch-info "qtop") mq-top)
+ (error "Topmost patch has changed!"))
+ (hg-sync-buffers hg-root)
+ (mq-refresh-internal hg-root "-m" (buffer-substring (point-min) (point-max)))
+ (let ((buf mq-prev-buffer))
+ (kill-buffer nil)
+ (switch-to-buffer buf)))
+
+(defun mq-edit-kill ()
+ "Kill the edit currently being prepared."
+ (interactive)
+ (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? "))
+ (let ((buf mq-prev-buffer))
+ (kill-buffer nil)
+ (switch-to-buffer buf))))
+
+(defun mq-edit-mode ()
+ "Mode for editing the description of a patch.
+
+Key bindings
+------------
+\\[mq-edit-finish] use this description
+\\[mq-edit-kill] abandon this description"
+ (interactive)
+ (use-local-map mq-edit-mode-map)
+ (set-syntax-table text-mode-syntax-table)
+ (setq local-abbrev-table text-mode-abbrev-table
+ major-mode 'mq-edit-mode
+ mode-name "MQ-Edit")
+ (set-buffer-modified-p nil)
+ (setq buffer-undo-list nil)
+ (run-hooks 'text-mode-hook 'mq-edit-mode-hook))
+
+(defun mq-refresh-edit ()
+ "Refresh the topmost applied patch, editing the patch description."
+ (interactive)
+ (while mq-prev-buffer
+ (set-buffer mq-prev-buffer))
+ (let ((root (hg-root))
+ (prev-buffer (current-buffer))
+ (patch (mq-patch-info "qtop")))
+ (hg-sync-buffers root)
+ (let ((buf-name (format "*MQ: Edit description of %s*" patch)))
+ (switch-to-buffer (get-buffer-create buf-name))
+ (when (= (point-min) (point-max))
+ (set (make-local-variable 'hg-root) root)
+ (set (make-local-variable 'mq-top) patch)
+ (setq mq-prev-buffer prev-buffer)
+ (insert (hg-run0 "qheader"))
+ (goto-char (point-min)))
+ (mq-edit-mode)
+ (cd root)))
+ (message "Type `C-c C-c' to finish editing and refresh the patch."))
+
+
+(provide 'mq)
+
+
+;;; Local Variables:
+;;; prompt-to-byte-compile: nil
+;;; end:
--- a/doc/hgrc.5.txt
+++ b/doc/hgrc.5.txt
@@ -377,6 +377,9 @@ ui::
remote command to use for clone/push/pull operations. Default is 'hg'.
ssh;;
command to use for SSH connections. Default is 'ssh'.
+ strict;;
+ Require exact command names, instead of allowing unambiguous
+ abbreviations. True or False. Default is False.
timeout;;
The timeout used when a lock is held (in seconds), a negative value
means no timeout. Default is 600.
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -31,8 +31,9 @@ refresh contents of top applied patch
from mercurial.demandload import *
from mercurial.i18n import gettext as _
+from mercurial import commands
demandload(globals(), "os sys re struct traceback errno bz2")
-demandload(globals(), "mercurial:cmdutil,commands,hg,patch,revlog,ui,util")
+demandload(globals(), "mercurial:cmdutil,hg,patch,revlog,ui,util")
commands.norepo += " qclone qversion"
@@ -915,7 +916,7 @@ class queue:
def refresh(self, repo, pats=None, **opts):
if len(self.applied) == 0:
self.ui.write("No patches applied\n")
- return
+ return 1
wlock = repo.wlock()
self.check_toppatch(repo)
(top, patch) = (self.applied[-1].rev, self.applied[-1].name)
@@ -1237,11 +1238,13 @@ class queue:
self.ui.write(p + '\n')
else:
self.ui.write("No patches applied\n")
+ return 1
def next(self, repo):
end = self.series_end()
if end == len(self.series):
self.ui.write("All patches applied\n")
+ return 1
else:
p = self.series[end]
if self.ui.verbose:
@@ -1254,8 +1257,10 @@ class queue:
self.ui.write(p + '\n')
elif len(self.applied) == 1:
self.ui.write("Only one patch applied\n")
+ return 1
else:
self.ui.write("No patches applied\n")
+ return 1
def qimport(self, repo, files, patch=None, existing=None, force=None):
if len(files) > 1 and patch:
@@ -1402,18 +1407,15 @@ def series(ui, repo, **opts):
def top(ui, repo, **opts):
"""print the name of the current patch"""
- repo.mq.top(repo)
- return 0
+ return repo.mq.top(repo)
def next(ui, repo, **opts):
"""print the name of the next patch"""
- repo.mq.next(repo)
- return 0
+ return repo.mq.next(repo)
def prev(ui, repo, **opts):
"""print the name of the previous patch"""
- repo.mq.prev(repo)
- return 0
+ return repo.mq.prev(repo)
def new(ui, repo, patch, **opts):
"""create a new patch
@@ -1449,9 +1451,9 @@ def refresh(ui, repo, *pats, **opts):
patch = q.applied[-1].name
(message, comment, user, date, hasdiff) = q.readheaders(patch)
message = ui.edit('\n'.join(message), user or ui.username())
- q.refresh(repo, pats, msg=message, **opts)
+ ret = q.refresh(repo, pats, msg=message, **opts)
q.save_dirty()
- return 0
+ return ret
def diff(ui, repo, *pats, **opts):
"""diff of the current patch"""
@@ -1571,7 +1573,7 @@ def header(ui, repo, patch=None):
else:
if not q.applied:
ui.write('No patches applied\n')
- return
+ return 1
patch = q.lookup('qtip')
message = repo.mq.readheaders(patch)[0]
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -505,7 +505,7 @@ def help_(ui, name=None, with_version=Fa
if with_version:
show_version(ui)
ui.write('\n')
- aliases, i = findcmd(name)
+ aliases, i = findcmd(ui, name)
# synopsis
ui.write("%s\n\n" % i[2])
@@ -818,6 +818,7 @@ def backout(ui, repo, rev, **opts):
parent = p1
hg.clean(repo, node, show_stats=False)
revert_opts = opts.copy()
+ revert_opts['all'] = True
revert_opts['rev'] = hex(parent)
revert(ui, repo, **revert_opts)
commit_opts = opts.copy()
@@ -1151,7 +1152,7 @@ def debugcomplete(ui, cmd='', **opts):
options = []
otables = [globalopts]
if cmd:
- aliases, entry = findcmd(cmd)
+ aliases, entry = findcmd(ui, cmd)
otables.append(entry[1])
for t in otables:
for o in t:
@@ -1161,7 +1162,7 @@ def debugcomplete(ui, cmd='', **opts):
ui.write("%s\n" % "\n".join(options))
return
- clist = findpossible(cmd).keys()
+ clist = findpossible(ui, cmd).keys()
clist.sort()
ui.write("%s\n" % "\n".join(clist))
@@ -2286,8 +2287,12 @@ def revert(ui, repo, *pats, **opts):
If names are given, all files matching the names are reverted.
- If no arguments are given, all files in the repository are reverted.
+ If no arguments are given, no files are reverted.
"""
+
+ if not pats and not opts['all']:
+ raise util.Abort(_('no files or directories specified'))
+
parent, p2 = repo.dirstate.parents()
if opts['rev']:
node = repo.lookup(opts['rev'])
@@ -3046,7 +3051,8 @@ table = {
_('hg rename [OPTION]... SOURCE... DEST')),
"^revert":
(revert,
- [('r', 'rev', '', _('revision to revert to')),
+ [('a', 'all', None, _('revert all changes when no arguments given')),
+ ('r', 'rev', '', _('revision to revert to')),
('', 'no-backup', None, _('do not save backup copies of files')),
('I', 'include', [], _('include names matching given patterns')),
('X', 'exclude', [], _('exclude names matching given patterns')),
@@ -3145,7 +3151,7 @@ norepo = ("clone init version help debug
" debugindex debugindexdot")
optionalrepo = ("paths serve debugconfig")
-def findpossible(cmd):
+def findpossible(ui, cmd):
"""
Return cmd -> (aliases, command table entry)
for each matching command.
@@ -3158,7 +3164,7 @@ def findpossible(cmd):
found = None
if cmd in aliases:
found = cmd
- else:
+ elif not ui.config("ui", "strict"):
for a in aliases:
if a.startswith(cmd):
found = a
@@ -3174,9 +3180,9 @@ def findpossible(cmd):
return choice
-def findcmd(cmd):
+def findcmd(ui, cmd):
"""Return (aliases, command table entry) for command string."""
- choice = findpossible(cmd)
+ choice = findpossible(ui, cmd)
if choice.has_key(cmd):
return choice[cmd]
@@ -3211,7 +3217,7 @@ def parse(ui, args):
if args:
cmd, args = args[0], args[1:]
- aliases, i = findcmd(cmd)
+ aliases, i = findcmd(ui, cmd)
cmd = aliases[0]
defaults = ui.config("defaults", cmd)
if defaults:
--- a/mercurial/packagescan.py
+++ b/mercurial/packagescan.py
@@ -26,6 +26,7 @@ def demandload(scope, modules):
foo import foo
foo bar import foo, bar
foo.bar import foo.bar
+ foo@bar import foo as bar
foo:bar from foo import bar
foo:bar,quux from foo import bar, quux
foo.bar:quux from foo.bar import quux"""
@@ -38,6 +39,9 @@ def demandload(scope, modules):
except:
module = m
fromlist = []
+ as_ = None
+ if '@' in module:
+ module, as_ = module.split('@')
mod = __import__(module, scope, scope, fromlist)
if fromlist == []:
# mod is only the top package, but we need all packages
@@ -46,7 +50,9 @@ def demandload(scope, modules):
mn = comp[0]
while True:
# mn and mod.__name__ might not be the same
- scope[mn] = mod
+ if not as_:
+ as_ = mn
+ scope[as_] = mod
requiredmodules[mod.__name__] = 1
if len(comp) == i: break
mod = getattr(mod,comp[i])
--- a/tests/README
+++ b/tests/README
@@ -31,3 +31,65 @@ writing tests:
use hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
-e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
to strip dates
+
+- You can append your own hgrc settings to the file that the environment
+ variable HGRCPATH points to. This file is cleared before running a test.
+
+You also need to be careful that the tests are portable from one platform
+to another. You're probably working on Linux, where the GNU toolchain has
+more (or different) functionality than on MacOS, *BSD, Solaris, AIX, etc.
+While testing on all platforms is the only sure-fire way to make sure that
+you've written portable code, here's a list of problems that have been
+found and fixed in the tests. Another, more comprehensive list may be
+found in the GNU Autoconf manual, online here:
+
+ http://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html
+
+sh:
+
+The Bourne shell is a very basic shell. /bin/sh on Linux is typically
+bash, which even in Bourne-shell mode has many features that Bourne shells
+on other Unix systems don't have (and even on Linux /bin/sh isn't
+guaranteed to be bash). You'll need to be careful about constructs that
+seem ubiquitous, but are actually not available in the least common
+denominator. While using another shell (ksh, bash explicitly, posix shell,
+etc.) explicitly may seem like another option, these may not exist in a
+portable location, and so are generally probably not a good idea. You may
+find that rewriting the test in python will be easier.
+
+- don't use pushd/popd; save the output of "pwd" and use "cd" in place of
+ the pushd, and cd back to the saved pwd instead of popd.
+
+- don't use math expressions like let, (( ... )), or $(( ... )); use "expr"
+ instead.
+
+grep:
+
+- don't use the -q option; redirect stdout to /dev/null instead.
+
+- don't use extended regular expressions with grep; use egrep instead, and
+ don't escape any regex operators.
+
+sed:
+
+- make sure that the beginning-of-line matcher ("^") is at the very
+ beginning of the expression -- it may not be supported inside parens.
+
+echo:
+
+- echo may interpret "\n" and print a newline; use printf instead if you
+ want a literal "\n" (backslash + n).
+
+false:
+
+- false is guaranteed only to return a non-zero value; you cannot depend on
+ it being 1. On Solaris in particular, /bin/false returns 255. Rewrite
+ your test to not depend on a particular return value, or create a
+ temporary "false" executable, and call that instead.
+
+diff:
+
+- don't use the -N option. There's no particularly good workaround short
+ of writing a reasonably complicated replacement script, but substituting
+ gdiff for diff if you can't rewrite the test not to need -N will probably
+ do.
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -211,6 +211,10 @@ def run_one(test):
sys.stdout.write('.')
sys.stdout.flush()
+ # create a fresh hgrc
+ hgrc = file(HGRCPATH, 'w+')
+ hgrc.close()
+
err = os.path.join(TESTDIR, test+".err")
ref = os.path.join(TESTDIR, test+".out")
@@ -319,11 +323,11 @@ os.environ['TZ'] = 'GMT'
os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
os.environ["HGMERGE"] = sys.executable + ' -c "import sys; sys.exit(0)"'
os.environ["HGUSER"] = "test"
-os.environ["HGRCPATH"] = ""
TESTDIR = os.environ["TESTDIR"] = os.getcwd()
HGTMP = os.environ["HGTMP"] = tempfile.mkdtemp("", "hgtests.")
DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
+HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
vlog("# Using TESTDIR", TESTDIR)
vlog("# Using HGTMP", HGTMP)
--- a/tests/test-abort-checkin
+++ b/tests/test-abort-checkin
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
cat > $HGTMP/false <<EOF
#!/bin/sh
exit 1
--- a/tests/test-bisect
+++ b/tests/test-bisect
@@ -2,9 +2,8 @@
set -e
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "hbisect=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "hbisect=" >> $HGRCPATH
echo % init
hg init
--- a/tests/test-confused-revert
+++ b/tests/test-confused-revert
@@ -13,7 +13,7 @@ echo "%%% should show a removed and b ad
hg status
echo "reverting..."
-hg revert
+hg revert --all
echo "%%% should show b unknown and a back to normal"
hg status
@@ -42,10 +42,10 @@ echo "%%% should show a removed and b ad
hg status
echo "%%% revert should fail"
-hg revert
+hg revert --all
echo "%%% revert should be ok now"
-hg revert -r2
+hg revert -r2 --all
echo "%%% should show b unknown and a marked modified (merged)"
hg status
--- a/tests/test-extdiff
+++ b/tests/test-extdiff
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "extdiff=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "extdiff=" >> $HGRCPATH
hg init a
cd a
@@ -14,9 +13,9 @@ if [ $? -ne 0 ]; then
fi
hg extdiff -o -Nr $opt
-echo "[extdiff]" >> $HGTMP/.hgrc
-echo "cmd.falabala=echo" >> $HGTMP/.hgrc
-echo "opts.falabala=diffing" >> $HGTMP/.hgrc
+echo "[extdiff]" >> $HGRCPATH
+echo "cmd.falabala=echo" >> $HGRCPATH
+echo "opts.falabala=diffing" >> $HGRCPATH
hg falabala
--- a/tests/test-fetch
+++ b/tests/test-fetch
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "fetch=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "fetch=" >> $HGRCPATH
hg init a
echo a > a/a
--- a/tests/test-http
+++ b/tests/test-http
@@ -11,7 +11,7 @@ cat hg1.pid hg2.pid >> $DAEMON_PIDS
echo % clone via stream
http_proxy= hg clone --uncompressed http://localhost:20059/ copy 2>&1 | \
- sed -e 's/[0-9][0-9.]*/XXX/g'
+ sed -e 's/[0-9][0-9.]*/XXX/g' -e 's/.\(B\/sec\)/X\1/'
hg verify -R copy
echo % try to clone via stream, should use pull instead
--- a/tests/test-http.out
+++ b/tests/test-http.out
@@ -2,7 +2,7 @@ adding foo
% clone via stream
streaming all changes
XXX files to transfer, XXX bytes of data
-transferred XXX bytes in XXX seconds (XXX KB/sec)
+transferred XXX bytes in XXX seconds (XXX XB/sec)
XXX files updated, XXX files merged, XXX files removed, XXX files unresolved
checking changesets
checking manifests
--- a/tests/test-merge-revert
+++ b/tests/test-merge-revert
@@ -15,7 +15,7 @@ hg update -C 0
hg id
echo "changed file1" >> file1
hg id
-hg revert
+hg revert --all
hg diff
hg status
hg id
@@ -29,11 +29,11 @@ HGMERGE=merge hg update
hg diff
hg status
hg id
-hg revert
+hg revert --all
hg diff
hg status
hg id
-hg revert -r tip
+hg revert -r tip --all
hg diff
hg status
hg id
--- a/tests/test-merge-revert2
+++ b/tests/test-merge-revert2
@@ -16,7 +16,7 @@ hg update -C 0
hg id
echo "changed file1" >> file1
hg id
-hg revert --no-backup
+hg revert --no-backup --all
hg diff
hg status
hg id
@@ -31,11 +31,11 @@ hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-
-e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" -e "s/\(>>>>>>>\) .*/\1/"
hg status
hg id
-hg revert --no-backup
+hg revert --no-backup --all
hg diff
hg status
hg id
-hg revert -r tip --no-backup
+hg revert -r tip --no-backup --all
hg diff
hg status
hg id
--- a/tests/test-mq
+++ b/tests/test-mq
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
echo % help
hg help mq
@@ -127,7 +126,7 @@ hg ci -Ama
hg strip tip 2>&1 | sed 's/\(saving bundle to \).*/\1/'
hg unbundle .hg/strip-backup/*
-cat >>$HGTMP/.hgrc <<EOF
+cat >>$HGRCPATH <<EOF
[diff]
git = True
EOF
--- a/tests/test-mq-guards
+++ b/tests/test-mq-guards
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
hg init
hg qinit
--- a/tests/test-mq-qdiff
+++ b/tests/test-mq-qdiff
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
echo % init
hg init a
--- a/tests/test-mq-qnew-twice
+++ b/tests/test-mq-qnew-twice
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
hg init a
cd a
--- a/tests/test-mq-qrefresh-replace-log-message
+++ b/tests/test-mq-qrefresh-replace-log-message
@@ -1,9 +1,8 @@
#!/bin/sh
# Environement setup for MQ
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
#Repo init
hg init
--- a/tests/test-mq-qsave
+++ b/tests/test-mq-qsave
@@ -1,8 +1,7 @@
#!/bin/sh
-HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
-echo "[extensions]" >> $HGTMP/.hgrc
-echo "mq=" >> $HGTMP/.hgrc
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
hg init a
cd a
--- a/tests/test-nested-repo
+++ b/tests/test-nested-repo
@@ -14,6 +14,6 @@ hg add b/x
echo '# should print A b/x'
hg st
echo '# should forget b/x'
-hg revert
+hg revert --all
echo '# should print nothing'
hg st b
--- a/tests/test-remove
+++ b/tests/test-remove
@@ -9,7 +9,7 @@ hg commit -m 1 -d "1000000 0"
hg remove
rm foo
hg remove foo
-hg revert
+hg revert --all
rm foo
hg remove --after
hg commit -m 2 -d "1000000 0"
--- a/tests/test-revert
+++ b/tests/test-revert
@@ -31,7 +31,7 @@ echo %% should show a b c e
ls
echo %% should verbosely save backup to e.orig
echo z > e
-hg revert -v
+hg revert --all -v
echo %% should say no changes needed
hg revert a
echo %% should say file not managed
@@ -46,9 +46,9 @@ echo z > z
hg add z
hg st
echo %% should add a, forget z
-hg revert -r0
+hg revert --all -r0
echo %% should forget a
-hg revert -rtip
+hg revert --all -rtip
rm -f a *.orig
echo %% should silently add a
hg revert -r0 a
@@ -56,7 +56,7 @@ hg st a
hg update -C
chmod +x c
-hg revert
+hg revert --all
echo %% should print non-executable
test -x c || echo non-executable
@@ -64,7 +64,7 @@ chmod +x c
hg commit -d '1000001 0' -m exe
chmod -x c
-hg revert
+hg revert --all
echo %% should print executable
test -x c && echo executable
@@ -78,6 +78,11 @@ hg commit -d '2 0' -m a
hg update 0
mkdir b
echo b > b/b
+
+echo % should fail - no arguments
hg revert -rtip
+echo % should succeed
+hg revert --all -rtip
+
true
--- a/tests/test-revert-unknown
+++ b/tests/test-revert-unknown
@@ -13,7 +13,7 @@ hg ci -m "2" -d "1000000 0"
echo %% Should show unknown
hg status
-hg revert -r 0
+hg revert -r 0 --all
echo %% Should show unknown and b removed
hg status
echo %% Should show a and unknown
--- a/tests/test-revert.out
+++ b/tests/test-revert.out
@@ -54,4 +54,7 @@ executable
%% issue 241
adding a
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% should fail - no arguments
+abort: no files or directories specified
+% should succeed
reverting a
new file mode 100755
--- /dev/null
+++ b/tests/test-strict
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+hg init
+
+echo a > a
+hg ci -d '0 0' -Ama
+
+hg an a
+
+echo "[ui]" >> $HGRCPATH
+echo "strict=True" >> $HGRCPATH
+
+hg an a
+hg annotate a
+
+echo % should succeed - up is an alias, not an abbreviation
+
+hg up
new file mode 100644
--- /dev/null
+++ b/tests/test-strict.out
@@ -0,0 +1,26 @@
+adding a
+0: a
+hg: unknown command 'an'
+Mercurial Distributed SCM
+
+basic commands (use "hg help" for the full list or option "-v" for details):
+
+ add add the specified files on the next commit
+ annotate show changeset information per file line
+ clone make a copy of an existing repository
+ commit commit the specified files or all outstanding changes
+ diff diff repository (or selected files)
+ export dump the header and diffs for one or more changesets
+ init create a new repository in the given directory
+ log show revision history of entire repository or files
+ parents show the parents of the working dir or revision
+ pull pull changes from the specified source
+ push push changes to the specified destination
+ remove remove the specified files on the next commit
+ revert revert files or dirs to their states as of some revision
+ serve export the repository via HTTP
+ status show changed files in the working directory
+ update update or merge working directory
+0: a
+% should succeed - up is an alias, not an abbreviation
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved