diff options
| author | Dmitry Gutov | 2015-09-01 15:02:52 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2015-09-01 15:03:30 +0300 |
| commit | 21d6414a4b0f37b2381859eeebf66908b6568c31 (patch) | |
| tree | 32a95543a0bc30caa98b7b94643f7393e223cc71 | |
| parent | 3e0e2339cd379eeba8d9bc758f2e8e574144e252 (diff) | |
| download | emacs-21d6414a4b0f37b2381859eeebf66908b6568c31.tar.gz emacs-21d6414a4b0f37b2381859eeebf66908b6568c31.zip | |
Make vc-git-working-revision always return the commit hash
* lisp/vc/vc-git.el (vc-git-working-revision):
Return the commit hash (bug#21383).
(vc-git--symbolic-ref): New function, extracted from above.
(vc-git-mode-line-string): Use it.
| -rw-r--r-- | lisp/vc/vc-git.el | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 9522328cae8..50c6d96e911 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el | |||
| @@ -248,26 +248,30 @@ matching the resulting Git log output, and KEYWORDS is a list of | |||
| 248 | (vc-git--state-code diff-letter))) | 248 | (vc-git--state-code diff-letter))) |
| 249 | (if (vc-git--empty-db-p) 'added 'up-to-date)))) | 249 | (if (vc-git--empty-db-p) 'added 'up-to-date)))) |
| 250 | 250 | ||
| 251 | (defun vc-git-working-revision (file) | 251 | (defun vc-git-working-revision (_file) |
| 252 | "Git-specific version of `vc-working-revision'." | 252 | "Git-specific version of `vc-working-revision'." |
| 253 | (let* (process-file-side-effects | 253 | (let (process-file-side-effects) |
| 254 | (str (vc-git--run-command-string nil "symbolic-ref" "HEAD"))) | 254 | (vc-git--rev-parse "HEAD"))) |
| 255 | (vc-file-setprop file 'vc-git-detached (null str)) | 255 | |
| 256 | (if str | 256 | (defun vc-git--symbolic-ref (file) |
| 257 | (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) | 257 | (or |
| 258 | (match-string 2 str) | 258 | (vc-file-getprop file 'vc-git-symbolic-ref) |
| 259 | str) | 259 | (let* (process-file-side-effects |
| 260 | (vc-git--rev-parse "HEAD")))) | 260 | (str (vc-git--run-command-string nil "symbolic-ref" "HEAD"))) |
| 261 | (vc-file-setprop file 'vc-git-symbolic-ref | ||
| 262 | (if str | ||
| 263 | (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) | ||
| 264 | (match-string 2 str) | ||
| 265 | str)))))) | ||
| 261 | 266 | ||
| 262 | (defun vc-git-mode-line-string (file) | 267 | (defun vc-git-mode-line-string (file) |
| 263 | "Return a string for `vc-mode-line' to put in the mode line for FILE." | 268 | "Return a string for `vc-mode-line' to put in the mode line for FILE." |
| 264 | (let* ((rev (vc-working-revision file)) | 269 | (let* ((rev (vc-working-revision file)) |
| 265 | (detached (vc-file-getprop file 'vc-git-detached)) | 270 | (disp-rev (or (vc-git--symbolic-ref file) |
| 271 | (substring rev 0 7))) | ||
| 266 | (def-ml (vc-default-mode-line-string 'Git file)) | 272 | (def-ml (vc-default-mode-line-string 'Git file)) |
| 267 | (help-echo (get-text-property 0 'help-echo def-ml))) | 273 | (help-echo (get-text-property 0 'help-echo def-ml))) |
| 268 | (propertize (if detached | 274 | (propertize (replace-regexp-in-string (concat rev "\\'") disp-rev def-ml t t) |
| 269 | (substring def-ml 0 (- 7 (length rev))) | ||
| 270 | def-ml) | ||
| 271 | 'help-echo (concat help-echo "\nCurrent revision: " rev)))) | 275 | 'help-echo (concat help-echo "\nCurrent revision: " rev)))) |
| 272 | 276 | ||
| 273 | (cl-defstruct (vc-git-extra-fileinfo | 277 | (cl-defstruct (vc-git-extra-fileinfo |