aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-06-26 17:59:52 +0000
committerStefan Monnier2007-06-26 17:59:52 +0000
commit56dada428edf7ecdbcf23a1915b23de83ca5b590 (patch)
tree283bc76a159bdf8c13742dbabc1b7e68e7591382
parent4d83a657852934b2291f0d1c1040b6628ca6788b (diff)
downloademacs-56dada428edf7ecdbcf23a1915b23de83ca5b590.tar.gz
emacs-56dada428edf7ecdbcf23a1915b23de83ca5b590.zip
(vc-arch-add-tagline): Do a slightly cleaner job.
(vc-arch-complete, vc-arch--version-completion-table) (vc-arch-revision-completion-table): New functions to provide completion of revision names. (vc-arch-trim-find-least-useful-rev, vc-arch-trim-make-sentinel) (vc-arch-trim-one-revlib, vc-arch-trim-revlib): New functions to let the user trim the revlib.
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/vc-arch.el136
3 files changed, 147 insertions, 4 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 8c01002f940..81127d728f3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -74,10 +74,11 @@ recenter the visited source file. Its value can be a number (for example,
74Only copyright lines with holders matching copyright-names-regexp will be 74Only copyright lines with holders matching copyright-names-regexp will be
75considered for update. 75considered for update.
76 76
77** VC
78*** VC backends can provide completion of revision names.
79*** VC has some support for Bazaar (bzr).
77 80
78** VC has some support for Bazaar (bzr). 81*** VC has some support for Mercurial (hg).
79
80** VC has some support for Mercurial (hg).
81 82
82** sgml-electric-tag-pair-mode lets you simultaneously edit matched tag pairs. 83** sgml-electric-tag-pair-mode lets you simultaneously edit matched tag pairs.
83 84
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 75cbc29d28a..437d439f284 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,13 @@
12007-06-26 Stefan Monnier <monnier@iro.umontreal.ca> 12007-06-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * vc-arch.el (vc-arch-add-tagline): Do a slightly cleaner job.
4 (vc-arch-complete, vc-arch--version-completion-table)
5 (vc-arch-revision-completion-table): New functions to provide
6 completion of revision names.
7 (vc-arch-trim-find-least-useful-rev, vc-arch-trim-make-sentinel)
8 (vc-arch-trim-one-revlib, vc-arch-trim-revlib): New functions
9 to let the user trim the revlib.
10
3 * vc.el: Add new VC operation `revision-completion-table'. 11 * vc.el: Add new VC operation `revision-completion-table'.
4 (vc-default-revision-completion-table): New function. 12 (vc-default-revision-completion-table): New function.
5 (vc-version-diff, vc-version-other-window): Use it to provide 13 (vc-version-diff, vc-version-other-window): Use it to provide
diff --git a/lisp/vc-arch.el b/lisp/vc-arch.el
index ede8c57ec98..e4c13d3039a 100644
--- a/lisp/vc-arch.el
+++ b/lisp/vc-arch.el
@@ -83,7 +83,10 @@
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
@@ -419,6 +422,137 @@ Return non-nil if FILE is unchanged."
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)