(x_new_font): Update f->scroll_bar_actual_width.
[emacs.git] / lisp / vc-arch.el
blob68146bcf1f78adda4db7dee0183531a9c2341dee
1 ;;; vc-arch.el --- VC backend for the Arch version-control system
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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 a 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 "Check if FILE is unchanged by diffing against the master version.
258 Return non-nil if FILE is unchanged."
259 nil)
261 (defun vc-arch-state (file)
262 ;; There's no checkout operation and merging is not done from VC
263 ;; so the only operation that's state dependent that VC supports is commit
264 ;; which is only activated if the file is `edited'.
265 (let* ((root (vc-arch-root file))
266 (ver (vc-arch-default-version file))
267 (pat (concat "\\`" (subst-char-in-string ?/ ?% ver)))
268 (dir (expand-file-name ",,inode-sigs/"
269 (expand-file-name "{arch}" root)))
270 (sigfile nil))
271 (dolist (f (if (file-directory-p dir) (directory-files dir t pat)))
272 (if (or (not sigfile) (file-newer-than-file-p f sigfile))
273 (setq sigfile f)))
274 (if (not sigfile)
275 'edited ;We know nothing.
276 (let ((id (vc-arch-file-id file)))
277 (setq id (replace-regexp-in-string "[ \t]" "_" id))
278 (with-current-buffer (find-file-noselect sigfile)
279 (goto-char (point-min))
280 (while (and (search-forward id nil 'move)
281 (save-excursion
282 (goto-char (- (match-beginning 0) 2))
283 ;; For `names', the lines start with `?./foo/bar'.
284 ;; For others there's 2 chars before the ./foo/bar.
285 (or (not (or (bolp) (looking-at "\n?")))
286 ;; Ignore E_ entries used for foo.id files.
287 (looking-at "E_")))))
288 (if (eobp)
289 ;; ID not found.
290 (if (equal (file-name-nondirectory sigfile)
291 (subst-char-in-string
292 ?/ ?% (vc-arch-working-revision file)))
293 'added
294 ;; Might be `added' or `up-to-date' as well.
295 ;; FIXME: Check in the patch logs to find out.
296 'edited)
297 ;; Found the ID, let's check the inode.
298 (if (not (re-search-forward
299 "\t.*mtime=\\([0-9]+\\):size=\\([0-9]+\\)"
300 (line-end-position) t))
301 ;; Buh? Unexpected format.
302 'edited
303 (let ((ats (file-attributes file)))
304 (if (and (eq (nth 7 ats) (string-to-number (match-string 2)))
305 (equal (format-time-string "%s" (nth 5 ats))
306 (match-string 1)))
307 'up-to-date
308 'edited)))))))))
310 (defun vc-arch-dir-status (dir callback)
311 "Run 'tla inventory' for DIR and pass results to CALLBACK.
312 CALLBACK expects (ENTRIES &optional MORE-TO-COME); see
313 `vc-dir-refresh'."
314 (let ((default-directory dir))
315 (vc-arch-command t 'async nil "changes"))
316 ;; The updating could be done asynchronously.
317 (vc-exec-after
318 `(vc-arch-after-dir-status ',callback)))
320 (defun vc-arch-after-dir-status (callback)
321 (let* ((state-map '(("M " . edited)
322 ("Mb" . edited) ;binary
323 ("D " . removed)
324 ("D/" . removed) ;directory
325 ("A " . added)
326 ("A/" . added) ;directory
327 ("=>" . renamed)
328 ("/>" . renamed) ;directory
329 ("lf" . symlink-to-file)
330 ("fl" . file-to-symlink)
331 ("--" . permissions-changed)
332 ("-/" . permissions-changed) ;directory
334 (state-map-regexp (regexp-opt (mapcar 'car state-map) t))
335 (entry-regexp (concat "^" state-map-regexp " \\(.*\\)$"))
336 result)
337 (goto-char (point-min))
338 ;;(message "Got %s" (buffer-string))
339 (while (re-search-forward entry-regexp nil t)
340 (let* ((state-string (match-string 1))
341 (state (cdr (assoc state-string state-map)))
342 (filename (match-string 2)))
343 (push (list filename state) result)))
345 (funcall callback result nil)))
347 (defun vc-arch-working-revision (file)
348 (let* ((root (expand-file-name "{arch}" (vc-arch-root file)))
349 (defbranch (vc-arch-default-version file)))
350 (when (and defbranch (string-match "\\`\\(.+@[^/\n]+\\)/\\(\\(\\(.*?\\)\\(?:--.*\\)?\\)--.*\\)\\'" defbranch))
351 (let* ((archive (match-string 1 defbranch))
352 (category (match-string 4 defbranch))
353 (branch (match-string 3 defbranch))
354 (version (match-string 2 defbranch))
355 (sealed nil) (rev-nb 0)
356 (rev nil)
357 logdir tmp)
358 (setq logdir (expand-file-name category root))
359 (setq logdir (expand-file-name branch logdir))
360 (setq logdir (expand-file-name version logdir))
361 (setq logdir (expand-file-name archive logdir))
362 (setq logdir (expand-file-name "patch-log" logdir))
363 (dolist (file (if (file-directory-p logdir) (directory-files logdir)))
364 ;; Revision names go: base-0, patch-N, version-0, versionfix-M.
365 (when (and (eq (aref file 0) ?v) (not sealed))
366 (setq sealed t rev-nb 0))
367 (if (and (string-match "-\\([0-9]+\\)\\'" file)
368 (setq tmp (string-to-number (match-string 1 file)))
369 (or (not sealed) (eq (aref file 0) ?v))
370 (>= tmp rev-nb))
371 (setq rev-nb tmp rev file)))
372 ;; Use "none-000" if the tree hasn't yet been committed on the
373 ;; default branch. We'll then get "Arch:000[branch]" on the mode-line.
374 (concat defbranch "--" (or rev "none-000"))))))
377 (defcustom vc-arch-mode-line-rewrite
378 '(("\\`.*--\\(.*--.*\\)--\\(v?\\).*-\\([0-9]+\\)\\'" . "\\2\\3[\\1]"))
379 "Rewrite rules to shorten Arch's revision names on the mode-line."
380 :type '(repeat (cons regexp string))
381 :group 'vc)
383 (defun vc-arch-mode-line-string (file)
384 "Return string for placement in modeline by `vc-mode-line' for FILE."
385 (let ((rev (vc-working-revision file)))
386 (dolist (rule vc-arch-mode-line-rewrite)
387 (if (string-match (car rule) rev)
388 (setq rev (replace-match (cdr rule) t nil rev))))
389 (format "Arch%c%s"
390 (case (vc-state file)
391 ((up-to-date needs-update) ?-)
392 (added ?@)
393 (t ?:))
394 rev)))
396 (defun vc-arch-diff3-rej-p (rej)
397 (let ((attrs (file-attributes rej)))
398 (and attrs (< (nth 7 attrs) 60)
399 (with-temp-buffer
400 (insert-file-contents rej)
401 (goto-char (point-min))
402 (looking-at "Conflicts occured, diff3 conflict markers left in file\\.")))))
404 (defun vc-arch-delete-rej-if-obsolete ()
405 "For use in `after-save-hook'."
406 (save-excursion
407 (let ((rej (concat buffer-file-name ".rej")))
408 (when (and buffer-file-name (vc-arch-diff3-rej-p rej))
409 (unless (re-search-forward "^<<<<<<< " nil t)
410 ;; The .rej file is obsolete.
411 (condition-case nil (delete-file rej) (error nil))
412 ;; Remove the hook so that it is not called multiple times.
413 (remove-hook 'after-save-hook 'vc-arch-delete-rej-if-obsolete t))))))
415 (defun vc-arch-find-file-hook ()
416 (let ((rej (concat buffer-file-name ".rej")))
417 (when (and buffer-file-name (file-exists-p rej))
418 (if (vc-arch-diff3-rej-p rej)
419 (save-excursion
420 (goto-char (point-min))
421 (if (not (re-search-forward "^<<<<<<< " nil t))
422 ;; The .rej file is obsolete.
423 (condition-case nil (delete-file rej) (error nil))
424 (smerge-mode 1)
425 (add-hook 'after-save-hook
426 'vc-arch-delete-rej-if-obsolete nil t)
427 (message "There are unresolved conflicts in this file")))
428 (message "There are unresolved conflicts in %s"
429 (file-name-nondirectory rej))))))
431 (defun vc-arch-checkin (files rev comment)
432 (if rev (error "Committing to a specific revision is unsupported"))
433 ;; FIXME: This implementation probably only works for singleton filesets
434 (let ((summary (file-relative-name (car files) (vc-arch-root (car files)))))
435 ;; Extract a summary from the comment.
436 (when (or (string-match "\\`Summary:[ \t]*\\(.*[^ \t\n]\\)\\([ \t]*\n\\)*" comment)
437 (string-match "\\`[ \t]*\\(.*[^ \t\n]\\)[ \t]*\\(\n?\\'\\|\n\\([ \t]*\n\\)+\\)" comment))
438 (setq summary (match-string 1 comment))
439 (setq comment (substring comment (match-end 0))))
440 (vc-arch-command nil 0 files "commit" "-s" summary "-L" comment "--"
441 (vc-switches 'Arch 'checkin))))
443 (defun vc-arch-diff (files &optional oldvers newvers buffer)
444 "Get a difference report using Arch between two versions of FILES."
445 ;; FIXME: This implementation only works for singleton filesets. To make
446 ;; it work for more cases, we have to either call `file-diffs' manually on
447 ;; each and every `file' in the fileset, or use `changes --diffs' (and
448 ;; variants) and maybe filter the output with `filterdiff' to only include
449 ;; the files in which we're interested.
450 (let ((file (car files)))
451 (if (and newvers
452 (vc-up-to-date-p file)
453 (equal newvers (vc-working-revision file)))
454 ;; Newvers is the base revision and the current file is unchanged,
455 ;; so we can diff with the current file.
456 (setq newvers nil))
457 (if newvers
458 (error "Diffing specific revisions not implemented")
459 (let* (process-file-side-effects
460 (async (not vc-disable-async-diff))
461 ;; Run the command from the root dir.
462 (default-directory (vc-arch-root file))
463 (status
464 (vc-arch-command
465 (or buffer "*vc-diff*")
466 (if async 'async 1)
467 nil "file-diffs"
468 (vc-switches 'Arch 'diff)
469 (file-relative-name file)
470 (if (equal oldvers (vc-working-revision file))
472 oldvers))))
473 (if async 1 status))))) ; async diff, pessimistic assumption.
475 (defun vc-arch-delete-file (file)
476 (vc-arch-command nil 0 file "rm"))
478 (defun vc-arch-rename-file (old new)
479 (vc-arch-command nil 0 new "mv" (file-relative-name old)))
481 (defalias 'vc-arch-responsible-p 'vc-arch-root)
483 (defun vc-arch-command (buffer okstatus file &rest flags)
484 "A wrapper around `vc-do-command' for use in vc-arch.el."
485 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-arch-program file flags))
487 (defun vc-arch-init-revision () nil)
489 ;;; Completion of versions and revisions.
491 (defun vc-arch--version-completion-table (root string)
492 (delq nil
493 (mapcar
494 (lambda (d)
495 (when (string-match "/\\([^/]+\\)/\\([^/]+\\)\\'" d)
496 (concat (match-string 2 d) "/" (match-string 1 d))))
497 (let ((default-directory root))
498 (file-expand-wildcards
499 (concat "*/*/"
500 (if (string-match "/" string)
501 (concat (substring string (match-end 0))
502 "*/" (substring string 0 (match-beginning 0)))
503 (concat "*/" string))
504 "*"))))))
506 (defun vc-arch-revision-completion-table (files)
507 (lexical-let ((files files))
508 (lambda (string pred action)
509 ;; FIXME: complete revision patches as well.
510 (let* ((root (expand-file-name "{arch}" (vc-arch-root (car files))))
511 (table (vc-arch--version-completion-table root string)))
512 (complete-with-action action table string pred)))))
514 ;;; Trimming revision libraries.
516 ;; This code is not directly related to VC and there are many variants of
517 ;; this functionality available as scripts, but I like this version better,
518 ;; so maybe others will like it too.
520 (defun vc-arch-trim-find-least-useful-rev (revs)
521 (let* ((first (pop revs))
522 (second (pop revs))
523 (third (pop revs))
524 ;; We try to give more importance to recent revisions. The idea is
525 ;; that it's OK if checking out a revision 1000-patch-old is ten
526 ;; times slower than checking out a revision 100-patch-old. But at
527 ;; the same time a 2-patch-old rev isn't really ten times more
528 ;; important than a 20-patch-old, so we use an arbitrary constant
529 ;; "100" to reduce this effect for recent revisions. Making this
530 ;; constant a float has the side effect of causing the subsequent
531 ;; computations to be done as floats as well.
532 (max (+ 100.0 (car (or (car (last revs)) third))))
533 (cost (lambda () (/ (- (car third) (car first)) (- max (car second)))))
534 (minrev second)
535 (mincost (funcall cost)))
536 (while revs
537 (setq first second)
538 (setq second third)
539 (setq third (pop revs))
540 (when (< (funcall cost) mincost)
541 (setq minrev second)
542 (setq mincost (funcall cost))))
543 minrev))
545 (defun vc-arch-trim-make-sentinel (revs)
546 (if (null revs) (lambda (proc msg) (message "VC-Arch trimming ... done"))
547 (lexical-let ((revs revs))
548 (lambda (proc msg)
549 (message "VC-Arch trimming %s..." (file-name-nondirectory (car revs)))
550 (rename-file (car revs) (concat (car revs) "*rm*"))
551 (setq proc (start-process "vc-arch-trim" nil
552 "rm" "-rf" (concat (car revs) "*rm*")))
553 (set-process-sentinel proc (vc-arch-trim-make-sentinel (cdr revs)))))))
555 (defun vc-arch-trim-one-revlib (dir)
556 "Delete half of the revisions in the revision library."
557 (interactive "Ddirectory: ")
558 (let ((garbage (directory-files dir 'full "\\`,," 'nosort)))
559 (when garbage
560 (funcall (vc-arch-trim-make-sentinel garbage) nil nil)))
561 (let ((revs
562 (sort (delq nil
563 (mapcar
564 (lambda (f)
565 (when (string-match "-\\([0-9]+\\)\\'" f)
566 (cons (string-to-number (match-string 1 f)) f)))
567 (directory-files dir nil nil 'nosort)))
568 'car-less-than-car))
569 (subdirs nil))
570 (when (cddr revs)
571 (dotimes (i (/ (length revs) 2))
572 (let ((minrev (vc-arch-trim-find-least-useful-rev revs)))
573 (setq revs (delq minrev revs))
574 (push minrev subdirs)))
575 (funcall (vc-arch-trim-make-sentinel
576 (mapcar (lambda (x) (expand-file-name (cdr x) dir)) subdirs))
577 nil nil))))
579 (defun vc-arch-trim-revlib ()
580 "Delete half of the revisions in the revision library."
581 (interactive)
582 (let ((rl-dir (with-output-to-string
583 (call-process vc-arch-program nil standard-output nil
584 "my-revision-library"))))
585 (while (string-match "\\(.*\\)\n" rl-dir)
586 (let ((dir (match-string 1 rl-dir)))
587 (setq rl-dir
588 (if (and (file-directory-p dir) (file-writable-p dir))
590 (substring rl-dir (match-end 0))))))
591 (unless (file-writable-p rl-dir)
592 (error "No writable revlib directory found"))
593 (message "Revlib at %s" rl-dir)
594 (let* ((archives (directory-files rl-dir 'full "[^.]\\|..."))
595 (categories
596 (apply 'append
597 (mapcar (lambda (dir)
598 (when (file-directory-p dir)
599 (directory-files dir 'full "[^.]\\|...")))
600 archives)))
601 (branches
602 (apply 'append
603 (mapcar (lambda (dir)
604 (when (file-directory-p dir)
605 (directory-files dir 'full "[^.]\\|...")))
606 categories)))
607 (versions
608 (apply 'append
609 (mapcar (lambda (dir)
610 (when (file-directory-p dir)
611 (directory-files dir 'full "--.*--")))
612 branches))))
613 (mapc 'vc-arch-trim-one-revlib versions))
616 (defvar vc-arch-extra-menu-map
617 (let ((map (make-sparse-keymap)))
618 (define-key map [add-tagline]
619 '(menu-item "Add tagline" vc-arch-add-tagline))
620 map))
622 (defun vc-arch-extra-menu () vc-arch-extra-menu-map)
625 ;;; Less obvious implementations.
627 (defun vc-arch-find-revision (file rev buffer)
628 (let ((out (make-temp-file "vc-out")))
629 (unwind-protect
630 (progn
631 (with-temp-buffer
632 (vc-arch-command (current-buffer) 1 nil "file-diffs" file rev)
633 (call-process-region (point-min) (point-max)
634 "patch" nil nil nil "-R" "-o" out file))
635 (with-current-buffer buffer
636 (insert-file-contents out)))
637 (delete-file out))))
639 (provide 'vc-arch)
641 ;; arch-tag: a35c7c1c-5237-429d-88ef-3d718fd2e704
642 ;;; vc-arch.el ends here