From: Dmitry Gutov Date: Mon, 27 May 2013 23:11:21 +0000 (+0400) Subject: * lisp/vc/vc-git.el (vc-git-working-revision): When in detached mode, X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~165 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f1a60a0f07666582843f324767f740b75c071fb9;p=emacs.git * lisp/vc/vc-git.el (vc-git-working-revision): When in detached mode, return the commit hash. Also set the `vc-git-detached' property. (vc-git--rev-parse): Extract from `vc-git-previous-revision'. (vc-git-mode-line-string): Use the same help-echo format whether in detached mode or not, because we know the actual revision now. When in detached mode, shorten the revision to 7 chars. Fixes: debbugs:14459 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cc3122f7e6f..ecdeb49f254 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -44,6 +44,16 @@ locally instead of changing `isearch-filter-predicate'. (wdired-isearch-filter-read-only): Don't use `isearch-filter-visible'. +2013-05-27 Dmitry Gutov + + * vc/vc-git.el (vc-git-working-revision): When in detached mode, + return the commit hash (Bug#14459). Also set the + `vc-git-detached' property. + (vc-git--rev-parse): Extract from `vc-git-previous-revision'. + (vc-git-mode-line-string): Use the same help-echo format whether + in detached mode or not, because we know the actual revision now. + When in detached mode, shorten the revision to 7 chars. + 2013-05-27 Stefan Monnier * emacs-lisp/easy-mmode.el (define-minor-mode): diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 06474cb4604..caece2ec277 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -234,30 +234,30 @@ matching the resulting Git log output, and KEYWORDS is a list of (vc-git--state-code diff-letter))) (if (vc-git--empty-db-p) 'added 'up-to-date)))) -(defun vc-git-working-revision (_file) +(defun vc-git-working-revision (file) "Git-specific version of `vc-working-revision'." (let* (process-file-side-effects - (str (with-output-to-string - (with-current-buffer standard-output - (vc-git--out-ok "symbolic-ref" "HEAD"))))) - (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) - (match-string 2 str) - str))) + (str (vc-git--run-command-string nil "symbolic-ref" "HEAD"))) + (vc-file-setprop file 'vc-git-detached (null str)) + (if str + (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) + (match-string 2 str) + str) + (vc-git--rev-parse "HEAD")))) (defun vc-git-workfile-unchanged-p (file) (eq 'up-to-date (vc-git-state file))) (defun vc-git-mode-line-string (file) "Return a string for `vc-mode-line' to put in the mode line for FILE." - (let* ((branch (vc-working-revision file)) + (let* ((rev (vc-working-revision file)) + (detached (vc-file-getprop file 'vc-git-detached)) (def-ml (vc-default-mode-line-string 'Git file)) (help-echo (get-text-property 0 'help-echo def-ml))) - (if (zerop (length branch)) - (propertize - (concat def-ml "!") - 'help-echo (concat help-echo "\nNo current branch (detached HEAD)")) - (propertize def-ml - 'help-echo (concat help-echo "\nCurrent branch: " branch))))) + (propertize (if detached + (substring def-ml 0 (- 7 (length rev))) + def-ml) + 'help-echo (concat help-echo "\nCurrent revision: " rev)))) (cl-defstruct (vc-git-extra-fileinfo (:copier nil) @@ -943,10 +943,13 @@ or BRANCH^ (where \"^\" can be repeated)." (point) (1- (point-max))))))) (or (vc-git-symbolic-commit prev-rev) prev-rev)) - (with-temp-buffer - (and - (vc-git--out-ok "rev-parse" (concat rev "^")) - (buffer-substring-no-properties (point-min) (+ (point-min) 40)))))) + (vc-git--rev-parse (concat rev "^")))) + +(defun vc-git--rev-parse (rev) + (with-temp-buffer + (and + (vc-git--out-ok "rev-parse" rev) + (buffer-substring-no-properties (point-min) (+ (point-min) 40))))) (defun vc-git-next-revision (file rev) "Git-specific version of `vc-next-revision'."