comparison lisp/vc-git.el @ 82144:d334990fbd70

vc-git.el (vc-git-revision-table) (vc-git-revision-completion-table): New functions.
author Dan Nicolaescu <dann@ics.uci.edu>
date Thu, 26 Jul 2007 17:26:08 +0000
parents b9d2156e3f5d
children f04985ac29f2
comparison
equal deleted inserted replaced
82143:81c81019e0c6 82144:d334990fbd70
49 ;; BACKEND PROPERTIES 49 ;; BACKEND PROPERTIES
50 ;; * revision-granularity OK 50 ;; * revision-granularity OK
51 ;; STATE-QUERYING FUNCTIONS 51 ;; STATE-QUERYING FUNCTIONS
52 ;; * registered (file) OK 52 ;; * registered (file) OK
53 ;; * state (file) OK 53 ;; * state (file) OK
54 ;; - state-heuristic (file) ?? PROBABLY NOT NEEDED 54 ;; - state-heuristic (file) NOT NEEDED
55 ;; - dir-state (dir) OK 55 ;; - dir-state (dir) OK
56 ;; * workfile-version (file) OK 56 ;; * workfile-version (file) OK
57 ;; - latest-on-branch-p (file) ?? 57 ;; - latest-on-branch-p (file) NOT NEEDED
58 ;; * checkout-model (file) OK 58 ;; * checkout-model (file) OK
59 ;; - workfile-unchanged-p (file) OK 59 ;; - workfile-unchanged-p (file) OK
60 ;; - mode-line-string (file) NOT NEEDED 60 ;; - mode-line-string (file) NOT NEEDED
61 ;; - dired-state-info (file) OK 61 ;; - dired-state-info (file) OK
62 ;; STATE-CHANGING FUNCTIONS 62 ;; STATE-CHANGING FUNCTIONS
63 ;; * create-repo () OK 63 ;; * create-repo () OK
64 ;; * register (files &optional rev comment) OK 64 ;; * register (files &optional rev comment) OK
65 ;; - init-version (file) ?? 65 ;; - init-version (file) NOT NEEDED
66 ;; - responsible-p (file) OK 66 ;; - responsible-p (file) OK
67 ;; - could-register (file) NEEDED 67 ;; - could-register (file) NOT NEEDED, DEFAULT IS GOOD
68 ;; - receive-file (file rev) ?? 68 ;; - receive-file (file rev) NOT NEEDED
69 ;; - unregister (file) OK 69 ;; - unregister (file) OK
70 ;; * checkin (files rev comment) OK 70 ;; * checkin (files rev comment) OK
71 ;; * find-version (file rev buffer) OK 71 ;; * find-version (file rev buffer) OK
72 ;; * checkout (file &optional editable rev) OK 72 ;; * checkout (file &optional editable rev) OK
73 ;; * revert (file &optional contents-done) OK 73 ;; * revert (file &optional contents-done) OK
74 ;; - rollback (files) ?? PROBABLY NOT NEEDED 74 ;; - rollback (files) COULD BE SUPPORTED
75 ;; - merge (file rev1 rev2) It would be possible to merge changes into 75 ;; - merge (file rev1 rev2) It would be possible to merge changes into
76 ;; a single file, but when committing they 76 ;; a single file, but when committing they
77 ;; wouldn't be identified as a merge by git, 77 ;; wouldn't be identified as a merge by git,
78 ;; so it's probably not a good idea. 78 ;; so it's probably not a good idea.
79 ;; - merge-news (file) see `merge' 79 ;; - merge-news (file) see `merge'
80 ;; - steal-lock (file &optional version) NOT NEEDED 80 ;; - steal-lock (file &optional version) NOT NEEDED
81 ;; HISTORY FUNCTIONS 81 ;; HISTORY FUNCTIONS
82 ;; * print-log (files &optional buffer) OK 82 ;; * print-log (files &optional buffer) OK
83 ;; - log-view-mode () OK 83 ;; - log-view-mode () OK
84 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD 84 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD
85 ;; - wash-log (file) ?? 85 ;; - wash-log (file) COULD BE SUPPORTED
86 ;; - logentry-check () ?? 86 ;; - logentry-check () NOT NEEDED
87 ;; - comment-history (file) ?? 87 ;; - comment-history (file) ??
88 ;; - update-changelog (files) ?? 88 ;; - update-changelog (files) COULD BE SUPPORTED
89 ;; * diff (file &optional rev1 rev2 buffer) OK 89 ;; * diff (file &optional rev1 rev2 buffer) OK
90 ;; - revision-completion-table (file) NEEDED? 90 ;; - revision-completion-table (file) NEEDED?
91 ;; - diff-tree (dir &optional rev1 rev2) OK 91 ;; - diff-tree (dir &optional rev1 rev2) OK
92 ;; - annotate-command (file buf &optional rev) OK 92 ;; - annotate-command (file buf &optional rev) OK
93 ;; - annotate-time () OK 93 ;; - annotate-time () OK
94 ;; - annotate-current-time () ?? NOT NEEDED 94 ;; - annotate-current-time () NOT NEEDED
95 ;; - annotate-extract-revision-at-line () OK 95 ;; - annotate-extract-revision-at-line () OK
96 ;; SNAPSHOT SYSTEM 96 ;; SNAPSHOT SYSTEM
97 ;; - create-snapshot (dir name branchp) OK 97 ;; - create-snapshot (dir name branchp) OK
98 ;; - assign-name (file name) NOT NEEDED 98 ;; - assign-name (file name) NOT NEEDED
99 ;; - retrieve-snapshot (dir name update) OK, needs to update buffers 99 ;; - retrieve-snapshot (dir name update) OK, needs to update buffers
100 ;; MISCELLANEOUS 100 ;; MISCELLANEOUS
101 ;; - make-version-backups-p (file) ?? 101 ;; - make-version-backups-p (file) NOT NEEDED
102 ;; - repository-hostname (dirname) ?? 102 ;; - repository-hostname (dirname) NOT NEEDED
103 ;; - previous-version (file rev) OK 103 ;; - previous-version (file rev) OK
104 ;; - next-version (file rev) OK 104 ;; - next-version (file rev) OK
105 ;; - check-headers () ?? 105 ;; - check-headers () COULD BE SUPPORTED
106 ;; - clear-headers () ?? 106 ;; - clear-headers () NOT NEEDED
107 ;; - delete-file (file) OK 107 ;; - delete-file (file) OK
108 ;; - rename-file (old new) OK 108 ;; - rename-file (old new) OK
109 ;; - find-file-hook () PROBABLY NOT NEEDED 109 ;; - find-file-hook () NOT NEEDED
110 ;; - find-file-not-found-hook () PROBABLY NOT NEEDED 110 ;; - find-file-not-found-hook () NOT NEEDED
111 111
112 (eval-when-compile (require 'cl) (require 'vc)) 112 (eval-when-compile (require 'cl) (require 'vc))
113 113
114 (defvar git-commits-coding-system 'utf-8 114 (defvar git-commits-coding-system 'utf-8
115 "Default coding system for git commits.") 115 "Default coding system for git commits.")
144 (when dir (cd dir)) 144 (when dir (cd dir))
145 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))) 145 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
146 (let ((str (buffer-string))) 146 (let ((str (buffer-string)))
147 (and (> (length str) (length name)) 147 (and (> (length str) (length name))
148 (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))) 148 (string= (substring str 0 (1+ (length name))) (concat name "\0")))))))))
149 149
150 (defun vc-git-state (file) 150 (defun vc-git-state (file)
151 "Git-specific version of `vc-state'." 151 "Git-specific version of `vc-state'."
152 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) 152 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--")))
153 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff)) 153 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff))
154 'edited 154 'edited
198 ;; The reason this does not use the result of vc-git-state is that 198 ;; The reason this does not use the result of vc-git-state is that
199 ;; git-diff-index (used by vc-git-state) doesn't refresh the cached 199 ;; git-diff-index (used by vc-git-state) doesn't refresh the cached
200 ;; stat info, so if the file has been modified it will always show 200 ;; stat info, so if the file has been modified it will always show
201 ;; up as modified in vc-git-state, even if the change has been 201 ;; up as modified in vc-git-state, even if the change has been
202 ;; undone, until git-update-index --refresh is run. 202 ;; undone, until git-update-index --refresh is run.
203 203
204 ;; OTOH the vc-git-workfile-unchanged-p implementation checks the 204 ;; OTOH the vc-git-workfile-unchanged-p implementation checks the
205 ;; actual content, so it will detect the case of a file reverted 205 ;; actual content, so it will detect the case of a file reverted
206 ;; back to its original state. 206 ;; back to its original state.
207 207
208 ;; The ideal implementation would be to refresh the stat cache and 208 ;; The ideal implementation would be to refresh the stat cache and
234 234
235 (defalias 'vc-git-responsible-p 'vc-git-root) 235 (defalias 'vc-git-responsible-p 'vc-git-root)
236 236
237 (defun vc-git-unregister (file) 237 (defun vc-git-unregister (file)
238 (vc-git-command nil 0 file "rm" "-f" "--cached" "--")) 238 (vc-git-command nil 0 file "rm" "-f" "--cached" "--"))
239 239
240 240
241 (defun vc-git-checkin (files rev comment) 241 (defun vc-git-checkin (files rev comment)
242 (let ((coding-system-for-write git-commits-coding-system)) 242 (let ((coding-system-for-write git-commits-coding-system))
243 (vc-git-command nil 0 files "commit" "-m" comment "--only" "--"))) 243 (vc-git-command nil 0 files "commit" "-m" comment "--only" "--")))
244 244
245 (defun vc-git-find-version (file rev buffer) 245 (defun vc-git-find-version (file rev buffer)
246 (let ((coding-system-for-read 'binary) 246 (let ((coding-system-for-read 'binary)
247 (coding-system-for-write 'binary) 247 (coding-system-for-write 'binary)
248 (fullname (substring 248 (fullname (substring
249 (vc-git--run-command-string 249 (vc-git--run-command-string
250 file "ls-files" "-z" "--full-name" "--") 250 file "ls-files" "-z" "--full-name" "--")
251 0 -1))) 251 0 -1)))
252 (vc-git-command 252 (vc-git-command
253 buffer 0 253 buffer 0
254 (concat (if rev rev "HEAD") ":" fullname) "cat-file" "blob"))) 254 (concat (if rev rev "HEAD") ":" fullname) "cat-file" "blob")))
255 255
256 (defun vc-git-checkout (file &optional editable rev) 256 (defun vc-git-checkout (file &optional editable rev)
257 (vc-git-command nil 0 file "checkout" (or rev "HEAD"))) 257 (vc-git-command nil 0 file "checkout" (or rev "HEAD")))
258 258
281 ;; log. Maybe there is a way to do this with one command... 281 ;; log. Maybe there is a way to do this with one command...
282 (dolist (file files) 282 (dolist (file files)
283 (with-current-buffer 283 (with-current-buffer
284 buffer 284 buffer
285 (insert "File: " (file-name-nondirectory file) "\n")) 285 (insert "File: " (file-name-nondirectory file) "\n"))
286 (vc-git-command buffer 'async (file-relative-name file) 286 (vc-git-command buffer 'async (file-relative-name file)
287 "rev-list" "--pretty" "HEAD" "--"))))) 287 "rev-list" "--pretty" "HEAD" "--")))))
288 288
289 (defvar log-view-message-re) 289 (defvar log-view-message-re)
290 (defvar log-view-file-re) 290 (defvar log-view-file-re)
291 (defvar log-view-font-lock-keywords) 291 (defvar log-view-font-lock-keywords)
315 (defun vc-git-diff (files &optional rev1 rev2 buffer) 315 (defun vc-git-diff (files &optional rev1 rev2 buffer)
316 (let ((buf (or buffer "*vc-diff*"))) 316 (let ((buf (or buffer "*vc-diff*")))
317 (if (and rev1 rev2) 317 (if (and rev1 rev2)
318 (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p" rev1 rev2 "--") 318 (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p" rev1 rev2 "--")
319 (vc-git-command buf 1 files "diff-index" "--exit-code" "-p" (or rev1 "HEAD") "--")))) 319 (vc-git-command buf 1 files "diff-index" "--exit-code" "-p" (or rev1 "HEAD") "--"))))
320
321 (defun vc-git-revision-table (file)
322 (let ((table (list "HEAD")))
323 (with-temp-buffer
324 (vc-git-command t nil nil "for-each-ref" "--format=%(refname)")
325 (goto-char (point-min))
326 (while (re-search-forward "^refs/\\(heads\\|tags\\)/\\(.*\\)$" nil t)
327 (push (match-string 2) table)))
328 table))
329
330 (defun vc-git-revision-completion-table (file)
331 (lexical-let ((file file)
332 table)
333 (setq table (lazy-completion-table
334 table (lambda () (vc-git-revision-table file))))
335 table))
320 336
321 (defun vc-git-diff-tree (dir &optional rev1 rev2) 337 (defun vc-git-diff-tree (dir &optional rev1 rev2)
322 (vc-git-diff dir rev1 rev2)) 338 (vc-git-diff dir rev1 rev2))
323 339
324 (defun vc-git-annotate-command (file buf &optional rev) 340 (defun vc-git-annotate-command (file buf &optional rev)