]> code.delx.au - gnu-emacs/blob - lisp/vc-hg.el
(vc-hg-print-log): Fix argument order.
[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 buffer &optional shortlog start-revision limit) 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 (let ((process-environment
171 ;; Avoid localization of messages so we can parse the output.
172 (append (list "TERM=dumb" "LANGUAGE=C" "HGRC=") process-environment)))
173
174 (process-file
175 "hg" nil t nil
176 "status" "-A" (file-relative-name file)))
177 ;; Some problem happened. E.g. We can't find an `hg'
178 ;; executable.
179 (error nil)))))))
180 (when (eq 0 status)
181 (when (null (string-match ".*: No such file or directory$" out))
182 (let ((state (aref out 0)))
183 (cond
184 ((eq state ?=) 'up-to-date)
185 ((eq state ?A) 'added)
186 ((eq state ?M) 'edited)
187 ((eq state ?I) 'ignored)
188 ((eq state ?R) 'removed)
189 ((eq state ?!) 'missing)
190 ((eq state ??) 'unregistered)
191 ((eq state ?C) 'up-to-date) ;; Older mercurials use this
192 (t 'up-to-date)))))))
193
194 (defun vc-hg-working-revision (file)
195 "Hg-specific version of `vc-working-revision'."
196 (let*
197 ((status nil)
198 (default-directory (file-name-directory file))
199 (out
200 (with-output-to-string
201 (with-current-buffer
202 standard-output
203 (setq status
204 (condition-case nil
205 ;; Ignore all errors.
206 (process-file
207 "hg" nil t nil
208 "log" "-l1" (file-relative-name file))
209 ;; Some problem happened. E.g. We can't find an `hg'
210 ;; executable.
211 (error nil)))))))
212 (when (eq 0 status)
213 (if (string-match "changeset: *\\([0-9]*\\)" out)
214 (match-string 1 out)
215 "0"))))
216
217 ;;; History functions
218
219 (defcustom vc-hg-log-switches nil
220 "String or list of strings specifying switches for hg log under VC."
221 :type '(choice (const :tag "None" nil)
222 (string :tag "Argument String")
223 (repeat :tag "Argument List" :value ("") string))
224 :group 'vc-hg)
225
226 (defun vc-hg-print-log (files buffer &optional shortlog start-revision limit)
227 "Get change log associated with FILES."
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 (append
238 (when start-revision (list (format "-r%s:" start-revision)))
239 (when limit (list "-l" (format "%s" limit)))
240 (when shortlog '("--style" "compact"))
241 vc-hg-log-switches)))))
242
243 (defvar log-view-message-re)
244 (defvar log-view-file-re)
245 (defvar log-view-font-lock-keywords)
246 (defvar log-view-per-file-logs)
247 (defvar vc-short-log)
248
249 (define-derived-mode vc-hg-log-view-mode log-view-mode "Hg-Log-View"
250 (require 'add-log) ;; we need the add-log faces
251 (set (make-local-variable 'log-view-file-re) "\\`a\\`")
252 (set (make-local-variable 'log-view-per-file-logs) nil)
253 (set (make-local-variable 'log-view-message-re)
254 (if vc-short-log
255 "^\\([0-9]+\\)\\(?:\\[.*\\]\\)? +\\([0-9a-z]\\{12\\}\\) +\\(\\(?:[0-9]+\\)-\\(?:[0-9]+\\)-\\(?:[0-9]+\\) \\(?:[0-9]+\\):\\(?:[0-9]+\\) \\(?:[-+0-9]+\\)\\) +\\(.*\\)$"
256 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)"))
257 (set (make-local-variable 'log-view-font-lock-keywords)
258 (if vc-short-log
259 (append `((,log-view-message-re
260 (1 'log-view-message-face)
261 (2 'log-view-message-face)
262 (3 'change-log-date)
263 (4 'change-log-name))))
264 (append
265 log-view-font-lock-keywords
266 '(
267 ;; Handle the case:
268 ;; user: FirstName LastName <foo@bar>
269 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]"
270 (1 'change-log-name)
271 (2 'change-log-email))
272 ;; Handle the cases:
273 ;; user: foo@bar
274 ;; and
275 ;; user: foo
276 ("^user:[ \t]+\\([A-Za-z0-9_.+-]+\\(?:@[A-Za-z0-9_.-]+\\)?\\)"
277 (1 'change-log-email))
278 ("^date: \\(.+\\)" (1 'change-log-date))
279 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))))
280
281 (defun vc-hg-diff (files &optional oldvers newvers buffer)
282 "Get a difference report using hg between two revisions of FILES."
283 (let* ((firstfile (car files))
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 files "diff"
290 (append
291 (vc-switches 'hg 'diff)
292 (when oldvers
293 (if newvers
294 (list "-r" oldvers "-r" newvers)
295 (list "-r" oldvers)))))))
296
297 (defun vc-hg-revision-table (files)
298 (let ((default-directory (file-name-directory (car files))))
299 (with-temp-buffer
300 (vc-hg-command t nil files "log" "--template" "{rev} ")
301 (split-string
302 (buffer-substring-no-properties (point-min) (point-max))))))
303
304 ;; Modeled after the similar function in vc-cvs.el
305 (defun vc-hg-revision-completion-table (files)
306 (lexical-let ((files files)
307 table)
308 (setq table (lazy-completion-table
309 table (lambda () (vc-hg-revision-table files))))
310 table))
311
312 (defun vc-hg-annotate-command (file buffer &optional revision)
313 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
314 Optional arg REVISION is a revision to annotate from."
315 (vc-hg-command buffer 0 file "annotate" "-d" "-n" "--follow"
316 (when revision (concat "-r" revision))))
317
318 (declare-function vc-annotate-convert-time "vc-annotate" (time))
319
320 ;; The format for one line output by "hg annotate -d -n" looks like this:
321 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS
322 ;; i.e: VERSION_NUMBER DATE: CONTENTS
323 ;; If the user has set the "--follow" option, the output looks like:
324 ;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS
325 ;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS
326 (defconst vc-hg-annotate-re
327 "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)\\(?:\\(: \\)\\|\\(?: +\\(.+\\): \\)\\)")
328
329 (defun vc-hg-annotate-time ()
330 (when (looking-at vc-hg-annotate-re)
331 (goto-char (match-end 0))
332 (vc-annotate-convert-time
333 (date-to-time (match-string-no-properties 2)))))
334
335 (defun vc-hg-annotate-extract-revision-at-line ()
336 (save-excursion
337 (beginning-of-line)
338 (when (looking-at vc-hg-annotate-re)
339 (if (match-beginning 3)
340 (match-string-no-properties 1)
341 (cons (match-string-no-properties 1)
342 (expand-file-name (match-string-no-properties 4)))))))
343
344 (defun vc-hg-previous-revision (file rev)
345 (let ((newrev (1- (string-to-number rev))))
346 (when (>= newrev 0)
347 (number-to-string newrev))))
348
349 (defun vc-hg-next-revision (file rev)
350 (let ((newrev (1+ (string-to-number rev)))
351 (tip-revision
352 (with-temp-buffer
353 (vc-hg-command t 0 nil "tip")
354 (goto-char (point-min))
355 (re-search-forward "^changeset:[ \t]*\\([0-9]+\\):")
356 (string-to-number (match-string-no-properties 1)))))
357 ;; We don't want to exceed the maximum possible revision number, ie
358 ;; the tip revision.
359 (when (<= newrev tip-revision)
360 (number-to-string newrev))))
361
362 ;; Modeled after the similar function in vc-bzr.el
363 (defun vc-hg-delete-file (file)
364 "Delete FILE and delete it in the hg repository."
365 (condition-case ()
366 (delete-file file)
367 (file-error nil))
368 (vc-hg-command nil 0 file "remove" "--after" "--force"))
369
370 ;; Modeled after the similar function in vc-bzr.el
371 (defun vc-hg-rename-file (old new)
372 "Rename file from OLD to NEW using `hg mv'."
373 (vc-hg-command nil 0 new "mv" old))
374
375 (defun vc-hg-register (files &optional rev comment)
376 "Register FILES under hg.
377 REV is ignored.
378 COMMENT is ignored."
379 (vc-hg-command nil 0 files "add"))
380
381 (defun vc-hg-create-repo ()
382 "Create a new Mercurial repository."
383 (vc-hg-command nil 0 nil "init"))
384
385 (defalias 'vc-hg-responsible-p 'vc-hg-root)
386
387 ;; Modeled after the similar function in vc-bzr.el
388 (defun vc-hg-could-register (file)
389 "Return non-nil if FILE could be registered under hg."
390 (and (vc-hg-responsible-p file) ; shortcut
391 (condition-case ()
392 (with-temp-buffer
393 (vc-hg-command t nil file "add" "--dry-run"))
394 ;; The command succeeds with no output if file is
395 ;; registered.
396 (error))))
397
398 ;; FIXME: This would remove the file. Is that correct?
399 ;; (defun vc-hg-unregister (file)
400 ;; "Unregister FILE from hg."
401 ;; (vc-hg-command nil nil file "remove"))
402
403 (defun vc-hg-checkin (files rev comment)
404 "Hg-specific version of `vc-backend-checkin'.
405 REV is ignored."
406 (vc-hg-command nil 0 files "commit" "-m" comment))
407
408 (defun vc-hg-find-revision (file rev buffer)
409 (let ((coding-system-for-read 'binary)
410 (coding-system-for-write 'binary))
411 (if rev
412 (vc-hg-command buffer 0 file "cat" "-r" rev)
413 (vc-hg-command buffer 0 file "cat"))))
414
415 ;; Modeled after the similar function in vc-bzr.el
416 (defun vc-hg-checkout (file &optional editable rev)
417 "Retrieve a revision of FILE.
418 EDITABLE is ignored.
419 REV is the revision to check out into WORKFILE."
420 (let ((coding-system-for-read 'binary)
421 (coding-system-for-write 'binary))
422 (with-current-buffer (or (get-file-buffer file) (current-buffer))
423 (if rev
424 (vc-hg-command t 0 file "cat" "-r" rev)
425 (vc-hg-command t 0 file "cat")))))
426
427 ;; Modeled after the similar function in vc-bzr.el
428 (defun vc-hg-workfile-unchanged-p (file)
429 (eq 'up-to-date (vc-hg-state file)))
430
431 ;; Modeled after the similar function in vc-bzr.el
432 (defun vc-hg-revert (file &optional contents-done)
433 (unless contents-done
434 (with-temp-buffer (vc-hg-command t 0 file "revert"))))
435
436 ;;; Hg specific functionality.
437
438 (defvar vc-hg-extra-menu-map
439 (let ((map (make-sparse-keymap)))
440 (define-key map [incoming] '(menu-item "Show incoming" vc-hg-incoming))
441 (define-key map [outgoing] '(menu-item "Show outgoing" vc-hg-outgoing))
442 map))
443
444 (defun vc-hg-extra-menu () vc-hg-extra-menu-map)
445
446 (defun vc-hg-extra-status-menu () vc-hg-extra-menu-map)
447
448 (defvar log-view-vc-backend)
449
450 (define-derived-mode vc-hg-outgoing-mode vc-hg-log-view-mode "Hg-Outgoing"
451 "Mode for browsing Hg outgoing changes."
452 (set (make-local-variable 'log-view-vc-backend) 'Hg))
453
454 (define-derived-mode vc-hg-incoming-mode vc-hg-log-view-mode "Hg-Incoming"
455 "Mode for browsing Hg incoming changes."
456 (set (make-local-variable 'log-view-vc-backend) 'Hg))
457
458 (defstruct (vc-hg-extra-fileinfo
459 (:copier nil)
460 (:constructor vc-hg-create-extra-fileinfo (rename-state extra-name))
461 (:conc-name vc-hg-extra-fileinfo->))
462 rename-state ;; rename or copy state
463 extra-name) ;; original name for copies and rename targets, new name for
464
465 (declare-function vc-default-dir-printer "vc-dir" (backend fileentry))
466
467 (defun vc-hg-dir-printer (info)
468 "Pretty-printer for the vc-dir-fileinfo structure."
469 (let ((extra (vc-dir-fileinfo->extra info)))
470 (vc-default-dir-printer 'Hg info)
471 (when extra
472 (insert (propertize
473 (format " (%s %s)"
474 (case (vc-hg-extra-fileinfo->rename-state extra)
475 ('copied "copied from")
476 ('renamed-from "renamed from")
477 ('renamed-to "renamed to"))
478 (vc-hg-extra-fileinfo->extra-name extra))
479 'face 'font-lock-comment-face)))))
480
481 (defun vc-hg-after-dir-status (update-function)
482 (let ((status-char nil)
483 (file nil)
484 (translation '((?= . up-to-date)
485 (?C . up-to-date)
486 (?A . added)
487 (?R . removed)
488 (?M . edited)
489 (?I . ignored)
490 (?! . missing)
491 (? . copy-rename-line)
492 (?? . unregistered)))
493 (translated nil)
494 (result nil)
495 (last-added nil)
496 (last-line-copy nil))
497 (goto-char (point-min))
498 (while (not (eobp))
499 (setq translated (cdr (assoc (char-after) translation)))
500 (setq file
501 (buffer-substring-no-properties (+ (point) 2)
502 (line-end-position)))
503 (cond ((not translated)
504 (setq last-line-copy nil))
505 ((eq translated 'up-to-date)
506 (setq last-line-copy nil))
507 ((eq translated 'copy-rename-line)
508 ;; For copied files the output looks like this:
509 ;; A COPIED_FILE_NAME
510 ;; ORIGINAL_FILE_NAME
511 (setf (nth 2 last-added)
512 (vc-hg-create-extra-fileinfo 'copied file))
513 (setq last-line-copy t))
514 ((and last-line-copy (eq translated 'removed))
515 ;; For renamed files the output looks like this:
516 ;; A NEW_FILE_NAME
517 ;; ORIGINAL_FILE_NAME
518 ;; R ORIGINAL_FILE_NAME
519 ;; We need to adjust the previous entry to not think it is a copy.
520 (setf (vc-hg-extra-fileinfo->rename-state (nth 2 last-added))
521 'renamed-from)
522 (push (list file translated
523 (vc-hg-create-extra-fileinfo
524 'renamed-to (nth 0 last-added))) result)
525 (setq last-line-copy nil))
526 (t
527 (setq last-added (list file translated nil))
528 (push last-added result)
529 (setq last-line-copy nil)))
530 (forward-line))
531 (funcall update-function result)))
532
533 (defun vc-hg-dir-status (dir update-function)
534 (vc-hg-command (current-buffer) 'async dir "status" "-C")
535 (vc-exec-after
536 `(vc-hg-after-dir-status (quote ,update-function))))
537
538 (defun vc-hg-dir-status-files (dir files default-state update-function)
539 (apply 'vc-hg-command (current-buffer) 'async dir "status" "-C" files)
540 (vc-exec-after
541 `(vc-hg-after-dir-status (quote ,update-function))))
542
543 (defun vc-hg-dir-extra-header (name &rest commands)
544 (concat (propertize name 'face 'font-lock-type-face)
545 (propertize
546 (with-temp-buffer
547 (apply 'vc-hg-command (current-buffer) 0 nil commands)
548 (buffer-substring-no-properties (point-min) (1- (point-max))))
549 'face 'font-lock-variable-name-face)))
550
551 (defun vc-hg-dir-extra-headers (dir)
552 "Generate extra status headers for a Mercurial tree."
553 (let ((default-directory dir))
554 (concat
555 (vc-hg-dir-extra-header "Root : " "root") "\n"
556 (vc-hg-dir-extra-header "Branch : " "id" "-b") "\n"
557 (vc-hg-dir-extra-header "Tags : " "id" "-t") ; "\n"
558 ;; these change after each commit
559 ;; (vc-hg-dir-extra-header "Local num : " "id" "-n") "\n"
560 ;; (vc-hg-dir-extra-header "Global id : " "id" "-i")
561 )))
562
563 ;; FIXME: this adds another top level menu, instead figure out how to
564 ;; replace the Log-View menu.
565 (easy-menu-define log-view-mode-menu vc-hg-outgoing-mode-map
566 "Hg-outgoing Display Menu"
567 `("Hg-outgoing"
568 ["Push selected" vc-hg-push]))
569
570 (easy-menu-define log-view-mode-menu vc-hg-incoming-mode-map
571 "Hg-incoming Display Menu"
572 `("Hg-incoming"
573 ["Pull selected" vc-hg-pull]))
574
575 (defun vc-hg-outgoing ()
576 (interactive)
577 (let ((bname "*Hg outgoing*")
578 (vc-short-log nil))
579 (vc-hg-command bname 1 nil "outgoing" "-n")
580 (pop-to-buffer bname)
581 (vc-hg-outgoing-mode)))
582
583 (defun vc-hg-incoming ()
584 (interactive)
585 (let ((bname "*Hg incoming*")
586 (vc-short-log nil))
587 (vc-hg-command bname 0 nil "incoming" "-n")
588 (pop-to-buffer bname)
589 (vc-hg-incoming-mode)))
590
591 (declare-function log-view-get-marked "log-view" ())
592
593 ;; XXX maybe also add key bindings for these functions.
594 (defun vc-hg-push ()
595 (interactive)
596 (let ((marked-list (log-view-get-marked)))
597 (if marked-list
598 (vc-hg-command
599 nil 0 nil
600 (cons "push"
601 (apply 'nconc
602 (mapcar (lambda (arg) (list "-r" arg)) marked-list))))
603 (error "No log entries selected for push"))))
604
605 (defun vc-hg-pull ()
606 (interactive)
607 (let ((marked-list (log-view-get-marked)))
608 (if marked-list
609 (vc-hg-command
610 nil 0 nil
611 (cons "pull"
612 (apply 'nconc
613 (mapcar (lambda (arg) (list "-r" arg)) marked-list))))
614 (error "No log entries selected for pull"))))
615
616 ;;; Internal functions
617
618 (defun vc-hg-command (buffer okstatus file-or-list &rest flags)
619 "A wrapper around `vc-do-command' for use in vc-hg.el.
620 The difference to vc-do-command is that this function always invokes `hg',
621 and that it passes `vc-hg-global-switches' to it before FLAGS."
622 (apply 'vc-do-command (or buffer "*vc*") okstatus "hg" file-or-list
623 (if (stringp vc-hg-global-switches)
624 (cons vc-hg-global-switches flags)
625 (append vc-hg-global-switches
626 flags))))
627
628 (defun vc-hg-root (file)
629 (vc-find-root file ".hg"))
630
631 (provide 'vc-hg)
632
633 ;; arch-tag: bd094dc5-715a-434f-a331-37b9fb7cd954
634 ;;; vc-hg.el ends here