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