Mercurial > emacs
comparison lisp/vc-git.el @ 93146:c73e70274c0c
(vc-git--empty-db-p)
(vc-git-after-dir-status-stage1-empty-db): New functions.
(vc-git-dir-status, vc-git-after-dir-status-stage1, vc-git-state):
Add support for empty repositories.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sat, 22 Mar 2008 17:33:52 +0000 |
parents | 9a34bf3a4363 |
children | 019e6794fecf |
comparison
equal
deleted
inserted
replaced
93145:9a34bf3a4363 | 93146:c73e70274c0c |
---|---|
147 (vc-git--call nil "add" "--refresh" "--" (file-relative-name file)) | 147 (vc-git--call nil "add" "--refresh" "--" (file-relative-name file)) |
148 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) | 148 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) |
149 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMU]\\)\0[^\0]+\0" | 149 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMU]\\)\0[^\0]+\0" |
150 diff)) | 150 diff)) |
151 (if (string= (match-string 1 diff) "A") 'added 'edited) | 151 (if (string= (match-string 1 diff) "A") 'added 'edited) |
152 'up-to-date))) | 152 (if (vc-git--empty-db-p) 'added 'up-to-date)))) |
153 | 153 |
154 (defun vc-git--ls-files-state (state &rest args) | 154 (defun vc-git--ls-files-state (state &rest args) |
155 "Set state to STATE on all files found with git-ls-files ARGS." | 155 "Set state to STATE on all files found with git-ls-files ARGS." |
156 (with-temp-buffer | 156 (with-temp-buffer |
157 (apply 'vc-git-command (current-buffer) nil nil "ls-files" "-z" args) | 157 (apply 'vc-git-command (current-buffer) nil nil "ls-files" "-z" args) |
227 (vc-git-command (current-buffer) 'async nil "ls-files" "-z" "-o" | 227 (vc-git-command (current-buffer) 'async nil "ls-files" "-z" "-o" |
228 "--directory" "--no-empty-directory" "--exclude-standard") | 228 "--directory" "--no-empty-directory" "--exclude-standard") |
229 (vc-exec-after | 229 (vc-exec-after |
230 `(vc-git-after-dir-status-stage2 (quote ,update-function) ,status-buffer))) | 230 `(vc-git-after-dir-status-stage2 (quote ,update-function) ,status-buffer))) |
231 | 231 |
232 (defun vc-git-after-dir-status-stage1-empty-db (update-function status-buffer) | |
233 (goto-char (point-min)) | |
234 (while (re-search-forward "\\([^\0]*?\\)\0" nil t 1) | |
235 (push (cons (match-string 1) 'added) vc-git-status-result)) | |
236 (erase-buffer) | |
237 (vc-git-command (current-buffer) 'async nil "ls-files" "-z" "-o" | |
238 "--directory" "--no-empty-directory" "--exclude-standard") | |
239 (vc-exec-after | |
240 `(vc-git-after-dir-status-stage2 (quote ,update-function) ,status-buffer))) | |
241 | |
232 (defun vc-git-dir-status (dir update-function status-buffer) | 242 (defun vc-git-dir-status (dir update-function status-buffer) |
233 "Return a list of conses (file . state) for DIR." | 243 "Return a list of conses (file . state) for DIR." |
234 ;; Further things that would have to be fixed later: | 244 ;; Further things that would have to be fixed later: |
235 ;; - support for an empty repository (with no initial commit) | |
236 ;; - how to handle unregistered directories | 245 ;; - how to handle unregistered directories |
237 ;; - how to support vc-status on a subdir of the project tree | 246 ;; - how to support vc-status on a subdir of the project tree |
238 (with-current-buffer | 247 (with-current-buffer |
239 (get-buffer-create | 248 (get-buffer-create |
240 (expand-file-name " *VC-Git* tmp status" dir)) | 249 (expand-file-name " *VC-Git* tmp status" dir)) |
241 (set (make-local-variable 'vc-git-status-result) nil) | 250 (set (make-local-variable 'vc-git-status-result) nil) |
242 (cd dir) | 251 (cd dir) |
243 (erase-buffer) | 252 (erase-buffer) |
244 (vc-git-command (current-buffer) 'async nil "diff-index" "-z" "HEAD") | 253 (if (vc-git--empty-db-p) |
245 (vc-exec-after | 254 (progn |
246 `(vc-git-after-dir-status-stage1 (quote ,update-function) ,status-buffer)) | 255 (vc-git-command (current-buffer) 'async nil "ls-files" "-z" "-c") |
256 (vc-exec-after | |
257 `(vc-git-after-dir-status-stage1-empty-db (quote ,update-function) ,status-buffer))) | |
258 (vc-git-command (current-buffer) 'async nil "diff-index" "-z" "HEAD") | |
259 (vc-exec-after | |
260 `(vc-git-after-dir-status-stage1 (quote ,update-function) ,status-buffer))) | |
247 (current-buffer))) | 261 (current-buffer))) |
248 | 262 |
249 ;;; STATE-CHANGING FUNCTIONS | 263 ;;; STATE-CHANGING FUNCTIONS |
250 | 264 |
251 (defun vc-git-create-repo () | 265 (defun vc-git-create-repo () |
480 (defun vc-git-command (buffer okstatus file-or-list &rest flags) | 494 (defun vc-git-command (buffer okstatus file-or-list &rest flags) |
481 "A wrapper around `vc-do-command' for use in vc-git.el. | 495 "A wrapper around `vc-do-command' for use in vc-git.el. |
482 The difference to vc-do-command is that this function always invokes `git'." | 496 The difference to vc-do-command is that this function always invokes `git'." |
483 (apply 'vc-do-command buffer okstatus "git" file-or-list flags)) | 497 (apply 'vc-do-command buffer okstatus "git" file-or-list flags)) |
484 | 498 |
499 (defun vc-git--empty-db-p () | |
500 "Check if the git db is empty (no commit done yet)." | |
501 (not (eq 0 (vc-git--call nil "rev-parse" "--verify" "HEAD")))) | |
502 | |
485 (defun vc-git--call (buffer command &rest args) | 503 (defun vc-git--call (buffer command &rest args) |
486 ;; We don't need to care the arguments. If there is a file name, it | 504 ;; We don't need to care the arguments. If there is a file name, it |
487 ;; is always a relative one. This works also for remote | 505 ;; is always a relative one. This works also for remote |
488 ;; directories. | 506 ;; directories. |
489 (apply 'process-file "git" nil buffer nil command args)) | 507 (apply 'process-file "git" nil buffer nil command args)) |