Mercurial > emacs
annotate lisp/vc-hg.el @ 81723:4e74ad9f4345
(eval-last-sexp): Avoid introducing any
dynamic bindings around the evaluation of the expression.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Fri, 06 Jul 2007 17:26:29 +0000 |
parents | 88604a3ac7e4 |
children | b7c76df62fba |
rev | line source |
---|---|
81474 | 1 ;;; vc-hg.el --- VC backend for the mercurial version control system |
2 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
4 |
81474 | 5 ;; Author: Ivan Kanis |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
6 ;; Keywords: tools |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
7 ;; Version: 1889 |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
8 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
10 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
81474 | 12 ;; it under the terms of the GNU General Public License as published by |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
14 ;; any later version. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
15 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
19 ;; GNU General Public License for more details. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
20 |
81474 | 21 ;; You should have received a copy of the GNU General Public License |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
81474 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This is a mercurial version control backend | |
29 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
30 ;;; Thanks: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
31 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
32 ;;; Bugs: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
33 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
34 ;;; Installation: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
35 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
36 ;;; Todo: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
37 |
81526 | 38 ;; Implement the rest of the vc interface: |
39 ;; - dired | |
40 ;; - snapshot? | |
81474 | 41 |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
42 ;; Implement Stefan Monnier's advice: |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
43 ;; vc-hg-registered and vc-hg-state |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
44 ;; Both of those functions should be super extra careful to fail gracefully in |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
45 ;; unexpected circumstances. The most important such case is when the `hg' |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
46 ;; executable is not available. The reason this is important is that any error |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
47 ;; there will prevent the user from even looking at the file :-( |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
48 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
49 ;; mercurial's control and extracting the current revision should be done |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
50 ;; without even using `hg' (this way even if you don't have `hg' installed, |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
51 ;; Emacs is able to tell you this file is under mercurial's control). |
81474 | 52 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
53 ;;; History: |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
54 ;; |
81474 | 55 |
56 ;;; Code: | |
57 | |
58 (eval-when-compile | |
59 (require 'vc)) | |
60 | |
61 ;;; Customization options | |
62 | |
63 (defcustom vc-hg-global-switches nil | |
64 "*Global switches to pass to any Hg command." | |
65 :type '(choice (const :tag "None" nil) | |
66 (string :tag "Argument String") | |
67 (repeat :tag "Argument List" | |
68 :value ("") | |
69 string)) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
70 ;; :version "22.2" |
81474 | 71 :group 'vc) |
72 | |
73 ;;; State querying functions | |
74 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
75 ;;;###autoload (defun vc-hg-registered (file) |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
76 ;;;###autoload "Return non-nil if FILE is registered with hg." |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
77 ;;;###autoload (if (vc-find-root file ".hg") ; short cut |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
78 ;;;###autoload (progn |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
79 ;;;###autoload (load "vc-hg") |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
80 ;;;###autoload (vc-hg-registered file)))) |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
81 |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
82 ;; Modelled after the similar function in vc-bzr.el |
81474 | 83 (defun vc-hg-registered (file) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
84 "Return non-nil if FILE is registered with hg." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
85 (if (vc-find-root file ".hg") ; short cut |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
86 (vc-hg-state file))) ; expensive |
81474 | 87 |
88 (defun vc-hg-state (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
89 "Hg-specific version of `vc-state'." |
81702
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
90 (let* |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
91 ((status nil) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
92 (out |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
93 (with-output-to-string |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
94 (with-current-buffer |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
95 standard-output |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
96 (setq status |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
97 (condition-case nil |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
98 ;; Ignore all errors. |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
99 (call-process |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
100 "hg" nil t nil "--cwd" (file-name-directory file) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
101 "status" (file-name-nondirectory file)) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
102 ;; Some problem happened. E.g. We can't find an `hg' |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
103 ;; executable. |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
104 (error nil))))))) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
105 (when (eq 0 status) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
106 (if (eq 0 (length out)) 'up-to-date |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
107 (let ((state (aref out 0))) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
108 (cond |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
109 ((eq state ?M) 'edited) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
110 ((eq state ?A) 'edited) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
111 ((eq state ?P) 'needs-patch) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
112 ((eq state ??) nil) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
113 (t 'up-to-date))))))) |
81474 | 114 |
115 (defun vc-hg-workfile-version (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
116 "Hg-specific version of `vc-workfile-version'." |
81702
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
117 (let* |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
118 ((status nil) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
119 (out |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
120 (with-output-to-string |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
121 (with-current-buffer |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
122 standard-output |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
123 (setq status |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
124 (condition-case nil |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
125 ;; Ignore all errors. |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
126 (call-process |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
127 "hg" nil t nil "--cwd" (file-name-directory file) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
128 "log" "-l1" (file-name-nondirectory file)) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
129 ;; Some problem happened. E.g. We can't find an `hg' |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
130 ;; executable. |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
131 (error nil))))))) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
132 (when (eq 0 status) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
133 (if (string-match "changeset: *\\([0-9]*\\)" out) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
134 (match-string 1 out) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
135 "0")))) |
81474 | 136 |
137 ;;; History functions | |
138 | |
139 (defun vc-hg-print-log(file &optional buffer) | |
140 "Get change log associated with FILE." | |
81564
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
141 ;; `log-view-mode' needs to have the file name in order to function |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
142 ;; correctly. "hg log" does not print it, so we insert it here by |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
143 ;; hand. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
144 |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
145 ;; `vc-do-command' creates the buffer, but we need it before running |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
146 ;; the command. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
147 (vc-setup-buffer buffer) |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
148 ;; If the buffer exists from a previous invocation it might be |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
149 ;; read-only. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
150 (let ((inhibit-read-only t)) |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
151 (with-current-buffer |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
152 buffer |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
153 (insert "File: " (file-name-nondirectory file) "\n"))) |
81474 | 154 (vc-hg-command |
155 buffer | |
156 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
157 file "log")) | |
158 | |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
159 (defvar log-view-message-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
160 (defvar log-view-file-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
161 (defvar log-view-font-lock-keywords) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
162 |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
163 (define-derived-mode vc-hg-log-view-mode log-view-mode "HG-Log-View" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
164 (require 'add-log) ;; we need the faces add-log |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
165 ;; Don't have file markers, so use impossible regexp. |
81564
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
166 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
167 (set (make-local-variable 'log-view-message-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
168 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)") |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
169 (set (make-local-variable 'log-view-font-lock-keywords) |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
170 (append |
81575
cea1e05b3c83
* vc-hg.el (vc-hg-log-view-mode): Revert incorrect change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81572
diff
changeset
|
171 log-view-font-lock-keywords |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
172 ;; Handle the case: |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
173 ;; user: foo@bar |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
174 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
175 (1 'change-log-email)) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
176 ;; Handle the case: |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
177 ;; user: FirstName LastName <foo@bar> |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
178 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
179 (1 'change-log-name) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
180 (2 'change-log-email)) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
181 ("^date: \\(.+\\)" (1 'change-log-date)) |
81575
cea1e05b3c83
* vc-hg.el (vc-hg-log-view-mode): Revert incorrect change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81572
diff
changeset
|
182 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
183 |
81526 | 184 (defun vc-hg-diff (file &optional oldvers newvers buffer) |
81474 | 185 "Get a difference report using hg between two versions of FILE." |
81526 | 186 (let ((working (vc-workfile-version file))) |
187 (if (and (equal oldvers working) (not newvers)) | |
188 (setq oldvers nil)) | |
189 (if (and (not oldvers) newvers) | |
190 (setq oldvers working)) | |
191 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
192 "--cwd" (file-name-directory file) "diff" |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
193 (append |
81526 | 194 (if oldvers |
195 (if newvers | |
196 (list "-r" oldvers "-r" newvers) | |
197 (list "-r" oldvers)) | |
198 (list "")) | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
199 (list (file-name-nondirectory file)))))) |
81526 | 200 |
201 (defun vc-hg-annotate-command (file buffer &optional version) | |
202 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. | |
203 Optional arg VERSION is a version to annotate from." | |
204 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) | |
205 (with-current-buffer buffer | |
206 (goto-char (point-min)) | |
207 (re-search-forward "^[0-9]") | |
208 (delete-region (point-min) (1- (point))))) | |
209 | |
210 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
211 ;; The format for one line output by "hg annotate -d -n" looks like this: |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
212 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
213 ;; i.e: VERSION_NUMBER DATE: CONTENTS |
81526 | 214 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ") |
215 | |
216 (defun vc-hg-annotate-time () | |
217 (when (looking-at vc-hg-annotate-re) | |
218 (goto-char (match-end 0)) | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
219 (vc-annotate-convert-time |
81526 | 220 (date-to-time (match-string-no-properties 2))))) |
221 | |
222 (defun vc-hg-annotate-extract-revision-at-line () | |
223 (save-excursion | |
224 (beginning-of-line) | |
225 (if (looking-at vc-hg-annotate-re) (match-string-no-properties 1)))) | |
226 | |
227 (defun vc-hg-previous-version (file rev) | |
228 (let ((newrev (1- (string-to-number rev)))) | |
229 (when (>= newrev 0) | |
230 (number-to-string newrev)))) | |
81474 | 231 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
232 (defun vc-hg-register (file &optional rev comment) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
233 "Register FILE under hg. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
234 REV is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
235 COMMENT is ignored." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
236 (vc-hg-command nil nil file "add")) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
237 |
81526 | 238 (defun vc-hg-checkin (file rev comment) |
239 "HG-specific version of `vc-backend-checkin'. | |
240 REV is ignored." | |
241 (vc-hg-command nil nil file "commit" "-m" comment)) | |
242 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
243 ;; Modelled after the similar function in vc-bzr.el |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
244 (defun vc-hg-checkout (file &optional editable rev workfile) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
245 "Retrieve a revision of FILE into a WORKFILE. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
246 EDITABLE is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
247 REV is the revision to check out into WORKFILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
248 (unless workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
249 (setq workfile (vc-version-backup-file-name file rev))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
250 (let ((coding-system-for-read 'binary) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
251 (coding-system-for-write 'binary)) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
252 (with-temp-file workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
253 (if rev |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
254 (vc-hg-command t nil file "cat" "-r" rev) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
255 (vc-hg-command t nil file "cat"))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
256 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
257 (defun vc-hg-checkout-model (file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
258 'implicit) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
259 |
81702
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
260 ;; Modelled after the similar function in vc-bzr.el |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
261 (defun vc-hg-revert (file &optional contents-done) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
262 (unless contents-done |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
263 (with-temp-buffer (vc-hg-command t nil file "revert")))) |
fc97b55f9678
* vc-hg.el (vc-hg-internal-status): Inline in `vc-hg-state', the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81575
diff
changeset
|
264 |
81474 | 265 ;;; Internal functions |
266 | |
267 (defun vc-hg-command (buffer okstatus file &rest flags) | |
268 "A wrapper around `vc-do-command' for use in vc-hg.el. | |
269 The difference to vc-do-command is that this function always invokes `hg', | |
270 and that it passes `vc-hg-global-switches' to it before FLAGS." | |
271 (apply 'vc-do-command buffer okstatus "hg" file | |
272 (if (stringp vc-hg-global-switches) | |
273 (cons vc-hg-global-switches flags) | |
274 (append vc-hg-global-switches | |
275 flags)))) | |
276 | |
277 (provide 'vc-hg) | |
278 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
279 ;;; vc-hg.el ends here |