Mercurial > emacs
annotate lisp/vc-git.el @ 85396:9ed1cbc73fd9
Regenerate.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 18 Oct 2007 04:46:28 +0000 |
parents | b16f7408cd3f |
children | dec6fdd5ddf4 |
rev | line source |
---|---|
78355 | 1 ;;; vc-git.el --- VC backend for the git version control system |
2 | |
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Alexandre Julliard <julliard@winehq.org> | |
6 ;; Keywords: tools | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 3, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 ;; Boston, MA 02110-1301, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This file contains a VC backend for the git version control | |
28 ;; system. | |
29 ;; | |
30 | |
31 ;;; Installation: | |
32 | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78359
diff
changeset
|
33 ;; To install: put this file on the load-path and add Git to the list |
78355 | 34 ;; of supported backends in `vc-handled-backends'; the following line, |
35 ;; placed in your ~/.emacs, will accomplish this: | |
36 ;; | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78359
diff
changeset
|
37 ;; (add-to-list 'vc-handled-backends 'Git) |
78355 | 38 |
39 ;;; Todo: | |
40 ;; - check if more functions could use vc-git-command instead | |
41 ;; of start-process. | |
42 ;; - changelog generation | |
43 | |
44 ;; Implement the rest of the vc interface. See the comment at the | |
45 ;; beginning of vc.el. The current status is: | |
46 ;; ("??" means: "figure out what to do about it") | |
47 ;; | |
48 ;; FUNCTION NAME STATUS | |
49 ;; BACKEND PROPERTIES | |
50 ;; * revision-granularity OK | |
51 ;; STATE-QUERYING FUNCTIONS | |
52 ;; * registered (file) OK | |
53 ;; * state (file) OK | |
54 ;; - state-heuristic (file) NOT NEEDED | |
55 ;; - dir-state (dir) OK | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
56 ;; * working-revision (file) OK |
78355 | 57 ;; - latest-on-branch-p (file) NOT NEEDED |
58 ;; * checkout-model (file) OK | |
59 ;; - workfile-unchanged-p (file) OK | |
82843
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
60 ;; - mode-line-string (file) OK |
78355 | 61 ;; - dired-state-info (file) OK |
62 ;; STATE-CHANGING FUNCTIONS | |
63 ;; * create-repo () OK | |
64 ;; * register (files &optional rev comment) OK | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
65 ;; - init-revision (file) NOT NEEDED |
78355 | 66 ;; - responsible-p (file) OK |
67 ;; - could-register (file) NOT NEEDED, DEFAULT IS GOOD | |
68 ;; - receive-file (file rev) NOT NEEDED | |
69 ;; - unregister (file) OK | |
70 ;; * checkin (files rev comment) OK | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
71 ;; * find-revision (file rev buffer) OK |
78355 | 72 ;; * checkout (file &optional editable rev) OK |
73 ;; * revert (file &optional contents-done) OK | |
74 ;; - rollback (files) COULD BE SUPPORTED | |
75 ;; - merge (file rev1 rev2) It would be possible to merge changes into | |
76 ;; a single file, but when committing they | |
77 ;; wouldn't be identified as a merge by git, | |
78 ;; so it's probably not a good idea. | |
79 ;; - merge-news (file) see `merge' | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
80 ;; - steal-lock (file &optional revision) NOT NEEDED |
78355 | 81 ;; HISTORY FUNCTIONS |
82 ;; * print-log (files &optional buffer) OK | |
83 ;; - log-view-mode () OK | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
84 ;; - show-log-entry (revision) NOT NEEDED, DEFAULT IS GOOD |
78355 | 85 ;; - wash-log (file) COULD BE SUPPORTED |
86 ;; - logentry-check () NOT NEEDED | |
87 ;; - comment-history (file) ?? | |
88 ;; - update-changelog (files) COULD BE SUPPORTED | |
89 ;; * diff (file &optional rev1 rev2 buffer) OK | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
90 ;; - revision-completion-table (file) NEEDED? |
78355 | 91 ;; - diff-tree (dir &optional rev1 rev2) OK |
92 ;; - annotate-command (file buf &optional rev) OK | |
93 ;; - annotate-time () OK | |
94 ;; - annotate-current-time () NOT NEEDED | |
95 ;; - annotate-extract-revision-at-line () OK | |
96 ;; SNAPSHOT SYSTEM | |
97 ;; - create-snapshot (dir name branchp) OK | |
98 ;; - assign-name (file name) NOT NEEDED | |
99 ;; - retrieve-snapshot (dir name update) OK, needs to update buffers | |
100 ;; MISCELLANEOUS | |
101 ;; - make-version-backups-p (file) NOT NEEDED | |
102 ;; - repository-hostname (dirname) NOT NEEDED | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
103 ;; - previous-revision (file rev) OK |
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
104 ;; - next-revision (file rev) OK |
78355 | 105 ;; - check-headers () COULD BE SUPPORTED |
106 ;; - clear-headers () NOT NEEDED | |
107 ;; - delete-file (file) OK | |
108 ;; - rename-file (old new) OK | |
109 ;; - find-file-hook () NOT NEEDED | |
110 ;; - find-file-not-found-hook () NOT NEEDED | |
111 | |
112 (eval-when-compile (require 'cl) (require 'vc)) | |
113 | |
114 (defvar git-commits-coding-system 'utf-8 | |
115 "Default coding system for git commits.") | |
116 | |
117 ;;; BACKEND PROPERTIES | |
118 | |
119 (defun vc-git-revision-granularity () | |
120 'repository) | |
121 | |
122 ;;; STATE-QUERYING FUNCTIONS | |
123 | |
124 ;;;###autoload (defun vc-git-registered (file) | |
125 ;;;###autoload "Return non-nil if FILE is registered with git." | |
126 ;;;###autoload (if (vc-find-root file ".git") ; short cut | |
127 ;;;###autoload (progn | |
128 ;;;###autoload (load "vc-git") | |
129 ;;;###autoload (vc-git-registered file)))) | |
130 | |
131 (defun vc-git-registered (file) | |
132 "Check whether FILE is registered with git." | |
133 (when (vc-git-root file) | |
134 (with-temp-buffer | |
135 (let* ((dir (file-name-directory file)) | |
136 (name (file-relative-name file dir))) | |
137 (and (ignore-errors | |
138 (when dir (cd dir)) | |
139 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))) | |
140 (let ((str (buffer-string))) | |
141 (and (> (length str) (length name)) | |
142 (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))) | |
143 | |
144 (defun vc-git-state (file) | |
145 "Git-specific version of `vc-state'." | |
78687
429a17d4958d
* vc-git.el (vc-git-state): Call git-add --refresh to update the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78404
diff
changeset
|
146 (call-process "git" nil nil nil "add" "--refresh" "--" (file-relative-name file)) |
78355 | 147 (let ((diff (vc-git--run-command-string file "diff-index" "-z" "HEAD" "--"))) |
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)) | |
149 'edited | |
150 'up-to-date))) | |
151 | |
152 (defun vc-git-dir-state (dir) | |
153 (with-temp-buffer | |
154 (vc-git-command (current-buffer) nil nil "ls-files" "-t") | |
155 (goto-char (point-min)) | |
156 (let ((status-char nil) | |
157 (file nil)) | |
158 (while (not (eobp)) | |
159 (setq status-char (char-after)) | |
160 (setq file | |
161 (expand-file-name | |
162 (buffer-substring-no-properties (+ (point) 2) (line-end-position)))) | |
163 (cond | |
164 ;; The rest of the possible states in "git ls-files -t" output: | |
165 ;; R removed/deleted | |
166 ;; K to be killed | |
167 ;; should not show up in vc-dired, so don't deal with them | |
168 ;; here. | |
169 ((eq status-char ?H) | |
170 (vc-file-setprop file 'vc-state 'up-to-date)) | |
171 ((eq status-char ?M) | |
172 (vc-file-setprop file 'vc-state 'edited)) | |
173 ((eq status-char ?C) | |
174 (vc-file-setprop file 'vc-state 'edited)) | |
175 ((eq status-char ??) | |
176 (vc-file-setprop file 'vc-backend 'none) | |
177 (vc-file-setprop file 'vc-state 'nil))) | |
178 (forward-line))))) | |
179 | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
180 (defun vc-git-working-revision (file) |
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
181 "Git-specific version of `vc-working-revision'." |
78355 | 182 (let ((str (with-output-to-string |
183 (with-current-buffer standard-output | |
184 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD"))))) | |
185 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) | |
186 (match-string 2 str) | |
187 str))) | |
188 | |
189 (defun vc-git-checkout-model (file) | |
190 'implicit) | |
191 | |
192 (defun vc-git-workfile-unchanged-p (file) | |
78687
429a17d4958d
* vc-git.el (vc-git-state): Call git-add --refresh to update the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78404
diff
changeset
|
193 (eq 'up-to-date (vc-git-state file))) |
78355 | 194 |
82843
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
195 (defun vc-git-mode-line-string (file) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
196 "Return string for placement into the modeline for FILE." |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
197 (let* ((branch (vc-git-working-revision file)) |
82843
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
198 (def-ml (vc-default-mode-line-string 'Git file)) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
199 (help-echo (get-text-property 0 'help-echo def-ml))) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
200 (if (zerop (length branch)) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
201 (propertize |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
202 (concat def-ml "!") |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
203 'help-echo (concat help-echo "\nNo current branch (detached HEAD)")) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
204 (propertize def-ml |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
205 'help-echo (concat help-echo "\nCurrent branch: " branch))))) |
768766d373a7
* vc-git.el (vc-git-mode-line-string): New function.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82245
diff
changeset
|
206 |
78355 | 207 (defun vc-git-dired-state-info (file) |
208 "Git-specific version of `vc-dired-state-info'." | |
209 (let ((git-state (vc-state file))) | |
210 (if (eq git-state 'edited) | |
211 "(modified)" | |
212 ;; fall back to the default VC representation | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78359
diff
changeset
|
213 (vc-default-dired-state-info 'Git file)))) |
78355 | 214 |
215 ;;; STATE-CHANGING FUNCTIONS | |
216 | |
217 (defun vc-git-create-repo () | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78359
diff
changeset
|
218 "Create a new Git repository." |
78687
429a17d4958d
* vc-git.el (vc-git-state): Call git-add --refresh to update the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78404
diff
changeset
|
219 (vc-git-command nil 0 nil "init")) |
78355 | 220 |
221 (defun vc-git-register (files &optional rev comment) | |
222 "Register FILE into the git version-control system." | |
223 (vc-git-command nil 0 files "update-index" "--add" "--")) | |
224 | |
225 (defalias 'vc-git-responsible-p 'vc-git-root) | |
226 | |
227 (defun vc-git-unregister (file) | |
228 (vc-git-command nil 0 file "rm" "-f" "--cached" "--")) | |
229 | |
230 | |
231 (defun vc-git-checkin (files rev comment) | |
232 (let ((coding-system-for-write git-commits-coding-system)) | |
233 (vc-git-command nil 0 files "commit" "-m" comment "--only" "--"))) | |
234 | |
85139
8ba0e30716a5
Terminology cleanup.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85114
diff
changeset
|
235 (defun vc-git-find-revision (file rev buffer) |
78355 | 236 (let ((coding-system-for-read 'binary) |
237 (coding-system-for-write 'binary) | |
238 (fullname (substring | |
239 (vc-git--run-command-string | |
240 file "ls-files" "-z" "--full-name" "--") | |
241 0 -1))) | |
242 (vc-git-command | |
243 buffer 0 | |
244 (concat (if rev rev "HEAD") ":" fullname) "cat-file" "blob"))) | |
245 | |
246 (defun vc-git-checkout (file &optional editable rev) | |
247 (vc-git-command nil 0 file "checkout" (or rev "HEAD"))) | |
248 | |
249 (defun vc-git-revert (file &optional contents-done) | |
250 "Revert FILE to the version stored in the git repository." | |
251 (if contents-done | |
252 (vc-git-command nil 0 file "update-index" "--") | |
253 (vc-git-command nil 0 file "checkout" "HEAD"))) | |
254 | |
255 ;;; HISTORY FUNCTIONS | |
256 | |
257 (defun vc-git-print-log (files &optional buffer) | |
258 "Get change log associated with FILES." | |
259 (let ((coding-system-for-read git-commits-coding-system) | |
260 ;; Support both the old print-log interface that passes a | |
261 ;; single file, and the new one that passes a file list. | |
262 (flist (if (listp files) files (list files)))) | |
263 ;; `vc-do-command' creates the buffer, but we need it before running | |
264 ;; the command. | |
265 (vc-setup-buffer buffer) | |
266 ;; If the buffer exists from a previous invocation it might be | |
267 ;; read-only. | |
268 (let ((inhibit-read-only t)) | |
269 ;; XXX `log-view-mode' needs to have something to identify where | |
270 ;; the log for each individual file starts. It seems that by | |
271 ;; default git does not output this info. So loop here and call | |
272 ;; "git rev-list" on each file separately to make sure that each | |
273 ;; file gets a "File:" header before the corresponding | |
274 ;; log. Maybe there is a way to do this with one command... | |
275 (dolist (file flist) | |
276 (with-current-buffer | |
277 buffer | |
278 (insert "File: " (file-name-nondirectory file) "\n")) | |
279 (vc-git-command buffer 'async (file-relative-name file) | |
280 "rev-list" "--pretty" "HEAD" "--"))))) | |
281 | |
282 (defvar log-view-message-re) | |
283 (defvar log-view-file-re) | |
284 (defvar log-view-font-lock-keywords) | |
285 | |
78404
27f00e50116a
Change capitalization of VC backend names for new backends
Miles Bader <miles@gnu.org>
parents:
78359
diff
changeset
|
286 (define-derived-mode vc-git-log-view-mode log-view-mode "Git-Log-View" |
78355 | 287 (require 'add-log) ;; we need the faces add-log |
288 ;; Don't have file markers, so use impossible regexp. | |
289 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") | |
290 (set (make-local-variable 'log-view-message-re) | |
291 "^commit *\\([0-9a-z]+\\)") | |
292 (set (make-local-variable 'log-view-font-lock-keywords) | |
293 (append | |
294 `((,log-view-message-re (1 'change-log-acknowledgement)) | |
295 (,log-view-file-re (1 'change-log-file-face))) | |
296 ;; Handle the case: | |
297 ;; user: foo@bar | |
298 '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" | |
299 (1 'change-log-email)) | |
300 ;; Handle the case: | |
301 ;; user: FirstName LastName <foo@bar> | |
302 ("^Author:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" | |
303 (1 'change-log-name) | |
304 (2 'change-log-email)) | |
78820
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
305 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
306 (1 'change-log-name)) |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
307 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
308 (1 'change-log-name) |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
309 (2 'change-log-email)) |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
310 ("^Merge: \\([0-9a-z]+\\) \\([0-9a-z]+\\)" |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
311 (1 'change-log-acknowledgement) |
25e6b97b8f02
(vc-git-log-view-mode): Add font-lock patterns for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78687
diff
changeset
|
312 (2 'change-log-acknowledgement)) |
78355 | 313 ("^Date: \\(.+\\)" (1 'change-log-date)) |
314 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) | |
315 | |
316 (defun vc-git-diff (files &optional rev1 rev2 buffer) | |
317 (let ((buf (or buffer "*vc-diff*"))) | |
318 (if (and rev1 rev2) | |
319 (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p" rev1 rev2 "--") | |
320 (vc-git-command buf 1 files "diff-index" "--exit-code" "-p" (or rev1 "HEAD") "--")))) | |
321 | |
322 (defun vc-git-revision-table (file) | |
323 (let ((table (list "HEAD"))) | |
324 (with-temp-buffer | |
325 (vc-git-command t nil nil "for-each-ref" "--format=%(refname)") | |
326 (goto-char (point-min)) | |
327 (while (re-search-forward "^refs/\\(heads\\|tags\\)/\\(.*\\)$" nil t) | |
328 (push (match-string 2) table))) | |
329 table)) | |
330 | |
78359
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
331 (defun vc-git-revision-completion-table (file) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
332 (lexical-let ((file file) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
333 table) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
334 (setq table (lazy-completion-table |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
335 table (lambda () (vc-git-revision-table file)))) |
2dd5d799a16d
* vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78356
diff
changeset
|
336 table)) |
78355 | 337 |
338 (defun vc-git-diff-tree (dir &optional rev1 rev2) | |
339 (vc-git-diff dir rev1 rev2)) | |
340 | |
341 (defun vc-git-annotate-command (file buf &optional rev) | |
342 ;; FIXME: rev is ignored | |
343 (let ((name (file-relative-name file))) | |
344 (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev))))) | |
345 | |
346 (defun vc-git-annotate-time () | |
347 (and (re-search-forward "[0-9a-f]+ (.* \\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([-+0-9]+\\) +[0-9]+)" nil t) | |
348 (vc-annotate-convert-time | |
349 (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7)))))) | |
350 | |
351 (defun vc-git-annotate-extract-revision-at-line () | |
352 (save-excursion | |
353 (move-beginning-of-line 1) | |
354 (and (looking-at "[0-9a-f]+") | |
355 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))) | |
356 | |
357 ;;; SNAPSHOT SYSTEM | |
358 | |
359 (defun vc-git-create-snapshot (dir name branchp) | |
360 (let ((default-directory dir)) | |
361 (and (vc-git-command nil 0 nil "update-index" "--refresh") | |
362 (if branchp | |
363 (vc-git-command nil 0 nil "checkout" "-b" name) | |
364 (vc-git-command nil 0 nil "tag" name))))) | |
365 | |
366 (defun vc-git-retrieve-snapshot (dir name update) | |
367 (let ((default-directory dir)) | |
368 (vc-git-command nil 0 nil "checkout" name) | |
369 ;; FIXME: update buffers if `update' is true | |
370 )) | |
371 | |
372 | |
373 ;;; MISCELLANEOUS | |
374 | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
375 (defun vc-git-previous-revision (file rev) |
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
376 "Git-specific version of `vc-previous-revision'." |
78355 | 377 (let ((default-directory (file-name-directory (expand-file-name file))) |
378 (file (file-name-nondirectory file))) | |
379 (vc-git-symbolic-commit | |
380 (with-temp-buffer | |
381 (and | |
382 (zerop | |
383 (call-process "git" nil '(t nil) nil "rev-list" | |
384 "-2" rev "--" file)) | |
385 (goto-char (point-max)) | |
386 (bolp) | |
387 (zerop (forward-line -1)) | |
388 (not (bobp)) | |
389 (buffer-substring-no-properties | |
390 (point) | |
391 (1- (point-max)))))))) | |
392 | |
85141
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
393 (defun vc-git-next-revision (file rev) |
b16f7408cd3f
Carry through today's big terminology change to a few places where I
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
85139
diff
changeset
|
394 "Git-specific version of `vc-next-revision'." |
78355 | 395 (let* ((default-directory (file-name-directory |
396 (expand-file-name file))) | |
397 (file (file-name-nondirectory file)) | |
398 (current-rev | |
399 (with-temp-buffer | |
400 (and | |
401 (zerop | |
402 (call-process "git" nil '(t nil) nil "rev-list" | |
403 "-1" rev "--" file)) | |
404 (goto-char (point-max)) | |
405 (bolp) | |
406 (zerop (forward-line -1)) | |
407 (bobp) | |
408 (buffer-substring-no-properties | |
409 (point) | |
410 (1- (point-max))))))) | |
411 (and current-rev | |
412 (vc-git-symbolic-commit | |
413 (with-temp-buffer | |
414 (and | |
415 (zerop | |
416 (call-process "git" nil '(t nil) nil "rev-list" | |
417 "HEAD" "--" file)) | |
418 (goto-char (point-min)) | |
419 (search-forward current-rev nil t) | |
420 (zerop (forward-line -1)) | |
421 (buffer-substring-no-properties | |
422 (point) | |
423 (progn (forward-line 1) (1- (point)))))))))) | |
424 | |
425 (defun vc-git-delete-file (file) | |
426 (vc-git-command nil 0 file "rm" "-f" "--")) | |
427 | |
428 (defun vc-git-rename-file (old new) | |
429 (vc-git-command nil 0 (list old new) "mv" "-f" "--")) | |
430 | |
431 | |
432 ;;; Internal commands | |
433 | |
434 (defun vc-git-root (file) | |
435 (vc-find-root file ".git")) | |
436 | |
437 (defun vc-git-command (buffer okstatus file-or-list &rest flags) | |
438 "A wrapper around `vc-do-command' for use in vc-git.el. | |
439 The difference to vc-do-command is that this function always invokes `git'." | |
440 (apply 'vc-do-command buffer okstatus "git" file-or-list flags)) | |
441 | |
442 (defun vc-git--run-command-string (file &rest args) | |
443 "Run a git command on FILE and return its output as string." | |
444 (let* ((ok t) | |
445 (str (with-output-to-string | |
446 (with-current-buffer standard-output | |
447 (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil | |
448 (append args (list (file-relative-name file))))) | |
449 (setq ok nil)))))) | |
450 (and ok str))) | |
451 | |
452 (defun vc-git-symbolic-commit (commit) | |
453 "Translate COMMIT string into symbolic form. | |
454 Returns nil if not possible." | |
455 (and commit | |
456 (with-temp-buffer | |
457 (and | |
458 (zerop | |
459 (call-process "git" nil '(t nil) nil "name-rev" | |
460 "--name-only" "--tags" | |
461 commit)) | |
462 (goto-char (point-min)) | |
463 (= (forward-line 2) 1) | |
464 (bolp) | |
465 (buffer-substring-no-properties (point-min) (1- (point-max))))))) | |
466 | |
467 (provide 'vc-git) | |
468 | |
469 ;; arch-tag: bd10664a-0e5b-48f5-a877-6c17b135be12 | |
470 ;;; vc-git.el ends here |