emacs-diffs
[Top][All Lists]
Advanced

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

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


From: Michael Albinus
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109147: * vc/vc-git.el (vc-git-state): Don't call `vc-git-registered',
Date: Wed, 18 Jul 2012 17:04:36 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109147
author: Dmitry Gutov <address@hidden>
committer: Michael Albinus <address@hidden>
branch nick: trunk
timestamp: Wed 2012-07-18 17:04:36 +0200
message:
  * vc/vc-git.el (vc-git-state): Don't call `vc-git-registered',
  assume it's always t.
  (vc-git-registered): Remove caching, the function is only called
  once.
  (vc-git-branches): Use `vc-git--call' instead of `call-process'.
modified:
  lisp/ChangeLog
  lisp/vc/vc-git.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-07-18 14:46:32 +0000
+++ b/lisp/ChangeLog    2012-07-18 15:04:36 +0000
@@ -1,3 +1,11 @@
+2012-07-18  Dmitry Gutov  <address@hidden>
+
+       * vc/vc-git.el (vc-git-state): Don't call `vc-git-registered',
+       assume it's always t.
+       (vc-git-registered): Remove caching, the function is only called
+       once.
+       (vc-git-branches): Use `vc-git--call' instead of `call-process'.
+
 2012-07-18  Chong Yidong  <address@hidden>
 
        * subr.el (last-input-char, last-command-char): Remove (Bug#9195).

=== modified file 'lisp/vc/vc-git.el'
--- a/lisp/vc/vc-git.el 2012-07-11 23:13:41 +0000
+++ b/lisp/vc/vc-git.el 2012-07-18 15:04:36 +0000
@@ -173,31 +173,28 @@
 
 (defun vc-git-registered (file)
   "Check whether FILE is registered with git."
-  (or (vc-file-getprop file 'git-registered)
-      (vc-file-setprop
-       file 'git-registered
-       (let ((dir (vc-git-root file)))
-        (when dir
-          (with-temp-buffer
-            (let* (process-file-side-effects
-                   ;; Do not use the `file-name-directory' here: git-ls-files
-                   ;; sometimes fails to return the correct status for relative
-                   ;; path specs.
-                   ;; See also: http://marc.info/?l=git&m=125787684318129&w=2
-                   (name (file-relative-name file dir))
-                   (str (ignore-errors
-                          (cd dir)
-                          (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
-                          ;; If result is empty, use ls-tree to check for 
deleted
-                          ;; file.
-                          (when (eq (point-min) (point-max))
-                            (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD"
-                                            "--" name))
-                          (buffer-string))))
-              (and str
-                   (> (length str) (length name))
-                   (string= (substring str 0 (1+ (length name)))
-                            (concat name "\0"))))))))))
+  (let ((dir (vc-git-root file)))
+    (when dir
+      (with-temp-buffer
+        (let* (process-file-side-effects
+               ;; Do not use the `file-name-directory' here: git-ls-files
+               ;; sometimes fails to return the correct status for relative
+               ;; path specs.
+               ;; See also: http://marc.info/?l=git&m=125787684318129&w=2
+               (name (file-relative-name file dir))
+               (str (ignore-errors
+                      (cd dir)
+                      (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
+                      ;; If result is empty, use ls-tree to check for deleted
+                      ;; file.
+                      (when (eq (point-min) (point-max))
+                        (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD"
+                                        "--" name))
+                      (buffer-string))))
+          (and str
+               (> (length str) (length name))
+               (string= (substring str 0 (1+ (length name)))
+                        (concat name "\0"))))))))
 
 (defun vc-git--state-code (code)
   "Convert from a string to a added/deleted/modified state."
@@ -218,23 +215,24 @@
   ;; is direct ancestor of corresponding upstream branch, and the file
   ;; was modified upstream.  But we can't check that without a network
   ;; operation.
-  (if (not (vc-git-registered file))
-      'unregistered
-    (let ((diff (vc-git--run-command-string
-                 file "diff-index" "-p" "--raw" "-z" "HEAD" "--")))
-      (if (and diff
-              (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} 
[0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?"
-                            diff))
-          (let ((diff-letter (match-string 1 diff)))
-            (if (not (match-beginning 2))
-                ;; Empty diff: file contents is the same as the HEAD
-                ;; revision, but timestamps are different (eg, file
-                ;; was "touch"ed).  Update timestamp in index:
-                (prog1 'up-to-date
-                  (vc-git--call nil "add" "--refresh" "--"
-                                (file-relative-name file)))
-              (vc-git--state-code diff-letter)))
-       (if (vc-git--empty-db-p) 'added 'up-to-date)))))
+  ;; This assumes that status is known to be not `unregistered' because
+  ;; we've been successfully dispatched here from `vc-state', that
+  ;; means `vc-git-registered' returned t earlier once.  Bug#11757
+  (let ((diff (vc-git--run-command-string
+               file "diff-index" "-p" "--raw" "-z" "HEAD" "--")))
+    (if (and diff
+             (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} 
[0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?"
+                           diff))
+        (let ((diff-letter (match-string 1 diff)))
+          (if (not (match-beginning 2))
+              ;; Empty diff: file contents is the same as the HEAD
+              ;; revision, but timestamps are different (eg, file
+              ;; was "touch"ed).  Update timestamp in index:
+              (prog1 'up-to-date
+                (vc-git--call nil "add" "--refresh" "--"
+                              (file-relative-name file)))
+            (vc-git--state-code diff-letter)))
+      (if (vc-git--empty-db-p) 'added 'up-to-date))))
 
 (defun vc-git-working-revision (_file)
   "Git-specific version of `vc-working-revision'."
@@ -576,7 +574,7 @@
   "Return the existing branches, as a list of strings.
 The car of the list is the current branch."
   (with-temp-buffer
-    (call-process vc-git-program nil t nil "branch")
+    (vc-git--call t "branch")
     (goto-char (point-min))
     (let (current-branch branches)
       (while (not (eobp))


reply via email to

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