magit-read-rev: add mechanism to mask uninteresting refs

This commit is contained in:
Hannu Koivisto 2010-09-23 22:33:26 +03:00 committed by Phil Jackson
parent adce2cbfc3
commit 50156dedc1

View file

@ -819,12 +819,14 @@ working directory state (or HEAD in a log buffer). If it's a
pair (START . END), then the range is START..END.")
(make-variable-buffer-local 'magit-current-range)
(defun magit-list-interesting-refs ()
(defun magit-list-interesting-refs (&optional uninteresting)
(let ((refs ()))
(dolist (line (magit-git-lines "show-ref"))
(if (string-match "[^ ]+ +\\(.*\\)" line)
(let ((ref (match-string 1 line)))
(cond ((string-match "refs/heads/\\(.*\\)" ref)
(cond ((loop for i in uninteresting
thereis (string-match i ref)))
((string-match "refs/heads/\\(.*\\)" ref)
(let ((branch (match-string 1 ref)))
(push (cons branch branch) refs)))
((string-match "refs/tags/\\(.*\\)" ref)
@ -844,13 +846,16 @@ pair (START . END), then the range is START..END.")
(match-string 2 ref)))
ref)
refs))))))
refs))
(nreverse refs)))
(defun magit-read-rev (prompt &optional def)
(let* ((prompt (if def
(format "%s (default %s): " prompt def)
(format "%s: " prompt)))
(interesting-refs (magit-list-interesting-refs))
(defvar magit-uninteresting-refs '("refs/remotes/\\([^/]+\\)/HEAD$"))
;; TODO: fix this so that def can (must?) be git rev instead of, say, "master (origin)"
;; which involves a particular display strategy and shouldn't be visible to callers
;; of magit-read-rev
(defun magit-read-rev (prompt &optional def uninteresting)
(let* ((interesting-refs (magit-list-interesting-refs
(or uninteresting magit-uninteresting-refs)))
(reply (magit-completing-read prompt interesting-refs nil nil nil
'magit-read-rev-history def))
(rev (or (cdr (assoc reply interesting-refs)) reply)))