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