diff options
| author | Dmitry Gutov <dgutov@yandex.ru> | 2013-05-28 03:11:21 +0400 |
|---|---|---|
| committer | Dmitry Gutov <dgutov@yandex.ru> | 2013-05-28 03:11:21 +0400 |
| commit | f1a60a0f07666582843f324767f740b75c071fb9 (patch) | |
| tree | 9f2a855a99ba9895ee7e6039ca6ecc52c659f56a /lisp/vc/vc-git.el | |
| parent | d289938a057ab8572fc60eb5367980eeef35d600 (diff) | |
| download | emacs-f1a60a0f07666582843f324767f740b75c071fb9.tar.gz | |
* 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
Diffstat (limited to 'lisp/vc/vc-git.el')
| -rw-r--r-- | lisp/vc/vc-git.el | 39 |
1 files changed, 21 insertions, 18 deletions
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'." |
