]> code.delx.au - gnu-emacs/blob - lisp/vc-hg.el
*** empty log message ***
[gnu-emacs] / lisp / vc-hg.el
1 ;;; vc-hg.el --- VC backend for the mercurial version control system
2
3 ;; Copyright (C) 2006, 2007, 2008, 2009 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
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; This is a mercurial version control backend
26
27 ;;; Thanks:
28
29 ;;; Bugs:
30
31 ;;; Installation:
32
33 ;;; Todo:
34
35 ;; 1) Implement the rest of the vc interface. See the comment at the
36 ;; beginning of vc.el. The current status is:
37
38 ;; FUNCTION NAME STATUS
39 ;; BACKEND PROPERTIES
40 ;; * revision-granularity OK
41 ;; STATE-QUERYING FUNCTIONS
42 ;; * registered (file) OK
43 ;; * state (file) OK
44 ;; - state-heuristic (file) NOT NEEDED
45 ;; - dir-status (dir update-function) OK
46 ;; - dir-status-files (dir files ds uf) OK
47 ;; - dir-extra-headers (dir) OK
48 ;; - dir-printer (fileinfo) OK
49 ;; * working-revision (file) OK
50 ;; - latest-on-branch-p (file) ??
51 ;; * checkout-model (files) OK
52 ;; - workfile-unchanged-p (file) OK
53 ;; - mode-line-string (file) NOT NEEDED
54 ;; STATE-CHANGING FUNCTIONS
55 ;; * register (files &optional rev comment) OK
56 ;; * create-repo () OK
57 ;; - init-revision () NOT NEEDED
58 ;; - responsible-p (file) OK
59 ;; - could-register (file) OK
60 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED
61 ;; - unregister (file) COMMENTED OUT, MAY BE INCORRECT
62 ;; * checkin (files rev comment) OK
63 ;; * find-revision (file rev buffer) OK
64 ;; * checkout (file &optional editable rev) OK
65 ;; * revert (file &optional contents-done) OK
66 ;; - rollback (files) ?? PROBABLY NOT NEEDED
67 ;; - merge (file rev1 rev2) NEEDED
68 ;; - merge-news (file) NEEDED
69 ;; - steal-lock (file &optional revision) NOT NEEDED
70 ;; HISTORY FUNCTIONS
71 ;; * print-log (files &optional buffer shortlog)OK
72 ;; - log-view-mode () OK
73 ;; - show-log-entry (revision) NOT NEEDED, DEFAULT IS GOOD
74 ;; - comment-history (file) NOT NEEDED
75 ;; - update-changelog (files) NOT NEEDED
76 ;; * diff (files &optional rev1 rev2 buffer) OK
77 ;; - revision-completion-table (files) OK?
78 ;; - annotate-command (file buf &optional rev) OK
79 ;; - annotate-time () OK
80 ;; - annotate-current-time () NOT NEEDED
81 ;; - annotate-extract-revision-at-line () OK
82 ;; TAG SYSTEM
83 ;; - create-tag (dir name branchp) NEEDED
84 ;; - retrieve-tag (dir name update) NEEDED
85 ;; MISCELLANEOUS
86 ;; - make-version-backups-p (file) ??
87 ;; - repository-hostname (dirname) ??
88 ;; - previous-revision (file rev) OK
89 ;; - next-revision (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
96 ;; 2) Implement Stefan Monnier's advice:
97 ;; vc-hg-registered and vc-hg-state
98 ;; Both of those functions should be super extra careful to fail gracefully in
99 ;; unexpected circumstances. The reason this is important is that any error
100 ;; there will prevent the user from even looking at the file :-(
101 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under
102 ;; mercurial's control and extracting the current revision should be done
103 ;; without even using `hg' (this way even if you don't have `hg' installed,
104 ;; Emacs is able to tell you this file is under mercurial's control).
105
106 ;;; History:
107 ;;
108
109 ;;; Code:
110
111 (eval-when-compile
112 (require 'cl)
113 (require 'vc)
114 (require 'vc-dir))
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" :value ("") string))
123 :version "22.2"
124 :group 'vc)
125
126 (defcustom vc-hg-diff-switches t ; Hg doesn't support common args like -u
127 "String or list of strings specifying switches for Hg diff under VC.
128 If nil, use the value of `vc-diff-switches'. If t, use no switches."
129 :type '(choice (const :tag "Unspecified" nil)
130 (const :tag "None" t)
131 (string :tag "Argument String")
132 (repeat :tag "Argument List" :value ("") string))
133 :version "23.1"
134 :group 'vc)
135
136 \f
137 ;;; Properties of the backend
138
139 (defun vc-hg-revision-granularity () 'repository)
140 (defun vc-hg-checkout-model (files) 'implicit)
141
142 ;;; State querying functions
143
144 ;;;###autoload (defun vc-hg-registered (file)
145 ;;;###autoload "Return non-nil if FILE is registered with hg."
146 ;;;###autoload (if (vc-find-root file ".hg") ; short cut
147 ;;;###autoload (progn
148 ;;;###autoload (load "vc-hg")
149 ;;;###autoload (vc-hg-registered file))))
150
151 ;; Modeled after the similar function in vc-bzr.el
152 (defun vc-hg-registered (file)
153 "Return non-nil if FILE is registered with hg."
154 (when (vc-hg-root file) ; short cut
155 (let ((state (vc-hg-state file))) ; expensive
156 (and state (not (memq state '(ignored unregistered)))))))
157
158 (defun vc-hg-state (file)
159 "Hg-specific version of `vc-state'."
160 (let*
161 ((status nil)
162 (default-directory (file-name-directory file))
163 (out
164 (with-output-to-string
165 (with-current-buffer
166 standard-output
167 (setq status
168 (condition-case nil
169 ;; Ignore all errors.
170 (process-file
171 "hg" nil t nil
172 "status" "-A" (file-relative-name file))
173 ;; Some problem happened. E.g. We can't find an `hg'
174 ;; executable.
175 (error nil)))))))
176 (when (eq 0 status)
177 (when (null (string-match ".*: No such file or directory$" out))
178 (let ((state (aref out 0)))
179 (cond
180 ((eq state ?=) 'up-to-date)
181 ((eq state ?A) 'added)
182 ((eq state ?M) 'edited)
183 ((eq state ?I) 'ignored)
184 ((eq state ?R) 'removed)
185 ((eq state ?!) 'missing)
186 ((eq state ??) 'unregistered)
187 ((eq state ?C) 'up-to-date) ;; Older mercurials use this
188 (t 'up-to-date)))))))
189
190 (defun vc-hg-working-revision (file)
191 "Hg-specific version of `vc-working-revision'."
192 (let*
193 ((status nil)
194 (default-directory (file-name-directory file))
195 (out
196 (with-output-to-string
197 (with-current-buffer
198 standard-output
199 (setq status
200 (condition-case nil
201 ;; Ignore all errors.
202 (process-file
203 "hg" nil t nil
204 "log" "-l1" (file-relative-name file))
205 ;; Some problem happened. E.g. We can't find an `hg'
206 ;; executable.
207 (error nil)))))))
208 (when (eq 0 status)
209 (if (string-match "changeset: *\\([0-9]*\\)" out)
210 (match-string 1 out)
211 "0"))))
212
213 ;;; History functions
214
215 (defcustom vc-hg-log-switches nil
216 "String or list of strings specifying switches for hg log under VC."
217 :type '(choice (const :tag "None" nil)
218 (string :tag "Argument String")
219 (repeat :tag "Argument List" :value ("") string))
220 :group 'vc-hg)
221
222 (defun vc-hg-print-log (files &optional buffer shortlog)
223 "Get change log associated with FILES."
224 ;; `log-view-mode' needs to have the file names in order to function
225 ;; correctly. "hg log" does not print it, so we insert it here by
226 ;; hand.
227
228 ;; `vc-do-command' creates the buffer, but we need it before running
229 ;; the command.
230 (vc-setup-buffer buffer)
231 ;; If the buffer exists from a previous invocation it might be
232 ;; read-only.
233 (let ((inhibit-read-only t))
234 (with-current-buffer
235 buffer
236 (apply 'vc-hg-command buffer 0 files "log"
237 (if shortlog
238 (append '("--style" "compact") vc-hg-log-switches)
239 vc-hg-log-switches)))))
240
241 (defvar log-view-message-re)
242 (defvar log-view-file-re)
243 (defvar log-view-font-lock-keywords)
244 (defvar log-view-per-file-logs)
245 (defvar vc-short-log)
246
247 (define-derived-mode vc-hg-log-view-mode log-view-mode "Hg-Log-View"
248 (require 'add-log) ;; we need the add-log faces
249 (set (make-local-variable 'log-view-file-re) "\\`a\\`")
250 (set (make-local-variable 'log-view-per-file-logs) nil)
251 (set (make-local-variable 'log-view-message-re)
252 (if vc-short-log
253 "^\\([0-9]+\\)\\(?:\\[.*\\]\\)? +\\([0-9a-z]\\{12\\}\\) +\\(\\(?:[0-9]+\\)-\\(?:[0-9]+\\)-\\(?:[0-9]+\\) \\(?:[0-9]+\\):\\(?:[0-9]+\\) \\(?:[-+0-9]+\\)\\) +\\(.*\\)$"
254 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)"))
255 (set (make-local-variable 'log-view-font-lock-keywords)
256 (if vc-short-log
257 (append `((,log-view-message-re
258 (1 'log-view-message-face)
259 (2 'log-view-message-face)
260 (3 'change-log-date)
261 (4 'change-log-name))))
262 (append
263 log-view-font-lock-keywords
264 '(
265 ;; Handle the case:
266 ;; user: FirstName LastName <foo@bar>
267 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]"
268 (1 'change-log-name)
269 (2 'change-log-email))
270 ;; Handle the cases:
271 ;; user: foo@bar
272 ;; and
273 ;; user: foo
274 ("^user:[ \t]+\\([A-Za-z0-9_.+-]+\\(?:@[A-Za-z0-9_.-]+\\)?\\)"
275 (1 'change-log-email))
276 ("^date: \\(.+\\)" (1 'change-log-date))
277 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))))
278
279 (defun vc-hg-diff (files &optional oldvers newvers buffer)
280 "Get a difference report using hg between two revisions of FILES."
281 (let* ((firstfile (car files))
282 (cwd (if firstfile (file-name-directory firstfile)
283 (expand-file-name default-directory)))
284 (working (and firstfile (vc-working-revision firstfile))))
285 (when (and (equal oldvers working) (not newvers))
286 (setq oldvers nil))
287 (when (and (not oldvers) newvers)
288 (setq oldvers working))
289 (apply #'vc-hg-command (or buffer "*vc-diff*") nil
290 (mapcar (lambda (file) (file-relative-name file cwd)) files)
291 "diff"
292 (append
293 (vc-switches 'hg 'diff)
294 (when oldvers
295 (if newvers
296 (list "-r" oldvers "-r" newvers)
297 (list "-r" oldvers)))))))
298
299 (defun vc-hg-revision-table (files)
300 (let ((default-directory (file-name-directory (car files))))
301 (with-temp-buffer
302 (vc-hg-command t nil files "log" "--template" "{rev} ")
303 (split-string
304 (buffer-substring-no-properties (point-min) (point-max))))))
305
306 ;; Modeled after the similar function in vc-cvs.el
307 (defun vc-hg-revision-completion-table (files)
308 (lexical-let ((files files)
309 table)
310 (setq table (lazy-completion-table
311 table (lambda () (vc-hg-revision-table files))))
312 table))
313
314 (defun vc-hg-annotate-command (file buffer &optional revision)
315 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
316 Optional arg REVISION is a revision to annotate from."
317 (vc-hg-command buffer 0 file "annotate" "-d" "-n" "--follow"
318 (when revision (concat "-r" revision))))
319
320 (declare-function vc-annotate-convert-time "vc-annotate" (time))
321
322 ;; The format for one line output by "hg annotate -d -n" looks like this:
323 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS
324 ;; i.e: VERSION_NUMBER DATE: CONTENTS
325 ;; If the user has set the "--follow" option, the output looks like:
326 ;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS
327 ;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS
328 (defconst vc-hg-annotate-re
329 "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)\\(?:\\(: \\)\\|\\(?: +\\(.+\\): \\)\\)")
330
331 (defun vc-hg-annotate-time ()
332 (when (looking-at vc-hg-annotate-re)
333 (goto-char (match-end 0))
334 (vc-annotate-convert-time
335 (date-to-time (match-string-no-properties 2)))))
336
337 (defun vc-hg-annotate-extract-revision-at-line ()
338 (save-excursion
339 (beginning-of-line)
340 (when (looking-at vc-hg-annotate-re)
341 (if (match-beginning 3)
342 (match-string-no-properties 1)
343 (cons (match-string-no-properties 1)
344 (expand-file-name (match-string-no-properties 4)))))))
345
346 (defun vc-hg-previous-revision (file rev)
347 (let ((newrev (1- (string-to-number rev))))
348 (when (>= newrev 0)
349 (number-to-string newrev))))
350
351 (defun vc-hg-next-revision (file rev)
352 (let ((newrev (1+ (string-to-number rev)))
353 (tip-revision
354 (with-temp-buffer
355 (vc-hg-command t 0 nil "tip")
356 (goto-char (point-min))
357 (re-search-forward "^changeset:[ \t]*\\([0-9]+\\):")
358 (string-to-number (match-string-no-properties 1)))))
359 ;; We don't want to exceed the maximum possible revision number, ie
360 ;; the tip revision.
361 (when (<= newrev tip-revision)
362 (number-to-string newrev))))
363
364 ;; Modeled after the similar function in vc-bzr.el
365 (defun vc-hg-delete-file (file)
366 "Delete FILE and delete it in the hg repository."
367 (condition-case ()
368 (delete-file file)
369 (file-error nil))
370 (vc-hg-command nil 0 file "remove" "--after" "--force"))
371
372 ;; Modeled after the similar function in vc-bzr.el
373 (defun vc-hg-rename-file (old new)
374 "Rename file from OLD to NEW using `hg mv'."
375 (vc-hg-command nil 0 new "mv" old))
376
377 (defun vc-hg-register (files &optional rev comment)
378 "Register FILES under hg.
379 REV is ignored.
380 COMMENT is ignored."
381 (vc-hg-command nil 0 files "add"))
382
383 (defun vc-hg-create-repo ()
384 "Create a new Mercurial repository."
385 (vc-hg-command nil 0 nil "init"))
386
387 (defalias 'vc-hg-responsible-p 'vc-hg-root)
388
389 ;; Modeled after the similar function in vc-bzr.el
390 (defun vc-hg-could-register (file)
391 "Return non-nil if FILE could be registered under hg."
392 (and (vc-hg-responsible-p file) ; shortcut
393 (condition-case ()
394 (with-temp-buffer
395 (vc-hg-command t nil file "add" "--dry-run"))
396 ;; The command succeeds with no output if file is
397 ;; registered.
398 (error))))
399
400 ;; FIXME: This would remove the file. Is that correct?
401 ;; (defun vc-hg-unregister (file)
402 ;; "Unregister FILE from hg."
403 ;; (vc-hg-command nil nil file "remove"))
404
405 (defun vc-hg-checkin (files rev comment)
406 "Hg-specific version of `vc-backend-checkin'.
407 REV is ignored."
408 (vc-hg-command nil 0 files "commit" "-m" comment))
409
410 (defun vc-hg-find-revision (file rev buffer)
411 (let ((coding-system-for-read 'binary)
412 (coding-system-for-write 'binary))
413 (if rev
414 (vc-hg-command buffer 0 file "cat" "-r" rev)
415 (vc-hg-command buffer 0 file "cat"))))
416
417 ;; Modeled after the similar function in vc-bzr.el
418 (defun vc-hg-checkout (file &optional editable rev)
419 "Retrieve a revision of FILE.
420 EDITABLE is ignored.
421 REV is the revision to check out into WORKFILE."
422 (let ((coding-system-for-read 'binary)
423 (coding-system-for-write 'binary))
424 (with-current-buffer (or (get-file-buffer file) (current-buffer))
425 (if rev
426 (vc-hg-command t 0 file "cat" "-r" rev)
427 (vc-hg-command t 0 file "cat")))))
428
429 ;; Modeled after the similar function in vc-bzr.el
430 (defun vc-hg-workfile-unchanged-p (file)
431 (eq 'up-to-date (vc-hg-state file)))
432
433 ;; Modeled after the similar function in vc-bzr.el
434 (defun vc-hg-revert (file &optional contents-done)
435 (unless contents-done
436 (with-temp-buffer (vc-hg-command t 0 file "revert"))))
437
438 ;;; Hg specific functionality.
439
440 (defvar vc-hg-extra-menu-map
441 (let ((map (make-sparse-keymap)))
442 (define-key map [incoming] '(menu-item "Show incoming" vc-hg-incoming))
443 (define-key map [outgoing] '(menu-item "Show outgoing" vc-hg-outgoing))
444 map))
445
446 (defun vc-hg-extra-menu () vc-hg-extra-menu-map)
447
448 (defun vc-hg-extra-status-menu () vc-hg-extra-menu-map)
449
450 (defvar log-view-vc-backend)
451
452 (define-derived-mode vc-hg-outgoing-mode vc-hg-log-view-mode "Hg-Outgoing"
453 "Mode for browsing Hg outgoing changes."
454 (set (make-local-variable 'log-view-vc-backend) 'Hg))
455
456 (define-derived-mode vc-hg-incoming-mode vc-hg-log-view-mode "Hg-Incoming"
457 "Mode for browsing Hg incoming changes."
458 (set (make-local-variable 'log-view-vc-backend) 'Hg))
459
460 (defstruct (vc-hg-extra-fileinfo
461 (:copier nil)
462 (:constructor vc-hg-create-extra-fileinfo (rename-state extra-name))
463 (:conc-name vc-hg-extra-fileinfo->))
464 rename-state ;; rename or copy state
465 extra-name) ;; original name for copies and rename targets, new name for
466
467 (declare-function vc-default-dir-printer "vc-dir" (backend fileentry))
468
469 (defun vc-hg-dir-printer (info)
470 "Pretty-printer for the vc-dir-fileinfo structure."
471 (let ((extra (vc-dir-fileinfo->extra info)))
472 (vc-default-dir-printer 'Hg info)
473 (when extra
474 (insert (propertize
475 (format " (%s %s)"
476 (case (vc-hg-extra-fileinfo->rename-state extra)
477 ('copied "copied from")
478 ('renamed-from "renamed from")
479 ('renamed-to "renamed to"))
480 (vc-hg-extra-fileinfo->extra-name extra))
481 'face 'font-lock-comment-face)))))
482
483 (defun vc-hg-after-dir-status (update-function)
484 (let ((status-char nil)
485 (file nil)
486 (translation '((?= . up-to-date)
487 (?C . up-to-date)
488 (?A . added)
489 (?R . removed)
490 (?M . edited)
491 (?I . ignored)
492 (?! . missing)
493 (? . copy-rename-line)
494 (?? . unregistered)))
495 (translated nil)
496 (result nil)
497 (last-added nil)
498 (last-line-copy nil))
499 (goto-char (point-min))
500 (while (not (eobp))
501 (setq translated (cdr (assoc (char-after) translation)))
502 (setq file
503 (buffer-substring-no-properties (+ (point) 2)
504 (line-end-position)))
505 (cond ((not translated)
506 (setq last-line-copy nil))
507 ((eq translated 'up-to-date)
508 (setq last-line-copy nil))
509 ((eq translated 'copy-rename-line)
510 ;; For copied files the output looks like this:
511 ;; A COPIED_FILE_NAME
512 ;; ORIGINAL_FILE_NAME
513 (setf (nth 2 last-added)
514 (vc-hg-create-extra-fileinfo 'copied file))
515 (setq last-line-copy t))
516 ((and last-line-copy (eq translated 'removed))
517 ;; For renamed files the output looks like this:
518 ;; A NEW_FILE_NAME
519 ;; ORIGINAL_FILE_NAME
520 ;; R ORIGINAL_FILE_NAME
521 ;; We need to adjust the previous entry to not think it is a copy.
522 (setf (vc-hg-extra-fileinfo->rename-state (nth 2 last-added))
523 'renamed-from)
524 (push (list file translated
525 (vc-hg-create-extra-fileinfo
526 'renamed-to (nth 0 last-added))) result)
527 (setq last-line-copy nil))
528 (t
529 (setq last-added (list file translated nil))
530 (push last-added result)
531 (setq last-line-copy nil)))
532 (forward-line))
533 (funcall update-function result)))
534
535 (defun vc-hg-dir-status (dir update-function)
536 (vc-hg-command (current-buffer) 'async dir "status" "-C")
537 (vc-exec-after
538 `(vc-hg-after-dir-status (quote ,update-function))))
539
540 (defun vc-hg-dir-status-files (dir files default-state update-function)
541 (apply 'vc-hg-command (current-buffer) 'async dir "status" "-C" files)
542 (vc-exec-after
543 `(vc-hg-after-dir-status (quote ,update-function))))
544
545 (defun vc-hg-dir-extra-header (name &rest commands)
546 (concat (propertize name 'face 'font-lock-type-face)
547 (propertize
548 (with-temp-buffer
549 (apply 'vc-hg-command (current-buffer) 0 nil commands)
550 (buffer-substring-no-properties (point-min) (1- (point-max))))
551 'face 'font-lock-variable-name-face)))
552
553 (defun vc-hg-dir-extra-headers (dir)
554 "Generate extra status headers for a Mercurial tree."
555 (let ((default-directory dir))
556 (concat
557 (vc-hg-dir-extra-header "Root : " "root") "\n"
558 (vc-hg-dir-extra-header "Branch : " "id" "-b") "\n"
559 (vc-hg-dir-extra-header "Tags : " "id" "-t") ; "\n"
560 ;; these change after each commit
561 ;; (vc-hg-dir-extra-header "Local num : " "id" "-n") "\n"
562 ;; (vc-hg-dir-extra-header "Global id : " "id" "-i")
563 )))
564
565 ;; FIXME: this adds another top level menu, instead figure out how to
566 ;; replace the Log-View menu.
567 (easy-menu-define log-view-mode-menu vc-hg-outgoing-mode-map
568 "Hg-outgoing Display Menu"
569 `("Hg-outgoing"
570 ["Push selected" vc-hg-push]))
571
572 (easy-menu-define log-view-mode-menu vc-hg-incoming-mode-map
573 "Hg-incoming Display Menu"
574 `("Hg-incoming"
575 ["Pull selected" vc-hg-pull]))
576
577 (defun vc-hg-outgoing ()
578 (interactive)
579 (let ((bname "*Hg outgoing*")
580 (vc-short-log nil))
581 (vc-hg-command bname 1 nil "outgoing" "-n")
582 (pop-to-buffer bname)
583 (vc-hg-outgoing-mode)))
584
585 (defun vc-hg-incoming ()
586 (interactive)
587 (let ((bname "*Hg incoming*")
588 (vc-short-log nil))
589 (vc-hg-command bname 0 nil "incoming" "-n")
590 (pop-to-buffer bname)
591 (vc-hg-incoming-mode)))
592
593 (declare-function log-view-get-marked "log-view" ())
594
595 ;; XXX maybe also add key bindings for these functions.
596 (defun vc-hg-push ()
597 (interactive)
598 (let ((marked-list (log-view-get-marked)))
599 (if marked-list
600 (vc-hg-command
601 nil 0 nil
602 (cons "push"
603 (apply 'nconc
604 (mapcar (lambda (arg) (list "-r" arg)) marked-list))))
605 (error "No log entries selected for push"))))
606
607 (defun vc-hg-pull ()
608 (interactive)
609 (let ((marked-list (log-view-get-marked)))
610 (if marked-list
611 (vc-hg-command
612 nil 0 nil
613 (cons "pull"
614 (apply 'nconc
615 (mapcar (lambda (arg) (list "-r" arg)) marked-list))))
616 (error "No log entries selected for pull"))))
617
618 ;;; Internal functions
619
620 (defun vc-hg-command (buffer okstatus file-or-list &rest flags)
621 "A wrapper around `vc-do-command' for use in vc-hg.el.
622 The difference to vc-do-command is that this function always invokes `hg',
623 and that it passes `vc-hg-global-switches' to it before FLAGS."
624 (apply 'vc-do-command (or buffer "*vc*") okstatus "hg" file-or-list
625 (if (stringp vc-hg-global-switches)
626 (cons vc-hg-global-switches flags)
627 (append vc-hg-global-switches
628 flags))))
629
630 (defun vc-hg-root (file)
631 (vc-find-root file ".hg"))
632
633 (provide 'vc-hg)
634
635 ;; arch-tag: bd094dc5-715a-434f-a331-37b9fb7cd954
636 ;;; vc-hg.el ends here