comparison lisp/vc-git.el @ 106331:1c9648ddfd5e

(vc-git-registered): Call vc-git-root only once.
author Dan Nicolaescu <dann@ics.uci.edu>
date Mon, 30 Nov 2009 21:21:35 +0000
parents a88a54e96796
children 8272f561b710
comparison
equal deleted inserted replaced
106330:e72085f5ccf5 106331:1c9648ddfd5e
142 ;;;###autoload (load "vc-git") 142 ;;;###autoload (load "vc-git")
143 ;;;###autoload (vc-git-registered file)))) 143 ;;;###autoload (vc-git-registered file))))
144 144
145 (defun vc-git-registered (file) 145 (defun vc-git-registered (file)
146 "Check whether FILE is registered with git." 146 "Check whether FILE is registered with git."
147 (when (vc-git-root file) 147 (let ((dir (vc-git-root file)))
148 (with-temp-buffer 148 (when dir
149 (let* (process-file-side-effects 149 (with-temp-buffer
150 ;; do not use the `file-name-directory' here: git-ls-files 150 (let* (process-file-side-effects
151 ;; sometimes fails to return the correct status for relative 151 ;; Do not use the `file-name-directory' here: git-ls-files
152 ;; path specs. 152 ;; sometimes fails to return the correct status for relative
153 ;; see also: http://marc.info/?l=git&m=125787684318129&w=2 153 ;; path specs.
154 (dir (vc-git-root file)) 154 ;; See also: http://marc.info/?l=git&m=125787684318129&w=2
155 (name (file-relative-name file dir)) 155 (name (file-relative-name file dir))
156 (str (ignore-errors 156 (str (ignore-errors
157 (when dir (cd dir)) 157 (cd dir)
158 (vc-git--out-ok "ls-files" "-c" "-z" "--" name) 158 (vc-git--out-ok "ls-files" "-c" "-z" "--" name)
159 ;; if result is empty, use ls-tree to check for deleted file 159 ;; if result is empty, use ls-tree to check for deleted file
160 (when (eq (point-min) (point-max)) 160 (when (eq (point-min) (point-max))
161 (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" "--" name)) 161 (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" "--" name))
162 (buffer-string)))) 162 (buffer-string))))
163 (and str 163 (and str
164 (> (length str) (length name)) 164 (> (length str) (length name))
165 (string= (substring str 0 (1+ (length name))) 165 (string= (substring str 0 (1+ (length name)))
166 (concat name "\0"))))))) 166 (concat name "\0"))))))))
167 167
168 (defun vc-git--state-code (code) 168 (defun vc-git--state-code (code)
169 "Convert from a string to a added/deleted/modified state." 169 "Convert from a string to a added/deleted/modified state."
170 (case (string-to-char code) 170 (case (string-to-char code)
171 (?M 'edited) 171 (?M 'edited)