aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Nicolaescu2007-07-22 21:16:34 +0000
committerDan Nicolaescu2007-07-22 21:16:34 +0000
commit53cc90abac468db36ec45f7f67c4389f8b134165 (patch)
tree4aaaffabdd99dafe495552baba6101a5d04e7e46
parent2e2eead345f7ab3e4ac81916f2d6b415fc54daf0 (diff)
downloademacs-53cc90abac468db36ec45f7f67c4389f8b134165.tar.gz
emacs-53cc90abac468db36ec45f7f67c4389f8b134165.zip
(vc-git-revision-granularity,vc-git-root),
(vc-git-command,vc-git-dir-state,vc-git-dired-state-info), (vc-git-create-repo): New functions. (vc-git-registered): New autoloaded function definition. (vc-git-registered): Use vc-git-root. (vc-git-responsible-p): New defalias. (vc-git-annotate-extract-revision-at-line): Uncomment. (vc-git-print-log): Add the file name to the log. (vc-git-log-view-mode): New derived mode. (vc-git-diff,vc-git-annotate-command): Use vc-git-command.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/vc-git.el234
2 files changed, 221 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0135fd6accd..ee6874c58a9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12007-07-22 Dan Nicolaescu <dann@ics.uci.edu>
2
3 * vc-git.el (vc-git-revision-granularity,vc-git-root),
4 (vc-git-command,vc-git-dir-state,vc-git-dired-state-info),
5 (vc-git-create-repo): New functions.
6 (vc-git-registered): New autoloaded function definition.
7 (vc-git-registered): Use vc-git-root.
8 (vc-git-responsible-p): New defalias.
9 (vc-git-annotate-extract-revision-at-line): Uncomment.
10 (vc-git-print-log): Add the file name to the log.
11 (vc-git-log-view-mode): New derived mode.
12 (vc-git-diff,vc-git-annotate-command): Use vc-git-command.
13
12007-07-22 Michael Albinus <michael.albinus@gmx.de> 142007-07-22 Michael Albinus <michael.albinus@gmx.de>
2 15
3 * progmodes/grep.el (grep-compute-defaults): Keep default values. 16 * progmodes/grep.el (grep-compute-defaults): Keep default values.
diff --git a/lisp/vc-git.el b/lisp/vc-git.el
index ffc45b10d55..c074b48ea74 100644
--- a/lisp/vc-git.el
+++ b/lisp/vc-git.el
@@ -37,36 +37,149 @@
37;; (add-to-list 'vc-handled-backends 'GIT) 37;; (add-to-list 'vc-handled-backends 'GIT)
38 38
39;;; Todo: 39;;; Todo:
40;; - !!!port to the new VC interface with multiple file arguments!!!
41;; - check if more functions could use vc-git-command instead
42;; of start-process.
40;; - changelog generation 43;; - changelog generation
41;; - working with revisions other than HEAD 44;; - working with revisions other than HEAD
45
46;; Implement the rest of the vc interface. See the comment at the
47;; beginning of vc.el. The current status is:
42;; 48;;
49;; FUNCTION NAME STATUS
50;; BACKEND PROPERTIES
51;; * revision-granularity OK
52;; STATE-QUERYING FUNCTIONS
53;; * registered (file) OK
54;; * state (file) OK
55;; - state-heuristic (file) ?? PROBABLY NOT NEEDED
56;; - dir-state (dir) OK
57;; * workfile-version (file) OK
58;; - latest-on-branch-p (file) ??
59;; * checkout-model (file) OK
60;; - workfile-unchanged-p (file) MAYBE CAN BE SIMPLIFIED
61;; - mode-line-string (file) NOT NEEDED
62;; - dired-state-info (file) OK
63;; STATE-CHANGING FUNCTIONS
64;; * create-repo () OK
65;; * register (files &optional rev comment) PORT TO NEW VC INTERFACE
66;; - init-version (file) ??
67;; - responsible-p (file) OK
68;; - could-register (file) NEEDED
69;; - receive-file (file rev) ??
70;; - unregister (file) NEEDED
71;; * checkin (files rev comment) PORT TO NEW VC INTERFACE
72;; * find-version (file rev buffer) NEEDED!
73;; * checkout (file &optional editable rev) OK
74;; * revert (file &optional contents-done) OK
75;; - rollback (files) NEEDED
76;; - merge (file rev1 rev2) NEEDED
77;; - merge-news (file) NEEDED
78;; - steal-lock (file &optional version) NOT NEEDED
79;; HISTORY FUNCTIONS
80;; * print-log (files &optional buffer) PORT TO NEW VC INTERFACE
81;; - log-view-mode () OK
82;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD
83;; - wash-log (file) ??
84;; - logentry-check () ??
85;; - comment-history (file) ??
86;; - update-changelog (files) ??
87;; * diff (file &optional rev1 rev2 buffer) PORT TO NEW VC INTERFACE
88;; - revision-completion-table (file) NEEDED?
89;; - diff-tree (dir &optional rev1 rev2) NEEDED
90;; - annotate-command (file buf &optional rev) OK
91;; - annotate-time () OK
92;; - annotate-current-time () ?? NOT NEEDED
93;; - annotate-extract-revision-at-line () OK
94;; SNAPSHOT SYSTEM
95;; - create-snapshot (dir name branchp) NEEDED
96;; - assign-name (file name) NOT NEEDED
97;; - retrieve-snapshot (dir name update) NEEDED
98;; MISCELLANEOUS
99;; - make-version-backups-p (file) ??
100;; - repository-hostname (dirname) ??
101;; - previous-version (file rev) ??
102;; - next-version (file rev) ??
103;; - check-headers () ??
104;; - clear-headers () ??
105;; - delete-file (file) NEEDED
106;; - rename-file (old new) NEEDED
107;; - find-file-hook () PROBABLY NOT NEEDED
108;; - find-file-not-found-hook () PROBABLY NOT NEEDED
43 109
44(eval-when-compile (require 'cl)) 110(eval-when-compile (require 'cl))
45 111
46(defvar git-commits-coding-system 'utf-8 112(defvar git-commits-coding-system 'utf-8
47 "Default coding system for git commits.") 113 "Default coding system for git commits.")
48 114
115;; XXX when this backend is considered sufficiently reliable this
116;; should be moved to vc-hooks.el
117(add-to-list 'vc-handled-backends 'GIT)
118
119;;; BACKEND PROPERTIES
120
121(defun vc-git-revision-granularity ()
122 'repository)
123
124;;; STATE-QUERYING FUNCTIONS
125
126;;;###autoload (defun vc-git-registered (file)
127;;;###autoload "Return non-nil if FILE is registered with git."
128;;;###autoload (if (vc-find-root file ".git") ; short cut
129;;;###autoload (progn
130;;;###autoload (load "vc-git")
131;;;###autoload (vc-git-registered file))))
132
49(defun vc-git-registered (file) 133(defun vc-git-registered (file)
50 "Check whether FILE is registered with git." 134 "Check whether FILE is registered with git."
51 (with-temp-buffer 135 (when (vc-git-root file)
52 (let* ((dir (file-name-directory file)) 136 (with-temp-buffer
53 (name (file-relative-name file dir))) 137 (let* ((dir (file-name-directory file))
54 (and (ignore-errors 138 (name (file-relative-name file dir)))
55 (when dir (cd dir)) 139 (and (ignore-errors
56 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))) 140 (when dir (cd dir))
57 (let ((str (buffer-string))) 141 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
58 (and (> (length str) (length name)) 142 (let ((str (buffer-string)))
59 (string= (substring str 0 (1+ (length name))) (concat name "\0")))))))) 143 (and (> (length str) (length name))
60 144 (string= (substring str 0 (1+ (length name))) (concat name "\0")))))))))
145
61(defun vc-git-state (file) 146(defun vc-git-state (file)
62 "git-specific version of `vc-state'." 147 "Git-specific version of `vc-state'."
63 (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" "--")))
64 (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 (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} [ADMU]\0[^\0]+\0" diff))
65 'edited 150 'edited
66 'up-to-date))) 151 'up-to-date)))
67 152
153(defun vc-git-dir-state (dir)
154 (with-temp-buffer
155 (vc-git-command (current-buffer) nil nil "ls-files" "-t")
156 (goto-char (point-min))
157 (let ((status-char nil)
158 (file nil))
159 (while (not (eobp))
160 (setq status-char (char-after))
161 (setq file
162 (expand-file-name
163 (buffer-substring-no-properties (+ (point) 2) (line-end-position))))
164 (cond
165 ;; The rest of the possible states in "git ls-files -t" output:
166 ;; R removed/deleted
167 ;; K to be killed
168 ;; should not show up in vc-dired, so don't deal with them
169 ;; here.
170 ((eq status-char ?H)
171 (vc-file-setprop file 'vc-state 'up-to-date))
172 ((eq status-char ?M)
173 (vc-file-setprop file 'vc-state 'edited))
174 ((eq status-char ?C)
175 (vc-file-setprop file 'vc-state 'edited))
176 ((eq status-char ??)
177 (vc-file-setprop file 'vc-backend 'none)
178 (vc-file-setprop file 'vc-state 'nil)))
179 (forward-line)))))
180
68(defun vc-git-workfile-version (file) 181(defun vc-git-workfile-version (file)
69 "git-specific version of `vc-workfile-version'." 182 "Git-specific version of `vc-workfile-version'."
70 (let ((str (with-output-to-string 183 (let ((str (with-output-to-string
71 (with-current-buffer standard-output 184 (with-current-buffer standard-output
72 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD"))))) 185 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD")))))
@@ -77,6 +190,7 @@
77(defun vc-git-checkout-model (file) 190(defun vc-git-checkout-model (file)
78 'implicit) 191 'implicit)
79 192
193;; XXX Can't this just use the result of vc-git-state?
80(defun vc-git-workfile-unchanged-p (file) 194(defun vc-git-workfile-unchanged-p (file)
81 (let ((sha1 (vc-git--run-command-string file "hash-object" "--")) 195 (let ((sha1 (vc-git--run-command-string file "hash-object" "--"))
82 (head (vc-git--run-command-string file "ls-tree" "-z" "HEAD" "--"))) 196 (head (vc-git--run-command-string file "ls-tree" "-z" "HEAD" "--")))
@@ -84,10 +198,26 @@
84 (string-match "[0-7]\\{6\\} blob \\([0-9a-f]\\{40\\}\\)\t[^\0]+\0" head) 198 (string-match "[0-7]\\{6\\} blob \\([0-9a-f]\\{40\\}\\)\t[^\0]+\0" head)
85 (string= (car (split-string sha1 "\n")) (match-string 1 head))))) 199 (string= (car (split-string sha1 "\n")) (match-string 1 head)))))
86 200
201(defun vc-git-dired-state-info (file)
202 "Git-specific version of `vc-dired-state-info'."
203 (let ((git-state (vc-state file)))
204 (if (eq git-state 'edited)
205 "(modified)"
206 ;; fall back to the default VC representation
207 (vc-default-dired-state-info 'GIT file))))
208
209;;; STATE-CHANGING FUNCTIONS
210
211(defun vc-git-create-repo ()
212 "Create a new GIT repository."
213 (vc-git-command "init" nil 0 nil))
214
87(defun vc-git-register (file &optional rev comment) 215(defun vc-git-register (file &optional rev comment)
88 "Register FILE into the git version-control system." 216 "Register FILE into the git version-control system."
89 (vc-git--run-command file "update-index" "--add" "--")) 217 (vc-git--run-command file "update-index" "--add" "--"))
90 218
219(defalias 'vc-git-responsible-p 'vc-git-root)
220
91(defun vc-git-checkin (file rev comment) 221(defun vc-git-checkin (file rev comment)
92 (let ((coding-system-for-write git-commits-coding-system)) 222 (let ((coding-system-for-write git-commits-coding-system))
93 (vc-git--run-command file "commit" "-m" comment "--only" "--"))) 223 (vc-git--run-command file "commit" "-m" comment "--only" "--")))
@@ -110,39 +240,81 @@
110 (vc-git--run-command file "update-index" "--") 240 (vc-git--run-command file "update-index" "--")
111 (vc-git--run-command file "checkout" "HEAD"))) 241 (vc-git--run-command file "checkout" "HEAD")))
112 242
243;;; HISTORY FUNCTIONS
244
113(defun vc-git-print-log (file &optional buffer) 245(defun vc-git-print-log (file &optional buffer)
114 (let ((name (file-relative-name file)) 246 (let ((name (file-relative-name file))
115 (coding-system-for-read git-commits-coding-system)) 247 (coding-system-for-read git-commits-coding-system))
116 (vc-do-command buffer 'async "git" name "rev-list" "--pretty" "HEAD" "--"))) 248 ;; `log-view-mode' needs to have the file name in order to function
249 ;; correctly. "git log" does not print it, so we insert it here by
250 ;; hand.
251
252 ;; `vc-do-command' creates the buffer, but we need it before running
253 ;; the command.
254 (vc-setup-buffer buffer)
255 ;; If the buffer exists from a previous invocation it might be
256 ;; read-only.
257 (let ((inhibit-read-only t))
258 (with-current-buffer
259 buffer
260 (insert "File: " (file-name-nondirectory file) "\n")))
261 (vc-git-command buffer 'async name "rev-list" "--pretty" "HEAD" "--")))
262
263(defvar log-view-message-re)
264(defvar log-view-file-re)
265(defvar log-view-font-lock-keywords)
266
267(define-derived-mode vc-git-log-view-mode log-view-mode "GIT-Log-View"
268 (require 'add-log) ;; we need the faces add-log
269 ;; Don't have file markers, so use impossible regexp.
270 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)")
271 (set (make-local-variable 'log-view-message-re)
272 "^commit *\\([0-9a-z]+\\)")
273 (set (make-local-variable 'log-view-font-lock-keywords)
274 (append
275 `((,log-view-message-re (1 'change-log-acknowledgement))
276 (,log-view-file-re (1 'change-log-file-face)))
277 ;; Handle the case:
278 ;; user: foo@bar
279 '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)"
280 (1 'change-log-email))
281 ;; Handle the case:
282 ;; user: FirstName LastName <foo@bar>
283 ("^Author:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]"
284 (1 'change-log-name)
285 (2 'change-log-email))
286 ("^Date: \\(.+\\)" (1 'change-log-date))
287 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message))))))
117 288
118(defun vc-git-diff (file &optional rev1 rev2 buffer) 289(defun vc-git-diff (file &optional rev1 rev2 buffer)
119 (let ((name (file-relative-name file)) 290 (let ((name (file-relative-name file))
120 (buf (or buffer "*vc-diff*"))) 291 (buf (or buffer "*vc-diff*")))
121 (if (and rev1 rev2) 292 (if (and rev1 rev2)
122 (vc-do-command buf 0 "git" name "diff-tree" "-p" rev1 rev2 "--") 293 (vc-git-command buf 0 name "diff-tree" "-p" rev1 rev2 "--")
123 (vc-do-command buf 0 "git" name "diff-index" "-p" (or rev1 "HEAD") "--")) 294 (vc-git-command buf 0 name "diff-index" "-p" (or rev1 "HEAD") "--"))
124 ; git-diff-index doesn't set exit status like diff does 295 ;; git-diff-index doesn't set exit status like diff does
125 (if (vc-git-workfile-unchanged-p file) 0 1))) 296 (if (vc-git-workfile-unchanged-p file) 0 1)))
126 297
127(defun vc-git-annotate-command (file buf &optional rev) 298(defun vc-git-annotate-command (file buf &optional rev)
128 ; FIXME: rev is ignored 299 ;; FIXME: rev is ignored
129 (let ((name (file-relative-name file))) 300 (let ((name (file-relative-name file)))
130 (call-process "git" nil buf nil "blame" name))) 301 (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev)))))
131 302
132(defun vc-git-annotate-time () 303(defun vc-git-annotate-time ()
133 (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) 304 (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)
134 (vc-annotate-convert-time 305 (vc-annotate-convert-time
135 (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7)))))) 306 (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7))))))
136 307
137;; Not really useful since we can't do anything with the revision yet 308(defun vc-git-annotate-extract-revision-at-line ()
138;;(defun vc-annotate-extract-revision-at-line () 309 (save-excursion
139;; (save-excursion 310 (move-beginning-of-line 1)
140;; (move-beginning-of-line 1) 311 (and (looking-at "[0-9a-f]+")
141;; (and (looking-at "[0-9a-f]+") 312 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))))
142;; (buffer-substring (match-beginning 0) (match-end 0))))) 313
314;;; MISCELLANEOUS
143 315
144(defun vc-git-previous-version (file rev) 316(defun vc-git-previous-version (file rev)
145 "git-specific version of `vc-previous-version'." 317 "Git-specific version of `vc-previous-version'."
146 (let ((default-directory (file-name-directory (expand-file-name file))) 318 (let ((default-directory (file-name-directory (expand-file-name file)))
147 (file (file-name-nondirectory file))) 319 (file (file-name-nondirectory file)))
148 (vc-git-symbolic-commit 320 (vc-git-symbolic-commit
@@ -160,7 +332,7 @@
160 (1- (point-max)))))))) 332 (1- (point-max))))))))
161 333
162(defun vc-git-next-version (file rev) 334(defun vc-git-next-version (file rev)
163 "git-specific version of `vc-next-version'." 335 "Git-specific version of `vc-next-version'."
164 (let* ((default-directory (file-name-directory 336 (let* ((default-directory (file-name-directory
165 (expand-file-name file))) 337 (expand-file-name file)))
166 (file (file-name-nondirectory file)) 338 (file (file-name-nondirectory file))
@@ -194,6 +366,14 @@
194 366
195;; Internal commands 367;; Internal commands
196 368
369(defun vc-git-root (file)
370 (vc-find-root file ".git"))
371
372(defun vc-git-command (buffer okstatus file &rest flags)
373 "A wrapper around `vc-do-command' for use in vc-git.el.
374The difference to vc-do-command is that this function always invokes `git'."
375 (apply 'vc-do-command buffer okstatus "git" file flags))
376
197(defun vc-git--run-command-string (file &rest args) 377(defun vc-git--run-command-string (file &rest args)
198 "Run a git command on FILE and return its output as string." 378 "Run a git command on FILE and return its output as string."
199 (let* ((ok t) 379 (let* ((ok t)
@@ -225,3 +405,5 @@ Returns nil if not possible."
225 (buffer-substring-no-properties (point-min) (1- (point-max))))))) 405 (buffer-substring-no-properties (point-min) (1- (point-max)))))))
226 406
227(provide 'vc-git) 407(provide 'vc-git)
408
409;;; vc-git.el ends here