From 8035692de90e463aa83576d68c6d008f77362fdc Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 28 Jun 2012 04:01:06 +0400 Subject: [PATCH 4/4] * vc-git.el (vc-git-state): Don't call `vc-git-registered', it's expensive. It's possible that file's status had changed to 'unregistered' since it was opened, but is checking this worth another process call? Note that if this is the case, `vc-next-action' won't add the file now. (vc-git-mode-line-string): Call `vc-working-revision' instead of `vc-git-working-revision' because it caches the result. --- lisp/vc/vc-git.el | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 63243cd..329a950 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -215,23 +215,25 @@ matching the resulting Git log output, and KEYWORDS is a list of ;; 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. Not 100% accurate, + ;; but close enough. + (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'." @@ -248,7 +250,7 @@ matching the resulting Git log output, and KEYWORDS is a list of (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-git-working-revision file)) + (let* ((branch (vc-working-revision file 'Git)) (def-ml (vc-default-mode-line-string 'Git file)) (help-echo (get-text-property 0 'help-echo def-ml))) (if (zerop (length branch)) -- 1.7.10.msysgit.1