Mercurial > hg
annotate contrib/hg-test-mode.el @ 27142:060f83d219b9
extensions: refuse to load extensions if minimum hg version not met
As the author of several 3rd party extensions, I frequently see bug
reports from users attempting to run my extension with an old version
of Mercurial that I no longer support in my extension. Oftentimes, the
extension will import just fine. But as soon as we run extsetup(),
reposetup(), or get into the guts of a wrapped function, we encounter
an exception and abort. Today, Mercurial will print a message about
extensions that don't have a "testedwith" declaring explicit
compatibility with the current version.
The existing mechanism is a good start. But it isn't as robust as I
would like. Specifically, Mercurial assumes compatibility by default.
This means extension authors must perform compatibility checking in
their extsetup() or we wait and see if we encounter an abort at
runtime. And, compatibility checking can involve a lot of code and
lots of error checking. It's a lot of effort for extension authors.
Oftentimes, extension authors know which versions of Mercurial there
extension works on and more importantly where it is broken.
This patch introduces a magic "minimumhgversion" attribute in
extensions. When found, the extension loading mechanism will compare
the declared version against the current Mercurial version. If the
extension explicitly states we require a newer Mercurial version, a
warning is printed and the extension isn't loaded beyond importing
the Python module. This causes a graceful failure while alerting
the user of the compatibility issue.
I would be receptive to the idea of making the failure more fatal.
However, care would need to be taken to not criple every hg command.
e.g. the user may use `hg config` to fix the hgrc and if we aborted
trying to run that, the user would effectively be locked out of `hg`!
A potential future improvement to this functionality would be to catch
ImportError for the extension/module and parse the source code for
"minimumhgversion = 'XXX'" and do similar checking. This way we could
give more information about why the extension failed to load.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 24 Nov 2015 15:16:25 -0800 |
parents | 7fce964be27d |
children | b6a757de2fff |
rev | line source |
---|---|
22081
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 ;; hg-test-mode.el - Major mode for editing Mercurial tests |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 ;; |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 ;; Copyright 2014 Matt Mackall <mpm@selenic.com> |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 ;; "I have no idea what I'm doing" |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 ;; |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 ;; This software may be used and distributed according to the terms of the |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 ;; GNU General Public License version 2 or any later version. |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
8 ;; |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 ;; To enable, add something like the following to your .emacs: |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
10 ;; |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
11 ;; (if (file-exists-p "~/hg/contrib/hg-test-mode.el") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 ;; (load "~/hg/contrib/hg-test-mode.el")) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 (defvar hg-test-mode-hook nil) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 (defvar hg-test-mode-map |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 (let ((map (make-keymap))) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
18 (define-key map "\C-j" 'newline-and-indent) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 map) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
20 "Keymap for hg test major mode") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
21 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 (add-to-list 'auto-mode-alist '("\\.t\\'" . hg-test-mode)) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
23 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
24 (defconst hg-test-font-lock-keywords-1 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
25 (list |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
26 '("^ \\(\\$\\|>>>\\) " 1 font-lock-builtin-face) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
27 '("^ \\(>\\|\\.\\.\\.\\) " 1 font-lock-constant-face) |
22125
7fce964be27d
hg-test-mode: make exit code highlight work again
Matt Mackall <mpm@selenic.com>
parents:
22109
diff
changeset
|
28 '("^ \\([[][0-9]+[]]\\)$" 1 font-lock-warning-face) |
22109
feab93a24e81
hg-test-mode: don't highlight variables in output
Matt Mackall <mpm@selenic.com>
parents:
22092
diff
changeset
|
29 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)*\\)$" 1 font-lock-string-face) |
22092
6e5ff8e26af6
hg-test-mode: colorize HGFOO and TESTFOO environment variables
Matt Mackall <mpm@selenic.com>
parents:
22081
diff
changeset
|
30 '("\\$?\\(HG\\|TEST\\)\\w+=?" . font-lock-variable-name-face) |
22081
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
31 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)+\\)$" 2 font-lock-type-face) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
32 '("^#.*" . font-lock-preprocessor-face) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 '("^\\([^ ].*\\)$" 1 font-lock-comment-face) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
34 ) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
35 "Minimal highlighting expressions for hg-test mode") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
36 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
37 (defvar hg-test-font-lock-keywords hg-test-font-lock-keywords-1 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
38 "Default highlighting expressions for hg-test mode") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
39 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
40 (defvar hg-test-mode-syntax-table |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
41 (let ((st (make-syntax-table))) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
42 (modify-syntax-entry ?\" "w" st) ;; disable standard quoting |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
43 st) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
44 "Syntax table for hg-test mode") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
45 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 (defun hg-test-mode () |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 (interactive) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
48 (kill-all-local-variables) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 (use-local-map hg-test-mode-map) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 (set-syntax-table hg-test-mode-syntax-table) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
51 (set (make-local-variable 'font-lock-defaults) '(hg-test-font-lock-keywords)) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
52 (setq major-mode 'hg-test-mode) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
53 (setq mode-name "hg-test") |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
54 (run-hooks 'hg-test-mode-hook)) |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
55 |
ed426b011612
contrib: add emacs mode for *.t files
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 (provide 'hg-test-mode) |