comparison lisp/vc-bzr.el @ 92980:ba464718dbd7

(vc-bzr-diff): Use a faster invocation when possible. (vc-bzr-complete-with-prefix, vc-bzr-revision-completion-table): New functions.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 15 Mar 2008 19:37:17 +0000
parents 89f7b102ea85
children 5f4eb3149e6d
comparison
equal deleted inserted replaced
92979:7967dd572109 92980:ba464718dbd7
426 (beginning-of-line 0) 426 (beginning-of-line 0)
427 (goto-char (point-min))))) 427 (goto-char (point-min)))))
428 428
429 (defun vc-bzr-diff (files &optional rev1 rev2 buffer) 429 (defun vc-bzr-diff (files &optional rev1 rev2 buffer)
430 "VC bzr backend for diff." 430 "VC bzr backend for diff."
431 ;; `bzr diff' exits with code 1 if diff is non-empty 431 ;; `bzr diff' exits with code 1 if diff is non-empty.
432 (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files 432 (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files
433 "--diff-options" (mapconcat 'identity 433 "--diff-options" (mapconcat 'identity
434 (vc-diff-switches-list bzr) 434 (vc-diff-switches-list bzr)
435 " ") 435 " ")
436 (list "-r" (format "%s..%s" 436 ;; This `when' is just an optimization because bzr-1.2 is *much*
437 (or rev1 "revno:-1") 437 ;; faster when the revision argument is not given.
438 (or rev2 ""))))) 438 (when (or rev1 rev2)
439 (list "-r" (format "%s..%s"
440 (or rev1 "revno:-1")
441 (or rev2 ""))))))
439 442
440 443
441 ;; FIXME: vc-{next,previous}-revision need fixing in vc.el to deal with 444 ;; FIXME: vc-{next,previous}-revision need fixing in vc.el to deal with
442 ;; straight integer revisions. 445 ;; straight integer revisions.
443 446
603 (concat "(" (symbol-name (or (vc-file-getprop file 'vc-bzr-state) 606 (concat "(" (symbol-name (or (vc-file-getprop file 'vc-bzr-state)
604 'edited)) ")") 607 'edited)) ")")
605 ;; else fall back to default vc.el representation 608 ;; else fall back to default vc.el representation
606 (vc-default-dired-state-info 'Bzr file))) 609 (vc-default-dired-state-info 'Bzr file)))
607 610
611 ;;; Revision completion
612
613 (defun vc-bzr-complete-with-prefix (prefix action table string pred)
614 (let ((comp (complete-with-action action table string pred)))
615 (if (stringp comp)
616 (concat prefix comp)
617 comp)))
618
619 (defun vc-bzr-revision-completion-table (files)
620 (lexical-let ((files files))
621 ;; What about using `files'?!? --Stef
622 (lambda (string pred action)
623 (cond
624 ((string-match "\\`\\(ancestor\\|branch\\|\\(revno:\\)?[-0-9]+:\\):"
625 string)
626 (vc-bzr-complete-with-prefix (substring string 0 (match-end 0))
627 action
628 'read-file-name-internal
629 (substring string (match-end 0))
630 ;; Dropping `pred'. Maybe we should just
631 ;; stash it in `read-file-name-predicate'?
632 nil))
633 ((string-match "\\`\\(before\\):" string)
634 (vc-bzr-complete-with-prefix (substring string 0 (match-end 0))
635 action
636 (vc-bzr-revision-completion-table files)
637 (substring string (match-end 0))
638 pred))
639 ((string-match "\\`\\(tag\\):" string)
640 (let ((prefix (substring string 0 (match-end 0)))
641 (tag (substring string (match-end 0)))
642 (table nil))
643 (with-temp-buffer
644 ;; "bzr-1.2 tags" is much faster with --show-ids.
645 (call-process vc-bzr-program nil '(t) nil "tags" "--show-ids")
646 ;; The output is ambiguous, unless we assume that revids do not
647 ;; contain spaces.
648 (goto-char (point-min))
649 (while (re-search-forward "^\\(.*[^ \n]\\) +[^ \n]*$" nil t)
650 (push (match-string-no-properties 1) table)))
651 (vc-bzr-complete-with-prefix prefix action table tag pred)))
652
653 ((string-match "\\`\\(revid\\):" string)
654 ;; FIXME: How can I get a list of revision ids?
655 )
656 (t
657 (complete-with-action action '("revno:" "revid:" "last:" "before:"
658 "tag:" "date:" "ancestor:" "branch:"
659 "submit:")
660 string pred))))))
661
608 (eval-after-load "vc" 662 (eval-after-load "vc"
609 '(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t)) 663 '(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t))
610 664
611 (provide 'vc-bzr) 665 (provide 'vc-bzr)
612 ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06 666 ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06