comparison lisp/vc-git.el @ 78687:429a17d4958d

* vc-git.el (vc-git-state): Call git-add --refresh to update the state of the file. (vc-git-workfile-unchanged-p): Delegate implementation to vc-git-state. (vc-git-create-repo): Fixed invalid command.
author Dan Nicolaescu <dann@ics.uci.edu>
date Mon, 27 Aug 2007 18:59:41 +0000
parents 27f00e50116a
children 25e6b97b8f02
comparison
equal deleted inserted replaced
78686:569977930fab 78687:429a17d4958d
141 (and (> (length str) (length name)) 141 (and (> (length str) (length name))
142 (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))) 142 (string= (substring str 0 (1+ (length name))) (concat name "\0")))))))))
143 143
144 (defun vc-git-state (file) 144 (defun vc-git-state (file)
145 "Git-specific version of `vc-state'." 145 "Git-specific version of `vc-state'."
146 (call-process "git" nil nil nil "add" "--refresh" "--" (file-relative-name file))
146 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) 147 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--")))
147 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff)) 148 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff))
148 'edited 149 'edited
149 'up-to-date))) 150 'up-to-date)))
150 151
187 188
188 (defun vc-git-checkout-model (file) 189 (defun vc-git-checkout-model (file)
189 'implicit) 190 'implicit)
190 191
191 (defun vc-git-workfile-unchanged-p (file) 192 (defun vc-git-workfile-unchanged-p (file)
192 ;; The reason this does not use the result of vc-git-state is that 193 (eq 'up-to-date (vc-git-state file)))
193 ;; git-diff-index (used by vc-git-state) doesn't refresh the cached
194 ;; stat info, so if the file has been modified it will always show
195 ;; up as modified in vc-git-state, even if the change has been
196 ;; undone, until git-update-index --refresh is run.
197
198 ;; OTOH the vc-git-workfile-unchanged-p implementation checks the
199 ;; actual content, so it will detect the case of a file reverted
200 ;; back to its original state.
201
202 ;; The ideal implementation would be to refresh the stat cache and
203 ;; then call vc-git-state, but at the moment there's no git command
204 ;; to refresh a single file, so this will have to be added first.
205 (let ((sha1 (vc-git--run-command-string file "hash-object" "--"))
206 (head (vc-git--run-command-string file "ls-tree" "-z" "HEAD" "--")))
207 (and head
208 (string-match "[0-7]\\{6\\} blob \\([0-9a-f]\\{40\\}\\)\t[^\0]+\0" head)
209 (string= (car (split-string sha1 "\n")) (match-string 1 head)))))
210 194
211 (defun vc-git-dired-state-info (file) 195 (defun vc-git-dired-state-info (file)
212 "Git-specific version of `vc-dired-state-info'." 196 "Git-specific version of `vc-dired-state-info'."
213 (let ((git-state (vc-state file))) 197 (let ((git-state (vc-state file)))
214 (if (eq git-state 'edited) 198 (if (eq git-state 'edited)
218 202
219 ;;; STATE-CHANGING FUNCTIONS 203 ;;; STATE-CHANGING FUNCTIONS
220 204
221 (defun vc-git-create-repo () 205 (defun vc-git-create-repo ()
222 "Create a new Git repository." 206 "Create a new Git repository."
223 (vc-git-command "init" nil 0 nil)) 207 (vc-git-command nil 0 nil "init"))
224 208
225 (defun vc-git-register (files &optional rev comment) 209 (defun vc-git-register (files &optional rev comment)
226 "Register FILE into the git version-control system." 210 "Register FILE into the git version-control system."
227 (vc-git-command nil 0 files "update-index" "--add" "--")) 211 (vc-git-command nil 0 files "update-index" "--add" "--"))
228 212