Mercurial > emacs
annotate lisp/vc-git.el @ 82044:1c7880df488d
*** empty log message ***
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Sun, 22 Jul 2007 23:17:14 +0000 |
parents | 7ee8cfeeb2b8 |
children | 7df018ac279e |
rev | line source |
---|---|
82029 | 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 | |
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 2, 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 | |
33 ;; To install: put this file on the load-path and add GIT to the list | |
34 ;; of supported backends in `vc-handled-backends'; the following line, | |
35 ;; placed in your ~/.emacs, will accomplish this: | |
36 ;; | |
37 ;; (add-to-list 'vc-handled-backends 'GIT) | |
38 | |
39 ;;; Todo: | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
40 ;; - check if more functions could use vc-git-command instead |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
41 ;; of start-process. |
82029 | 42 ;; - changelog generation |
43 ;; - working with revisions other than HEAD | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
44 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
45 ;; Implement the rest of the vc interface. See the comment at the |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
46 ;; beginning of vc.el. The current status is: |
82029 | 47 ;; |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
48 ;; FUNCTION NAME STATUS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
49 ;; BACKEND PROPERTIES |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
50 ;; * revision-granularity OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
51 ;; STATE-QUERYING FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
52 ;; * registered (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
53 ;; * state (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
54 ;; - state-heuristic (file) ?? PROBABLY NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
55 ;; - dir-state (dir) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
56 ;; * workfile-version (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
57 ;; - latest-on-branch-p (file) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
58 ;; * checkout-model (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
59 ;; - workfile-unchanged-p (file) MAYBE CAN BE SIMPLIFIED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
60 ;; - mode-line-string (file) NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
61 ;; - dired-state-info (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
62 ;; STATE-CHANGING FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
63 ;; * create-repo () OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
64 ;; * register (files &optional rev comment) PORT TO NEW VC INTERFACE |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
65 ;; - init-version (file) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
66 ;; - responsible-p (file) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
67 ;; - could-register (file) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
68 ;; - receive-file (file rev) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
69 ;; - unregister (file) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
70 ;; * checkin (files rev comment) PORT TO NEW VC INTERFACE |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
71 ;; * find-version (file rev buffer) NEEDED! |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
72 ;; * checkout (file &optional editable rev) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
73 ;; * revert (file &optional contents-done) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
74 ;; - rollback (files) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
75 ;; - merge (file rev1 rev2) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
76 ;; - merge-news (file) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
77 ;; - steal-lock (file &optional version) NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
78 ;; HISTORY FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
79 ;; * print-log (files &optional buffer) PORT TO NEW VC INTERFACE |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
80 ;; - log-view-mode () OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
81 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
82 ;; - wash-log (file) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
83 ;; - logentry-check () ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
84 ;; - comment-history (file) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
85 ;; - update-changelog (files) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
86 ;; * diff (file &optional rev1 rev2 buffer) PORT TO NEW VC INTERFACE |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
87 ;; - revision-completion-table (file) NEEDED? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
88 ;; - diff-tree (dir &optional rev1 rev2) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
89 ;; - annotate-command (file buf &optional rev) OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
90 ;; - annotate-time () OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
91 ;; - annotate-current-time () ?? NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
92 ;; - annotate-extract-revision-at-line () OK |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
93 ;; SNAPSHOT SYSTEM |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
94 ;; - create-snapshot (dir name branchp) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
95 ;; - assign-name (file name) NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
96 ;; - retrieve-snapshot (dir name update) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
97 ;; MISCELLANEOUS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
98 ;; - make-version-backups-p (file) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
99 ;; - repository-hostname (dirname) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
100 ;; - previous-version (file rev) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
101 ;; - next-version (file rev) ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
102 ;; - check-headers () ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
103 ;; - clear-headers () ?? |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
104 ;; - delete-file (file) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
105 ;; - rename-file (old new) NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
106 ;; - find-file-hook () PROBABLY NOT NEEDED |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
107 ;; - find-file-not-found-hook () PROBABLY NOT NEEDED |
82029 | 108 |
109 (eval-when-compile (require 'cl)) | |
110 | |
111 (defvar git-commits-coding-system 'utf-8 | |
112 "Default coding system for git commits.") | |
113 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
114 ;; XXX when this backend is considered sufficiently reliable this |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
115 ;; should be moved to vc-hooks.el |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
116 (add-to-list 'vc-handled-backends 'GIT) |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
117 (add-to-list 'vc-directory-exclusion-list ".git" t) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
118 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
119 ;;; BACKEND PROPERTIES |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
120 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
121 (defun vc-git-revision-granularity () |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
122 'repository) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
123 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
124 ;;; STATE-QUERYING FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
125 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
126 ;;;###autoload (defun vc-git-registered (file) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
127 ;;;###autoload "Return non-nil if FILE is registered with git." |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
128 ;;;###autoload (if (vc-find-root file ".git") ; short cut |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
129 ;;;###autoload (progn |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
130 ;;;###autoload (load "vc-git") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
131 ;;;###autoload (vc-git-registered file)))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
132 |
82029 | 133 (defun vc-git-registered (file) |
134 "Check whether FILE is registered with git." | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
135 (when (vc-git-root file) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
136 (with-temp-buffer |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
137 (let* ((dir (file-name-directory file)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
138 (name (file-relative-name file dir))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
139 (and (ignore-errors |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
140 (when dir (cd dir)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
141 (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
142 (let ((str (buffer-string))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
143 (and (> (length str) (length name)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
144 (string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
145 |
82029 | 146 (defun vc-git-state (file) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
147 "Git-specific version of `vc-state'." |
82029 | 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" diff)) | |
150 'edited | |
151 'up-to-date))) | |
152 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
153 (defun vc-git-dir-state (dir) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
154 (with-temp-buffer |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
155 (vc-git-command (current-buffer) nil nil "ls-files" "-t") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
156 (goto-char (point-min)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
157 (let ((status-char nil) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
158 (file nil)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
159 (while (not (eobp)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
160 (setq status-char (char-after)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
161 (setq file |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
162 (expand-file-name |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
163 (buffer-substring-no-properties (+ (point) 2) (line-end-position)))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
164 (cond |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
165 ;; The rest of the possible states in "git ls-files -t" output: |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
166 ;; R removed/deleted |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
167 ;; K to be killed |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
168 ;; should not show up in vc-dired, so don't deal with them |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
169 ;; here. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
170 ((eq status-char ?H) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
171 (vc-file-setprop file 'vc-state 'up-to-date)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
172 ((eq status-char ?M) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
173 (vc-file-setprop file 'vc-state 'edited)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
174 ((eq status-char ?C) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
175 (vc-file-setprop file 'vc-state 'edited)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
176 ((eq status-char ??) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
177 (vc-file-setprop file 'vc-backend 'none) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
178 (vc-file-setprop file 'vc-state 'nil))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
179 (forward-line))))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
180 |
82029 | 181 (defun vc-git-workfile-version (file) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
182 "Git-specific version of `vc-workfile-version'." |
82029 | 183 (let ((str (with-output-to-string |
184 (with-current-buffer standard-output | |
185 (call-process "git" nil '(t nil) nil "symbolic-ref" "HEAD"))))) | |
186 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) | |
187 (match-string 2 str) | |
188 str))) | |
189 | |
190 (defun vc-git-checkout-model (file) | |
191 'implicit) | |
192 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
193 ;; XXX Can't this just use the result of vc-git-state? |
82029 | 194 (defun vc-git-workfile-unchanged-p (file) |
195 (let ((sha1 (vc-git--run-command-string file "hash-object" "--")) | |
196 (head (vc-git--run-command-string file "ls-tree" "-z" "HEAD" "--"))) | |
197 (and head | |
198 (string-match "[0-7]\\{6\\} blob \\([0-9a-f]\\{40\\}\\)\t[^\0]+\0" head) | |
199 (string= (car (split-string sha1 "\n")) (match-string 1 head))))) | |
200 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
201 (defun vc-git-dired-state-info (file) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
202 "Git-specific version of `vc-dired-state-info'." |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
203 (let ((git-state (vc-state file))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
204 (if (eq git-state 'edited) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
205 "(modified)" |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
206 ;; fall back to the default VC representation |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
207 (vc-default-dired-state-info 'GIT file)))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
208 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
209 ;;; STATE-CHANGING FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
210 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
211 (defun vc-git-create-repo () |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
212 "Create a new GIT repository." |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
213 (vc-git-command "init" nil 0 nil)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
214 |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
215 (defun vc-git-register (files &optional rev comment) |
82029 | 216 "Register FILE into the git version-control system." |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
217 (vc-git-command nil 0 files "update-index" "--add" "--")) |
82029 | 218 |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
219 (defalias 'vc-git-responsible-p 'vc-git-root) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
220 |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
221 (defun vc-git-checkin (files rev comment) |
82029 | 222 (let ((coding-system-for-write git-commits-coding-system)) |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
223 (vc-git-command nil 0 files "commit" "-m" comment "--only" "--"))) |
82029 | 224 |
225 (defun vc-git-checkout (file &optional editable rev destfile) | |
226 (if destfile | |
227 (let ((fullname (substring | |
228 (vc-git--run-command-string file "ls-files" "-z" "--full-name" "--") | |
229 0 -1)) | |
230 (coding-system-for-read 'no-conversion) | |
231 (coding-system-for-write 'no-conversion)) | |
232 (with-temp-file destfile | |
233 (eq 0 (call-process "git" nil t nil "cat-file" "blob" | |
234 (concat (or rev "HEAD") ":" fullname))))) | |
235 (vc-git--run-command file "checkout" (or rev "HEAD")))) | |
236 | |
237 (defun vc-git-revert (file &optional contents-done) | |
238 "Revert FILE to the version stored in the git repository." | |
239 (if contents-done | |
240 (vc-git--run-command file "update-index" "--") | |
241 (vc-git--run-command file "checkout" "HEAD"))) | |
242 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
243 ;;; HISTORY FUNCTIONS |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
244 |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
245 (defun vc-git-print-log (files &optional buffer) |
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
246 "Get change log associated with FILES." |
82029 | 247 (let ((name (file-relative-name file)) |
248 (coding-system-for-read git-commits-coding-system)) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
249 ;; `log-view-mode' needs to have the file name in order to function |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
250 ;; correctly. "git log" does not print it, so we insert it here by |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
251 ;; hand. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
252 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
253 ;; `vc-do-command' creates the buffer, but we need it before running |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
254 ;; the command. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
255 (vc-setup-buffer buffer) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
256 ;; If the buffer exists from a previous invocation it might be |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
257 ;; read-only. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
258 (let ((inhibit-read-only t)) |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
259 ;; XXX Here loop and call "git rev-list" on each file separately |
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
260 ;; to make sure that each file gets a "File:" header before the |
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
261 ;; corresponding log. Maybe there is a way to do this with one |
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
262 ;; command... |
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
263 (dolist (file files) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
264 (with-current-buffer |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
265 buffer |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
266 (insert "File: " (file-name-nondirectory file) "\n"))) |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
267 (vc-git-command buffer 'async name "rev-list" "--pretty" "HEAD" "--")))) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
268 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
269 (defvar log-view-message-re) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
270 (defvar log-view-file-re) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
271 (defvar log-view-font-lock-keywords) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
272 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
273 (define-derived-mode vc-git-log-view-mode log-view-mode "GIT-Log-View" |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
274 (require 'add-log) ;; we need the faces add-log |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
275 ;; Don't have file markers, so use impossible regexp. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
276 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
277 (set (make-local-variable 'log-view-message-re) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
278 "^commit *\\([0-9a-z]+\\)") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
279 (set (make-local-variable 'log-view-font-lock-keywords) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
280 (append |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
281 `((,log-view-message-re (1 'change-log-acknowledgement)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
282 (,log-view-file-re (1 'change-log-file-face))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
283 ;; Handle the case: |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
284 ;; user: foo@bar |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
285 '(("^Author:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)" |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
286 (1 'change-log-email)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
287 ;; Handle the case: |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
288 ;; user: FirstName LastName <foo@bar> |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
289 ("^Author:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]" |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
290 (1 'change-log-name) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
291 (2 'change-log-email)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
292 ("^Date: \\(.+\\)" (1 'change-log-date)) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
293 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) |
82029 | 294 |
295 (defun vc-git-diff (file &optional rev1 rev2 buffer) | |
296 (let ((name (file-relative-name file)) | |
297 (buf (or buffer "*vc-diff*"))) | |
298 (if (and rev1 rev2) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
299 (vc-git-command buf 0 name "diff-tree" "-p" rev1 rev2 "--") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
300 (vc-git-command buf 0 name "diff-index" "-p" (or rev1 "HEAD") "--")) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
301 ;; git-diff-index doesn't set exit status like diff does |
82029 | 302 (if (vc-git-workfile-unchanged-p file) 0 1))) |
303 | |
304 (defun vc-git-annotate-command (file buf &optional rev) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
305 ;; FIXME: rev is ignored |
82029 | 306 (let ((name (file-relative-name file))) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
307 (vc-git-command buf 0 name "blame" (if rev (concat "-r" rev))))) |
82029 | 308 |
309 (defun vc-git-annotate-time () | |
310 (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) | |
311 (vc-annotate-convert-time | |
312 (apply #'encode-time (mapcar (lambda (match) (string-to-number (match-string match))) '(6 5 4 3 2 1 7)))))) | |
313 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
314 (defun vc-git-annotate-extract-revision-at-line () |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
315 (save-excursion |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
316 (move-beginning-of-line 1) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
317 (and (looking-at "[0-9a-f]+") |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
318 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
319 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
320 ;;; MISCELLANEOUS |
82029 | 321 |
322 (defun vc-git-previous-version (file rev) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
323 "Git-specific version of `vc-previous-version'." |
82029 | 324 (let ((default-directory (file-name-directory (expand-file-name file))) |
325 (file (file-name-nondirectory file))) | |
326 (vc-git-symbolic-commit | |
327 (with-temp-buffer | |
328 (and | |
329 (zerop | |
330 (call-process "git" nil '(t nil) nil "rev-list" | |
331 "-2" rev "--" file)) | |
332 (goto-char (point-max)) | |
333 (bolp) | |
334 (zerop (forward-line -1)) | |
335 (not (bobp)) | |
336 (buffer-substring-no-properties | |
337 (point) | |
338 (1- (point-max)))))))) | |
339 | |
340 (defun vc-git-next-version (file rev) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
341 "Git-specific version of `vc-next-version'." |
82029 | 342 (let* ((default-directory (file-name-directory |
343 (expand-file-name file))) | |
344 (file (file-name-nondirectory file)) | |
345 (current-rev | |
346 (with-temp-buffer | |
347 (and | |
348 (zerop | |
349 (call-process "git" nil '(t nil) nil "rev-list" | |
350 "-1" rev "--" file)) | |
351 (goto-char (point-max)) | |
352 (bolp) | |
353 (zerop (forward-line -1)) | |
354 (bobp) | |
355 (buffer-substring-no-properties | |
356 (point) | |
357 (1- (point-max))))))) | |
358 (and current-rev | |
359 (vc-git-symbolic-commit | |
360 (with-temp-buffer | |
361 (and | |
362 (zerop | |
363 (call-process "git" nil '(t nil) nil "rev-list" | |
364 "HEAD" "--" file)) | |
365 (goto-char (point-min)) | |
366 (search-forward current-rev nil t) | |
367 (zerop (forward-line -1)) | |
368 (buffer-substring-no-properties | |
369 (point) | |
370 (progn (forward-line 1) (1- (point)))))))))) | |
371 | |
372 | |
373 ;; Internal commands | |
374 | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
375 (defun vc-git-root (file) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
376 (vc-find-root file ".git")) |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
377 |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
378 (defun vc-git-command (buffer okstatus file-or-list &rest flags) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
379 "A wrapper around `vc-do-command' for use in vc-git.el. |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
380 The difference to vc-do-command is that this function always invokes `git'." |
82038
7ee8cfeeb2b8
(vc-git-register, vc-git-checkin): Use vc-git-command,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82032
diff
changeset
|
381 (apply 'vc-do-command buffer okstatus "git" file-or-list flags)) |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
382 |
82029 | 383 (defun vc-git--run-command-string (file &rest args) |
384 "Run a git command on FILE and return its output as string." | |
385 (let* ((ok t) | |
386 (str (with-output-to-string | |
387 (with-current-buffer standard-output | |
388 (unless (eq 0 (apply #'call-process "git" nil '(t nil) nil | |
389 (append args (list (file-relative-name file))))) | |
390 (setq ok nil)))))) | |
391 (and ok str))) | |
392 | |
393 (defun vc-git--run-command (file &rest args) | |
394 "Run a git command on FILE, discarding any output." | |
395 (let ((name (file-relative-name file))) | |
396 (eq 0 (apply #'call-process "git" nil (get-buffer "*Messages") nil (append args (list name)))))) | |
397 | |
398 (defun vc-git-symbolic-commit (commit) | |
399 "Translate COMMIT string into symbolic form. | |
400 Returns nil if not possible." | |
401 (and commit | |
402 (with-temp-buffer | |
403 (and | |
404 (zerop | |
405 (call-process "git" nil '(t nil) nil "name-rev" | |
406 "--name-only" "--tags" | |
407 commit)) | |
408 (goto-char (point-min)) | |
409 (= (forward-line 2) 1) | |
410 (bolp) | |
411 (buffer-substring-no-properties (point-min) (1- (point-max))))))) | |
412 | |
413 (provide 'vc-git) | |
82032
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
414 |
7d7ee463e4e9
(vc-git-revision-granularity,vc-git-root),
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82029
diff
changeset
|
415 ;;; vc-git.el ends here |