Commit | Line | Data |
---|---|---|
0f6c7af8 SM |
1 | ;;; vc-arch.el --- VC backend for the Arch version-control system |
2 | ||
95df8112 | 3 | ;; Copyright (C) 2004-2011 Free Software Foundation, Inc. |
0f6c7af8 SM |
4 | |
5 | ;; Author: FSF (see vc.el for full credits) | |
6 | ;; Maintainer: Stefan Monnier <monnier@gnu.org> | |
bd78fa1d | 7 | ;; Package: vc |
0f6c7af8 SM |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
0f6c7af8 | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
0f6c7af8 SM |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
0f6c7af8 SM |
23 | |
24 | ;;; Commentary: | |
25 | ||
26 | ;; The home page of the Arch version control system is at | |
df617e7f | 27 | ;; |
0f6c7af8 | 28 | ;; http://www.gnuarch.org/ |
df617e7f | 29 | ;; |
0f6c7af8 SM |
30 | ;; This is derived from vc-mcvs.el as follows: |
31 | ;; - cp vc-mcvs.el vc-arch.el and then M-% mcvs RET arch RET | |
32 | ;; | |
33 | ;; Then of course started the hacking. | |
34 | ;; | |
35 | ;; What has been partly tested: | |
df617e7f SM |
36 | ;; - Open a file. |
37 | ;; - C-x v = without any prefix arg. | |
38 | ;; - C-x v v to commit a change to a single file. | |
0f6c7af8 SM |
39 | |
40 | ;; Bugs: | |
41 | ||
ce1438d6 | 42 | ;; - *vc-log*'s initial content lacks the `Summary:' lines. |
0f6c7af8 SM |
43 | ;; - All files under the tree are considered as "under Arch's control" |
44 | ;; without regards to =tagging-method and such. | |
45 | ;; - Files are always considered as `edited'. | |
27fde599 | 46 | ;; - C-x v l does not work. |
0f6c7af8 | 47 | ;; - C-x v i does not work. |
27fde599 SM |
48 | ;; - C-x v ~ does not work. |
49 | ;; - C-x v u does not work. | |
50 | ;; - C-x v s does not work. | |
51 | ;; - C-x v r does not work. | |
caf37b1f | 52 | ;; - VC directory listings do not work. |
0f6c7af8 SM |
53 | ;; - And more... |
54 | ||
55 | ;;; Code: | |
56 | ||
e5d31f9f | 57 | (eval-when-compile (require 'vc) (require 'cl)) |
0f6c7af8 | 58 | |
70e2f6c7 ER |
59 | ;;; Properties of the backend |
60 | ||
61 | (defun vc-arch-revision-granularity () 'repository) | |
62 | (defun vc-arch-checkout-model (files) 'implicit) | |
63 | ||
0f6c7af8 SM |
64 | ;;; |
65 | ;;; Customization options | |
66 | ;;; | |
67 | ||
e98a0cab GM |
68 | ;; It seems Arch diff does not accept many options, so this is not |
69 | ;; very useful. It exists mainly so that the VC backends are all | |
70 | ;; consistent with regards to their treatment of diff switches. | |
71 | (defcustom vc-arch-diff-switches t | |
72 | "String or list of strings specifying switches for Arch diff under VC. | |
73 | If nil, use the value of `vc-diff-switches'. If t, use no switches." | |
74 | :type '(choice (const :tag "Unspecified" nil) | |
75 | (const :tag "None" t) | |
76 | (string :tag "Argument String") | |
77 | (repeat :tag "Argument List" :value ("") string)) | |
78 | :version "23.1" | |
79 | :group 'vc) | |
80 | ||
e94851d3 GM |
81 | (define-obsolete-variable-alias 'vc-arch-command 'vc-arch-program "23.1") |
82 | ||
83 | (defcustom vc-arch-program | |
b4c4ba41 | 84 | (let ((candidates '("tla" "baz"))) |
0f6c7af8 SM |
85 | (while (and candidates (not (executable-find (car candidates)))) |
86 | (setq candidates (cdr candidates))) | |
e94851d3 GM |
87 | (or (car candidates) "tla")) |
88 | "Name of the Arch executable." | |
89 | :type 'string | |
90 | :group 'vc) | |
0f6c7af8 SM |
91 | |
92 | ;; Clear up the cache to force vc-call to check again and discover | |
93 | ;; new functions when we reload this file. | |
94 | (put 'Arch 'vc-functions nil) | |
95 | ||
96 | ;;;###autoload (defun vc-arch-registered (file) | |
ef9c4df0 SM |
97 | ;;;###autoload (if (vc-find-root file "{arch}/=tagging-method") |
98 | ;;;###autoload (progn | |
99 | ;;;###autoload (load "vc-arch") | |
100 | ;;;###autoload (vc-arch-registered file)))) | |
0f6c7af8 | 101 | |
df617e7f | 102 | (defun vc-arch-add-tagline () |
0f6c7af8 SM |
103 | "Add an `arch-tag' to the end of the current file." |
104 | (interactive) | |
df617e7f | 105 | (comment-normalize-vars) |
0f6c7af8 SM |
106 | (goto-char (point-max)) |
107 | (forward-comment -1) | |
56dada42 SM |
108 | (skip-chars-forward " \t\n") |
109 | (cond | |
110 | ((not (bolp)) (insert "\n\n")) | |
111 | ((not (eq ?\n (char-before (1- (point))))) (insert "\n"))) | |
df617e7f SM |
112 | (let ((beg (point)) |
113 | (idfile (and buffer-file-name | |
114 | (expand-file-name | |
115 | (concat ".arch-ids/" | |
116 | (file-name-nondirectory buffer-file-name) | |
117 | ".id") | |
118 | (file-name-directory buffer-file-name))))) | |
0f6c7af8 | 119 | (insert "arch-tag: ") |
df617e7f SM |
120 | (if (and idfile (file-exists-p idfile)) |
121 | ;; If the file is unreadable, we do want to get an error here. | |
122 | (progn | |
123 | (insert-file-contents idfile) | |
124 | (forward-line 1) | |
125 | (delete-file idfile)) | |
126 | (condition-case nil | |
127 | (call-process "uuidgen" nil t) | |
128 | (file-error (insert (format "%s <%s> %s" | |
129 | (current-time-string) | |
130 | user-mail-address | |
131 | (+ (nth 2 (current-time)) | |
132 | (buffer-size))))))) | |
0f6c7af8 SM |
133 | (comment-region beg (point)))) |
134 | ||
df617e7f SM |
135 | (defconst vc-arch-tagline-re "^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)") |
136 | ||
74cb3d21 SM |
137 | (defmacro vc-with-current-file-buffer (file &rest body) |
138 | (declare (indent 2) (debug t)) | |
139 | `(let ((-kill-buf- nil) | |
140 | (-file- ,file)) | |
141 | (with-current-buffer (or (find-buffer-visiting -file-) | |
142 | (setq -kill-buf- (generate-new-buffer " temp"))) | |
143 | ;; Avoid find-file-literally since it can do many undesirable extra | |
144 | ;; things (among which, call us back into an infinite loop). | |
145 | (if -kill-buf- (insert-file-contents -file-)) | |
146 | (unwind-protect | |
147 | (progn ,@body) | |
148 | (if (buffer-live-p -kill-buf-) (kill-buffer -kill-buf-)))))) | |
149 | ||
df617e7f SM |
150 | (defun vc-arch-file-source-p (file) |
151 | "Can return nil, `maybe' or a non-nil value. | |
152 | Only the value `maybe' can be trusted :-(." | |
153 | ;; FIXME: Check the tag and name of parent dirs. | |
154 | (unless (string-match "\\`[,+]" (file-name-nondirectory file)) | |
155 | (or (string-match "\\`{arch}/" | |
156 | (file-relative-name file (vc-arch-root file))) | |
157 | (file-exists-p | |
158 | ;; Check the presence of an ID file. | |
159 | (expand-file-name | |
160 | (concat ".arch-ids/" (file-name-nondirectory file) ".id") | |
161 | (file-name-directory file))) | |
162 | ;; Check the presence of a tagline. | |
74cb3d21 | 163 | (vc-with-current-file-buffer file |
df617e7f SM |
164 | (save-excursion |
165 | (goto-char (point-max)) | |
166 | (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t) | |
167 | (progn | |
168 | (goto-char (point-min)) | |
169 | (re-search-forward vc-arch-tagline-re (+ (point) 1000) t))))) | |
170 | ;; FIXME: check =tagging-method to see whether untagged files might | |
171 | ;; be source or not. | |
172 | (with-current-buffer | |
173 | (find-file-noselect (expand-file-name "{arch}/=tagging-method" | |
174 | (vc-arch-root file))) | |
175 | (let ((untagged-source t)) ;Default is `names'. | |
176 | (save-excursion | |
177 | (goto-char (point-min)) | |
178 | (if (re-search-forward "^[ \t]*\\(\\(tagline\\|implicit\\|names\\)\\|explicit\\)" nil t) | |
179 | (setq untagged-source (match-end 2))) | |
180 | (if (re-search-forward "^[ \t]*untagged-source[ \t]+\\(\\(source\\)\\|precious\\|backup\\|junk\\|unrecognized\\)" nil t) | |
181 | (setq untagged-source (match-end 2)))) | |
182 | (if untagged-source 'maybe)))))) | |
183 | ||
184 | (defun vc-arch-file-id (file) | |
185 | ;; Don't include the kind of ID this is because it seems to be too messy. | |
186 | (let ((idfile (expand-file-name | |
187 | (concat ".arch-ids/" (file-name-nondirectory file) ".id") | |
188 | (file-name-directory file)))) | |
189 | (if (file-exists-p idfile) | |
190 | (with-temp-buffer | |
191 | (insert-file-contents idfile) | |
192 | (looking-at ".*[^ \n\t]") | |
e56b4640 | 193 | (match-string 0)) |
df617e7f SM |
194 | (with-current-buffer (find-file-noselect file) |
195 | (save-excursion | |
196 | (goto-char (point-max)) | |
197 | (if (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t) | |
198 | (progn | |
199 | (goto-char (point-min)) | |
200 | (re-search-forward vc-arch-tagline-re (+ (point) 1000) t))) | |
201 | (match-string 1) | |
e56b4640 | 202 | (concat "./" (file-relative-name file (vc-arch-root file))))))))) |
df617e7f SM |
203 | |
204 | (defun vc-arch-tagging-method (file) | |
205 | (with-current-buffer | |
206 | (find-file-noselect | |
207 | (expand-file-name "{arch}/=tagging-method" (vc-arch-root file))) | |
208 | (save-excursion | |
209 | (goto-char (point-min)) | |
210 | (if (re-search-forward | |
211 | "^[ \t]*\\(tagline\\|implicit\\|names\\|explicit\\)" nil t) | |
212 | (intern (match-string 1)) | |
213 | 'names)))) | |
214 | ||
0f6c7af8 | 215 | (defun vc-arch-root (file) |
d1f18ec0 | 216 | "Return the root directory of an Arch project, if any." |
0f6c7af8 | 217 | (or (vc-file-getprop file 'arch-root) |
b38f5e6f DN |
218 | ;; Check the =tagging-method, in case someone naively manually |
219 | ;; creates a {arch} directory somewhere. | |
220 | (let ((root (vc-find-root file "{arch}/=tagging-method"))) | |
221 | (when root | |
222 | (vc-file-setprop | |
223 | file 'arch-root root))))) | |
0f6c7af8 | 224 | |
8cdd17b4 | 225 | (defun vc-arch-register (files &optional rev comment) |
7bbdf1cb | 226 | (if rev (error "Explicit initial revision not supported for Arch")) |
8cdd17b4 ER |
227 | (dolist (file files) |
228 | (let ((tagmet (vc-arch-tagging-method file))) | |
229 | (if (and (memq tagmet '(tagline implicit)) comment-start) | |
230 | (with-current-buffer (find-file-noselect file) | |
231 | (if (buffer-modified-p) | |
232 | (error "Save %s first" (buffer-name))) | |
233 | (vc-arch-add-tagline) | |
234 | (save-buffer))))) | |
235 | (vc-arch-command nil 0 files "add")) | |
df617e7f | 236 | |
0f6c7af8 | 237 | (defun vc-arch-registered (file) |
df617e7f SM |
238 | ;; Don't seriously check whether it's source or not. Checking would |
239 | ;; require running TLA, so it's better to not do it, so it also works if | |
240 | ;; TLA is not installed. | |
241 | (and (vc-arch-root file) | |
242 | (vc-arch-file-source-p file))) | |
0f6c7af8 SM |
243 | |
244 | (defun vc-arch-default-version (file) | |
245 | (or (vc-file-getprop (vc-arch-root file) 'arch-default-version) | |
246 | (let* ((root (vc-arch-root file)) | |
247 | (f (expand-file-name "{arch}/++default-version" root))) | |
248 | (if (file-readable-p f) | |
249 | (vc-file-setprop | |
250 | root 'arch-default-version | |
251 | (with-temp-buffer | |
252 | (insert-file-contents f) | |
253 | ;; Strip the terminating newline. | |
254 | (buffer-substring (point-min) (1- (point-max))))))))) | |
255 | ||
68eb03ca | 256 | (defun vc-arch-workfile-unchanged-p (file) |
004f9b3f | 257 | "Stub: arch workfiles are always considered to be in a changed state," |
68eb03ca SM |
258 | nil) |
259 | ||
0f6c7af8 SM |
260 | (defun vc-arch-state (file) |
261 | ;; There's no checkout operation and merging is not done from VC | |
262 | ;; so the only operation that's state dependent that VC supports is commit | |
263 | ;; which is only activated if the file is `edited'. | |
df617e7f SM |
264 | (let* ((root (vc-arch-root file)) |
265 | (ver (vc-arch-default-version file)) | |
266 | (pat (concat "\\`" (subst-char-in-string ?/ ?% ver))) | |
267 | (dir (expand-file-name ",,inode-sigs/" | |
268 | (expand-file-name "{arch}" root))) | |
269 | (sigfile nil)) | |
270 | (dolist (f (if (file-directory-p dir) (directory-files dir t pat))) | |
271 | (if (or (not sigfile) (file-newer-than-file-p f sigfile)) | |
272 | (setq sigfile f))) | |
273 | (if (not sigfile) | |
274 | 'edited ;We know nothing. | |
275 | (let ((id (vc-arch-file-id file))) | |
276 | (setq id (replace-regexp-in-string "[ \t]" "_" id)) | |
277 | (with-current-buffer (find-file-noselect sigfile) | |
278 | (goto-char (point-min)) | |
279 | (while (and (search-forward id nil 'move) | |
c9cb3a26 SM |
280 | (save-excursion |
281 | (goto-char (- (match-beginning 0) 2)) | |
282 | ;; For `names', the lines start with `?./foo/bar'. | |
283 | ;; For others there's 2 chars before the ./foo/bar. | |
284 | (or (not (or (bolp) (looking-at "\n?"))) | |
285 | ;; Ignore E_ entries used for foo.id files. | |
286 | (looking-at "E_"))))) | |
df617e7f SM |
287 | (if (eobp) |
288 | ;; ID not found. | |
289 | (if (equal (file-name-nondirectory sigfile) | |
290 | (subst-char-in-string | |
ac3f4c6f | 291 | ?/ ?% (vc-arch-working-revision file))) |
df617e7f SM |
292 | 'added |
293 | ;; Might be `added' or `up-to-date' as well. | |
294 | ;; FIXME: Check in the patch logs to find out. | |
295 | 'edited) | |
296 | ;; Found the ID, let's check the inode. | |
297 | (if (not (re-search-forward | |
298 | "\t.*mtime=\\([0-9]+\\):size=\\([0-9]+\\)" | |
299 | (line-end-position) t)) | |
300 | ;; Buh? Unexpected format. | |
301 | 'edited | |
302 | (let ((ats (file-attributes file))) | |
f9e66e49 | 303 | (if (and (eq (nth 7 ats) (string-to-number (match-string 2))) |
df617e7f SM |
304 | (equal (format-time-string "%s" (nth 5 ats)) |
305 | (match-string 1))) | |
306 | 'up-to-date | |
307 | 'edited))))))))) | |
7bbdf1cb | 308 | |
b4a7be38 MH |
309 | (defun vc-arch-dir-status (dir callback) |
310 | "Run 'tla inventory' for DIR and pass results to CALLBACK. | |
311 | CALLBACK expects (ENTRIES &optional MORE-TO-COME); see | |
312 | `vc-dir-refresh'." | |
313 | (let ((default-directory dir)) | |
314 | (vc-arch-command t 'async nil "changes")) | |
315 | ;; The updating could be done asynchronously. | |
316 | (vc-exec-after | |
317 | `(vc-arch-after-dir-status ',callback))) | |
318 | ||
319 | (defun vc-arch-after-dir-status (callback) | |
320 | (let* ((state-map '(("M " . edited) | |
321 | ("Mb" . edited) ;binary | |
322 | ("D " . removed) | |
323 | ("D/" . removed) ;directory | |
324 | ("A " . added) | |
325 | ("A/" . added) ;directory | |
326 | ("=>" . renamed) | |
327 | ("/>" . renamed) ;directory | |
328 | ("lf" . symlink-to-file) | |
329 | ("fl" . file-to-symlink) | |
330 | ("--" . permissions-changed) | |
331 | ("-/" . permissions-changed) ;directory | |
332 | )) | |
333 | (state-map-regexp (regexp-opt (mapcar 'car state-map) t)) | |
334 | (entry-regexp (concat "^" state-map-regexp " \\(.*\\)$")) | |
335 | result) | |
336 | (goto-char (point-min)) | |
337 | ;;(message "Got %s" (buffer-string)) | |
338 | (while (re-search-forward entry-regexp nil t) | |
339 | (let* ((state-string (match-string 1)) | |
340 | (state (cdr (assoc state-string state-map))) | |
341 | (filename (match-string 2))) | |
342 | (push (list filename state) result))) | |
343 | ||
344 | (funcall callback result nil))) | |
345 | ||
ac3f4c6f | 346 | (defun vc-arch-working-revision (file) |
0f6c7af8 SM |
347 | (let* ((root (expand-file-name "{arch}" (vc-arch-root file))) |
348 | (defbranch (vc-arch-default-version file))) | |
c771f3d6 | 349 | (when (and defbranch (string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*?\\)\\(?:--.*\\)?\\)--.*\\)\\'" defbranch)) |
0f6c7af8 SM |
350 | (let* ((archive (match-string 1 defbranch)) |
351 | (category (match-string 4 defbranch)) | |
352 | (branch (match-string 3 defbranch)) | |
353 | (version (match-string 2 defbranch)) | |
27fde599 | 354 | (sealed nil) (rev-nb 0) |
0f6c7af8 SM |
355 | (rev nil) |
356 | logdir tmp) | |
357 | (setq logdir (expand-file-name category root)) | |
358 | (setq logdir (expand-file-name branch logdir)) | |
359 | (setq logdir (expand-file-name version logdir)) | |
360 | (setq logdir (expand-file-name archive logdir)) | |
361 | (setq logdir (expand-file-name "patch-log" logdir)) | |
bcabe045 SM |
362 | (dolist (file (if (file-directory-p logdir) (directory-files logdir))) |
363 | ;; Revision names go: base-0, patch-N, version-0, versionfix-M. | |
27fde599 SM |
364 | (when (and (eq (aref file 0) ?v) (not sealed)) |
365 | (setq sealed t rev-nb 0)) | |
0f6c7af8 SM |
366 | (if (and (string-match "-\\([0-9]+\\)\\'" file) |
367 | (setq tmp (string-to-number (match-string 1 file))) | |
27fde599 | 368 | (or (not sealed) (eq (aref file 0) ?v)) |
0f6c7af8 SM |
369 | (>= tmp rev-nb)) |
370 | (setq rev-nb tmp rev file))) | |
86d660c6 SM |
371 | ;; Use "none-000" if the tree hasn't yet been committed on the |
372 | ;; default branch. We'll then get "Arch:000[branch]" on the mode-line. | |
373 | (concat defbranch "--" (or rev "none-000")))))) | |
0f6c7af8 SM |
374 | |
375 | ||
376 | (defcustom vc-arch-mode-line-rewrite | |
27fde599 | 377 | '(("\\`.*--\\(.*--.*\\)--\\(v?\\).*-\\([0-9]+\\)\\'" . "\\2\\3[\\1]")) |
0f6c7af8 | 378 | "Rewrite rules to shorten Arch's revision names on the mode-line." |
d30bef64 KS |
379 | :type '(repeat (cons regexp string)) |
380 | :group 'vc) | |
0f6c7af8 SM |
381 | |
382 | (defun vc-arch-mode-line-string (file) | |
383 | "Return string for placement in modeline by `vc-mode-line' for FILE." | |
ac3f4c6f | 384 | (let ((rev (vc-working-revision file))) |
0f6c7af8 SM |
385 | (dolist (rule vc-arch-mode-line-rewrite) |
386 | (if (string-match (car rule) rev) | |
387 | (setq rev (replace-match (cdr rule) t nil rev)))) | |
388 | (format "Arch%c%s" | |
df617e7f | 389 | (case (vc-state file) |
3702367b | 390 | ((up-to-date needs-update) ?-) |
df617e7f SM |
391 | (added ?@) |
392 | (t ?:)) | |
0f6c7af8 SM |
393 | rev))) |
394 | ||
395 | (defun vc-arch-diff3-rej-p (rej) | |
df617e7f SM |
396 | (let ((attrs (file-attributes rej))) |
397 | (and attrs (< (nth 7 attrs) 60) | |
398 | (with-temp-buffer | |
399 | (insert-file-contents rej) | |
400 | (goto-char (point-min)) | |
e1dbe924 | 401 | (looking-at "Conflicts occurred, diff3 conflict markers left in file\\."))))) |
0f6c7af8 SM |
402 | |
403 | (defun vc-arch-delete-rej-if-obsolete () | |
7bbdf1cb SM |
404 | "For use in `after-save-hook'." |
405 | (save-excursion | |
406 | (let ((rej (concat buffer-file-name ".rej"))) | |
407 | (when (and buffer-file-name (vc-arch-diff3-rej-p rej)) | |
54648b5c DN |
408 | (unless (re-search-forward "^<<<<<<< " nil t) |
409 | ;; The .rej file is obsolete. | |
410 | (condition-case nil (delete-file rej) (error nil)) | |
411 | ;; Remove the hook so that it is not called multiple times. | |
412 | (remove-hook 'after-save-hook 'vc-arch-delete-rej-if-obsolete t)))))) | |
0f6c7af8 SM |
413 | |
414 | (defun vc-arch-find-file-hook () | |
415 | (let ((rej (concat buffer-file-name ".rej"))) | |
416 | (when (and buffer-file-name (file-exists-p rej)) | |
417 | (if (vc-arch-diff3-rej-p rej) | |
418 | (save-excursion | |
419 | (goto-char (point-min)) | |
7bbdf1cb | 420 | (if (not (re-search-forward "^<<<<<<< " nil t)) |
0f6c7af8 SM |
421 | ;; The .rej file is obsolete. |
422 | (condition-case nil (delete-file rej) (error nil)) | |
28e4e2b4 | 423 | (smerge-mode 1) |
7bbdf1cb | 424 | (add-hook 'after-save-hook |
0f6c7af8 SM |
425 | 'vc-arch-delete-rej-if-obsolete nil t) |
426 | (message "There are unresolved conflicts in this file"))) | |
427 | (message "There are unresolved conflicts in %s" | |
428 | (file-name-nondirectory rej)))))) | |
429 | ||
4624de78 | 430 | (defun vc-arch-checkin (files rev comment) |
ef5c2eca | 431 | (if rev (error "Committing to a specific revision is unsupported")) |
8cdd17b4 | 432 | ;; FIXME: This implementation probably only works for singleton filesets |
98a6dc9f | 433 | (let ((summary (file-relative-name (car files) (vc-arch-root (car files))))) |
27fde599 SM |
434 | ;; Extract a summary from the comment. |
435 | (when (or (string-match "\\`Summary:[ \t]*\\(.*[^ \t\n]\\)\\([ \t]*\n\\)*" comment) | |
436 | (string-match "\\`[ \t]*\\(.*[^ \t\n]\\)[ \t]*\\(\n?\\'\\|\n\\([ \t]*\n\\)+\\)" comment)) | |
437 | (setq summary (match-string 1 comment)) | |
438 | (setq comment (substring comment (match-end 0)))) | |
8cdd17b4 | 439 | (vc-arch-command nil 0 files "commit" "-s" summary "-L" comment "--" |
27fde599 | 440 | (vc-switches 'Arch 'checkin)))) |
0f6c7af8 | 441 | |
8cdd17b4 ER |
442 | (defun vc-arch-diff (files &optional oldvers newvers buffer) |
443 | "Get a difference report using Arch between two versions of FILES." | |
f3b8feb4 SM |
444 | ;; FIXME: This implementation only works for singleton filesets. To make |
445 | ;; it work for more cases, we have to either call `file-diffs' manually on | |
446 | ;; each and every `file' in the fileset, or use `changes --diffs' (and | |
447 | ;; variants) and maybe filter the output with `filterdiff' to only include | |
448 | ;; the files in which we're interested. | |
449 | (let ((file (car files))) | |
450 | (if (and newvers | |
451 | (vc-up-to-date-p file) | |
ac3f4c6f | 452 | (equal newvers (vc-working-revision file))) |
f3b8feb4 SM |
453 | ;; Newvers is the base revision and the current file is unchanged, |
454 | ;; so we can diff with the current file. | |
455 | (setq newvers nil)) | |
456 | (if newvers | |
457 | (error "Diffing specific revisions not implemented") | |
9fb5c929 MA |
458 | (let* (process-file-side-effects |
459 | (async (not vc-disable-async-diff)) | |
f3b8feb4 SM |
460 | ;; Run the command from the root dir. |
461 | (default-directory (vc-arch-root file)) | |
462 | (status | |
463 | (vc-arch-command | |
464 | (or buffer "*vc-diff*") | |
465 | (if async 'async 1) | |
466 | nil "file-diffs" | |
e98a0cab | 467 | (vc-switches 'Arch 'diff) |
f3b8feb4 | 468 | (file-relative-name file) |
ac3f4c6f | 469 | (if (equal oldvers (vc-working-revision file)) |
f3b8feb4 SM |
470 | nil |
471 | oldvers)))) | |
472 | (if async 1 status))))) ; async diff, pessimistic assumption. | |
0f6c7af8 SM |
473 | |
474 | (defun vc-arch-delete-file (file) | |
475 | (vc-arch-command nil 0 file "rm")) | |
476 | ||
477 | (defun vc-arch-rename-file (old new) | |
478 | (vc-arch-command nil 0 new "mv" (file-relative-name old))) | |
479 | ||
7bbdf1cb SM |
480 | (defalias 'vc-arch-responsible-p 'vc-arch-root) |
481 | ||
0f6c7af8 SM |
482 | (defun vc-arch-command (buffer okstatus file &rest flags) |
483 | "A wrapper around `vc-do-command' for use in vc-arch.el." | |
e94851d3 | 484 | (apply 'vc-do-command (or buffer "*vc*") okstatus vc-arch-program file flags)) |
0f6c7af8 | 485 | |
ac3f4c6f | 486 | (defun vc-arch-init-revision () nil) |
7bbdf1cb | 487 | |
56dada42 SM |
488 | ;;; Completion of versions and revisions. |
489 | ||
56dada42 SM |
490 | (defun vc-arch--version-completion-table (root string) |
491 | (delq nil | |
492 | (mapcar | |
493 | (lambda (d) | |
494 | (when (string-match "/\\([^/]+\\)/\\([^/]+\\)\\'" d) | |
495 | (concat (match-string 2 d) "/" (match-string 1 d)))) | |
496 | (let ((default-directory root)) | |
497 | (file-expand-wildcards | |
498 | (concat "*/*/" | |
499 | (if (string-match "/" string) | |
500 | (concat (substring string (match-end 0)) | |
501 | "*/" (substring string 0 (match-beginning 0))) | |
502 | (concat "*/" string)) | |
503 | "*")))))) | |
504 | ||
a44d450b SM |
505 | (defun vc-arch-revision-completion-table (files) |
506 | (lexical-let ((files files)) | |
56dada42 SM |
507 | (lambda (string pred action) |
508 | ;; FIXME: complete revision patches as well. | |
a44d450b | 509 | (let* ((root (expand-file-name "{arch}" (vc-arch-root (car files)))) |
ebaba1bd SM |
510 | (table (vc-arch--version-completion-table root string))) |
511 | (complete-with-action action table string pred))))) | |
56dada42 SM |
512 | |
513 | ;;; Trimming revision libraries. | |
514 | ||
515 | ;; This code is not directly related to VC and there are many variants of | |
516 | ;; this functionality available as scripts, but I like this version better, | |
517 | ;; so maybe others will like it too. | |
518 | ||
519 | (defun vc-arch-trim-find-least-useful-rev (revs) | |
520 | (let* ((first (pop revs)) | |
521 | (second (pop revs)) | |
522 | (third (pop revs)) | |
523 | ;; We try to give more importance to recent revisions. The idea is | |
524 | ;; that it's OK if checking out a revision 1000-patch-old is ten | |
525 | ;; times slower than checking out a revision 100-patch-old. But at | |
526 | ;; the same time a 2-patch-old rev isn't really ten times more | |
527 | ;; important than a 20-patch-old, so we use an arbitrary constant | |
528 | ;; "100" to reduce this effect for recent revisions. Making this | |
529 | ;; constant a float has the side effect of causing the subsequent | |
530 | ;; computations to be done as floats as well. | |
531 | (max (+ 100.0 (car (or (car (last revs)) third)))) | |
532 | (cost (lambda () (/ (- (car third) (car first)) (- max (car second))))) | |
533 | (minrev second) | |
534 | (mincost (funcall cost))) | |
535 | (while revs | |
536 | (setq first second) | |
537 | (setq second third) | |
538 | (setq third (pop revs)) | |
539 | (when (< (funcall cost) mincost) | |
540 | (setq minrev second) | |
541 | (setq mincost (funcall cost)))) | |
542 | minrev)) | |
543 | ||
544 | (defun vc-arch-trim-make-sentinel (revs) | |
545 | (if (null revs) (lambda (proc msg) (message "VC-Arch trimming ... done")) | |
e87c4c6e SM |
546 | (lexical-let ((revs revs)) |
547 | (lambda (proc msg) | |
548 | (message "VC-Arch trimming %s..." (file-name-nondirectory (car revs))) | |
549 | (rename-file (car revs) (concat (car revs) "*rm*")) | |
56dada42 | 550 | (setq proc (start-process "vc-arch-trim" nil |
e87c4c6e SM |
551 | "rm" "-rf" (concat (car revs) "*rm*"))) |
552 | (set-process-sentinel proc (vc-arch-trim-make-sentinel (cdr revs))))))) | |
56dada42 SM |
553 | |
554 | (defun vc-arch-trim-one-revlib (dir) | |
555 | "Delete half of the revisions in the revision library." | |
556 | (interactive "Ddirectory: ") | |
e87c4c6e SM |
557 | (let ((garbage (directory-files dir 'full "\\`,," 'nosort))) |
558 | (when garbage | |
559 | (funcall (vc-arch-trim-make-sentinel garbage) nil nil))) | |
56dada42 SM |
560 | (let ((revs |
561 | (sort (delq nil | |
562 | (mapcar | |
563 | (lambda (f) | |
564 | (when (string-match "-\\([0-9]+\\)\\'" f) | |
565 | (cons (string-to-number (match-string 1 f)) f))) | |
566 | (directory-files dir nil nil 'nosort))) | |
567 | 'car-less-than-car)) | |
568 | (subdirs nil)) | |
569 | (when (cddr revs) | |
570 | (dotimes (i (/ (length revs) 2)) | |
571 | (let ((minrev (vc-arch-trim-find-least-useful-rev revs))) | |
572 | (setq revs (delq minrev revs)) | |
573 | (push minrev subdirs))) | |
574 | (funcall (vc-arch-trim-make-sentinel | |
575 | (mapcar (lambda (x) (expand-file-name (cdr x) dir)) subdirs)) | |
576 | nil nil)))) | |
577 | ||
578 | (defun vc-arch-trim-revlib () | |
579 | "Delete half of the revisions in the revision library." | |
580 | (interactive) | |
581 | (let ((rl-dir (with-output-to-string | |
e94851d3 | 582 | (call-process vc-arch-program nil standard-output nil |
56dada42 SM |
583 | "my-revision-library")))) |
584 | (while (string-match "\\(.*\\)\n" rl-dir) | |
585 | (let ((dir (match-string 1 rl-dir))) | |
586 | (setq rl-dir | |
587 | (if (and (file-directory-p dir) (file-writable-p dir)) | |
588 | dir | |
589 | (substring rl-dir (match-end 0)))))) | |
590 | (unless (file-writable-p rl-dir) | |
591 | (error "No writable revlib directory found")) | |
592 | (message "Revlib at %s" rl-dir) | |
593 | (let* ((archives (directory-files rl-dir 'full "[^.]\\|...")) | |
594 | (categories | |
595 | (apply 'append | |
596 | (mapcar (lambda (dir) | |
597 | (when (file-directory-p dir) | |
598 | (directory-files dir 'full "[^.]\\|..."))) | |
599 | archives))) | |
600 | (branches | |
601 | (apply 'append | |
602 | (mapcar (lambda (dir) | |
603 | (when (file-directory-p dir) | |
604 | (directory-files dir 'full "[^.]\\|..."))) | |
605 | categories))) | |
606 | (versions | |
607 | (apply 'append | |
608 | (mapcar (lambda (dir) | |
609 | (when (file-directory-p dir) | |
610 | (directory-files dir 'full "--.*--"))) | |
611 | branches)))) | |
612 | (mapc 'vc-arch-trim-one-revlib versions)) | |
613 | )) | |
80d7d79f SM |
614 | |
615 | (defvar vc-arch-extra-menu-map | |
616 | (let ((map (make-sparse-keymap))) | |
617 | (define-key map [add-tagline] | |
618 | '(menu-item "Add tagline" vc-arch-add-tagline)) | |
619 | map)) | |
620 | ||
621 | (defun vc-arch-extra-menu () vc-arch-extra-menu-map) | |
e94851d3 | 622 | |
80d7d79f | 623 | |
544bdc40 SM |
624 | ;;; Less obvious implementations. |
625 | ||
ac3f4c6f | 626 | (defun vc-arch-find-revision (file rev buffer) |
544bdc40 SM |
627 | (let ((out (make-temp-file "vc-out"))) |
628 | (unwind-protect | |
629 | (progn | |
630 | (with-temp-buffer | |
631 | (vc-arch-command (current-buffer) 1 nil "file-diffs" file rev) | |
632 | (call-process-region (point-min) (point-max) | |
633 | "patch" nil nil nil "-R" "-o" out file)) | |
634 | (with-current-buffer buffer | |
635 | (insert-file-contents out))) | |
636 | (delete-file out)))) | |
637 | ||
0f6c7af8 SM |
638 | (provide 'vc-arch) |
639 | ||
0f6c7af8 | 640 | ;;; vc-arch.el ends here |