Mercurial > hg
changeset 3011:6e49bb42620b
merge.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Wed, 23 Aug 2006 08:42:21 -0700 |
parents | 06696f9c30c0 (diff) 962b9c7df641 (current diff) |
children | abcd6ae3cf5a |
files | |
diffstat | 31 files changed, 587 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Aug 22 19:12:09 2006 -0500 +++ b/.hgignore Wed Aug 23 08:42:21 2006 -0700 @@ -21,6 +21,7 @@ MANIFEST patches mercurial/__version__.py +.DS_Store syntax: regexp ^\.pc/
--- a/contrib/mercurial.el Tue Aug 22 19:12:09 2006 -0500 +++ b/contrib/mercurial.el Wed Aug 23 08:42:21 2006 -0700 @@ -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 @@ (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 @@ (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 @@ '(("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 @@ (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 @@ ;;; 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 @@ 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 @@ (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 @@ (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 @@ (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 @@ 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.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/mq.el Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/doc/hgrc.5.txt Wed Aug 23 08:42:21 2006 -0700 @@ -377,6 +377,9 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/hgext/mq.py Wed Aug 23 08:42:21 2006 -0700 @@ -31,8 +31,9 @@ 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 @@ 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 @@ 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 @@ 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 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 @@ 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 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/mercurial/commands.py Wed Aug 23 08:42:21 2006 -0700 @@ -505,7 +505,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ _('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 @@ " 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 @@ 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 @@ 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 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/mercurial/packagescan.py Wed Aug 23 08:42:21 2006 -0700 @@ -26,6 +26,7 @@ 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 @@ 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 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/README Wed Aug 23 08:42:21 2006 -0700 @@ -31,3 +31,65 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/run-tests.py Wed Aug 23 08:42:21 2006 -0700 @@ -211,6 +211,10 @@ 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["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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-abort-checkin Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-bisect Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-confused-revert Wed Aug 23 08:42:21 2006 -0700 @@ -13,7 +13,7 @@ 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 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-extdiff Wed Aug 23 08:42:21 2006 -0700 @@ -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 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-fetch Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-http Wed Aug 23 08:42:21 2006 -0700 @@ -11,7 +11,7 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-http.out Wed Aug 23 08:42:21 2006 -0700 @@ -2,7 +2,7 @@ % 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-merge-revert Wed Aug 23 08:42:21 2006 -0700 @@ -15,7 +15,7 @@ hg id echo "changed file1" >> file1 hg id -hg revert +hg revert --all hg diff hg status hg id @@ -29,11 +29,11 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-merge-revert2 Wed Aug 23 08:42:21 2006 -0700 @@ -16,7 +16,7 @@ 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 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq Wed Aug 23 08:42:21 2006 -0700 @@ -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 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq-guards Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq-qdiff Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq-qnew-twice Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq-qrefresh-replace-log-message Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-mq-qsave Wed Aug 23 08:42:21 2006 -0700 @@ -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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-nested-repo Wed Aug 23 08:42:21 2006 -0700 @@ -14,6 +14,6 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-remove Wed Aug 23 08:42:21 2006 -0700 @@ -9,7 +9,7 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-revert Wed Aug 23 08:42:21 2006 -0700 @@ -31,7 +31,7 @@ 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 @@ 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 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 @@ 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 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-revert-unknown Wed Aug 23 08:42:21 2006 -0700 @@ -13,7 +13,7 @@ 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 Tue Aug 22 19:12:09 2006 -0500 +++ b/tests/test-revert.out Wed Aug 23 08:42:21 2006 -0700 @@ -54,4 +54,7 @@ %% 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-strict Wed Aug 23 08:42:21 2006 -0700 @@ -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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-strict.out Wed Aug 23 08:42:21 2006 -0700 @@ -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