Add "Package:" file headers to denote built-in packages.
[emacs.git] / lisp / vc / vc-arch.el
blob3ca9d59e3c1f273eb44b5f375cdec2bb5c4c2041
1 ;;; vc-arch.el --- VC backend for the Arch version-control system
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
8 ;; Package: vc
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; The home page of the Arch version control system is at
29 ;; http://www.gnuarch.org/
31 ;; This is derived from vc-mcvs.el as follows:
32 ;; - cp vc-mcvs.el vc-arch.el and then M-% mcvs RET arch RET
34 ;; Then of course started the hacking.
36 ;; What has been partly tested:
37 ;; - Open a file.
38 ;; - C-x v = without any prefix arg.
39 ;; - C-x v v to commit a change to a single file.
41 ;; Bugs:
43 ;; - *VC-log*'s initial content lacks the `Summary:' lines.
44 ;; - All files under the tree are considered as "under Arch's control"
45 ;; without regards to =tagging-method and such.
46 ;; - Files are always considered as `edited'.
47 ;; - C-x v l does not work.
48 ;; - C-x v i does not work.
49 ;; - C-x v ~ does not work.
50 ;; - C-x v u does not work.
51 ;; - C-x v s does not work.
52 ;; - C-x v r does not work.
53 ;; - VC directory listings do not work.
54 ;; - And more...
56 ;;; Code:
58 (eval-when-compile (require 'vc) (require 'cl))
60 ;;; Properties of the backend
62 (defun vc-arch-revision-granularity () 'repository)
63 (defun vc-arch-checkout-model (files) 'implicit)
65 ;;;
66 ;;; Customization options
67 ;;;
69 ;; It seems Arch diff does not accept many options, so this is not
70 ;; very useful. It exists mainly so that the VC backends are all
71 ;; consistent with regards to their treatment of diff switches.
72 (defcustom vc-arch-diff-switches t
73 "String or list of strings specifying switches for Arch diff under VC.
74 If nil, use the value of `vc-diff-switches'. If t, use no switches."
75 :type '(choice (const :tag "Unspecified" nil)
76 (const :tag "None" t)
77 (string :tag "Argument String")
78 (repeat :tag "Argument List" :value ("") string))
79 :version "23.1"
80 :group 'vc)
82 (define-obsolete-variable-alias 'vc-arch-command 'vc-arch-program "23.1")
84 (defcustom vc-arch-program
85 (let ((candidates '("tla" "baz")))
86 (while (and candidates (not (executable-find (car candidates))))
87 (setq candidates (cdr candidates)))
88 (or (car candidates) "tla"))
89 "Name of the Arch executable."
90 :type 'string
91 :group 'vc)
93 ;; Clear up the cache to force vc-call to check again and discover
94 ;; new functions when we reload this file.
95 (put 'Arch 'vc-functions nil)
97 ;;;###autoload (defun vc-arch-registered (file)
98 ;;;###autoload (if (vc-find-root file "{arch}/=tagging-method")
99 ;;;###autoload (progn
100 ;;;###autoload (load "vc-arch")
101 ;;;###autoload (vc-arch-registered file))))
103 (defun vc-arch-add-tagline ()
104 "Add an `arch-tag' to the end of the current file."
105 (interactive)
106 (comment-normalize-vars)
107 (goto-char (point-max))
108 (forward-comment -1)
109 (skip-chars-forward " \t\n")
110 (cond
111 ((not (bolp)) (insert "\n\n"))
112 ((not (eq ?\n (char-before (1- (point))))) (insert "\n")))
113 (let ((beg (point))
114 (idfile (and buffer-file-name
115 (expand-file-name
116 (concat ".arch-ids/"
117 (file-name-nondirectory buffer-file-name)
118 ".id")
119 (file-name-directory buffer-file-name)))))
120 (insert "arch-tag: ")
121 (if (and idfile (file-exists-p idfile))
122 ;; If the file is unreadable, we do want to get an error here.
123 (progn
124 (insert-file-contents idfile)
125 (forward-line 1)
126 (delete-file idfile))
127 (condition-case nil
128 (call-process "uuidgen" nil t)
129 (file-error (insert (format "%s <%s> %s"
130 (current-time-string)
131 user-mail-address
132 (+ (nth 2 (current-time))
133 (buffer-size)))))))
134 (comment-region beg (point))))
136 (defconst vc-arch-tagline-re "^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)")
138 (defmacro vc-with-current-file-buffer (file &rest body)
139 (declare (indent 2) (debug t))
140 `(let ((-kill-buf- nil)
141 (-file- ,file))
142 (with-current-buffer (or (find-buffer-visiting -file-)
143 (setq -kill-buf- (generate-new-buffer " temp")))
144 ;; Avoid find-file-literally since it can do many undesirable extra
145 ;; things (among which, call us back into an infinite loop).
146 (if -kill-buf- (insert-file-contents -file-))
147 (unwind-protect
148 (progn ,@body)
149 (if (buffer-live-p -kill-buf-) (kill-buffer -kill-buf-))))))
151 (defun vc-arch-file-source-p (file)
152 "Can return nil, `maybe' or a non-nil value.
153 Only the value `maybe' can be trusted :-(."
154 ;; FIXME: Check the tag and name of parent dirs.
155 (unless (string-match "\\`[,+]" (file-name-nondirectory file))
156 (or (string-match "\\`{arch}/"
157 (file-relative-name file (vc-arch-root file)))
158 (file-exists-p
159 ;; Check the presence of an ID file.
160 (expand-file-name
161 (concat ".arch-ids/" (file-name-nondirectory file) ".id")
162 (file-name-directory file)))
163 ;; Check the presence of a tagline.
164 (vc-with-current-file-buffer file
165 (save-excursion
166 (goto-char (point-max))
167 (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t)
168 (progn
169 (goto-char (point-min))
170 (re-search-forward vc-arch-tagline-re (+ (point) 1000) t)))))
171 ;; FIXME: check =tagging-method to see whether untagged files might
172 ;; be source or not.
173 (with-current-buffer
174 (find-file-noselect (expand-file-name "{arch}/=tagging-method"
175 (vc-arch-root file)))
176 (let ((untagged-source t)) ;Default is `names'.
177 (save-excursion
178 (goto-char (point-min))
179 (if (re-search-forward "^[ \t]*\\(\\(tagline\\|implicit\\|names\\)\\|explicit\\)" nil t)
180 (setq untagged-source (match-end 2)))
181 (if (re-search-forward "^[ \t]*untagged-source[ \t]+\\(\\(source\\)\\|precious\\|backup\\|junk\\|unrecognized\\)" nil t)
182 (setq untagged-source (match-end 2))))
183 (if untagged-source 'maybe))))))
185 (defun vc-arch-file-id (file)
186 ;; Don't include the kind of ID this is because it seems to be too messy.
187 (let ((idfile (expand-file-name
188 (concat ".arch-ids/" (file-name-nondirectory file) ".id")
189 (file-name-directory file))))
190 (if (file-exists-p idfile)
191 (with-temp-buffer
192 (insert-file-contents idfile)
193 (looking-at ".*[^ \n\t]")
194 (match-string 0))
195 (with-current-buffer (find-file-noselect file)
196 (save-excursion
197 (goto-char (point-max))
198 (if (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t)
199 (progn
200 (goto-char (point-min))
201 (re-search-forward vc-arch-tagline-re (+ (point) 1000) t)))
202 (match-string 1)
203 (concat "./" (file-relative-name file (vc-arch-root file)))))))))
205 (defun vc-arch-tagging-method (file)
206 (with-current-buffer
207 (find-file-noselect
208 (expand-file-name "{arch}/=tagging-method" (vc-arch-root file)))
209 (save-excursion
210 (goto-char (point-min))
211 (if (re-search-forward
212 "^[ \t]*\\(tagline\\|implicit\\|names\\|explicit\\)" nil t)
213 (intern (match-string 1))
214 'names))))
216 (defun vc-arch-root (file)
217 "Return the root directory of an Arch project, if any."
218 (or (vc-file-getprop file 'arch-root)
219 ;; Check the =tagging-method, in case someone naively manually
220 ;; creates a {arch} directory somewhere.
221 (let ((root (vc-find-root file "{arch}/=tagging-method")))
222 (when root
223 (vc-file-setprop
224 file 'arch-root root)))))
226 (defun vc-arch-register (files &optional rev comment)
227 (if rev (error "Explicit initial revision not supported for Arch"))
228 (dolist (file files)
229 (let ((tagmet (vc-arch-tagging-method file)))
230 (if (and (memq tagmet '(tagline implicit)) comment-start)
231 (with-current-buffer (find-file-noselect file)
232 (if (buffer-modified-p)
233 (error "Save %s first" (buffer-name)))
234 (vc-arch-add-tagline)
235 (save-buffer)))))
236 (vc-arch-command nil 0 files "add"))
238 (defun vc-arch-registered (file)
239 ;; Don't seriously check whether it's source or not. Checking would
240 ;; require running TLA, so it's better to not do it, so it also works if
241 ;; TLA is not installed.
242 (and (vc-arch-root file)
243 (vc-arch-file-source-p file)))
245 (defun vc-arch-default-version (file)
246 (or (vc-file-getprop (vc-arch-root file) 'arch-default-version)
247 (let* ((root (vc-arch-root file))
248 (f (expand-file-name "{arch}/++default-version" root)))
249 (if (file-readable-p f)
250 (vc-file-setprop
251 root 'arch-default-version
252 (with-temp-buffer
253 (insert-file-contents f)
254 ;; Strip the terminating newline.
255 (buffer-substring (point-min) (1- (point-max)))))))))
257 (defun vc-arch-workfile-unchanged-p (file)
258 "Stub: arch workfiles are always considered to be in a changed state,"
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 &optional extra-args-ignored)
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