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