merge emacs-23
[emacs.git] / lisp / vc-arch.el
blob57bc487cafab97de0aa40feed8be263e97fdc218
1 ;;; vc-arch.el --- VC backend for the Arch version-control system
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; The home page of the Arch version control system is at
28 ;; http://www.gnuarch.org/
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
33 ;; Then of course started the hacking.
35 ;; What has been partly tested:
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.
40 ;; Bugs:
42 ;; - *VC-log*'s initial content lacks the `Summary:' lines.
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'.
46 ;; - C-x v l does not work.
47 ;; - C-x v i does not work.
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.
52 ;; - VC directory listings do not work.
53 ;; - And more...
55 ;;; Code:
57 (eval-when-compile (require 'vc) (require 'cl))
59 ;;; Properties of the backend
61 (defun vc-arch-revision-granularity () 'repository)
62 (defun vc-arch-checkout-model (files) 'implicit)
64 ;;;
65 ;;; Customization options
66 ;;;
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)
81 (define-obsolete-variable-alias 'vc-arch-command 'vc-arch-program "23.1")
83 (defcustom vc-arch-program
84 (let ((candidates '("tla" "baz")))
85 (while (and candidates (not (executable-find (car candidates))))
86 (setq candidates (cdr candidates)))
87 (or (car candidates) "tla"))
88 "Name of the Arch executable."
89 :type 'string
90 :group 'vc)
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)
96 ;;;###autoload (defun vc-arch-registered (file)
97 ;;;###autoload (if (vc-find-root file "{arch}/=tagging-method")
98 ;;;###autoload (progn
99 ;;;###autoload (load "vc-arch")
100 ;;;###autoload (vc-arch-registered file))))
102 (defun vc-arch-add-tagline ()
103 "Add an `arch-tag' to the end of the current file."
104 (interactive)
105 (comment-normalize-vars)
106 (goto-char (point-max))
107 (forward-comment -1)
108 (skip-chars-forward " \t\n")
109 (cond
110 ((not (bolp)) (insert "\n\n"))
111 ((not (eq ?\n (char-before (1- (point))))) (insert "\n")))
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)))))
119 (insert "arch-tag: ")
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)))))))
133 (comment-region beg (point))))
135 (defconst vc-arch-tagline-re "^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)")
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-))))))
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.
163 (vc-with-current-file-buffer file
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))))))
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]")
193 (match-string 0))
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)
202 (concat "./" (file-relative-name file (vc-arch-root file)))))))))
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))))
215 (defun vc-arch-root (file)
216 "Return the root directory of an Arch project, if any."
217 (or (vc-file-getprop file 'arch-root)
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)))))
225 (defun vc-arch-register (files &optional rev comment)
226 (if rev (error "Explicit initial revision not supported for Arch"))
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"))
237 (defun vc-arch-registered (file)
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)))
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)))))))))
256 (defun vc-arch-workfile-unchanged-p (file)
257 "Stub: arch workfiles are always considered to be in a changed state,"
258 nil)
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'.
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)
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_")))))
287 (if (eobp)
288 ;; ID not found.
289 (if (equal (file-name-nondirectory sigfile)
290 (subst-char-in-string
291 ?/ ?% (vc-arch-working-revision file)))
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)))
303 (if (and (eq (nth 7 ats) (string-to-number (match-string 2)))
304 (equal (format-time-string "%s" (nth 5 ats))
305 (match-string 1)))
306 'up-to-date
307 'edited)))))))))
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)))
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
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)))
344 (funcall callback result nil)))
346 (defun vc-arch-working-revision (file)
347 (let* ((root (expand-file-name "{arch}" (vc-arch-root file)))
348 (defbranch (vc-arch-default-version file)))
349 (when (and defbranch (string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*?\\)\\(?:--.*\\)?\\)--.*\\)\\'" defbranch))
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))
354 (sealed nil) (rev-nb 0)
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))
362 (dolist (file (if (file-directory-p logdir) (directory-files logdir)))
363 ;; Revision names go: base-0, patch-N, version-0, versionfix-M.
364 (when (and (eq (aref file 0) ?v) (not sealed))
365 (setq sealed t rev-nb 0))
366 (if (and (string-match "-\\([0-9]+\\)\\'" file)
367 (setq tmp (string-to-number (match-string 1 file)))
368 (or (not sealed) (eq (aref file 0) ?v))
369 (>= tmp rev-nb))
370 (setq rev-nb tmp rev file)))
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"))))))
376 (defcustom vc-arch-mode-line-rewrite
377 '(("\\`.*--\\(.*--.*\\)--\\(v?\\).*-\\([0-9]+\\)\\'" . "\\2\\3[\\1]"))
378 "Rewrite rules to shorten Arch's revision names on the mode-line."
379 :type '(repeat (cons regexp string))
380 :group 'vc)
382 (defun vc-arch-mode-line-string (file)
383 "Return string for placement in modeline by `vc-mode-line' for FILE."
384 (let ((rev (vc-working-revision file)))
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"
389 (case (vc-state file)
390 ((up-to-date needs-update) ?-)
391 (added ?@)
392 (t ?:))
393 rev)))
395 (defun vc-arch-diff3-rej-p (rej)
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))
401 (looking-at "Conflicts occured, diff3 conflict markers left in file\\.")))))
403 (defun vc-arch-delete-rej-if-obsolete ()
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))
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))))))
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))
420 (if (not (re-search-forward "^<<<<<<< " nil t))
421 ;; The .rej file is obsolete.
422 (condition-case nil (delete-file rej) (error nil))
423 (smerge-mode 1)
424 (add-hook 'after-save-hook
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))))))
430 (defun vc-arch-checkin (files rev comment)
431 (if rev (error "Committing to a specific revision is unsupported"))
432 ;; FIXME: This implementation probably only works for singleton filesets
433 (let ((summary (file-relative-name (car files) (vc-arch-root (car files)))))
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))))
439 (vc-arch-command nil 0 files "commit" "-s" summary "-L" comment "--"
440 (vc-switches 'Arch 'checkin))))
442 (defun vc-arch-diff (files &optional oldvers newvers buffer)
443 "Get a difference report using Arch between two versions of FILES."
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)
452 (equal newvers (vc-working-revision file)))
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")
458 (let* (process-file-side-effects
459 (async (not vc-disable-async-diff))
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"
467 (vc-switches 'Arch 'diff)
468 (file-relative-name file)
469 (if (equal oldvers (vc-working-revision file))
471 oldvers))))
472 (if async 1 status))))) ; async diff, pessimistic assumption.
474 (defun vc-arch-delete-file (file)
475 (vc-arch-command nil 0 file "rm"))
477 (defun vc-arch-rename-file (old new)
478 (vc-arch-command nil 0 new "mv" (file-relative-name old)))
480 (defalias 'vc-arch-responsible-p 'vc-arch-root)
482 (defun vc-arch-command (buffer okstatus file &rest flags)
483 "A wrapper around `vc-do-command' for use in vc-arch.el."
484 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-arch-program file flags))
486 (defun vc-arch-init-revision () nil)
488 ;;; Completion of versions and revisions.
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 "*"))))))
505 (defun vc-arch-revision-completion-table (files)
506 (lexical-let ((files files))
507 (lambda (string pred action)
508 ;; FIXME: complete revision patches as well.
509 (let* ((root (expand-file-name "{arch}" (vc-arch-root (car files))))
510 (table (vc-arch--version-completion-table root string)))
511 (complete-with-action action table string pred)))))
513 ;;; Trimming revision libraries.
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.
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))
544 (defun vc-arch-trim-make-sentinel (revs)
545 (if (null revs) (lambda (proc msg) (message "VC-Arch trimming ... done"))
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*"))
550 (setq proc (start-process "vc-arch-trim" nil
551 "rm" "-rf" (concat (car revs) "*rm*")))
552 (set-process-sentinel proc (vc-arch-trim-make-sentinel (cdr revs)))))))
554 (defun vc-arch-trim-one-revlib (dir)
555 "Delete half of the revisions in the revision library."
556 (interactive "Ddirectory: ")
557 (let ((garbage (directory-files dir 'full "\\`,," 'nosort)))
558 (when garbage
559 (funcall (vc-arch-trim-make-sentinel garbage) nil nil)))
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))))
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
582 (call-process vc-arch-program nil standard-output nil
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))
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))
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))
621 (defun vc-arch-extra-menu () vc-arch-extra-menu-map)
624 ;;; Less obvious implementations.
626 (defun vc-arch-find-revision (file rev buffer)
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))))
638 (provide 'vc-arch)
640 ;; arch-tag: a35c7c1c-5237-429d-88ef-3d718fd2e704
641 ;;; vc-arch.el ends here