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