Fix merge error.
[emacs.git] / lisp / vc-arch.el
blobf9ead1847316762288c810a558b65314614e9d8b
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* ((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