Mercurial > emacs
comparison lisp/vc-git.el @ 86400:fdd891feb624
Refill; nfc.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Sat, 24 Nov 2007 14:35:54 +0000 |
parents | 38193bd1ab69 |
children | d2c8f5a27761 |
comparison
equal
deleted
inserted
replaced
86399:5617af3c5da1 | 86400:fdd891feb624 |
---|---|
114 "Default coding system for git commits.") | 114 "Default coding system for git commits.") |
115 | 115 |
116 ;;; BACKEND PROPERTIES | 116 ;;; BACKEND PROPERTIES |
117 | 117 |
118 (defun vc-git-revision-granularity () | 118 (defun vc-git-revision-granularity () |
119 'repository) | 119 'repository) |
120 | 120 |
121 ;;; STATE-QUERYING FUNCTIONS | 121 ;;; STATE-QUERYING FUNCTIONS |
122 | 122 |
123 ;;;###autoload (defun vc-git-registered (file) | 123 ;;;###autoload (defun vc-git-registered (file) |
124 ;;;###autoload "Return non-nil if FILE is registered with git." | 124 ;;;###autoload "Return non-nil if FILE is registered with git." |
132 (when (vc-git-root file) | 132 (when (vc-git-root file) |
133 (with-temp-buffer | 133 (with-temp-buffer |
134 (let* ((dir (file-name-directory file)) | 134 (let* ((dir (file-name-directory file)) |
135 (name (file-relative-name file dir))) | 135 (name (file-relative-name file dir))) |
136 (and (ignore-errors | 136 (and (ignore-errors |
137 (when dir (cd dir)) | 137 (when dir (cd dir)) |
138 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))) | 138 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" |
139 "-c" "-z" "--" name))) | |
139 (let ((str (buffer-string))) | 140 (let ((str (buffer-string))) |
140 (and (> (length str) (length name)) | 141 (and (> (length str) (length name)) |
141 (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))) | 142 (string= (substring str 0 (1+ (length name))) |
143 (concat name "\0"))))))))) | |
142 | 144 |
143 (defun vc-git-state (file) | 145 (defun vc-git-state (file) |
144 "Git-specific version of `vc-state'." | 146 "Git-specific version of `vc-state'." |
145 (call-process "git" nil nil nil "add" "--refresh" "--" (file-relative-name file)) | 147 (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" "--"))) | 148 (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)) | 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)) | |
148 'edited | 151 'edited |
149 'up-to-date))) | 152 'up-to-date))) |
150 | 153 |
151 (defun vc-git-dir-state (dir) | 154 (defun vc-git-dir-state (dir) |
152 (with-temp-buffer | 155 (with-temp-buffer |
156 (file nil)) | 159 (file nil)) |
157 (while (not (eobp)) | 160 (while (not (eobp)) |
158 (setq status-char (char-after)) | 161 (setq status-char (char-after)) |
159 (setq file | 162 (setq file |
160 (expand-file-name | 163 (expand-file-name |
161 (buffer-substring-no-properties (+ (point) 2) (line-end-position)))) | 164 (buffer-substring-no-properties (+ (point) 2) |
165 (line-end-position)))) | |
162 (cond | 166 (cond |
163 ;; The rest of the possible states in "git ls-files -t" output: | 167 ;; The rest of the possible states in "git ls-files -t" output: |
164 ;; R removed/deleted | 168 ;; R removed/deleted |
165 ;; K to be killed | 169 ;; K to be killed |
166 ;; should not show up in vc-dired, so don't deal with them | 170 ;; should not show up in vc-dired, so don't deal with them |
288 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") | 292 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") |
289 (set (make-local-variable 'log-view-message-re) | 293 (set (make-local-variable 'log-view-message-re) |
290 "^commit *\\([0-9a-z]+\\)") | 294 "^commit *\\([0-9a-z]+\\)") |
291 (set (make-local-variable 'log-view-font-lock-keywords) | 295 (set (make-local-variable 'log-view-font-lock-keywords) |
292 (append | 296 (append |
293 `((,log-view-message-re (1 'change-log-acknowledgement)) | 297 `((,log-view-message-re (1 'change-log-acknowledgement)) |
294 (,log-view-file-re (1 'change-log-file-face))) | 298 (,log-view-file-re (1 'change-log-file-face))) |
295 ;; Handle the case: | 299 ;; Handle the case: |
296 ;; user: foo@bar | 300 ;; user: foo@bar |
297 '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" | 301 '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
298 (1 'change-log-email)) | 302 (1 'change-log-email)) |
299 ;; Handle the case: | 303 ;; Handle the case: |
300 ;; user: FirstName LastName <foo@bar> | 304 ;; user: FirstName LastName <foo@bar> |
301 ("^Author:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" | 305 ("^Author:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
302 (1 'change-log-name) | 306 (1 'change-log-name) |
303 (2 'change-log-email)) | 307 (2 'change-log-email)) |
304 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" | 308 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
305 (1 'change-log-name)) | 309 (1 'change-log-name)) |
306 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" | 310 ("^ +\\(?:\\(?:[Aa]cked\\|[Ss]igned-[Oo]ff\\)-[Bb]y:\\)[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
307 (1 'change-log-name) | 311 (1 'change-log-name) |
308 (2 'change-log-email)) | 312 (2 'change-log-email)) |
309 ("^Merge: \\([0-9a-z]+\\) \\([0-9a-z]+\\)" | 313 ("^Merge: \\([0-9a-z]+\\) \\([0-9a-z]+\\)" |
310 (1 'change-log-acknowledgement) | 314 (1 'change-log-acknowledgement) |
311 (2 'change-log-acknowledgement)) | 315 (2 'change-log-acknowledgement)) |
312 ("^Date: \\(.+\\)" (1 'change-log-date)) | 316 ("^Date: \\(.+\\)" (1 'change-log-date)) |
313 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) | 317 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) |
314 | 318 |
315 (defun vc-git-show-log-entry (revision) | 319 (defun vc-git-show-log-entry (revision) |
316 "Move to the log entry for REVISION. | 320 "Move to the log entry for REVISION. |
317 REVISION may have the form BRANCH, BRANCH~N, | 321 REVISION may have the form BRANCH, BRANCH~N, |
318 or BRANCH^ (where \"^\" can be repeated)." | 322 or BRANCH^ (where \"^\" can be repeated)." |
326 (beginning-of-line)) | 330 (beginning-of-line)) |
327 | 331 |
328 (defun vc-git-diff (files &optional rev1 rev2 buffer) | 332 (defun vc-git-diff (files &optional rev1 rev2 buffer) |
329 (let ((buf (or buffer "*vc-diff*"))) | 333 (let ((buf (or buffer "*vc-diff*"))) |
330 (if (and rev1 rev2) | 334 (if (and rev1 rev2) |
331 (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p" rev1 rev2 "--") | 335 (vc-git-command buf 1 files "diff-tree" "--exit-code" "-p" |
332 (vc-git-command buf 1 files "diff-index" "--exit-code" "-p" (or rev1 "HEAD") "--")))) | 336 rev1 rev2 "--") |
337 (vc-git-command buf 1 files "diff-index" "--exit-code" "-p" | |
338 (or rev1 "HEAD") "--")))) | |
333 | 339 |
334 (defun vc-git-revision-table (files) | 340 (defun vc-git-revision-table (files) |
335 ;; What about `files'?!? --Stef | 341 ;; What about `files'?!? --Stef |
336 (let ((table (list "HEAD"))) | 342 (let ((table (list "HEAD"))) |
337 (with-temp-buffer | 343 (with-temp-buffer |
354 (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev))))) | 360 (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev))))) |
355 | 361 |
356 (defun vc-git-annotate-time () | 362 (defun vc-git-annotate-time () |
357 (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) | 363 (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) |
358 (vc-annotate-convert-time | 364 (vc-annotate-convert-time |
359 (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7)))))) | 365 (apply #'encode-time (mapcar (lambda (match) |
366 (string-to-number (match-string match))) | |
367 '(6 5 4 3 2 1 7)))))) | |
360 | 368 |
361 (defun vc-git-annotate-extract-revision-at-line () | 369 (defun vc-git-annotate-extract-revision-at-line () |
362 (save-excursion | 370 (save-excursion |
363 (move-beginning-of-line 1) | 371 (move-beginning-of-line 1) |
364 (and (looking-at "[0-9a-f]+") | 372 (and (looking-at "[0-9a-f]+") |
365 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))) | 373 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))) |
366 | 374 |
367 ;;; SNAPSHOT SYSTEM | 375 ;;; SNAPSHOT SYSTEM |
368 | 376 |
369 (defun vc-git-create-snapshot (dir name branchp) | 377 (defun vc-git-create-snapshot (dir name branchp) |
370 (let ((default-directory dir)) | 378 (let ((default-directory dir)) |
395 (goto-char (point-max)) | 403 (goto-char (point-max)) |
396 (bolp) | 404 (bolp) |
397 (zerop (forward-line -1)) | 405 (zerop (forward-line -1)) |
398 (not (bobp)) | 406 (not (bobp)) |
399 (buffer-substring-no-properties | 407 (buffer-substring-no-properties |
400 (point) | 408 (point) |
401 (1- (point-max)))))))) | 409 (1- (point-max)))))))) |
402 | 410 |
403 (defun vc-git-next-revision (file rev) | 411 (defun vc-git-next-revision (file rev) |
404 "Git-specific version of `vc-next-revision'." | 412 "Git-specific version of `vc-next-revision'." |
405 (let* ((default-directory (file-name-directory | 413 (let* ((default-directory (file-name-directory |
406 (expand-file-name file))) | 414 (expand-file-name file))) |
407 (file (file-name-nondirectory file)) | 415 (file (file-name-nondirectory file)) |
408 (current-rev | 416 (current-rev |
409 (with-temp-buffer | 417 (with-temp-buffer |
410 (and | 418 (and |
411 (zerop | 419 (zerop |
412 (call-process "git" nil '(t nil) nil "rev-list" | 420 (call-process "git" nil '(t nil) nil "rev-list" |
413 "-1" rev "--" file)) | 421 "-1" rev "--" file)) |
414 (goto-char (point-max)) | 422 (goto-char (point-max)) |
415 (bolp) | 423 (bolp) |
416 (zerop (forward-line -1)) | 424 (zerop (forward-line -1)) |
417 (bobp) | 425 (bobp) |
418 (buffer-substring-no-properties | 426 (buffer-substring-no-properties |
419 (point) | 427 (point) |
420 (1- (point-max))))))) | 428 (1- (point-max))))))) |
421 (and current-rev | 429 (and current-rev |
422 (vc-git-symbolic-commit | 430 (vc-git-symbolic-commit |
423 (with-temp-buffer | 431 (with-temp-buffer |
424 (and | 432 (and |
425 (zerop | 433 (zerop |
453 "Run a git command on FILE and return its output as string." | 461 "Run a git command on FILE and return its output as string." |
454 (let* ((ok t) | 462 (let* ((ok t) |
455 (str (with-output-to-string | 463 (str (with-output-to-string |
456 (with-current-buffer standard-output | 464 (with-current-buffer standard-output |
457 (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil | 465 (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil |
458 (append args (list (file-relative-name file))))) | 466 (append args (list (file-relative-name |
467 file))))) | |
459 (setq ok nil)))))) | 468 (setq ok nil)))))) |
460 (and ok str))) | 469 (and ok str))) |
461 | 470 |
462 (defun vc-git-symbolic-commit (commit) | 471 (defun vc-git-symbolic-commit (commit) |
463 "Translate COMMIT string into symbolic form. | 472 "Translate COMMIT string into symbolic form. |