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