Mercurial > emacs
annotate lisp/vc-hg.el @ 79709:b6fdfff4ae81
Add 2008 to copyright years.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 07 Jan 2008 01:26:07 +0000 |
parents | 2fe98820fa48 |
children | 73661ddc7ac7 |
rev | line source |
---|---|
78075 | 1 ;;; vc-hg.el --- VC backend for the mercurial version control system |
2 | |
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Ivan Kanis | |
6 ;; Keywords: tools | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
78211
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
78075 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 ;; Boston, MA 02110-1301, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This is a mercurial version control backend | |
28 | |
29 ;;; Thanks: | |
30 | |
31 ;;; Bugs: | |
32 | |
33 ;;; Installation: | |
34 | |
35 ;;; Todo: | |
36 | |
37 ;; Implement the rest of the vc interface. See the comment at the | |
38 ;; beginning of vc.el. The current status is: | |
39 | |
40 ;; FUNCTION NAME STATUS | |
41 ;; * registered (file) OK | |
42 ;; * state (file) OK | |
43 ;; - state-heuristic (file) ?? PROBABLY NOT NEEDED | |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
44 ;; - dir-state (dir) OK |
78075 | 45 ;; * workfile-version (file) OK |
46 ;; - latest-on-branch-p (file) ?? | |
47 ;; * checkout-model (file) OK | |
78167
252b7f091c04
(vc-hg-workfile-unchanged-p): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78166
diff
changeset
|
48 ;; - workfile-unchanged-p (file) OK |
78075 | 49 ;; - mode-line-string (file) NOT NEEDED |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
50 ;; - dired-state-info (file) OK |
78075 | 51 ;; STATE-CHANGING FUNCTIONS |
52 ;; * register (file &optional rev comment) OK | |
53 ;; - init-version () NOT NEEDED | |
54 ;; - responsible-p (file) OK | |
55 ;; - could-register (file) OK | |
56 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED | |
57 ;; - unregister (file) COMMENTED OUT, MAY BE INCORRECT | |
58 ;; * checkin (file rev comment) OK | |
59 ;; * find-version (file rev buffer) OK | |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
60 ;; * checkout (file &optional editable rev) OK |
78075 | 61 ;; * revert (file &optional contents-done) OK |
62 ;; - cancel-version (file editable) ?? PROBABLY NOT NEEDED | |
63 ;; - merge (file rev1 rev2) NEEDED | |
64 ;; - merge-news (file) NEEDED | |
65 ;; - steal-lock (file &optional version) NOT NEEDED | |
66 ;; HISTORY FUNCTIONS | |
67 ;; * print-log (file &optional buffer) OK | |
68 ;; - log-view-mode () OK | |
69 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD | |
70 ;; - wash-log (file) ?? | |
71 ;; - logentry-check () NOT NEEDED | |
72 ;; - comment-history (file) NOT NEEDED | |
73 ;; - update-changelog (files) NOT NEEDED | |
74 ;; * diff (file &optional rev1 rev2 buffer) OK | |
78211
ce0473a5b031
(vc-hg-revision-completion-table): Temporarily comment
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78182
diff
changeset
|
75 ;; - revision-completion-table (file) COMMENTED OUT AS A WORKAROUND FOR A BUG |
78075 | 76 ;; - diff-tree (dir &optional rev1 rev2) TEST IT |
77 ;; - annotate-command (file buf &optional rev) OK | |
78 ;; - annotate-time () OK | |
79 ;; - annotate-current-time () ?? NOT NEEDED | |
80 ;; - annotate-extract-revision-at-line () OK | |
81 ;; SNAPSHOT SYSTEM | |
82 ;; - create-snapshot (dir name branchp) NEEDED (probably branch?) | |
83 ;; - assign-name (file name) NOT NEEDED | |
84 ;; - retrieve-snapshot (dir name update) ?? NEEDED?? | |
85 ;; MISCELLANEOUS | |
86 ;; - make-version-backups-p (file) ?? | |
87 ;; - repository-hostname (dirname) ?? | |
88 ;; - previous-version (file rev) OK | |
89 ;; - next-version (file rev) OK | |
90 ;; - check-headers () ?? | |
91 ;; - clear-headers () ?? | |
92 ;; - delete-file (file) TEST IT | |
93 ;; - rename-file (old new) OK | |
94 ;; - find-file-hook () PROBABLY NOT NEEDED | |
95 ;; - find-file-not-found-hook () PROBABLY NOT NEEDED | |
96 | |
97 ;; Implement Stefan Monnier's advice: | |
98 ;; vc-hg-registered and vc-hg-state | |
99 ;; Both of those functions should be super extra careful to fail gracefully in | |
100 ;; unexpected circumstances. The reason this is important is that any error | |
101 ;; there will prevent the user from even looking at the file :-( | |
102 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under | |
103 ;; mercurial's control and extracting the current revision should be done | |
104 ;; without even using `hg' (this way even if you don't have `hg' installed, | |
105 ;; Emacs is able to tell you this file is under mercurial's control). | |
106 | |
107 ;;; History: | |
108 ;; | |
109 | |
110 ;;; Code: | |
111 | |
112 (eval-when-compile | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
113 (require 'cl) |
78075 | 114 (require 'vc)) |
115 | |
116 ;;; Customization options | |
117 | |
118 (defcustom vc-hg-global-switches nil | |
119 "*Global switches to pass to any Hg command." | |
120 :type '(choice (const :tag "None" nil) | |
121 (string :tag "Argument String") | |
122 (repeat :tag "Argument List" | |
123 :value ("") | |
124 string)) | |
125 :version "22.2" | |
126 :group 'vc) | |
127 | |
128 ;;; State querying functions | |
129 | |
130 ;;;###autoload (defun vc-hg-registered (file) | |
131 ;;;###autoload "Return non-nil if FILE is registered with hg." | |
132 ;;;###autoload (if (vc-find-root file ".hg") ; short cut | |
133 ;;;###autoload (progn | |
134 ;;;###autoload (load "vc-hg") | |
135 ;;;###autoload (vc-hg-registered file)))) | |
136 | |
137 ;; Modelled after the similar function in vc-bzr.el | |
138 (defun vc-hg-registered (file) | |
139 "Return non-nil if FILE is registered with hg." | |
78166
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
140 (when (vc-hg-root file) ; short cut |
78363
9b9e30a9b135
* vc-hg.el (vc-hg-registered): Set the vc-state property.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78359
diff
changeset
|
141 (vc-file-setprop file 'vc-state (vc-hg-state file)))) ; expensive |
78075 | 142 |
143 (defun vc-hg-state (file) | |
144 "Hg-specific version of `vc-state'." | |
145 (let* | |
146 ((status nil) | |
147 (out | |
148 (with-output-to-string | |
149 (with-current-buffer | |
150 standard-output | |
151 (setq status | |
152 (condition-case nil | |
153 ;; Ignore all errors. | |
154 (call-process | |
155 "hg" nil t nil "--cwd" (file-name-directory file) | |
156 "status" (file-name-nondirectory file)) | |
157 ;; Some problem happened. E.g. We can't find an `hg' | |
158 ;; executable. | |
159 (error nil))))))) | |
160 (when (eq 0 status) | |
161 (if (eq 0 (length out)) 'up-to-date | |
78166
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
162 (when (null (string-match ".*: No such file or directory$" out)) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
163 (let ((state (aref out 0))) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
164 (cond |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
165 ((eq state ?A) 'edited) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
166 ((eq state ?M) 'edited) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
167 ((eq state ?R) nil) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
168 ((eq state ??) nil) |
516805bc7988
(vc-hg-registered): Replace if with when.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78148
diff
changeset
|
169 (t 'up-to-date)))))))) |
78075 | 170 |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
171 (defun vc-hg-dir-state (dir) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
172 (with-temp-buffer |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
173 (vc-hg-command (current-buffer) nil nil "status") |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
174 (goto-char (point-min)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
175 (let ((status-char nil) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
176 (file nil)) |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
177 (while (not (eobp)) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
178 (setq status-char (char-after)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
179 (setq file |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
180 (expand-file-name |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
181 (buffer-substring-no-properties (+ (point) 2) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
182 (line-end-position)))) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
183 (cond |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
184 ;; The rest of the possible states in "hg status" output: |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
185 ;; R = removed |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
186 ;; ! = deleted, but still tracked |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
187 ;; ? = not tracked |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
188 ;; should not show up in vc-dired, so don't deal with them |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
189 ;; here. |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
190 ((eq status-char ?A) |
79687
2fe98820fa48
* vc-git.el (vc-git-dir-state):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78404
diff
changeset
|
191 (vc-file-setprop file 'vc-backend 'Hg) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
192 (vc-file-setprop file 'vc-workfile-version "0") |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
193 (vc-file-setprop file 'vc-state 'edited)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
194 ((eq status-char ?M) |
79687
2fe98820fa48
* vc-git.el (vc-git-dir-state):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78404
diff
changeset
|
195 (vc-file-setprop file 'vc-backend 'Hg) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
196 (vc-file-setprop file 'vc-state 'edited)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
197 ((eq status-char ??) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
198 (vc-file-setprop file 'vc-backend 'none) |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
199 (vc-file-setprop file 'vc-state 'nil))) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
200 (forward-line))))) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
201 |
78075 | 202 (defun vc-hg-workfile-version (file) |
203 "Hg-specific version of `vc-workfile-version'." | |
204 (let* | |
205 ((status nil) | |
206 (out | |
207 (with-output-to-string | |
208 (with-current-buffer | |
209 standard-output | |
210 (setq status | |
211 (condition-case nil | |
212 ;; Ignore all errors. | |
213 (call-process | |
214 "hg" nil t nil "--cwd" (file-name-directory file) | |
215 "log" "-l1" (file-name-nondirectory file)) | |
216 ;; Some problem happened. E.g. We can't find an `hg' | |
217 ;; executable. | |
218 (error nil))))))) | |
219 (when (eq 0 status) | |
220 (if (string-match "changeset: *\\([0-9]*\\)" out) | |
221 (match-string 1 out) | |
222 "0")))) | |
223 | |
224 ;;; History functions | |
225 | |
226 (defun vc-hg-print-log(file &optional buffer) | |
227 "Get change log associated with FILE." | |
228 ;; `log-view-mode' needs to have the file name in order to function | |
229 ;; correctly. "hg log" does not print it, so we insert it here by | |
230 ;; hand. | |
231 | |
232 ;; `vc-do-command' creates the buffer, but we need it before running | |
233 ;; the command. | |
234 (vc-setup-buffer buffer) | |
235 ;; If the buffer exists from a previous invocation it might be | |
236 ;; read-only. | |
237 (let ((inhibit-read-only t)) | |
238 (with-current-buffer | |
239 buffer | |
240 (insert "File: " (file-name-nondirectory file) "\n"))) | |
241 (vc-hg-command | |
242 buffer | |
243 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
244 file "log")) | |
245 | |
246 (defvar log-view-message-re) | |
247 (defvar log-view-file-re) | |
248 (defvar log-view-font-lock-keywords) | |
249 | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78363
diff
changeset
|
250 (define-derived-mode vc-hg-log-view-mode log-view-mode "Hg-Log-View" |
78075 | 251 (require 'add-log) ;; we need the faces add-log |
252 ;; Don't have file markers, so use impossible regexp. | |
253 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") | |
254 (set (make-local-variable 'log-view-message-re) | |
255 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)") | |
256 (set (make-local-variable 'log-view-font-lock-keywords) | |
257 (append | |
258 log-view-font-lock-keywords | |
259 ;; Handle the case: | |
260 ;; user: foo@bar | |
261 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" | |
262 (1 'change-log-email)) | |
263 ;; Handle the case: | |
264 ;; user: FirstName LastName <foo@bar> | |
265 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" | |
266 (1 'change-log-name) | |
267 (2 'change-log-email)) | |
268 ("^date: \\(.+\\)" (1 'change-log-date)) | |
269 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) | |
270 | |
271 (defun vc-hg-diff (file &optional oldvers newvers buffer) | |
272 "Get a difference report using hg between two versions of FILE." | |
273 (let ((working (vc-workfile-version file))) | |
274 (if (and (equal oldvers working) (not newvers)) | |
275 (setq oldvers nil)) | |
276 (if (and (not oldvers) newvers) | |
277 (setq oldvers working)) | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
278 (apply #'vc-hg-command (or buffer "*vc-diff*") nil |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
279 (file-name-nondirectory file) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
280 "--cwd" (file-name-directory file) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
281 "diff" |
78075 | 282 (append |
283 (if oldvers | |
284 (if newvers | |
285 (list "-r" oldvers "-r" newvers) | |
286 (list "-r" oldvers)) | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
287 (list "")))))) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
288 |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
289 (defun vc-hg-revision-table (file) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
290 (let ((default-directory (file-name-directory file))) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
291 (with-temp-buffer |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
292 (vc-hg-command t nil file "log" "--template" "{rev} ") |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
293 (split-string |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
294 (buffer-substring-no-properties (point-min) (point-max)))))) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
295 |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
296 ;; Modelled after the similar function in vc-cvs.el |
78359
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
297 (defun vc-hg-revision-completion-table (file) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
298 (lexical-let ((file file) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
299 table) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
300 (setq table (lazy-completion-table |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
301 table (lambda () (vc-hg-revision-table file)))) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78236
diff
changeset
|
302 table)) |
78075 | 303 |
304 (defalias 'vc-hg-diff-tree 'vc-hg-diff) | |
305 | |
306 (defun vc-hg-annotate-command (file buffer &optional version) | |
307 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. | |
308 Optional arg VERSION is a version to annotate from." | |
309 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) | |
310 (with-current-buffer buffer | |
311 (goto-char (point-min)) | |
312 (re-search-forward "^[0-9]") | |
313 (delete-region (point-min) (1- (point))))) | |
314 | |
315 | |
316 ;; The format for one line output by "hg annotate -d -n" looks like this: | |
317 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS | |
318 ;; i.e: VERSION_NUMBER DATE: CONTENTS | |
319 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ") | |
320 | |
321 (defun vc-hg-annotate-time () | |
322 (when (looking-at vc-hg-annotate-re) | |
323 (goto-char (match-end 0)) | |
324 (vc-annotate-convert-time | |
325 (date-to-time (match-string-no-properties 2))))) | |
326 | |
327 (defun vc-hg-annotate-extract-revision-at-line () | |
328 (save-excursion | |
329 (beginning-of-line) | |
330 (if (looking-at vc-hg-annotate-re) (match-string-no-properties 1)))) | |
331 | |
332 (defun vc-hg-previous-version (file rev) | |
333 (let ((newrev (1- (string-to-number rev)))) | |
334 (when (>= newrev 0) | |
335 (number-to-string newrev)))) | |
336 | |
337 (defun vc-hg-next-version (file rev) | |
338 (let ((newrev (1+ (string-to-number rev))) | |
339 (tip-version | |
340 (with-temp-buffer | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
341 (vc-hg-command t 0 nil "tip") |
78075 | 342 (goto-char (point-min)) |
343 (re-search-forward "^changeset:[ \t]*\\([0-9]+\\):") | |
344 (string-to-number (match-string-no-properties 1))))) | |
345 ;; We don't want to exceed the maximum possible version number, ie | |
346 ;; the tip version. | |
347 (when (<= newrev tip-version) | |
348 (number-to-string newrev)))) | |
349 | |
350 ;; Modelled after the similar function in vc-bzr.el | |
351 (defun vc-hg-delete-file (file) | |
352 "Delete FILE and delete it in the hg repository." | |
353 (condition-case () | |
354 (delete-file file) | |
355 (file-error nil)) | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
356 (vc-hg-command nil 0 file "remove" "--after" "--force")) |
78075 | 357 |
358 ;; Modelled after the similar function in vc-bzr.el | |
359 (defun vc-hg-rename-file (old new) | |
360 "Rename file from OLD to NEW using `hg mv'." | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
361 (vc-hg-command nil 0 new old "mv")) |
78075 | 362 |
363 (defun vc-hg-register (file &optional rev comment) | |
364 "Register FILE under hg. | |
365 REV is ignored. | |
366 COMMENT is ignored." | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
367 (vc-hg-command nil 0 file "add")) |
78075 | 368 |
369 (defalias 'vc-hg-responsible-p 'vc-hg-root) | |
370 | |
371 ;; Modelled after the similar function in vc-bzr.el | |
372 (defun vc-hg-could-register (file) | |
373 "Return non-nil if FILE could be registered under hg." | |
374 (and (vc-hg-responsible-p file) ; shortcut | |
375 (condition-case () | |
376 (with-temp-buffer | |
377 (vc-hg-command t nil file "add" "--dry-run")) | |
378 ;; The command succeeds with no output if file is | |
379 ;; registered. | |
380 (error)))) | |
381 | |
382 ;; XXX This would remove the file. Is that correct? | |
383 ;; (defun vc-hg-unregister (file) | |
384 ;; "Unregister FILE from hg." | |
385 ;; (vc-hg-command nil nil file "remove")) | |
386 | |
387 (defun vc-hg-checkin (file rev comment) | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78363
diff
changeset
|
388 "Hg-specific version of `vc-backend-checkin'. |
78075 | 389 REV is ignored." |
78211
ce0473a5b031
(vc-hg-revision-completion-table): Temporarily comment
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78182
diff
changeset
|
390 (vc-hg-command nil 0 file "commit" "-m" comment)) |
78075 | 391 |
392 (defun vc-hg-find-version (file rev buffer) | |
393 (let ((coding-system-for-read 'binary) | |
394 (coding-system-for-write 'binary)) | |
395 (if rev | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
396 (vc-hg-command buffer 0 file "cat" "-r" rev) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
397 (vc-hg-command buffer 0 file "cat")))) |
78075 | 398 |
399 ;; Modelled after the similar function in vc-bzr.el | |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
400 (defun vc-hg-checkout (file &optional editable rev) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
401 "Retrieve a revision of FILE. |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
402 EDITABLE is ignored. |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
403 REV is the revision to check out into WORKFILE." |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
404 (let ((coding-system-for-read 'binary) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
405 (coding-system-for-write 'binary)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
406 (with-current-buffer (or (get-file-buffer file) (current-buffer)) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
407 (if rev |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
408 (vc-hg-command t 0 file "cat" "-r" rev) |
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
409 (vc-hg-command t 0 file "cat"))))) |
78075 | 410 |
411 (defun vc-hg-checkout-model (file) | |
412 'implicit) | |
413 | |
78167
252b7f091c04
(vc-hg-workfile-unchanged-p): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78166
diff
changeset
|
414 ;; Modelled after the similar function in vc-bzr.el |
252b7f091c04
(vc-hg-workfile-unchanged-p): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78166
diff
changeset
|
415 (defun vc-hg-workfile-unchanged-p (file) |
252b7f091c04
(vc-hg-workfile-unchanged-p): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78166
diff
changeset
|
416 (eq 'up-to-date (vc-hg-state file))) |
252b7f091c04
(vc-hg-workfile-unchanged-p): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78166
diff
changeset
|
417 |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
418 (defun vc-hg-dired-state-info (file) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
419 "Hg-specific version of `vc-dired-state-info'." |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
420 (let ((hg-state (vc-state file))) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
421 (if (eq hg-state 'edited) |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
422 (if (equal (vc-workfile-version file) "0") |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
423 "(added)" "(modified)") |
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
424 ;; fall back to the default VC representation |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78363
diff
changeset
|
425 (vc-default-dired-state-info 'Hg file)))) |
78148
9cbb2ce8ec8c
(vc-hg-state): Handle removed files.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78086
diff
changeset
|
426 |
78075 | 427 ;; Modelled after the similar function in vc-bzr.el |
428 (defun vc-hg-revert (file &optional contents-done) | |
429 (unless contents-done | |
78182
86c8d81f944f
(vc-hg-diff): Use vc-hg-command.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78167
diff
changeset
|
430 (with-temp-buffer (vc-hg-command t 0 file "revert")))) |
78075 | 431 |
432 ;;; Internal functions | |
433 | |
434 (defun vc-hg-command (buffer okstatus file &rest flags) | |
435 "A wrapper around `vc-do-command' for use in vc-hg.el. | |
436 The difference to vc-do-command is that this function always invokes `hg', | |
437 and that it passes `vc-hg-global-switches' to it before FLAGS." | |
438 (apply 'vc-do-command buffer okstatus "hg" file | |
439 (if (stringp vc-hg-global-switches) | |
440 (cons vc-hg-global-switches flags) | |
441 (append vc-hg-global-switches | |
442 flags)))) | |
443 | |
444 (defun vc-hg-root (file) | |
445 (vc-find-root file ".hg")) | |
446 | |
447 (provide 'vc-hg) | |
448 | |
78086 | 449 ;; arch-tag: bd094dc5-715a-434f-a331-37b9fb7cd954 |
78075 | 450 ;;; vc-hg.el ends here |