Mercurial > emacs
comparison lisp/vc-arch.el @ 90979:988f1edc9674
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 803-805)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-227
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 09 Jul 2007 08:00:55 +0000 |
parents | 3619e7770f2e 205f0e2270e9 |
children | a66921565bcb |
comparison
equal
deleted
inserted
replaced
90978:f866074aedc4 | 90979:988f1edc9674 |
---|---|
81 "Add an `arch-tag' to the end of the current file." | 81 "Add an `arch-tag' to the end of the current file." |
82 (interactive) | 82 (interactive) |
83 (comment-normalize-vars) | 83 (comment-normalize-vars) |
84 (goto-char (point-max)) | 84 (goto-char (point-max)) |
85 (forward-comment -1) | 85 (forward-comment -1) |
86 (unless (bolp) (insert "\n")) | 86 (skip-chars-forward " \t\n") |
87 (cond | |
88 ((not (bolp)) (insert "\n\n")) | |
89 ((not (eq ?\n (char-before (1- (point))))) (insert "\n"))) | |
87 (let ((beg (point)) | 90 (let ((beg (point)) |
88 (idfile (and buffer-file-name | 91 (idfile (and buffer-file-name |
89 (expand-file-name | 92 (expand-file-name |
90 (concat ".arch-ids/" | 93 (concat ".arch-ids/" |
91 (file-name-nondirectory buffer-file-name) | 94 (file-name-nondirectory buffer-file-name) |
417 "A wrapper around `vc-do-command' for use in vc-arch.el." | 420 "A wrapper around `vc-do-command' for use in vc-arch.el." |
418 (apply 'vc-do-command buffer okstatus vc-arch-command file flags)) | 421 (apply 'vc-do-command buffer okstatus vc-arch-command file flags)) |
419 | 422 |
420 (defun vc-arch-init-version () nil) | 423 (defun vc-arch-init-version () nil) |
421 | 424 |
425 ;;; Completion of versions and revisions. | |
426 | |
427 (defun vc-arch-complete (table string pred action) | |
428 (assert (not (functionp table))) | |
429 (cond | |
430 ((null action) (try-completion string table pred)) | |
431 ((eq action t) (all-completions string table pred)) | |
432 (t (test-completion string table pred)))) | |
433 | |
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 | |
449 (defun vc-arch-revision-completion-table (file) | |
450 (lexical-let ((file file)) | |
451 (lambda (string pred action) | |
452 ;; FIXME: complete revision patches as well. | |
453 (let ((root (expand-file-name "{arch}" (vc-arch-root file)))) | |
454 (vc-arch-complete | |
455 (vc-arch--version-completion-table root string) | |
456 string pred action))))) | |
457 | |
458 ;;; Trimming revision libraries. | |
459 | |
460 ;; This code is not directly related to VC and there are many variants of | |
461 ;; this functionality available as scripts, but I like this version better, | |
462 ;; so maybe others will like it too. | |
463 | |
464 (defun vc-arch-trim-find-least-useful-rev (revs) | |
465 (let* ((first (pop revs)) | |
466 (second (pop revs)) | |
467 (third (pop revs)) | |
468 ;; We try to give more importance to recent revisions. The idea is | |
469 ;; that it's OK if checking out a revision 1000-patch-old is ten | |
470 ;; times slower than checking out a revision 100-patch-old. But at | |
471 ;; the same time a 2-patch-old rev isn't really ten times more | |
472 ;; important than a 20-patch-old, so we use an arbitrary constant | |
473 ;; "100" to reduce this effect for recent revisions. Making this | |
474 ;; constant a float has the side effect of causing the subsequent | |
475 ;; computations to be done as floats as well. | |
476 (max (+ 100.0 (car (or (car (last revs)) third)))) | |
477 (cost (lambda () (/ (- (car third) (car first)) (- max (car second))))) | |
478 (minrev second) | |
479 (mincost (funcall cost))) | |
480 (while revs | |
481 (setq first second) | |
482 (setq second third) | |
483 (setq third (pop revs)) | |
484 (when (< (funcall cost) mincost) | |
485 (setq minrev second) | |
486 (setq mincost (funcall cost)))) | |
487 minrev)) | |
488 | |
489 (defun vc-arch-trim-make-sentinel (revs) | |
490 (if (null revs) (lambda (proc msg) (message "VC-Arch trimming ... done")) | |
491 `(lambda (proc msg) | |
492 (message "VC-Arch trimming %s..." ',(file-name-nondirectory (car revs))) | |
493 (rename-file ,(car revs) ,(concat (car revs) "*rm*")) | |
494 (setq proc (start-process "vc-arch-trim" nil | |
495 "rm" "-rf" ',(concat (car revs) "*rm*"))) | |
496 (set-process-sentinel proc (vc-arch-trim-make-sentinel ',(cdr revs)))))) | |
497 | |
498 (defun vc-arch-trim-one-revlib (dir) | |
499 "Delete half of the revisions in the revision library." | |
500 (interactive "Ddirectory: ") | |
501 (let ((revs | |
502 (sort (delq nil | |
503 (mapcar | |
504 (lambda (f) | |
505 (when (string-match "-\\([0-9]+\\)\\'" f) | |
506 (cons (string-to-number (match-string 1 f)) f))) | |
507 (directory-files dir nil nil 'nosort))) | |
508 'car-less-than-car)) | |
509 (subdirs nil)) | |
510 (when (cddr revs) | |
511 (dotimes (i (/ (length revs) 2)) | |
512 (let ((minrev (vc-arch-trim-find-least-useful-rev revs))) | |
513 (setq revs (delq minrev revs)) | |
514 (push minrev subdirs))) | |
515 (funcall (vc-arch-trim-make-sentinel | |
516 (mapcar (lambda (x) (expand-file-name (cdr x) dir)) subdirs)) | |
517 nil nil)))) | |
518 | |
519 (defun vc-arch-trim-revlib () | |
520 "Delete half of the revisions in the revision library." | |
521 (interactive) | |
522 (let ((rl-dir (with-output-to-string | |
523 (call-process vc-arch-command nil standard-output nil | |
524 "my-revision-library")))) | |
525 (while (string-match "\\(.*\\)\n" rl-dir) | |
526 (let ((dir (match-string 1 rl-dir))) | |
527 (setq rl-dir | |
528 (if (and (file-directory-p dir) (file-writable-p dir)) | |
529 dir | |
530 (substring rl-dir (match-end 0)))))) | |
531 (unless (file-writable-p rl-dir) | |
532 (error "No writable revlib directory found")) | |
533 (message "Revlib at %s" rl-dir) | |
534 (let* ((archives (directory-files rl-dir 'full "[^.]\\|...")) | |
535 (categories | |
536 (apply 'append | |
537 (mapcar (lambda (dir) | |
538 (when (file-directory-p dir) | |
539 (directory-files dir 'full "[^.]\\|..."))) | |
540 archives))) | |
541 (branches | |
542 (apply 'append | |
543 (mapcar (lambda (dir) | |
544 (when (file-directory-p dir) | |
545 (directory-files dir 'full "[^.]\\|..."))) | |
546 categories))) | |
547 (versions | |
548 (apply 'append | |
549 (mapcar (lambda (dir) | |
550 (when (file-directory-p dir) | |
551 (directory-files dir 'full "--.*--"))) | |
552 branches)))) | |
553 (mapc 'vc-arch-trim-one-revlib versions)) | |
554 )) | |
555 | |
422 ;;; Less obvious implementations. | 556 ;;; Less obvious implementations. |
423 | 557 |
424 (defun vc-arch-find-version (file rev buffer) | 558 (defun vc-arch-find-version (file rev buffer) |
425 (let ((out (make-temp-file "vc-out"))) | 559 (let ((out (make-temp-file "vc-out"))) |
426 (unwind-protect | 560 (unwind-protect |