emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r112748: * lisp/vc/vc-git.el (vc-git-


From: Dmitry Gutov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112748: * lisp/vc/vc-git.el (vc-git-working-revision): When in detached mode,
Date: Tue, 28 May 2013 03:11:21 +0400
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112748
fixes bug: http://debbugs.gnu.org/14459
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Tue 2013-05-28 03:11:21 +0400
message:
  * 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.
modified:
  lisp/ChangeLog
  lisp/vc/vc-git.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-05-27 23:02:37 +0000
+++ b/lisp/ChangeLog    2013-05-27 23:11:21 +0000
@@ -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  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/easy-mmode.el (define-minor-mode):

=== modified file 'lisp/vc/vc-git.el'
--- a/lisp/vc/vc-git.el 2013-04-24 07:52:00 +0000
+++ b/lisp/vc/vc-git.el 2013-05-27 23:11:21 +0000
@@ -234,30 +234,30 @@
             (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 @@
                            (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'."


reply via email to

[Prev in Thread] Current Thread [Next in Thread]