Mercurial > emacs
annotate lisp/vc-mtn.el @ 94678:ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 06 May 2008 07:58:00 +0000 |
parents | a0bb8ca25a33 |
children | eedf64b515f0 |
rev | line source |
---|---|
78791 | 1 ;;; vc-mtn.el --- VC backend for Monotone |
2 | |
79721 | 3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
78791 | 4 |
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> | |
6 ;; Keywords: | |
7 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
9 |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
78791 | 11 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
13 ;; (at your option) any later version. |
78791 | 14 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
78791 | 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 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
78791 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; | |
26 | |
27 ;;; Code: | |
28 | |
29 (eval-when-compile (require 'cl) (require 'vc)) | |
30 | |
31 ;; Clear up the cache to force vc-call to check again and discover | |
32 ;; new functions when we reload this file. | |
33 (put 'Mtn 'vc-functions nil) | |
34 | |
35 (defvar vc-mtn-command "mtn") | |
36 (unless (executable-find vc-mtn-command) | |
37 ;; vc-mtn.el is 100% non-functional without the `mtn' executable. | |
38 (setq vc-handled-backends (delq 'Mtn vc-handled-backends))) | |
39 | |
40 ;;;###autoload | |
41 (defconst vc-mtn-admin-dir "_MTN") | |
42 ;;;###autoload | |
43 (defconst vc-mtn-admin-format (concat vc-mtn-admin-dir "/format")) | |
44 | |
45 ;;;###autoload (defun vc-mtn-registered (file) | |
46 ;;;###autoload (if (vc-find-root file vc-mtn-admin-format) | |
47 ;;;###autoload (progn | |
48 ;;;###autoload (load "vc-mtn") | |
49 ;;;###autoload (vc-mtn-registered file)))) | |
50 | |
51 (defun vc-mtn-revision-granularity () 'repository) | |
94563
a0bb8ca25a33
Clean up vc*-revision-granularity and vc*-checkout-model.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
94521
diff
changeset
|
52 (defun vc-mtn-checkout-model (files) 'implicit) |
78791 | 53 |
54 (defun vc-mtn-root (file) | |
55 (setq file (if (file-directory-p file) | |
56 (file-name-as-directory file) | |
57 (file-name-directory file))) | |
58 (or (vc-file-getprop file 'vc-mtn-root) | |
59 (vc-file-setprop file 'vc-mtn-root | |
60 (vc-find-root file vc-mtn-admin-format)))) | |
61 | |
62 | |
63 (defun vc-mtn-registered (file) | |
64 (let ((root (vc-mtn-root file))) | |
65 (when root | |
66 (vc-mtn-state file)))) | |
67 | |
68 (defun vc-mtn-command (buffer okstatus files &rest flags) | |
69 "A wrapper around `vc-do-command' for use in vc-mtn.el." | |
93564
eeb1bb8489e4
(vc-mtn-command): Avoid localization of messages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93144
diff
changeset
|
70 (let ((process-environment |
eeb1bb8489e4
(vc-mtn-command): Avoid localization of messages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93144
diff
changeset
|
71 ;; Avoid localization of messages so we can parse the output. |
eeb1bb8489e4
(vc-mtn-command): Avoid localization of messages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93144
diff
changeset
|
72 (cons "LC_MESSAGES=C" process-environment))) |
eeb1bb8489e4
(vc-mtn-command): Avoid localization of messages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93144
diff
changeset
|
73 (apply 'vc-do-command buffer okstatus vc-mtn-command files flags))) |
78791 | 74 |
75 (defun vc-mtn-state (file) | |
76 ;; If `mtn' fails or returns status>0, or if the search files, just | |
77 ;; return nil. | |
78 (ignore-errors | |
79 (with-temp-buffer | |
80 (vc-mtn-command t 0 file "status") | |
81 (goto-char (point-min)) | |
93144
33c08cf9fb3a
(vc-mtn-state): Support the added state.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92692
diff
changeset
|
82 (re-search-forward |
33c08cf9fb3a
(vc-mtn-state): Support the added state.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92692
diff
changeset
|
83 "^ \\(?:\\(patched\\)\\|\\(added\\) \\(?:.*\\)\\)\\|no changes$") |
33c08cf9fb3a
(vc-mtn-state): Support the added state.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92692
diff
changeset
|
84 (cond ((match-end 1) 'edited) |
33c08cf9fb3a
(vc-mtn-state): Support the added state.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92692
diff
changeset
|
85 ((match-end 2) 'added) |
33c08cf9fb3a
(vc-mtn-state): Support the added state.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92692
diff
changeset
|
86 (t 'up-to-date))))) |
78791 | 87 |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
78791
diff
changeset
|
88 (defun vc-mtn-working-revision (file) |
78791 | 89 ;; If `mtn' fails or returns status>0, or if the search fails, just |
90 ;; return nil. | |
91 (ignore-errors | |
92 (with-temp-buffer | |
93 (vc-mtn-command t 0 file "status") | |
94 (goto-char (point-min)) | |
95 (re-search-forward "Current branch: \\(.*\\)\nChanges against parent \\(.*\\)") | |
96 (match-string 2)))) | |
97 | |
98 (defun vc-mtn-workfile-branch (file) | |
99 ;; If `mtn' fails or returns status>0, or if the search files, just | |
100 ;; return nil. | |
101 (ignore-errors | |
102 (with-temp-buffer | |
103 (vc-mtn-command t 0 file "status") | |
104 (goto-char (point-min)) | |
105 (re-search-forward "Current branch: \\(.*\\)\nChanges against parent \\(.*\\)") | |
106 (match-string 1)))) | |
107 | |
108 (defun vc-mtn-workfile-unchanged-p (file) | |
109 (not (eq (vc-mtn-state file) 'edited))) | |
110 | |
111 ;; Mode-line rewrite code copied from vc-arch.el. | |
112 | |
113 (defcustom vc-mtn-mode-line-rewrite | |
114 '(("\\`[^:/#]*[:/#]" . "")) ;Drop the host part. | |
115 "Rewrite rules to shorten Mtn's revision names on the mode-line." | |
116 :type '(repeat (cons regexp string)) | |
80261
4af0bb174714
* textmodes/css-mode.el (css-indent-offset, css-electric-keys):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79721
diff
changeset
|
117 :version "22.2" |
78791 | 118 :group 'vc) |
119 | |
120 (defun vc-mtn-mode-line-string (file) | |
121 "Return string for placement in modeline by `vc-mode-line' for FILE." | |
122 (let ((branch (vc-mtn-workfile-branch file))) | |
123 (dolist (rule vc-mtn-mode-line-rewrite) | |
124 (if (string-match (car rule) branch) | |
125 (setq branch (replace-match (cdr rule) t nil branch)))) | |
126 (format "Mtn%c%s" | |
127 (case (vc-state file) | |
94521
2a61c5f918a5
Change 'needs-patch to 'needs-update.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
93564
diff
changeset
|
128 ((up-to-date needs-update) ?-) |
78791 | 129 (added ?@) |
130 (t ?:)) | |
131 branch))) | |
132 | |
133 (defun vc-mtn-register (files &optional rest) | |
134 (vc-mtn-command nil 0 files "add")) | |
135 | |
136 (defun vc-mtn-responsible-p (file) (vc-mtn-root file)) | |
137 (defun vc-mtn-could-register (file) (vc-mtn-root file)) | |
138 | |
139 (defun vc-mtn-checkin (files rev comment) | |
140 (vc-mtn-command nil 0 files "commit" "-m" comment)) | |
141 | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
78791
diff
changeset
|
142 (defun vc-mtn-find-revision (file rev buffer) |
78791 | 143 (vc-mtn-command buffer 0 file "cat" "-r" rev)) |
144 | |
145 ;; (defun vc-mtn-checkout (file &optional editable rev) | |
146 ;; ) | |
147 | |
148 (defun vc-mtn-revert (file &optional contents-done) | |
149 (unless contents-done | |
150 (vc-mtn-command nil 0 file "revert"))) | |
151 | |
152 ;; (defun vc-mtn-roolback (files) | |
153 ;; ) | |
154 | |
155 (defun vc-mtn-print-log (files &optional buffer) | |
156 (vc-mtn-command buffer 0 files "log")) | |
157 | |
85478
786d3a985758
* term/x-win.el (x-gtk-stock-map, icon-map-list)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85462
diff
changeset
|
158 (defvar log-view-message-re) |
786d3a985758
* term/x-win.el (x-gtk-stock-map, icon-map-list)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85462
diff
changeset
|
159 (defvar log-view-file-re) |
786d3a985758
* term/x-win.el (x-gtk-stock-map, icon-map-list)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85462
diff
changeset
|
160 (defvar log-view-font-lock-keywords) |
786d3a985758
* term/x-win.el (x-gtk-stock-map, icon-map-list)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85462
diff
changeset
|
161 |
78791 | 162 (define-derived-mode vc-mtn-log-view-mode log-view-mode "Mtn-Log-View" |
163 ;; TODO: Not sure what to do about file markers for now. | |
164 (set (make-local-variable 'log-view-file-re) "\\'\\`") | |
165 ;; TODO: Use a more precise regexp than "[ |/]+" to avoid false positives | |
166 ;; in the ChangeLog text. | |
167 (set (make-local-variable 'log-view-message-re) | |
168 "^[ |/]+Revision: \\([0-9a-f]+\\)") | |
169 (require 'add-log) ;For change-log faces. | |
170 (set (make-local-variable 'log-view-font-lock-keywords) | |
171 (append log-view-font-lock-keywords | |
172 '(("^[ |]+Author: \\(.*\\)" (1 'change-log-email)) | |
173 ("^[ |]+Date: \\(.*\\)" (1 'change-log-date-face)))))) | |
174 | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
175 ;; (defun vc-mtn-show-log-entry (revision) |
78791 | 176 ;; ) |
177 | |
178 (defun vc-mtn-wash-log (file)) | |
179 | |
180 (defun vc-mtn-diff (files &optional rev1 rev2 buffer) | |
181 (apply 'vc-mtn-command (or buffer "*vc-diff*") 1 files "diff" | |
182 (append (if rev1 (list "-r" rev1)) (if rev2 (list "-r" rev2))))) | |
183 | |
184 (defun vc-mtn-annotate-command (file buf &optional rev) | |
185 (apply 'vc-mtn-command buf 0 file "annotate" | |
186 (if rev (list "-r" rev)))) | |
187 | |
188 (defconst vc-mtn-annotate-full-re | |
189 "^ *\\([0-9a-f]+\\)\\.* by [^ ]+ \\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\): ") | |
190 (defconst vc-mtn-annotate-any-re | |
191 (concat "^\\(?: +: \\|" vc-mtn-annotate-full-re "\\)")) | |
192 | |
193 (defun vc-mtn-annotate-time () | |
194 (when (looking-at vc-mtn-annotate-any-re) | |
195 (goto-char (match-end 0)) | |
196 (let ((year (match-string 2))) | |
197 (if (not year) | |
198 ;; Look for the date on a previous line. | |
199 (save-excursion | |
200 (get-text-property (1- (previous-single-property-change | |
201 (point) 'vc-mtn-time nil (point-min))) | |
202 'vc-mtn-time)) | |
203 (let ((time (vc-annotate-convert-time | |
204 (encode-time 0 0 0 | |
205 (string-to-number (match-string 4)) | |
206 (string-to-number (match-string 3)) | |
207 (string-to-number year) | |
208 t)))) | |
209 (let ((inhibit-read-only t) | |
210 (inhibit-modification-hooks t)) | |
211 (put-text-property (match-beginning 0) (match-end 0) | |
212 'vc-mtn-time time)) | |
213 time))))) | |
214 | |
215 (defun vc-mtn-annotate-extract-revision-at-line () | |
216 (save-excursion | |
217 (when (or (looking-at vc-mtn-annotate-full-re) | |
218 (re-search-backward vc-mtn-annotate-full-re nil t)) | |
219 (match-string 1)))) | |
220 | |
221 ;;; Revision completion. | |
222 | |
223 (defun vc-mtn-list-tags () | |
224 (with-temp-buffer | |
225 (vc-mtn-command t 0 nil "list" "tags") | |
226 (goto-char (point-min)) | |
227 (let ((tags ())) | |
228 (while (re-search-forward "^[^ ]+" nil t) | |
229 (push (match-string 0) tags)) | |
230 tags))) | |
231 | |
232 (defun vc-mtn-list-branches () | |
233 (with-temp-buffer | |
234 (vc-mtn-command t 0 nil "list" "branches") | |
235 (goto-char (point-min)) | |
236 (let ((branches ())) | |
237 (while (re-search-forward "^.+" nil t) | |
238 (push (match-string 0) branches)) | |
239 branches))) | |
240 | |
241 (defun vc-mtn-list-revision-ids (prefix) | |
242 (with-temp-buffer | |
243 (vc-mtn-command t 0 nil "complete" "revision" prefix) | |
244 (goto-char (point-min)) | |
245 (let ((ids ())) | |
246 (while (re-search-forward "^.+" nil t) | |
247 (push (match-string 0) ids)) | |
248 ids))) | |
249 | |
85461
abd6fdb45765
(vc-mtn-revision-completion-table):Make it work when the arg is a list of files.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85141
diff
changeset
|
250 (defun vc-mtn-revision-completion-table (files) |
78791 | 251 ;; TODO: Implement completion for for selectors |
252 ;; TODO: Implement completion for composite selectors. | |
85461
abd6fdb45765
(vc-mtn-revision-completion-table):Make it work when the arg is a list of files.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85141
diff
changeset
|
253 (lexical-let ((files files)) |
abd6fdb45765
(vc-mtn-revision-completion-table):Make it work when the arg is a list of files.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85141
diff
changeset
|
254 ;; What about using `files'?!? --Stef |
78791 | 255 (lambda (string pred action) |
256 (cond | |
257 ;; "Tag" selectors. | |
258 ((string-match "\\`t:" string) | |
259 (complete-with-action action | |
260 (mapcar (lambda (tag) (concat "t:" tag)) | |
261 (vc-mtn-list-tags)) | |
262 string pred)) | |
263 ;; "Branch" selectors. | |
264 ((string-match "\\`b:" string) | |
265 (complete-with-action action | |
266 (mapcar (lambda (tag) (concat "b:" tag)) | |
267 (vc-mtn-list-branches)) | |
268 string pred)) | |
269 ;; "Head" selectors. Not sure how they differ from "branch" selectors. | |
270 ((string-match "\\`h:" string) | |
271 (complete-with-action action | |
272 (mapcar (lambda (tag) (concat "h:" tag)) | |
273 (vc-mtn-list-branches)) | |
274 string pred)) | |
275 ;; "ID" selectors. | |
276 ((string-match "\\`i:" string) | |
277 (complete-with-action action | |
278 (mapcar (lambda (tag) (concat "i:" tag)) | |
279 (vc-mtn-list-revision-ids | |
280 (substring string (match-end 0)))) | |
281 string pred)) | |
282 (t | |
283 (complete-with-action action | |
284 '("t:" "b:" "h:" "i:" | |
285 ;; Completion not implemented for these. | |
286 "a:" "c:" "d:" "e:" "l:") | |
287 string pred)))))) | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
288 |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94563
diff
changeset
|
289 |
78791 | 290 |
291 (provide 'vc-mtn) | |
292 | |
293 ;; arch-tag: 2b89ffbc-cbb8-405a-9080-2eafd4becb70 | |
294 ;;; vc-mtn.el ends here |