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