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