1 ;;; vc-hg.el --- VC backend for the mercurial version control system -*- lexical-binding: t -*-
3 ;; Copyright (C) 2006-2016 Free Software Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This is a mercurial version control backend
37 ;; 1) Implement the rest of the vc interface. See the comment at the
38 ;; beginning of vc.el. The current status is:
40 ;; FUNCTION NAME STATUS
42 ;; * revision-granularity OK
43 ;; STATE-QUERYING FUNCTIONS
44 ;; * registered (file) OK
46 ;; - dir-status-files (dir files uf) OK
47 ;; - dir-extra-headers (dir) OK
48 ;; - dir-printer (fileinfo) OK
49 ;; * working-revision (file) OK
50 ;; * checkout-model (files) OK
51 ;; - mode-line-string (file) OK
52 ;; STATE-CHANGING FUNCTIONS
53 ;; * register (files &optional rev comment) OK
54 ;; * create-repo () OK
55 ;; - responsible-p (file) OK
56 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED
57 ;; - unregister (file) OK
58 ;; * checkin (files rev comment) OK
59 ;; * find-revision (file rev buffer) OK
60 ;; * checkout (file &optional rev) OK
61 ;; * revert (file &optional contents-done) OK
62 ;; - merge (file rev1 rev2) NEEDED
63 ;; - merge-news (file) NEEDED
64 ;; - steal-lock (file &optional revision) NOT NEEDED
66 ;; * print-log (files buffer &optional shortlog start-revision limit) OK
67 ;; - log-view-mode () OK
68 ;; - show-log-entry (revision) NOT NEEDED, DEFAULT IS GOOD
69 ;; - comment-history (file) NOT NEEDED
70 ;; - update-changelog (files) NOT NEEDED
71 ;; * diff (files &optional rev1 rev2 buffer) OK
72 ;; - revision-completion-table (files) OK?
73 ;; - annotate-command (file buf &optional rev) OK
74 ;; - annotate-time () OK
75 ;; - annotate-current-time () NOT NEEDED
76 ;; - annotate-extract-revision-at-line () OK
78 ;; - create-tag (dir name branchp) OK
79 ;; - retrieve-tag (dir name update) OK FIXME UPDATE BUFFERS
81 ;; - make-version-backups-p (file) ??
82 ;; - previous-revision (file rev) OK
83 ;; - next-revision (file rev) OK
84 ;; - check-headers () ??
85 ;; - delete-file (file) TEST IT
86 ;; - rename-file (old new) OK
87 ;; - find-file-hook () added for bug#10709
89 ;; 2) Implement Stefan Monnier's advice:
90 ;; vc-hg-registered and vc-hg-state
91 ;; Both of those functions should be super extra careful to fail gracefully in
92 ;; unexpected circumstances. The reason this is important is that any error
93 ;; there will prevent the user from even looking at the file :-(
94 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under
95 ;; mercurial's control and extracting the current revision should be done
96 ;; without even using `hg' (this way even if you don't have `hg' installed,
97 ;; Emacs is able to tell you this file is under mercurial's control).
109 ;;; Customization options
112 "VC Mercurial (hg) backend."
116 (defcustom vc-hg-global-switches nil
117 "Global switches to pass to any Hg command."
118 :type '(choice (const :tag "None" nil)
119 (string :tag "Argument String")
120 (repeat :tag "Argument List" :value ("") string))
124 (defcustom vc-hg-diff-switches t ; Hg doesn't support common args like -u
125 "String or list of strings specifying switches for Hg diff under VC.
126 If nil, use the value of `vc-diff-switches'. If t, use no switches."
127 :type '(choice (const :tag "Unspecified" nil)
128 (const :tag "None" t)
129 (string :tag "Argument String")
130 (repeat :tag "Argument List" :value ("") string))
134 (defcustom vc-hg-annotate-switches '("-u" "--follow")
135 "String or list of strings specifying switches for hg annotate under VC.
136 If nil, use the value of `vc-annotate-switches'. If t, use no
138 :type '(choice (const :tag "Unspecified" nil)
139 (const :tag "None" t)
140 (string :tag "Argument String")
141 (repeat :tag "Argument List" :value ("") string))
145 (defcustom vc-hg-program "hg"
146 "Name of the Mercurial executable (excluding any arguments)."
150 (defcustom vc-hg-root-log-format
151 `(,(concat "{rev}:{ifeq(branch, 'default','', '{branch}')}"
152 ":{bookmarks}:{tags}:{author|person}"
153 " {date|shortdate} {desc|firstline}\\n")
154 ,(concat "^\\(?:[+@o x|-]*\\)" ;Graph data.
155 "\\([0-9]+\\):\\([^:]*\\)"
156 ":\\([^:]*\\):\\([^:]*\\):\\(.*?\\)"
157 "[ \t]+\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)")
158 ((1 'log-view-message-face)
161 (4 'change-log-conditionals)
163 (6 'change-log-date)))
164 "Mercurial log template for `vc-hg-print-log' short format.
165 This should be a list (TEMPLATE REGEXP KEYWORDS), where TEMPLATE
166 is the \"--template\" argument string to pass to Mercurial,
167 REGEXP is a regular expression matching the resulting Mercurial
168 output, and KEYWORDS is a list of `font-lock-keywords' for
169 highlighting the Log View buffer."
170 :type '(list string string (repeat sexp))
175 ;;; Properties of the backend
177 (defvar vc-hg-history nil)
179 (defun vc-hg-revision-granularity () 'repository)
180 (defun vc-hg-checkout-model (_files) 'implicit)
182 ;;; State querying functions
184 ;;;###autoload (defun vc-hg-registered (file)
185 ;;;###autoload "Return non-nil if FILE is registered with hg."
186 ;;;###autoload (if (vc-find-root file ".hg") ; short cut
187 ;;;###autoload (progn
188 ;;;###autoload (load "vc-hg" nil t)
189 ;;;###autoload (vc-hg-registered file))))
191 ;; Modeled after the similar function in vc-bzr.el
192 (defun vc-hg-registered (file)
193 "Return non-nil if FILE is registered with hg."
194 (when (vc-hg-root file) ; short cut
195 (let ((state (vc-hg-state file))) ; expensive
196 (and state (not (memq state '(ignored unregistered)))))))
198 (defun vc-hg-state (file)
199 "Hg-specific version of `vc-state'."
200 (let ((state (vc-hg-state-fast file)))
201 (if (eq state 'unsupported) (vc-hg-state-slow file) state)))
203 (defun vc-hg-state-slow (file)
204 "Determine status of FILE by running hg."
205 (setq file (expand-file-name file))
208 (default-directory (file-name-directory file))
210 (with-output-to-string
215 ;; Ignore all errors.
216 (let ((process-environment
217 ;; Avoid localization of messages so we
218 ;; can parse the output. Disable pager.
220 (list "TERM=dumb" "LANGUAGE=C" "HGPLAIN=1")
221 process-environment)))
223 vc-hg-program nil t nil
224 "--config" "alias.status=status"
225 "--config" "defaults.status="
226 "status" "-A" (file-relative-name file)))
227 ;; Some problem happened. E.g. We can't find an `hg'
230 (when (and (eq 0 status)
232 (null (string-match ".*: No such file or directory$" out)))
233 (let ((state (aref out 0)))
235 ((eq state ?=) 'up-to-date)
236 ((eq state ?A) 'added)
237 ((eq state ?M) 'edited)
238 ((eq state ?I) 'ignored)
239 ((eq state ?R) 'removed)
240 ((eq state ?!) 'missing)
241 ((eq state ??) 'unregistered)
242 ((eq state ?C) 'up-to-date) ;; Older mercurial versions use this.
245 (defun vc-hg-working-revision (file)
246 "Hg-specific version of `vc-working-revision'."
248 (with-output-to-string
249 (vc-hg-command standard-output 0 file
250 "parent" "--template" "{rev}")))
253 (defcustom vc-hg-symbolic-revision-styles
254 '(builtin-active-bookmark
255 "{if(bookmarks,sub(' ',',',bookmarks),if(phabdiff,phabdiff,shortest(node,6)))}")
256 "List of ways to present versions symbolically. The version
257 that we use is the first one that successfully produces a
260 Each entry in the list can be either:
262 - The symbol `builtin-active-bookmark', which indicates that we
263 should use the active bookmark if one exists. A template can
264 supply this information as well, but `builtin-active-bookmark' is
265 handled entirely inside Emacs and so is more efficient than using
266 the generic Mercurial mechanism.
268 - A string giving the Mercurial template to supply to \"hg
269 parent\". \"hg help template\" may be useful reading.
271 - A function to call; it should accept two arguments (a revision
272 and an optional path to which to limit history) and produce a
273 string. The function is called with `default-directory' set to
274 within the repository.
276 If no list entry produces a useful revision, return `nil'."
277 :type '(repeat (choice
278 (const :tag "Active bookmark" 'bookmark)
279 (string :tag "Hg template")
280 (function :tag "Custom")))
284 (defcustom vc-hg-use-file-version-for-mode-line-version nil
285 "When enabled, the modeline contains revision information for the visited file.
286 When not, the revision in the modeline is for the repository
287 working copy. `nil' is the much faster setting for
293 (defun vc-hg--active-bookmark-internal (rev)
294 (when (equal rev ".")
295 (let* ((current-bookmarks-file ".hg/bookmarks.current"))
296 (when (file-exists-p current-bookmarks-file)
299 (insert-file-contents current-bookmarks-file)
300 (buffer-substring-no-properties
301 (point-min) (point-max))))))))
303 (defun vc-hg--run-log (template rev path)
305 (with-output-to-string
308 standard-output 0 nil
309 "log" "-f" "-l1" "--template" template path)
311 standard-output 0 nil
312 "log" "-r" rev "-l1" "--template" template)))))
314 (defun vc-hg--symbolic-revision (rev &optional path)
315 "Make a Mercurial revision human-readable.
316 REV is a Mercurial revision. `default-directory' is assumed to
317 be in the repository root of interest. PATH, if set, is a
318 specific file to query."
319 (let ((symbolic-revision nil)
320 (styles vc-hg-symbolic-revision-styles))
321 (while (and (not symbolic-revision) styles)
322 (let ((style (pop styles)))
323 (setf symbolic-revision
324 (cond ((and (null path) (eq style 'builtin-active-bookmark))
325 (vc-hg--active-bookmark-internal rev))
327 (vc-hg--run-log style rev path))
329 (funcall style rev path))))))
332 (defun vc-hg-mode-line-string (file)
333 "Hg-specific version of `vc-mode-line-string'."
334 (let* ((backend-name "Hg")
335 (truename (file-truename file))
336 (state (vc-state truename))
340 (let ((default-directory
341 (expand-file-name (vc-hg-root truename))))
342 (vc-hg--symbolic-revision
344 (and vc-hg-use-file-version-for-mode-line-version
346 (rev (or rev "???")))
348 (cond ((or (eq state 'up-to-date)
349 (eq state 'needs-update))
350 (setq state-echo "Up to date file")
351 (setq face 'vc-up-to-date-state)
352 (concat backend-name "-" rev))
354 (setq state-echo "Locally added file")
355 (setq face 'vc-locally-added-state)
356 (concat backend-name "@" rev))
357 ((eq state 'conflict)
358 (setq state-echo "File contains conflicts after the last merge")
359 (setq face 'vc-conflict-state)
360 (concat backend-name "!" rev))
362 (setq state-echo "File removed from the VC system")
363 (setq face 'vc-removed-state)
364 (concat backend-name "!" rev))
366 (setq state-echo "File tracked by the VC system, but missing from the file system")
367 (setq face 'vc-missing-state)
368 (concat backend-name "?" rev))
370 (setq state-echo "Locally modified file")
371 (setq face 'vc-edited-state)
372 (concat backend-name ":" rev)))
374 'help-echo (concat state-echo " under the " backend-name
375 " version control system"))))
377 ;;; History functions
379 (defcustom vc-hg-log-switches nil
380 "String or list of strings specifying switches for hg log under VC."
381 :type '(choice (const :tag "None" nil)
382 (string :tag "Argument String")
383 (repeat :tag "Argument List" :value ("") string))
386 (autoload 'vc-setup-buffer "vc-dispatcher")
388 (defvar vc-hg-log-graph nil
389 "If non-nil, use `--graph' in the short log output.")
391 (defvar vc-hg-log-format (concat "changeset: {rev}:{node|short}\n"
392 "{tags % 'tag: {tag}\n'}"
393 "{if(parents, 'parents: {parents}\n')}"
395 "Date: {date|date}\n"
396 "summary: {desc|tabindent}\n\n")
397 "Mercurial log template for `vc-hg-print-log' long format.")
399 (defun vc-hg-print-log (files buffer &optional shortlog start-revision limit)
400 "Print commit log associated with FILES into specified BUFFER.
401 If SHORTLOG is non-nil, use a short format based on `vc-hg-root-log-format'.
402 If START-REVISION is non-nil, it is the newest revision to show.
403 If LIMIT is non-nil, show no more than this many entries."
404 ;; `vc-do-command' creates the buffer, but we need it before running
406 (vc-setup-buffer buffer)
407 ;; If the buffer exists from a previous invocation it might be
409 (let ((inhibit-read-only t))
412 (apply 'vc-hg-command buffer 'async files "log"
414 (when start-revision (list (format "-r%s:0" start-revision)))
415 (when limit (list "-l" (format "%s" limit)))
417 `(,@(if vc-hg-log-graph '("--graph"))
419 ,(car vc-hg-root-log-format))
420 `("--template" ,vc-hg-log-format))
421 vc-hg-log-switches)))))
423 (defvar log-view-message-re)
424 (defvar log-view-file-re)
425 (defvar log-view-font-lock-keywords)
426 (defvar log-view-per-file-logs)
427 (defvar log-view-expanded-log-entry-function)
429 (define-derived-mode vc-hg-log-view-mode log-view-mode "Hg-Log-View"
430 (require 'add-log) ;; we need the add-log faces
431 (set (make-local-variable 'log-view-file-re) "\\`a\\`")
432 (set (make-local-variable 'log-view-per-file-logs) nil)
433 (set (make-local-variable 'log-view-message-re)
434 (if (eq vc-log-view-type 'short)
435 (cadr vc-hg-root-log-format)
436 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)"))
437 (set (make-local-variable 'tab-width) 2)
438 ;; Allow expanding short log entries
439 (when (eq vc-log-view-type 'short)
440 (setq truncate-lines t)
441 (set (make-local-variable 'log-view-expanded-log-entry-function)
442 'vc-hg-expanded-log-entry))
443 (set (make-local-variable 'log-view-font-lock-keywords)
444 (if (eq vc-log-view-type 'short)
445 (list (cons (nth 1 vc-hg-root-log-format)
446 (nth 2 vc-hg-root-log-format)))
448 log-view-font-lock-keywords
451 ;; user: FirstName LastName <foo@bar>
452 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]"
454 (2 'change-log-email))
459 ("^user:[ \t]+\\([A-Za-z0-9_.+-]+\\(?:@[A-Za-z0-9_.-]+\\)?\\)"
460 (1 'change-log-email))
461 ("^date: \\(.+\\)" (1 'change-log-date))
462 ("^tag: +\\([^ ]+\\)$" (1 'highlight))
463 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))))
465 (autoload 'vc-switches "vc")
467 (defun vc-hg-diff (files &optional oldvers newvers buffer _async)
468 "Get a difference report using hg between two revisions of FILES."
469 (let* ((firstfile (car files))
470 (working (and firstfile (vc-working-revision firstfile))))
471 (when (and (equal oldvers working) (not newvers))
473 (when (and (not oldvers) newvers)
474 (setq oldvers working))
475 (apply #'vc-hg-command
476 (or buffer "*vc-diff*")
480 (vc-switches 'hg 'diff)
483 (list "-r" oldvers "-r" newvers)
484 (list "-r" oldvers)))))))
486 (defun vc-hg-expanded-log-entry (revision)
488 (vc-hg-command t nil nil "log" "-r" revision "--template" vc-hg-log-format)
489 (goto-char (point-min))
491 ;; Indent the expanded log entry.
492 (indent-region (point-min) (point-max) 2)
493 (goto-char (point-max))
496 (defun vc-hg-revision-table (files)
497 (let ((default-directory (file-name-directory (car files))))
499 (vc-hg-command t nil files "log" "--template" "{rev} ")
501 (buffer-substring-no-properties (point-min) (point-max))))))
503 ;; Modeled after the similar function in vc-cvs.el
504 (defun vc-hg-revision-completion-table (files)
505 (letrec ((table (lazy-completion-table
506 table (lambda () (vc-hg-revision-table files)))))
509 (defun vc-hg-annotate-command (file buffer &optional revision)
510 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
511 Optional arg REVISION is a revision to annotate from."
512 (apply #'vc-hg-command buffer 0 file "annotate" "-dq" "-n"
513 (append (vc-switches 'hg 'annotate)
514 (if revision (list (concat "-r" revision))))))
516 (declare-function vc-annotate-convert-time "vc-annotate" (&optional time))
518 ;; One line printed by "hg annotate -dq -n -u --follow" looks like this:
519 ;; b56girard 114590 2012-03-13 CLOBBER: Lorem ipsum dolor sit
520 ;; i.e. AUTHOR REVISION DATE FILENAME: CONTENTS
521 ;; The user can omit options "-u" and/or "--follow". Then it'll look like:
522 ;; 114590 2012-03-13 CLOBBER:
524 ;; b56girard 114590 2012-03-13:
525 (defconst vc-hg-annotate-re
527 "^\\(?: *[^ ]+ +\\)?\\([0-9]+\\) " ;User and revision.
528 "\\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\)" ;Date.
529 "\\(?: +\\([^:]+\\)\\)?:")) ;Filename.
531 (defun vc-hg-annotate-time ()
532 (when (looking-at vc-hg-annotate-re)
533 (goto-char (match-end 0))
534 (vc-annotate-convert-time
535 (let ((str (match-string-no-properties 2)))
537 (string-to-number (substring str 6 8))
538 (string-to-number (substring str 4 6))
539 (string-to-number (substring str 0 4)))))))
541 (defun vc-hg-annotate-extract-revision-at-line ()
544 (when (looking-at vc-hg-annotate-re)
545 (if (match-beginning 3)
546 (cons (match-string-no-properties 1)
547 (expand-file-name (match-string-no-properties 3)
548 (vc-hg-root default-directory)))
549 (match-string-no-properties 1)))))
553 (defun vc-hg-create-tag (dir name branchp)
554 "Attach the tag NAME to the state of the working copy."
555 (let ((default-directory dir))
556 (and (vc-hg-command nil 0 nil "status")
557 (vc-hg-command nil 0 nil (if branchp "bookmark" "tag") name))))
559 (defun vc-hg-retrieve-tag (dir name _update)
560 "Retrieve the version tagged by NAME of all registered files at or below DIR."
561 (let ((default-directory dir))
562 (vc-hg-command nil 0 nil "update" name)
563 ;; FIXME: update buffers if `update' is true
564 ;; TODO: update *vc-change-log* buffer so can see @ if --graph
567 ;;; Native data structure reading
569 (defcustom vc-hg-parse-hg-data-structures t
570 "If true, try directly parsing Mercurial data structures
571 directly instead of always running Mercurial. We try to be safe
572 against Mercurial data structure format changes and always fall
573 back to running Mercurial directly."
578 (defsubst vc-hg--read-u8 ()
579 "Read and advance over an unsigned byte.
584 (defsubst vc-hg--read-u32-be ()
585 "Read and advance over a big-endian unsigned 32-bit integer.
586 Return a fixnum; on overflow, result is undefined."
587 ;; Because elisp bytecode has an instruction for multiply and
588 ;; doesn't have one for lsh, it's somewhat counter-intuitively
589 ;; faster to multiply than to shift.
590 (+ (* (vc-hg--read-u8) (* 256 256 256))
591 (* (vc-hg--read-u8) (* 256 256))
592 (* (vc-hg--read-u8) 256)
593 (identity (vc-hg--read-u8))))
595 (defun vc-hg--raw-dirstate-search (dirstate fname)
597 (set-buffer-multibyte nil)
598 (insert-file-contents-literally dirstate)
600 (flen (length fname))
601 (case-fold-search nil)
602 (inhibit-changing-match-data t)
603 ;; Find a conservative bound for the loop below by using
604 ;; Boyer-Moore on the raw dirstate without parsing it; we
605 ;; know we can't possibly find fname _after_ the last place
606 ;; it appears, so we can bail out early if we try to parse
607 ;; past it, which especially helps when the file we're
608 ;; trying to find isn't in dirstate at all. There's no way
609 ;; to similarly bound the starting search position, since
610 ;; the file format is such that we need to parse it from
611 ;; the beginning to find record boundaries.
614 (goto-char (point-max))
615 (or (search-backward fname (+ (point-min) 40) t)
617 ;; 40 is just after the header, which contains the working
619 (goto-char (+ (point-min) 40))
620 ;; Iterate over all dirstate entries; we might run this loop
621 ;; hundreds of thousands of times, so performance is important
623 (while (< (point) search-limit)
624 ;; 1+4*4 is the length of the dirstate item header, which we
625 ;; spell as a literal for performance, since the elisp
626 ;; compiler lacks constant propagation
627 (forward-char (1+ (* 3 4)))
628 (let ((this-flen (vc-hg--read-u32-be)))
629 (if (and (or (eq this-flen flen)
630 (and (> this-flen flen)
631 (eq (char-after (+ (point) flen)) 0)))
632 (search-forward fname (+ (point) flen) t))
634 (backward-char (+ flen (1+ (* 4 4))))
636 (list (vc-hg--read-u8) ; status
637 (vc-hg--read-u32-be) ; mode
638 (vc-hg--read-u32-be) ; size (of file)
639 (vc-hg--read-u32-be) ; mtime
641 (goto-char (point-max)))
642 (forward-char this-flen))))
645 (define-error 'vc-hg-unsupported-syntax "unsupported hgignore syntax")
647 (defconst vc-hg--pcre-c-escapes
659 (defconst vc-hg--pcre-metacharacters
660 '(?. ?^ ?$ ?* ?+ ?? ?{ ?\\ ?\[ ?\| ?\())
662 (defconst vc-hg--elisp-metacharacters
663 '(?. ?* ?+ ?? ?\[ ?$ ?\\))
665 (defun vc-hg--escape-for-pcre (c)
666 (if (memq c vc-hg--pcre-metacharacters)
670 (defun vc-hg--parts-to-string (parts)
671 "Build a string from list PARTS. Each element is a character or string."
674 (let* ((partcell (prog1 parts (setf parts (cdr parts))))
675 (part (car partcell)))
677 (setf parts2 (nconc (append part nil) parts2))
678 (setcdr partcell parts2)
679 (setf parts2 partcell))))
680 (apply #'string parts2)))
682 (defun vc-hg--pcre-to-elisp-re (pcre prefix)
683 "Transform PCRE, a Mercurial file PCRE, into an elisp RE against PREFIX.
684 PREFIX is the directory name of the directory against which these
685 patterns are rooted. We understand only a subset of PCRE syntax;
686 if we don't understand a construct, we signal
687 `vc-hg-unsupported-syntax'."
688 (cl-assert (string-match "^/\\(.*/\\)?$" prefix))
693 (pcrelen (length pcre)))
695 (let ((c (aref pcre i)))
696 (cond ((eq state 'normal)
698 (rx (| "}\\?" (: "(?" (not (any ":")))))
700 (signal 'vc-hg-unsupported-syntax (list pcre)))
702 (setf state 'backslash))
704 (setf state 'charclass-enter)
707 (if (eq i 0) (setf anchored t)
708 (signal 'vc-hg-unsupported-syntax (list pcre))))
710 ;; Patterns can also match directories exactly,
711 ;; ignoring everything under a matched directory
712 (push "\\(?:$\\|/\\)" parts))
713 ((memq c '(?| ?\( ?\)))
717 ((eq state 'backslash)
718 (cond ((memq c '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
719 ?A ?b ?B ?d ?D ?s ?S ?w ?W ?Z ?x))
720 (signal 'vc-hg-unsupported-syntax (list pcre)))
721 ((memq c vc-hg--elisp-metacharacters)
724 (t (push (or (cdr (assq c vc-hg--pcre-c-escapes)) c) parts)))
725 (setf state 'normal))
726 ((eq state 'charclass-enter)
731 'charclass-backslash)))
732 ((eq state 'charclass-backslash)
733 (if (memq c '(?0 ?x))
734 (signal 'vc-hg-unsupported-syntax (list pcre)))
735 (push (or (cdr (assq c vc-hg--pcre-c-escapes)) c) parts)
736 (setf state 'charclass))
737 ((eq state 'charclass)
739 (cond ((eq c ?\\) (setf state 'charclass-backslash))
740 ((eq c ?\]) (setf state 'normal))))
741 (t (error "invalid state")))
743 (unless (eq state 'normal)
744 (signal 'vc-hg-unsupported-syntax (list pcre)))
748 (if anchored "" "\\(?:.*/\\)?")
749 (vc-hg--parts-to-string parts))))
751 (defun vc-hg--glob-to-pcre (glob)
752 "Transform a glob pattern into a Mercurial file pattern regex."
753 (let ((parts nil) (i 0) (n (length glob)) (group 0) c)
754 (cl-macrolet ((peek () '(and (< i n) (aref glob i))))
756 (setf c (aref glob i))
758 (cond ((not (memq c '(?* ?? ?\[ ?\{ ?\} ?, ?\\)))
759 (push (vc-hg--escape-for-pcre c) parts))
761 (cond ((eq (peek) ?*)
763 (cond ((eq (peek) ?/)
765 (push "(?:.*/)?" parts))
768 (t (push "[^/]*" parts))))
773 (when (and (< j n) (memq (aref glob j) '(?! ?\])))
775 (while (and (< j n) (not (eq (aref glob j) ?\])))
780 (let ((x (substring glob i j)))
781 (setf x (replace-regexp-in-string
782 "\\\\" "\\\\" x t t))
784 (cond ((eq (aref x 0) ?!)
785 (setf (aref x 0) ?^))
787 (setf x (concat "\\" x))))
790 (push ?\] parts))))))
797 ((and (eq c ?,) (> group 0))
806 (push (vc-hg--escape-for-pcre c) parts)))))
807 (concat (vc-hg--parts-to-string parts) "$")))
809 (defvar vc-hg--hgignore-patterns)
810 (defvar vc-hg--hgignore-filenames)
812 (defun vc-hg--hgignore-add-pcre (pcre prefix)
813 (push (vc-hg--pcre-to-elisp-re pcre prefix) vc-hg--hgignore-patterns))
815 (defun vc-hg--hgignore-add-glob (glob prefix)
816 (push (vc-hg--pcre-to-elisp-re (vc-hg--glob-to-pcre glob) prefix)
817 vc-hg--hgignore-patterns))
819 (defun vc-hg--hgignore-add-path (path prefix)
821 (dotimes (i (length path))
822 (push (vc-hg--escape-for-pcre (aref path i)) parts))
823 (vc-hg--hgignore-add-pcre
824 (concat "^" (vc-hg--parts-to-string parts) "$")
827 (defun vc-hg--slurp-hgignore-1 (hgignore prefix)
828 (let ((default-syntax 'vc-hg--hgignore-add-glob))
830 (let ((attr (file-attributes hgignore)))
831 (when attr (insert-file-contents hgignore))
832 (push (list hgignore (nth 5 attr) (nth 7 attr))
833 vc-hg--hgignore-filenames))
835 ;; This list of pattern-file commands isn't complete, but it
836 ;; should cover the common cases. Remember that we fall back
837 ;; to regular hg commands if we see something we don't like.
839 (narrow-to-region (point) (point-at-eol))
840 (cond ((looking-at "[ \t]*\\(?:#.*\\)?$"))
841 ((looking-at "syntax:[ \t]*re[ \t]*$")
842 (setf default-syntax 'vc-hg--hgignore-add-pcre))
843 ((looking-at "syntax:[ \t]*glob[ \t]*$")
844 (setf default-syntax 'vc-hg--hgignore-add-glob))
845 ((looking-at "path:\\(.+?\\)[ \t]*$")
846 (vc-hg--hgignore-add-path (match-string 1) prefix))
847 ((looking-at "glob:\\(.+?\\)[ \t]*$")
848 (vc-hg--hgignore-add-glob (match-string 1) prefix))
849 ((looking-at "re:\\(.+?\\)[ \t]*$")
850 (vc-hg--hgignore-add-pcre (match-string 1) prefix))
851 ((looking-at "\\(sub\\)?include:\\(.+?\\)[ \t]*$")
852 (let* ((sub (equal (match-string 1) "sub"))
853 (arg (match-string 2))
855 (if (string-match "^/" arg) arg
856 (concat (file-name-directory hgignore) arg))))
857 (vc-hg--slurp-hgignore-1
859 (if sub (file-name-directory included-file) prefix))))
860 ((looking-at "[a-zA-Z0-9_]*:")
861 (signal 'vc-hg-unsupported-syntax (list (match-string 0))))
863 (funcall default-syntax (match-string 0) prefix))))
866 (cl-defstruct (vc-hg--ignore-patterns
868 (:constructor vc-hg--ignore-patterns-make))
873 (defun vc-hg--slurp-hgignore (repo)
874 "Read hg ignore patterns from REPO.
875 REPO must be the directory name of an hg repository."
876 (cl-assert (string-match "^/\\(.*/\\)?$" repo))
877 (let* ((hgignore (concat repo ".hgignore"))
878 (vc-hg--hgignore-patterns nil)
879 (vc-hg--hgignore-filenames nil))
880 (vc-hg--slurp-hgignore-1 hgignore repo)
881 (vc-hg--ignore-patterns-make
883 :ignore-patterns (nreverse vc-hg--hgignore-patterns)
884 :file-sources (nreverse vc-hg--hgignore-filenames))))
886 (defun vc-hg--ignore-patterns-valid-p (hgip)
887 "Return whether the cached ignore patterns in HGIP are still valid"
889 (file-sources (vc-hg--ignore-patterns-file-sources hgip)))
890 (while (and file-sources valid)
891 (let* ((fs (pop file-sources))
892 (saved-mtime (nth 1 fs))
893 (saved-size (nth 2 fs))
894 (attr (file-attributes (nth 0 fs)))
895 (current-mtime (nth 5 attr))
896 (current-size (nth 7 attr)))
897 (unless (and (equal saved-mtime current-mtime)
898 (equal saved-size current-size))
902 (defun vc-hg--ignore-patterns-ignored-p (hgip filename)
903 "Test whether the ignore pattern set HGIP says to ignore FILENAME.
904 FILENAME must be the file's true absolute name."
905 (let ((patterns (vc-hg--ignore-patterns-ignore-patterns hgip))
906 (inhibit-changing-match-data t)
908 (while (and patterns (not ignored))
909 (setf ignored (string-match (pop patterns) filename)))
912 (defun vc-hg--time-to-fixnum (ts)
913 (+ (* 65536 (car ts)) (cadr ts)))
915 (defvar vc-hg--cached-ignore-patterns nil
916 "Cached pre-parsed hg ignore patterns.")
918 (defun vc-hg--file-ignored-p (repo repo-relative-filename)
919 (let ((hgip vc-hg--cached-ignore-patterns))
921 (equal repo (vc-hg--ignore-patterns-repo hgip))
922 (vc-hg--ignore-patterns-valid-p hgip))
923 (setf vc-hg--cached-ignore-patterns nil)
924 (setf hgip (vc-hg--slurp-hgignore repo))
925 (setf vc-hg--cached-ignore-patterns hgip))
926 (vc-hg--ignore-patterns-ignored-p
928 (concat repo repo-relative-filename))))
930 (defun vc-hg--read-repo-requirements (repo)
931 (cl-assert (string-match "^/\\(.*/\\)?$" repo))
932 (let* ((requires-filename (concat repo ".hg/requires")))
933 (and (file-exists-p requires-filename)
935 (set-buffer-multibyte nil)
936 (insert-file-contents-literally requires-filename)
937 (split-string (buffer-substring-no-properties
938 (point-min) (point-max)))))))
940 (defconst vc-hg-supported-requirements
948 "List of Mercurial repository requirements we understand; if a
949 repository requires features not present in this list, we avoid
950 attempting to parse Mercurial data structures.")
952 (defun vc-hg--requirements-understood-p (repo)
953 "Check that we understand the format of the given repository.
954 REPO is the directory name of a Mercurial repository."
955 (null (cl-set-difference (vc-hg--read-repo-requirements repo)
956 vc-hg-supported-requirements
959 (defvar vc-hg--dirstate-scan-cache nil
960 "Cache of the last result of `vc-hg--raw-dirstate-search'.
961 Avoids the need to repeatedly scan dirstate on repeated calls to
962 `vc-hg-state', as we see during registration queries.")
964 (defun vc-hg--cached-dirstate-search (dirstate dirstate-attr ascii-fname)
965 (let* ((mtime (nth 5 dirstate-attr))
966 (size (nth 7 dirstate-attr))
967 (cache vc-hg--dirstate-scan-cache)
970 (equal dirstate (pop cache))
971 (equal mtime (pop cache))
972 (equal size (pop cache))
973 (equal ascii-fname (pop cache)))
975 (let ((result (vc-hg--raw-dirstate-search dirstate ascii-fname)))
976 (setf vc-hg--dirstate-scan-cache
977 (list dirstate mtime size ascii-fname result))
980 (defun vc-hg-state-fast (filename)
981 "Like `vc-hg-state', but parse internal data structures directly.
982 Returns one of the usual `vc-state' enumeration values or
983 `unsupported' if we need to take the slow path and run the
989 repo-relative-filename
992 ;; Explicit user disable
993 (not vc-hg-parse-hg-data-structures)
994 ;; It'll probably be faster to run hg remotely
995 (file-remote-p filename)
997 (setf truename (file-truename filename))
998 (file-remote-p truename))
999 (not (setf repo (vc-hg-root truename)))
1000 ;; dirstate must exist
1002 (setf repo (expand-file-name repo))
1003 (cl-assert (string-match "^/\\(.*/\\)?$" repo))
1004 (setf dirstate (concat repo ".hg/dirstate"))
1005 (setf dirstate-attr (file-attributes dirstate))))
1006 ;; Repository must be in an understood format
1007 (not (vc-hg--requirements-understood-p repo))
1008 ;; Dirstate too small to be valid
1009 (< (nth 7 dirstate-attr) 40)
1010 ;; We want to store 32-bit unsigned values in fixnums
1011 (< most-positive-fixnum 4294967295)
1013 (setf repo-relative-filename
1014 (file-relative-name truename repo))
1017 (let (last-coding-system-used)
1018 (encode-coding-string
1019 repo-relative-filename
1021 ;; We only try dealing with ASCII filenames
1022 (not (equal ascii-fname repo-relative-filename))))
1024 (let* ((dirstate-entry
1025 (vc-hg--cached-dirstate-search
1026 dirstate dirstate-attr ascii-fname))
1027 (state (car dirstate-entry))
1028 (stat (file-attributes
1029 (concat repo repo-relative-filename))))
1030 (cond ((eq state ?r) 'removed)
1031 ((and (not state) stat)
1033 (if (vc-hg--file-ignored-p repo repo-relative-filename)
1036 (vc-hg-unsupported-syntax 'unsupported)))
1037 ((and state (not stat)) 'missing)
1039 (let ((vc-hg-size (nth 2 dirstate-entry))
1040 (vc-hg-mtime (nth 3 dirstate-entry))
1041 (fs-size (nth 7 stat))
1042 (fs-mtime (vc-hg--time-to-fixnum (nth 5 stat))))
1043 (if (and (eql vc-hg-size fs-size) (eql vc-hg-mtime fs-mtime))
1046 ((eq state ?a) 'added)
1047 (state 'unsupported))))))
1051 (defun vc-hg-previous-revision (_file rev)
1052 ;; We can't simply decrement by 1, because that revision might be
1053 ;; e.g. on a different branch (bug#22032).
1056 (vc-hg-command t nil nil "id" "-n" "-r" (concat rev "^")))
1057 ;; Trim the trailing newline.
1058 (buffer-substring (point-min) (1- (point-max))))))
1060 (defun vc-hg-next-revision (_file rev)
1061 (let ((newrev (1+ (string-to-number rev)))
1064 (vc-hg-command t 0 nil "tip" "--style=default")
1065 (goto-char (point-min))
1066 (re-search-forward "^changeset:[ \t]*\\([0-9]+\\):")
1067 (string-to-number (match-string-no-properties 1)))))
1068 ;; We don't want to exceed the maximum possible revision number, ie
1069 ;; the tip revision.
1070 (when (<= newrev tip-revision)
1071 (number-to-string newrev))))
1073 ;; Modeled after the similar function in vc-bzr.el
1074 (defun vc-hg-delete-file (file)
1075 "Delete FILE and delete it in the hg repository."
1079 (vc-hg-command nil 0 file "remove" "--after" "--force"))
1081 ;; Modeled after the similar function in vc-bzr.el
1082 (defun vc-hg-rename-file (old new)
1083 "Rename file from OLD to NEW using `hg mv'."
1084 (vc-hg-command nil 0 new "mv" old))
1086 (defun vc-hg-register (files &optional _comment)
1087 "Register FILES under hg. COMMENT is ignored."
1088 (vc-hg-command nil 0 files "add"))
1090 (defun vc-hg-create-repo ()
1091 "Create a new Mercurial repository."
1092 (vc-hg-command nil 0 nil "init"))
1094 (defalias 'vc-hg-responsible-p 'vc-hg-root)
1096 (defun vc-hg-unregister (file)
1097 "Unregister FILE from hg."
1098 (vc-hg-command nil 0 file "forget"))
1100 (declare-function log-edit-extract-headers "log-edit" (headers string))
1102 (defun vc-hg-checkin (files comment &optional _rev)
1103 "Hg-specific version of `vc-backend-checkin'.
1105 (apply 'vc-hg-command nil 0 files
1106 (nconc (list "commit" "-m")
1107 (log-edit-extract-headers '(("Author" . "--user")
1108 ("Date" . "--date"))
1111 (defun vc-hg-find-revision (file rev buffer)
1112 (let ((coding-system-for-read 'binary)
1113 (coding-system-for-write 'binary))
1115 (vc-hg-command buffer 0 file "cat" "-r" rev)
1116 (vc-hg-command buffer 0 file "cat"))))
1118 (defun vc-hg-find-ignore-file (file)
1119 "Return the root directory of the repository of FILE."
1120 (expand-file-name ".hgignore"
1123 ;; Modeled after the similar function in vc-bzr.el
1124 (defun vc-hg-checkout (file &optional rev)
1125 "Retrieve a revision of FILE.
1126 EDITABLE is ignored.
1127 REV is the revision to check out into WORKFILE."
1128 (let ((coding-system-for-read 'binary)
1129 (coding-system-for-write 'binary))
1130 (with-current-buffer (or (get-file-buffer file) (current-buffer))
1132 (vc-hg-command t 0 file "cat" "-r" rev)
1133 (vc-hg-command t 0 file "cat")))))
1135 (defun vc-hg-resolve-when-done ()
1136 "Call \"hg resolve -m\" if the conflict markers have been removed."
1138 (goto-char (point-min))
1139 (unless (re-search-forward "^<<<<<<< " nil t)
1140 (vc-hg-command nil 0 buffer-file-name "resolve" "-m")
1141 ;; Remove the hook so that it is not called multiple times.
1142 (remove-hook 'after-save-hook 'vc-hg-resolve-when-done t))))
1144 (defun vc-hg-find-file-hook ()
1145 (when (and buffer-file-name
1146 (file-exists-p (concat buffer-file-name ".orig"))
1147 ;; Hg does not seem to have a "conflict" status, eg
1148 ;; hg http://bz.selenic.com/show_bug.cgi?id=2724
1149 (memq (vc-file-getprop buffer-file-name 'vc-state)
1151 ;; Maybe go on to check that "hg resolve -l" says "U"?
1152 ;; If "hg resolve -l" says there's a conflict but there are no
1153 ;; conflict markers, it's not clear what we should do.
1155 (goto-char (point-min))
1156 (re-search-forward "^<<<<<<< " nil t)))
1157 ;; Hg may not recognize "conflict" as a state, but we can do better.
1158 (vc-file-setprop buffer-file-name 'vc-state 'conflict)
1159 (smerge-start-session)
1160 (add-hook 'after-save-hook 'vc-hg-resolve-when-done nil t)
1161 (vc-message-unresolved-conflicts buffer-file-name)))
1164 ;; Modeled after the similar function in vc-bzr.el
1165 (defun vc-hg-revert (file &optional contents-done)
1166 (unless contents-done
1167 (with-temp-buffer (vc-hg-command t 0 file "revert"))))
1169 ;;; Hg specific functionality.
1171 (defvar vc-hg-extra-menu-map
1172 (let ((map (make-sparse-keymap)))
1175 (defun vc-hg-extra-menu () vc-hg-extra-menu-map)
1177 (defun vc-hg-extra-status-menu () vc-hg-extra-menu-map)
1179 (defvar log-view-vc-backend)
1181 (cl-defstruct (vc-hg-extra-fileinfo
1183 (:constructor vc-hg-create-extra-fileinfo (rename-state extra-name))
1184 (:conc-name vc-hg-extra-fileinfo->))
1185 rename-state ;; rename or copy state
1186 extra-name) ;; original name for copies and rename targets, new name for
1188 (declare-function vc-default-dir-printer "vc-dir" (backend fileentry))
1190 (defun vc-hg-dir-printer (info)
1191 "Pretty-printer for the vc-dir-fileinfo structure."
1192 (let ((extra (vc-dir-fileinfo->extra info)))
1193 (vc-default-dir-printer 'Hg info)
1197 (pcase (vc-hg-extra-fileinfo->rename-state extra)
1198 (`copied "copied from")
1199 (`renamed-from "renamed from")
1200 (`renamed-to "renamed to"))
1201 (vc-hg-extra-fileinfo->extra-name extra))
1202 'face 'font-lock-comment-face)))))
1204 (defun vc-hg-after-dir-status (update-function)
1206 (translation '((?= . up-to-date)
1213 (? . copy-rename-line)
1214 (?? . unregistered)))
1218 (last-line-copy nil))
1219 (goto-char (point-min))
1221 (setq translated (cdr (assoc (char-after) translation)))
1223 (buffer-substring-no-properties (+ (point) 2)
1224 (line-end-position)))
1225 (cond ((not translated)
1226 (setq last-line-copy nil))
1227 ((eq translated 'up-to-date)
1228 (setq last-line-copy nil))
1229 ((eq translated 'copy-rename-line)
1230 ;; For copied files the output looks like this:
1231 ;; A COPIED_FILE_NAME
1232 ;; ORIGINAL_FILE_NAME
1233 (setf (nth 2 last-added)
1234 (vc-hg-create-extra-fileinfo 'copied file))
1235 (setq last-line-copy t))
1236 ((and last-line-copy (eq translated 'removed))
1237 ;; For renamed files the output looks like this:
1239 ;; ORIGINAL_FILE_NAME
1240 ;; R ORIGINAL_FILE_NAME
1241 ;; We need to adjust the previous entry to not think it is a copy.
1242 (setf (vc-hg-extra-fileinfo->rename-state (nth 2 last-added))
1244 (push (list file translated
1245 (vc-hg-create-extra-fileinfo
1246 'renamed-to (nth 0 last-added))) result)
1247 (setq last-line-copy nil))
1249 (setq last-added (list file translated nil))
1250 (push last-added result)
1251 (setq last-line-copy nil)))
1253 (funcall update-function result)))
1255 ;; Follows vc-hg-command (or vc-do-async-command), which uses vc-do-command
1256 ;; from vc-dispatcher.
1257 (declare-function vc-exec-after "vc-dispatcher" (code))
1258 ;; Follows vc-exec-after.
1259 (declare-function vc-set-async-update "vc-dispatcher" (process-buffer))
1261 (defun vc-hg-dir-status-files (_dir files update-function)
1262 ;; XXX: We can't pass DIR directly to 'hg status' because that
1263 ;; returns all ignored files if FILES is non-nil (bug#22481).
1264 ;; If honoring DIR ever becomes important, try using '-I DIR/'.
1265 (vc-hg-command (current-buffer) 'async files
1267 (concat "-mardu" (if files "i"))
1270 (vc-hg-after-dir-status update-function)))
1272 (defun vc-hg-dir-extra-header (name &rest commands)
1273 (concat (propertize name 'face 'font-lock-type-face)
1276 (apply 'vc-hg-command (current-buffer) 0 nil commands)
1277 (buffer-substring-no-properties (point-min) (1- (point-max))))
1278 'face 'font-lock-variable-name-face)))
1280 (defun vc-hg-dir-extra-headers (dir)
1281 "Generate extra status headers for a Mercurial tree."
1282 (let ((default-directory dir))
1284 (vc-hg-dir-extra-header "Root : " "root") "\n"
1285 (vc-hg-dir-extra-header "Branch : " "id" "-b") "\n"
1286 (vc-hg-dir-extra-header "Tags : " "id" "-t") ; "\n"
1287 ;; these change after each commit
1288 ;; (vc-hg-dir-extra-header "Local num : " "id" "-n") "\n"
1289 ;; (vc-hg-dir-extra-header "Global id : " "id" "-i")
1292 (defun vc-hg-log-incoming (buffer remote-location)
1293 (vc-hg-command buffer 1 nil "incoming" "-n" (unless (string= remote-location "")
1296 (defun vc-hg-log-outgoing (buffer remote-location)
1297 (vc-hg-command buffer 1 nil "outgoing" "-n" (unless (string= remote-location "")
1300 (defvar vc-hg-error-regexp-alist nil
1301 ;; 'hg pull' does not list modified files, so, for now, the only
1302 ;; benefit of `vc-compilation-mode' is that one can get rid of
1303 ;; *vc-hg* buffer with 'q' or 'z'.
1304 ;; TODO: call 'hg incoming' before pull/merge to get the list of
1306 "Value of `compilation-error-regexp-alist' in *vc-hg* buffers.")
1308 (autoload 'vc-do-async-command "vc-dispatcher")
1309 (autoload 'log-view-get-marked "log-view")
1311 (defun vc-hg--pushpull (command prompt &optional obsolete)
1312 "Run COMMAND (a string; either push or pull) on the current Hg branch.
1313 If PROMPT is non-nil, prompt for the Hg command to run.
1314 If OBSOLETE is non-nil, behave like the old versions of the Hg push/pull
1315 commands, which only operated on marked files."
1317 ;; The `vc-hg-pull' and `vc-hg-push' commands existed before the
1318 ;; `pull'/`push' VC actions were implemented.
1319 ;; The following is for backwards compatibility.
1320 (if (and obsolete (setq marked-list (log-view-get-marked)))
1321 (apply #'vc-hg-command
1325 (mapcar (lambda (arg) (list "-r" arg)) marked-list)))
1326 (let* ((root (vc-hg-root default-directory))
1327 (buffer (format "*vc-hg : %s*" (expand-file-name root)))
1328 (hg-program vc-hg-program)
1329 ;; Fixme: before updating the working copy to the latest
1330 ;; state, should check if it's visiting an old revision.
1331 (args (if (equal command "pull") '("-u"))))
1332 ;; If necessary, prompt for the exact command.
1333 ;; TODO if pushing, prompt if no default push location - cf bzr.
1335 (setq args (split-string
1337 (format "Hg %s command: " command)
1338 (format "%s %s%s" hg-program command
1340 (concat " " (mapconcat 'identity args " "))))
1343 (setq hg-program (car args)
1346 (apply 'vc-do-async-command buffer root hg-program command args)
1347 (with-current-buffer buffer
1348 (vc-run-delayed (vc-compilation-mode 'hg)))
1349 (vc-set-async-update buffer)))))
1351 (defun vc-hg-pull (prompt)
1352 "Issue a Mercurial pull command.
1353 If called interactively with a set of marked Log View buffers,
1354 call \"hg pull -r REVS\" to pull in the specified revisions REVS.
1356 With a prefix argument or if PROMPT is non-nil, prompt for a
1357 specific Mercurial pull command. The default is \"hg pull -u\",
1358 which fetches changesets from the default remote repository and
1359 then attempts to update the working directory."
1361 (vc-hg--pushpull "pull" prompt (called-interactively-p 'interactive)))
1363 (defun vc-hg-push (prompt)
1364 "Push changes from the current Mercurial branch.
1365 Normally, this runs \"hg push\". If PROMPT is non-nil, prompt
1366 for the Hg command to run.
1368 If called interactively with a set of marked Log View buffers,
1369 call \"hg push -r REVS\" to push the specified revisions REVS."
1371 (vc-hg--pushpull "push" prompt (called-interactively-p 'interactive)))
1373 (defun vc-hg-merge-branch ()
1374 "Merge incoming changes into the current working directory.
1375 This runs the command \"hg merge\"."
1376 (let* ((root (vc-hg-root default-directory))
1377 (buffer (format "*vc-hg : %s*" (expand-file-name root))))
1378 (apply 'vc-do-async-command buffer root vc-hg-program '("merge"))
1379 (with-current-buffer buffer (vc-run-delayed (vc-compilation-mode 'hg)))
1380 (vc-set-async-update buffer)))
1382 ;;; Internal functions
1384 (defun vc-hg-command (buffer okstatus file-or-list &rest flags)
1385 "A wrapper around `vc-do-command' for use in vc-hg.el.
1386 This function differs from vc-do-command in that it invokes
1387 `vc-hg-program', and passes `vc-hg-global-switches' to it before FLAGS."
1388 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-hg-program file-or-list
1389 (if (stringp vc-hg-global-switches)
1390 (cons vc-hg-global-switches flags)
1391 (append vc-hg-global-switches
1394 (defun vc-hg-root (file)
1395 (vc-find-root file ".hg"))
1399 ;;; vc-hg.el ends here