@matheusbsbs / matheus-bagliano / commits / 248c648a0d
Fork 0

Add missing functions to contrib/emacs/vc-git.el

This is necessary to make several editing functions work, like C-u C-x v = Signed-off-by: David Kastrup <dak@gnu.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Kastrup committed Jul 12, 2007 at 16:48 UTC 248c648a0de945ec37af13e0a9b8671da525c323
1 file changed +65
contrib/emacs/vc-git.el
+65
@@ -81,6 +81,71 @@
81 (match-string 2 str)
82 str)))
83
84 +(defun vc-git-symbolic-commit (commit)
85 + "Translate COMMIT string into symbolic form.
86 +Returns nil if not possible."
87 + (and commit
88 + (with-temp-buffer
89 + (and
90 + (zerop
91 + (call-process "git" nil '(t nil) nil "name-rev"
92 + "--name-only" "--tags"
93 + commit))
94 + (goto-char (point-min))
95 + (= (forward-line 2) 1)
96 + (bolp)
97 + (buffer-substring-no-properties (point-min) (1- (point-max)))))))
98 +
99 +(defun vc-git-previous-version (file rev)
100 + "git-specific version of `vc-previous-version'."
101 + (let ((default-directory (file-name-directory (expand-file-name file)))
102 + (file (file-name-nondirectory file)))
103 + (vc-git-symbolic-commit
104 + (with-temp-buffer
105 + (and
106 + (zerop
107 + (call-process "git" nil '(t nil) nil "rev-list"
108 + "-2" rev "--" file))
109 + (goto-char (point-max))
110 + (bolp)
111 + (zerop (forward-line -1))
112 + (not (bobp))
113 + (buffer-substring-no-properties
114 + (point)
115 + (1- (point-max))))))))
116 +
117 +(defun vc-git-next-version (file rev)
118 + "git-specific version of `vc-next-version'."
119 + (let* ((default-directory (file-name-directory
120 + (expand-file-name file)))
121 + (file (file-name-nondirectory file))
122 + (current-rev
123 + (with-temp-buffer
124 + (and
125 + (zerop
126 + (call-process "git" nil '(t nil) nil "rev-list"
127 + "-1" rev "--" file))
128 + (goto-char (point-max))
129 + (bolp)
130 + (zerop (forward-line -1))
131 + (bobp)
132 + (buffer-substring-no-properties
133 + (point)
134 + (1- (point-max)))))))
135 + (and current-rev
136 + (vc-git-symbolic-commit
137 + (with-temp-buffer
138 + (and
139 + (zerop
140 + (call-process "git" nil '(t nil) nil "rev-list"
141 + "HEAD" "--" file))
142 + (goto-char (point-min))
143 + (search-forward current-rev nil t)
144 + (zerop (forward-line -1))
145 + (buffer-substring-no-properties
146 + (point)
147 + (progn (forward-line 1) (1- (point))))))))))
148 +
149 (defun vc-git-revert (file &optional contents-done)
150 "Revert FILE to the version stored in the git repository."
151 (if contents-done