Mercurial > emacs
annotate lisp/vc-hg.el @ 81689:34951f8eb3b1
*** empty log message ***
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Mon, 02 Jul 2007 21:53:51 +0000 |
parents | cea1e05b3c83 |
children | fc97b55f9678 |
rev | line source |
---|---|
81474 | 1 ;;; vc-hg.el --- VC backend for the mercurial version control system |
2 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
4 |
81474 | 5 ;; Author: Ivan Kanis |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
6 ;; Keywords: tools |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
7 ;; Version: 1889 |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
8 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
10 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
81474 | 12 ;; it under the terms of the GNU General Public License as published by |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
14 ;; any later version. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
15 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
19 ;; GNU General Public License for more details. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
20 |
81474 | 21 ;; You should have received a copy of the GNU General Public License |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
81474 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This is a mercurial version control backend | |
29 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
30 ;;; Thanks: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
31 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
32 ;;; Bugs: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
33 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
34 ;;; Installation: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
35 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
36 ;;; Todo: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
37 |
81526 | 38 ;; Implement the rest of the vc interface: |
39 ;; - dired | |
40 ;; - snapshot? | |
81474 | 41 |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
42 ;; Implement Stefan Monnier's advice: |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
43 ;; vc-hg-registered and vc-hg-state |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
44 ;; Both of those functions should be super extra careful to fail gracefully in |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
45 ;; unexpected circumstances. The most important such case is when the `hg' |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
46 ;; executable is not available. The reason this is important is that any error |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
47 ;; there will prevent the user from even looking at the file :-( |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
48 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
49 ;; mercurial's control and extracting the current revision should be done |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
50 ;; without even using `hg' (this way even if you don't have `hg' installed, |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
51 ;; Emacs is able to tell you this file is under mercurial's control). |
81474 | 52 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
53 ;;; History: |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
54 ;; |
81474 | 55 |
56 ;;; Code: | |
57 | |
58 (eval-when-compile | |
59 (require 'vc)) | |
60 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
61 ;; XXX This should be moved to vc-hooks when we can be sure that vc-state |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
62 ;; and friends are always harmless. |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
63 (add-to-list 'vc-handled-backends 'HG) |
81474 | 64 |
65 ;;; Customization options | |
66 | |
67 (defcustom vc-hg-global-switches nil | |
68 "*Global switches to pass to any Hg command." | |
69 :type '(choice (const :tag "None" nil) | |
70 (string :tag "Argument String") | |
71 (repeat :tag "Argument List" | |
72 :value ("") | |
73 string)) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
74 ;; :version "22.2" |
81474 | 75 :group 'vc) |
76 | |
77 ;;; State querying functions | |
78 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
79 ;;;###autoload (defun vc-hg-registered (file) |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
80 ;;;###autoload "Return non-nil if FILE is registered with hg." |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
81 ;;;###autoload (if (vc-find-root file ".hg") ; short cut |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
82 ;;;###autoload (progn |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
83 ;;;###autoload (load "vc-hg") |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
84 ;;;###autoload (vc-hg-registered file)))) |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
85 |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
86 ;; Modelled after the similar function in vc-bzr.el |
81474 | 87 (defun vc-hg-registered (file) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
88 "Return non-nil if FILE is registered with hg." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
89 (if (vc-find-root file ".hg") ; short cut |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
90 (vc-hg-state file))) ; expensive |
81474 | 91 |
92 (defun vc-hg-state (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
93 "Hg-specific version of `vc-state'." |
81474 | 94 (let ((out (vc-hg-internal-status file))) |
95 (if (eq 0 (length out)) 'up-to-date | |
96 (let ((state (aref out 0))) | |
97 (cond | |
98 ((eq state ?M) 'edited) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
99 ((eq state ?A) 'edited) |
81474 | 100 ((eq state ?P) 'needs-patch) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
101 ((eq state ??) nil) |
81474 | 102 (t 'up-to-date)))))) |
103 | |
104 (defun vc-hg-workfile-version (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
105 "Hg-specific version of `vc-workfile-version'." |
81474 | 106 (let ((out (vc-hg-internal-log file))) |
107 (if (string-match "changeset: *\\([0-9]*\\)" out) | |
108 (match-string 1 out) | |
109 "0"))) | |
110 | |
111 ;;; History functions | |
112 | |
113 (defun vc-hg-print-log(file &optional buffer) | |
114 "Get change log associated with FILE." | |
81564
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
115 ;; `log-view-mode' needs to have the file name in order to function |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
116 ;; correctly. "hg log" does not print it, so we insert it here by |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
117 ;; hand. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
118 |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
119 ;; `vc-do-command' creates the buffer, but we need it before running |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
120 ;; the command. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
121 (vc-setup-buffer buffer) |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
122 ;; If the buffer exists from a previous invocation it might be |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
123 ;; read-only. |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
124 (let ((inhibit-read-only t)) |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
125 (with-current-buffer |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
126 buffer |
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
127 (insert "File: " (file-name-nondirectory file) "\n"))) |
81474 | 128 (vc-hg-command |
129 buffer | |
130 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
131 file "log")) | |
132 | |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
133 (defvar log-view-message-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
134 (defvar log-view-file-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
135 (defvar log-view-font-lock-keywords) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
136 |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
137 (define-derived-mode vc-hg-log-view-mode log-view-mode "HG-Log-View" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
138 (require 'add-log) ;; we need the faces add-log |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
139 ;; Don't have file markers, so use impossible regexp. |
81564
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
140 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
141 (set (make-local-variable 'log-view-message-re) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
142 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)") |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
143 (set (make-local-variable 'log-view-font-lock-keywords) |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
144 (append |
81575
cea1e05b3c83
* vc-hg.el (vc-hg-log-view-mode): Revert incorrect change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81572
diff
changeset
|
145 log-view-font-lock-keywords |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
146 ;; Handle the case: |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
147 ;; user: foo@bar |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
148 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
149 (1 'change-log-email)) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
150 ;; Handle the case: |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
151 ;; user: FirstName LastName <foo@bar> |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
152 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
153 (1 'change-log-name) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
154 (2 'change-log-email)) |
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
155 ("^date: \\(.+\\)" (1 'change-log-date)) |
81575
cea1e05b3c83
* vc-hg.el (vc-hg-log-view-mode): Revert incorrect change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81572
diff
changeset
|
156 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) |
81538
ac8e3d72984f
(vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81526
diff
changeset
|
157 |
81526 | 158 (defun vc-hg-diff (file &optional oldvers newvers buffer) |
81474 | 159 "Get a difference report using hg between two versions of FILE." |
81526 | 160 (let ((working (vc-workfile-version file))) |
161 (if (and (equal oldvers working) (not newvers)) | |
162 (setq oldvers nil)) | |
163 (if (and (not oldvers) newvers) | |
164 (setq oldvers working)) | |
165 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
166 "--cwd" (file-name-directory file) "diff" |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
167 (append |
81526 | 168 (if oldvers |
169 (if newvers | |
170 (list "-r" oldvers "-r" newvers) | |
171 (list "-r" oldvers)) | |
172 (list "")) | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
173 (list (file-name-nondirectory file)))))) |
81526 | 174 |
175 (defun vc-hg-annotate-command (file buffer &optional version) | |
176 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. | |
177 Optional arg VERSION is a version to annotate from." | |
178 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) | |
179 (with-current-buffer buffer | |
180 (goto-char (point-min)) | |
181 (re-search-forward "^[0-9]") | |
182 (delete-region (point-min) (1- (point))))) | |
183 | |
184 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
185 ;; The format for one line output by "hg annotate -d -n" looks like this: |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
186 ;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS |
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
187 ;; i.e: VERSION_NUMBER DATE: CONTENTS |
81526 | 188 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ") |
189 | |
190 (defun vc-hg-annotate-time () | |
191 (when (looking-at vc-hg-annotate-re) | |
192 (goto-char (match-end 0)) | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
193 (vc-annotate-convert-time |
81526 | 194 (date-to-time (match-string-no-properties 2))))) |
195 | |
196 (defun vc-hg-annotate-extract-revision-at-line () | |
197 (save-excursion | |
198 (beginning-of-line) | |
199 (if (looking-at vc-hg-annotate-re) (match-string-no-properties 1)))) | |
200 | |
201 (defun vc-hg-previous-version (file rev) | |
202 (let ((newrev (1- (string-to-number rev)))) | |
203 (when (>= newrev 0) | |
204 (number-to-string newrev)))) | |
81474 | 205 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
206 (defun vc-hg-register (file &optional rev comment) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
207 "Register FILE under hg. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
208 REV is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
209 COMMENT is ignored." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
210 (vc-hg-command nil nil file "add")) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
211 |
81526 | 212 (defun vc-hg-checkin (file rev comment) |
213 "HG-specific version of `vc-backend-checkin'. | |
214 REV is ignored." | |
215 (vc-hg-command nil nil file "commit" "-m" comment)) | |
216 | |
81566
0e2a83705e5f
(vc-hg-registered): Add an autoloaded version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81564
diff
changeset
|
217 ;; Modelled after the similar function in vc-bzr.el |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
218 (defun vc-hg-checkout (file &optional editable rev workfile) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
219 "Retrieve a revision of FILE into a WORKFILE. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
220 EDITABLE is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
221 REV is the revision to check out into WORKFILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
222 (unless workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
223 (setq workfile (vc-version-backup-file-name file rev))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
224 (let ((coding-system-for-read 'binary) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
225 (coding-system-for-write 'binary)) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
226 (with-temp-file workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
227 (if rev |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
228 (vc-hg-command t nil file "cat" "-r" rev) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
229 (vc-hg-command t nil file "cat"))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
230 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
231 (defun vc-hg-checkout-model (file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
232 'implicit) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
233 |
81474 | 234 ;;; Internal functions |
235 | |
236 (defun vc-hg-command (buffer okstatus file &rest flags) | |
237 "A wrapper around `vc-do-command' for use in vc-hg.el. | |
238 The difference to vc-do-command is that this function always invokes `hg', | |
239 and that it passes `vc-hg-global-switches' to it before FLAGS." | |
240 (apply 'vc-do-command buffer okstatus "hg" file | |
241 (if (stringp vc-hg-global-switches) | |
242 (cons vc-hg-global-switches flags) | |
243 (append vc-hg-global-switches | |
244 flags)))) | |
245 | |
81564
99961edaa9c1
(vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81538
diff
changeset
|
246 (defun vc-hg-internal-log (file &optional buffer) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
247 "Return log of FILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
248 (with-output-to-string |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
249 (with-current-buffer |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
250 standard-output |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
251 (call-process |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
252 "hg" nil t nil "--cwd" (file-name-directory file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
253 "log" "-l1" (file-name-nondirectory file))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
254 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
255 (defun vc-hg-internal-status(file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
256 "Return status of FILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
257 (with-output-to-string |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
258 (with-current-buffer |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
259 standard-output |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
260 (call-process |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
261 "hg" nil t nil "--cwd" (file-name-directory file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
262 "status" (file-name-nondirectory file))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
263 |
81474 | 264 (provide 'vc-hg) |
265 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
266 ;;; vc-hg.el ends here |