Blame


1 406d7b4d 2020-12-26 op ;;; vc-got.el --- Game of Tree backend for VC -*- lexical-binding: t; -*-
2 af5ef7cd 2020-11-29 op
3 406d7b4d 2020-12-26 op ;; Copyright (C) 2020 Omar Polo
4 af5ef7cd 2020-11-29 op
5 406d7b4d 2020-12-26 op ;; Author: Omar Polo <op@venera>
6 406d7b4d 2020-12-26 op ;; Keywords: vc
7 af5ef7cd 2020-11-29 op
8 406d7b4d 2020-12-26 op ;; This program is free software; you can redistribute it and/or modify
9 406d7b4d 2020-12-26 op ;; it under the terms of the GNU General Public License as published by
10 406d7b4d 2020-12-26 op ;; the Free Software Foundation, either version 3 of the License, or
11 406d7b4d 2020-12-26 op ;; (at your option) any later version.
12 af5ef7cd 2020-11-29 op
13 406d7b4d 2020-12-26 op ;; This program is distributed in the hope that it will be useful,
14 406d7b4d 2020-12-26 op ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 406d7b4d 2020-12-26 op ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 406d7b4d 2020-12-26 op ;; GNU General Public License for more details.
17 af5ef7cd 2020-11-29 op
18 406d7b4d 2020-12-26 op ;; You should have received a copy of the GNU General Public License
19 406d7b4d 2020-12-26 op ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20 406d7b4d 2020-12-26 op
21 af5ef7cd 2020-11-29 op ;;; Commentary
22 af5ef7cd 2020-11-29 op
23 af5ef7cd 2020-11-29 op ;; Backend implementation status
24 af5ef7cd 2020-11-29 op ;;
25 af5ef7cd 2020-11-29 op ;; Function marked with `*' are required, those with `-' are optional.
26 af5ef7cd 2020-11-29 op ;;
27 af5ef7cd 2020-11-29 op ;; FUNCTION NAME STATUS
28 af5ef7cd 2020-11-29 op ;;
29 af5ef7cd 2020-11-29 op ;; BACKEND PROPERTIES:
30 af5ef7cd 2020-11-29 op ;; * revision-granularity DONE
31 af5ef7cd 2020-11-29 op ;; - update-on-retrieve-tag XXX: what should this do?
32 af5ef7cd 2020-11-29 op ;;
33 af5ef7cd 2020-11-29 op ;; STATE-QUERYING FUNCTIONS:
34 af5ef7cd 2020-11-29 op ;; * registered DONE
35 af5ef7cd 2020-11-29 op ;; * state DONE
36 af5ef7cd 2020-11-29 op ;; - dir-status-files DONE
37 a8466f02 2020-12-07 op ;; - dir-extra-headers DONE
38 2d83de2e 2021-01-05 op ;; - dir-printer DONE
39 af5ef7cd 2020-11-29 op ;; - status-fileinfo-extra NOT IMPLEMENTED
40 af5ef7cd 2020-11-29 op ;; * working-revision DONE
41 af5ef7cd 2020-11-29 op ;; * checkout-model DONE
42 694534b4 2020-12-05 op ;; - mode-line-string DONE
43 23a0b465 2020-11-30 op ;;
44 23a0b465 2020-11-30 op ;; STATE-CHANGING FUNCTIONS:
45 23a0b465 2020-11-30 op ;; * create-repo NOT IMPLEMENTED
46 eb85ad27 2020-12-05 op ;; I don't think got init does what this function is supposed to
47 eb85ad27 2020-12-05 op ;; do.
48 23a0b465 2020-11-30 op ;; * register DONE
49 23a0b465 2020-11-30 op ;; - responsible-p DONE
50 3cdb0759 2020-01-03 47739920+ ;; - receive-file NOT NEEDED, default `register' works fine
51 3d2d3c39 2020-01-03 47739920+ ;; - unregister NOT IMPLEMENTED, no use case
52 23a0b465 2020-11-30 op ;; * checkin DONE
53 23a0b465 2020-11-30 op ;; * find-revision DONE
54 eb85ad27 2020-12-05 op ;; * checkout NOT IMPLEMENTED
55 eb85ad27 2020-12-05 op ;; I'm not sure how to properly implement this. Does filling
56 eb85ad27 2020-12-05 op ;; FILE with the find-revision do the trick? Or use got update?
57 eb85ad27 2020-12-05 op ;; * revert DONE
58 eb85ad27 2020-12-05 op ;; - merge-file NOT IMPLEMENTED
59 eb85ad27 2020-12-05 op ;; - merge-branch DONE
60 eb85ad27 2020-12-05 op ;; - merge-news NOT IMPLEMENTED
61 eb85ad27 2020-12-05 op ;; - pull DONE
62 686eac9a 2020-12-07 op ;; - push DONE
63 686eac9a 2020-12-07 op ;; uses git
64 3cdb0759 2020-01-03 47739920+ ;; - steal-lock NOT NEEDED, `got' is not using locks
65 eb85ad27 2020-12-05 op ;; - modify-change-comment NOT IMPLEMENTED
66 eb85ad27 2020-12-05 op ;; can be implemented via histedit, if I understood correctly
67 eb85ad27 2020-12-05 op ;; what it is supposed to do.
68 eb85ad27 2020-12-05 op ;; - mark-resolved NOT IMPLEMENTED
69 eb85ad27 2020-12-05 op ;; - find-admin-dir NOT IMPLEMENTED
70 eb85ad27 2020-12-05 op ;;
71 eb85ad27 2020-12-05 op ;; HISTORY FUNCTIONS
72 eb85ad27 2020-12-05 op ;; * print-log DONE
73 9ad1eb5d 2020-12-07 op ;; * log-outgoing DONE
74 6eda2f1f 2020-12-26 op ;; * log-incoming DONE
75 eb85ad27 2020-12-05 op ;; - log-search DONE
76 eb85ad27 2020-12-05 op ;; - log-view-mode NOT IMPLEMENTED
77 6eda2f1f 2020-12-26 op ;; - show-log-entry NOT IMPLEMENTED
78 6eda2f1f 2020-12-26 op ;; - comment-history NOT IMPLEMENTED
79 6eda2f1f 2020-12-26 op ;; - update-changelog NOT IMPLEMENTED
80 7c257a7b 2020-12-31 noreply ;; * diff DONE
81 7c257a7b 2020-12-31 noreply ;; - revision-completion-table NOT IMPLEMENTED
82 3f25d9ff 2020-01-02 noreply ;; - annotate-command DONE
83 3f25d9ff 2020-01-02 noreply ;; - annotate-time DONE
84 7c257a7b 2020-12-31 noreply ;; - annotate-current-time NOT IMPLEMENTED
85 3f25d9ff 2020-01-02 noreply ;; - annotate-extract-revision-at-line DONE
86 7c257a7b 2020-12-31 noreply ;; - region-history NOT IMPLEMENTED
87 7c257a7b 2020-12-31 noreply ;; - region-history-mode NOT IMPLEMENTED
88 7c257a7b 2020-12-31 noreply ;; - mergebase NOT IMPLEMENTED
89 7c257a7b 2020-12-31 noreply ;;
90 7c257a7b 2020-12-31 noreply ;; TAG SYSTEM
91 7c257a7b 2020-12-31 noreply ;; - create-tag NOT IMPLEMENTED
92 7c257a7b 2020-12-31 noreply ;; - retrieve-tag NOT IMPLEMENTED
93 7c257a7b 2020-12-31 noreply ;;
94 7c257a7b 2020-12-31 noreply ;; MISCELLANEOUS NOT IMPLEMENTED
95 3cdb0759 2020-01-03 47739920+ ;; - make-version-backups-p NOT NEEDED, `got' works fine locally
96 7c257a7b 2020-12-31 noreply ;; - root DONE
97 7c257a7b 2020-12-31 noreply ;; - ignore NOT IMPLEMENTED
98 7c257a7b 2020-12-31 noreply ;; - ignore-completion-table NOT IMPLEMENTED
99 3f25d9ff 2020-01-02 noreply ;; - previous-revision DONE
100 3f25d9ff 2020-01-02 noreply ;; - next-revision DONE
101 7c257a7b 2020-12-31 noreply ;; - log-edit-mode NOT IMPLEMENTED
102 3cdb0759 2020-01-03 47739920+ ;; - check-headers NOT NEEDED, `got' does not use headers
103 a96df0e8 2020-01-03 noreply ;; - delete-file DONE
104 3cdb0759 2020-01-03 47739920+ ;; - rename-file NOT NEEDED, `delete' + `register' is enough
105 3cdb0759 2020-01-03 47739920+ ;; - find-file-hook NOT NEEDED, no need for hooks yet
106 3cdb0759 2020-01-03 47739920+ ;; - extra-menu NOT IMPLEMENTED, add `import', `integrate', `stage'?
107 3cdb0759 2020-01-03 47739920+ ;; - extra-dir-menu NOT IMPLEMENTED, same as above
108 7bb16f79 2020-01-03 op ;; - conflicted-files DONE
109 8b635a9f 2020-01-03 op ;; - repository-url DONE
110 af5ef7cd 2020-11-29 op
111 af5ef7cd 2020-11-29 op ;; TODO: use the idiom
112 af5ef7cd 2020-11-29 op ;; (let (process-file-side-effects) ...)
113 af5ef7cd 2020-11-29 op ;; when the got command WON'T change the file. This can enable some
114 af5ef7cd 2020-11-29 op ;; emacs optimizations
115 af5ef7cd 2020-11-29 op
116 eb85ad27 2020-12-05 op ;; TODO: vc-git has most function that starts with:
117 eb85ad27 2020-12-05 op ;;
118 eb85ad27 2020-12-05 op ;; (let* ((root (vc-git-root default-directory))
119 eb85ad27 2020-12-05 op ;; (buffer (format "*vc-git : %s*" (expand-file-name root)))
120 eb85ad27 2020-12-05 op ;; ...)
121 eb85ad27 2020-12-05 op ;; ...)
122 eb85ad27 2020-12-05 op ;;
123 eb85ad27 2020-12-05 op ;; we should 1) investigate if also other backends do something like
124 eb85ad27 2020-12-05 op ;; this (or if there is a better way) and 2) try to do the same.
125 eb85ad27 2020-12-05 op
126 af5ef7cd 2020-11-29 op ;;; Code:
127 af5ef7cd 2020-11-29 op
128 af5ef7cd 2020-11-29 op (eval-when-compile
129 af5ef7cd 2020-11-29 op (require 'subr-x))
130 af5ef7cd 2020-11-29 op
131 af5ef7cd 2020-11-29 op (require 'cl-lib)
132 518ede14 2020-12-05 op (require 'cl-seq)
133 af5ef7cd 2020-11-29 op (require 'seq)
134 23a0b465 2020-11-30 op (require 'vc)
135 3f25d9ff 2020-01-02 noreply (require 'vc-annotate)
136 6b6c8a78 2021-01-04 op
137 2d83de2e 2021-01-05 op ;; FIXME: avoid loading this? We only need it for
138 2d83de2e 2021-01-05 op ;; vc-dir-filename-mouse-map in our custom printer.
139 2d83de2e 2021-01-05 op (require 'vc-dir)
140 2d83de2e 2021-01-05 op
141 6b6c8a78 2021-01-04 op (require 'vc-got-stage)
142 ba123905 2020-12-08 op
143 e79563bd 2020-12-31 noreply (defgroup vc-got nil
144 e79563bd 2020-12-31 noreply "VC GoT backend."
145 e79563bd 2020-12-31 noreply :group 'vc)
146 af5ef7cd 2020-11-29 op
147 e79563bd 2020-12-31 noreply (defcustom vc-got-program "got"
148 e79563bd 2020-12-31 noreply "Name of the Got executable (excluding any arguments)."
149 6eea6cfb 2021-01-05 op :type 'string)
150 e79563bd 2020-12-31 noreply
151 12ca62f2 2020-12-26 op (defcustom vc-got-diff-switches t
152 12ca62f2 2020-12-26 op "String or list of strings specifying switches for Got diff under VC.
153 12ca62f2 2020-12-26 op If nil, use the value of `vc-diff-switches'. If t, use no switches."
154 12ca62f2 2020-12-26 op :type '(choice (const :tag "Unspecified" nil)
155 12ca62f2 2020-12-26 op (const :tag "None" t)
156 12ca62f2 2020-12-26 op (string :tag "Argument String")
157 6eea6cfb 2021-01-05 op (repeat :tag "Argument List" :value ("") string)))
158 12ca62f2 2020-12-26 op
159 af5ef7cd 2020-11-29 op ;; helpers
160 f09d6359 2020-12-31 noreply (defun vc-got--program-version ()
161 67332bad 2021-01-05 op "Return the version string of used `Got' command."
162 f09d6359 2020-12-31 noreply (let (process-file-side-effects)
163 f09d6359 2020-12-31 noreply (with-temp-buffer
164 f09d6359 2020-12-31 noreply (vc-got--call "-V")
165 f09d6359 2020-12-31 noreply (substring (buffer-string) 4 -1))))
166 af5ef7cd 2020-11-29 op
167 af5ef7cd 2020-11-29 op (defun vc-got-root (file)
168 af5ef7cd 2020-11-29 op "Return the work tree root for FILE, or nil."
169 f6e414a6 2020-11-30 op (or (vc-file-getprop file 'got-root)
170 f6e414a6 2020-11-30 op (vc-file-setprop file 'got-root (vc-find-root file ".got"))))
171 af5ef7cd 2020-11-29 op
172 af5ef7cd 2020-11-29 op (defmacro vc-got-with-worktree (file &rest body)
173 af5ef7cd 2020-11-29 op "Evaluate BODY in the work tree directory of FILE."
174 af5ef7cd 2020-11-29 op (declare (indent defun))
175 af5ef7cd 2020-11-29 op `(when-let (default-directory (vc-got-root ,file))
176 af5ef7cd 2020-11-29 op ,@body))
177 686eac9a 2020-12-07 op
178 686eac9a 2020-12-07 op (defun vc-got--repo-root ()
179 686eac9a 2020-12-07 op "Return the path to the repository root.
180 686eac9a 2020-12-07 op Assume `default-directory' is inside a got worktree."
181 686eac9a 2020-12-07 op (vc-got-with-worktree default-directory
182 686eac9a 2020-12-07 op (with-temp-buffer
183 686eac9a 2020-12-07 op (insert-file-contents ".got/repository")
184 686eac9a 2020-12-07 op (string-trim (buffer-string) nil "\n"))))
185 af5ef7cd 2020-11-29 op
186 af5ef7cd 2020-11-29 op (defun vc-got--call (&rest args)
187 e79563bd 2020-12-31 noreply "Call `vc-got-program' in the `default-directory' with ARGS and put the output in the current buffer."
188 fab791a2 2020-01-03 op (apply #'process-file vc-got-program nil (current-buffer) nil
189 fab791a2 2020-01-03 op (cl-remove-if #'null (flatten-list args))))
190 af5ef7cd 2020-11-29 op
191 23a0b465 2020-11-30 op (defun vc-got--add (files)
192 23a0b465 2020-11-30 op "Add FILES to got, passing `vc-register-switches' to the command invocation."
193 23a0b465 2020-11-30 op (with-temp-buffer
194 23a0b465 2020-11-30 op (apply #'vc-got--call "add" (append vc-register-switches files))))
195 23a0b465 2020-11-30 op
196 0a66694e 2020-01-02 op (defun vc-got--log (&optional path limit start-commit stop-commit
197 0a66694e 2020-01-02 op search-pattern reverse)
198 23a0b465 2020-11-30 op "Execute the log command in the worktree of PATH.
199 518ede14 2020-12-05 op The output in the current buffer.
200 af5ef7cd 2020-11-29 op
201 23a0b465 2020-11-30 op LIMIT limits the maximum number of commit returned.
202 23a0b465 2020-11-30 op
203 518ede14 2020-12-05 op START-COMMIT: start traversing history at the specified commit.
204 9ad1eb5d 2020-12-07 op STOP-COMMIT: stop traversing history at the specified commit.
205 518ede14 2020-12-05 op SEARCH-PATTERN: limit to log messages matched by the regexp given.
206 0a66694e 2020-01-02 op REVERSE: display the log messages in reverse order.
207 518ede14 2020-12-05 op
208 23a0b465 2020-11-30 op Return nil if the command failed or if PATH isn't included in any
209 23a0b465 2020-11-30 op worktree."
210 0a66694e 2020-01-02 op (let (process-file-side-effects)
211 0a66694e 2020-01-02 op (vc-got-with-worktree (or path default-directory)
212 0a66694e 2020-01-02 op (zerop
213 fab791a2 2020-01-03 op (vc-got--call "log"
214 fab791a2 2020-01-03 op (when limit (list "-l" (format "%s" limit)))
215 fab791a2 2020-01-03 op (when start-commit (list "-c" start-commit))
216 fab791a2 2020-01-03 op (when stop-commit (list "-x" stop-commit))
217 fab791a2 2020-01-03 op (when search-pattern (list "-s" search-pattern))
218 fab791a2 2020-01-03 op (when reverse '("-R"))
219 fab791a2 2020-01-03 op path)))))
220 af5ef7cd 2020-11-29 op
221 668dc8eb 2021-01-04 op (defun vc-got--status (status-codes dir-or-file &rest files)
222 668dc8eb 2021-01-04 op "Return a list of lists '(FILE STATUS STAGE-STATUS).
223 af5ef7cd 2020-11-29 op DIR-OR-FILE can be either a directory or a file. If FILES is
224 af5ef7cd 2020-11-29 op given, return the status of those files, otherwise the status of
225 668dc8eb 2021-01-04 op DIR-OR-FILE. STATUS-CODES is either nil, or a string that's
226 668dc8eb 2021-01-04 op passed as the -s flag to got status to limit the types of status
227 668dc8eb 2021-01-04 op to report (e.g. \"CD\" to report only conflicts and deleted
228 668dc8eb 2021-01-04 op files)."
229 af5ef7cd 2020-11-29 op (vc-got-with-worktree dir-or-file
230 af5ef7cd 2020-11-29 op (with-temp-buffer
231 668dc8eb 2021-01-04 op (when (zerop (vc-got--call "status"
232 668dc8eb 2021-01-04 op (when status-codes (list "-s" status-codes))
233 668dc8eb 2021-01-04 op (or files dir-or-file)))
234 668dc8eb 2021-01-04 op (goto-char (point-min))
235 668dc8eb 2021-01-04 op (cl-loop until (eobp)
236 668dc8eb 2021-01-04 op ;; the format of each line is
237 668dc8eb 2021-01-04 op ;; <status-char> <stage-char> <spc> <filename> \n
238 2d83de2e 2021-01-05 op collect (let* ((file-status (prog1 (vc-got--parse-status-char
239 2d83de2e 2021-01-05 op (char-after))
240 668dc8eb 2021-01-04 op (forward-char)))
241 2d83de2e 2021-01-05 op (stage-status (prog1 (vc-got--parse-stage-char
242 2d83de2e 2021-01-05 op (char-after))
243 668dc8eb 2021-01-04 op (forward-char)))
244 668dc8eb 2021-01-04 op (filename (progn
245 668dc8eb 2021-01-04 op (forward-char)
246 668dc8eb 2021-01-04 op (buffer-substring (point)
247 668dc8eb 2021-01-04 op (line-end-position)))))
248 668dc8eb 2021-01-04 op (list filename
249 2d83de2e 2021-01-05 op (or file-status (and stage-status 'up-to-date))
250 2d83de2e 2021-01-05 op stage-status))
251 668dc8eb 2021-01-04 op do (forward-line))))))
252 af5ef7cd 2020-11-29 op
253 668dc8eb 2021-01-04 op (defun vc-got--parse-status-char (c)
254 668dc8eb 2021-01-04 op "Parse status char C into a symbol accepted by `vc-state'."
255 668dc8eb 2021-01-04 op (cl-case c
256 668dc8eb 2021-01-04 op (?M 'edited)
257 668dc8eb 2021-01-04 op (?A 'added)
258 668dc8eb 2021-01-04 op (?D 'removed)
259 668dc8eb 2021-01-04 op (?C 'conflict)
260 668dc8eb 2021-01-04 op (?! 'missing)
261 668dc8eb 2021-01-04 op (?~ 'edited) ;XXX: what does it means for a file to be ``obstructed''?
262 668dc8eb 2021-01-04 op (?? 'unregistered)
263 668dc8eb 2021-01-04 op (?m 'edited) ;modified file modes
264 668dc8eb 2021-01-04 op (?N nil)))
265 af5ef7cd 2020-11-29 op
266 668dc8eb 2021-01-04 op (defun vc-got--parse-stage-char (c)
267 668dc8eb 2021-01-04 op "Parse the stage status char C into a symbol."
268 668dc8eb 2021-01-04 op (cl-case c
269 2d83de2e 2021-01-05 op (?M 'edit)
270 2d83de2e 2021-01-05 op (?A 'add)
271 2d83de2e 2021-01-05 op (?D 'remove)))
272 af5ef7cd 2020-11-29 op
273 23a0b465 2020-11-30 op (defun vc-got--tree-parse ()
274 23a0b465 2020-11-30 op "Parse into an alist the output of got tree -i in the current buffer."
275 23a0b465 2020-11-30 op (goto-char (point-min))
276 23a0b465 2020-11-30 op (cl-loop
277 23a0b465 2020-11-30 op until (= (point) (point-max))
278 23a0b465 2020-11-30 op collect (let* ((obj-start (point))
279 23a0b465 2020-11-30 op (_ (forward-word))
280 23a0b465 2020-11-30 op (obj (buffer-substring obj-start (point)))
281 23a0b465 2020-11-30 op (_ (forward-char)) ;skip the space
282 23a0b465 2020-11-30 op (filename-start (point))
283 23a0b465 2020-11-30 op (_ (move-end-of-line nil))
284 23a0b465 2020-11-30 op (filename (buffer-substring filename-start (point))))
285 23a0b465 2020-11-30 op ;; goto the start of the next line
286 23a0b465 2020-11-30 op (forward-line)
287 23a0b465 2020-11-30 op (move-beginning-of-line nil)
288 23a0b465 2020-11-30 op `(,filename . ,obj))))
289 23a0b465 2020-11-30 op
290 23a0b465 2020-11-30 op (defun vc-got--tree (commit path)
291 67332bad 2021-01-05 op "Return an alist representing the got tree command output.
292 67332bad 2021-01-05 op The outputted tree will be localised for the given PATH at the
293 67332bad 2021-01-05 op given COMMIT."
294 23a0b465 2020-11-30 op (vc-got-with-worktree path
295 23a0b465 2020-11-30 op (with-temp-buffer
296 23a0b465 2020-11-30 op (vc-got--call "tree" "-c" commit "-i" path)
297 23a0b465 2020-11-30 op (vc-got--tree-parse))))
298 23a0b465 2020-11-30 op
299 23a0b465 2020-11-30 op (defun vc-got--cat (commit obj-id)
300 23a0b465 2020-11-30 op "Execute got cat -c COMMIT OBJ-ID in the current buffer."
301 23a0b465 2020-11-30 op (vc-got--call "cat" "-c" commit obj-id))
302 eb85ad27 2020-12-05 op
303 eb85ad27 2020-12-05 op (defun vc-got--revert (&rest files)
304 eb85ad27 2020-12-05 op "Execute got revert FILES..."
305 eb85ad27 2020-12-05 op (vc-got-with-worktree (car files)
306 eb85ad27 2020-12-05 op (with-temp-buffer
307 eb85ad27 2020-12-05 op (apply #'vc-got--call "revert" files))))
308 eb85ad27 2020-12-05 op
309 eb85ad27 2020-12-05 op (defun vc-got--list-branches ()
310 eb85ad27 2020-12-05 op "Return an alist of (branch . commit)."
311 eb85ad27 2020-12-05 op (with-temp-buffer
312 eb85ad27 2020-12-05 op (when (zerop (vc-got--call "branch" "-l"))
313 eb85ad27 2020-12-05 op (goto-char (point-min))
314 eb85ad27 2020-12-05 op (cl-loop
315 eb85ad27 2020-12-05 op until (= (point) (point-max))
316 eb85ad27 2020-12-05 op ;; parse the `* $branchname: $commit', from the end
317 eb85ad27 2020-12-05 op collect (let* ((_ (move-end-of-line nil))
318 eb85ad27 2020-12-05 op (end-commit (point))
319 eb85ad27 2020-12-05 op (_ (backward-word))
320 eb85ad27 2020-12-05 op (start-commit (point))
321 eb85ad27 2020-12-05 op (_ (backward-char 2))
322 eb85ad27 2020-12-05 op (end-branchname (point))
323 eb85ad27 2020-12-05 op (_ (move-beginning-of-line nil))
324 eb85ad27 2020-12-05 op (_ (forward-char 2))
325 eb85ad27 2020-12-05 op (start-branchname (point))
326 eb85ad27 2020-12-05 op (branchname (buffer-substring start-branchname end-branchname))
327 eb85ad27 2020-12-05 op (commit (buffer-substring start-commit end-commit)))
328 eb85ad27 2020-12-05 op (forward-line)
329 eb85ad27 2020-12-05 op (move-beginning-of-line nil)
330 eb85ad27 2020-12-05 op `(,branchname . ,commit))))))
331 eb85ad27 2020-12-05 op
332 694534b4 2020-12-05 op (defun vc-got--current-branch ()
333 694534b4 2020-12-05 op "Return the current branch."
334 694534b4 2020-12-05 op (with-temp-buffer
335 694534b4 2020-12-05 op (when (zerop (vc-got--call "branch"))
336 694534b4 2020-12-05 op (string-trim (buffer-string) "" "\n"))))
337 eb85ad27 2020-12-05 op
338 eb85ad27 2020-12-05 op (defun vc-got--integrate (branch)
339 eb85ad27 2020-12-05 op "Integrate BRANCH into the current one."
340 eb85ad27 2020-12-05 op (with-temp-buffer
341 eb85ad27 2020-12-05 op (vc-got--call "integrate" branch)))
342 23a0b465 2020-11-30 op
343 eb85ad27 2020-12-05 op (defun vc-got--diff (&rest args)
344 eb85ad27 2020-12-05 op "Call got diff with ARGS. The result will be stored in the current buffer."
345 345290bf 2020-12-05 op (apply #'vc-got--call "diff"
346 12ca62f2 2020-12-26 op (append (vc-switches 'got 'diff)
347 12ca62f2 2020-12-26 op (mapcar #'file-relative-name args))))
348 6b6c8a78 2021-01-04 op
349 6b6c8a78 2021-01-04 op (defun vc-got--unstage (file-or-directory)
350 6b6c8a78 2021-01-04 op "Unstage all the staged hunks at or within FILE-OR-DIRECTORY.
351 6b6c8a78 2021-01-04 op If it's nil, unstage every staged changes across the entire work
352 6b6c8a78 2021-01-04 op tree."
353 6b6c8a78 2021-01-04 op (vc-got--call "unstage" file-or-directory))
354 a96df0e8 2020-01-03 noreply
355 a96df0e8 2020-01-03 noreply (defun vc-got--remove (file &optional force keep-local)
356 a96df0e8 2020-01-03 noreply "Internal helper to removing FILE from got."
357 a96df0e8 2020-01-03 noreply (vc-got-with-worktree (or file default-directory)
358 a96df0e8 2020-01-03 noreply (with-temp-buffer
359 a96df0e8 2020-01-03 noreply (vc-got--call "remove"
360 a96df0e8 2020-01-03 noreply (when force "-f")
361 a96df0e8 2020-01-03 noreply (when keep-local "-k")
362 a96df0e8 2020-01-03 noreply file))))
363 eb85ad27 2020-12-05 op
364 af5ef7cd 2020-11-29 op
365 af5ef7cd 2020-11-29 op ;; Backend properties
366 af5ef7cd 2020-11-29 op
367 af5ef7cd 2020-11-29 op (defun vc-got-revision-granularity ()
368 af5ef7cd 2020-11-29 op "Got has REPOSITORY granularity."
369 af5ef7cd 2020-11-29 op 'repository)
370 af5ef7cd 2020-11-29 op
371 af5ef7cd 2020-11-29 op ;; XXX: what this should do? The description is not entirely clear
372 af5ef7cd 2020-11-29 op (defun vc-got-update-on-retrieve-tag ()
373 af5ef7cd 2020-11-29 op nil)
374 af5ef7cd 2020-11-29 op
375 af5ef7cd 2020-11-29 op
376 af5ef7cd 2020-11-29 op ;; State-querying functions
377 af5ef7cd 2020-11-29 op
378 af5ef7cd 2020-11-29 op ;;;###autoload (defun vc-got-registered (file)
379 af5ef7cd 2020-11-29 op ;;;###autoload "Return non-nil if FILE is registered with got."
380 af5ef7cd 2020-11-29 op ;;;###autoload (when (vc-find-root file ".got")
381 af5ef7cd 2020-11-29 op ;;;###autoload (load "vc-got" nil t)
382 af5ef7cd 2020-11-29 op ;;;###autoload (vc-got-registered file)))
383 af5ef7cd 2020-11-29 op
384 af5ef7cd 2020-11-29 op (defun vc-got-registered (file)
385 af5ef7cd 2020-11-29 op "Return non-nil if FILE is registered with got."
386 af5ef7cd 2020-11-29 op (if (file-directory-p file)
387 af5ef7cd 2020-11-29 op nil ;got doesn't track directories
388 4093d2f9 2020-12-04 op (when (vc-find-root file ".got")
389 668dc8eb 2021-01-04 op (let ((s (vc-got-state file)))
390 668dc8eb 2021-01-04 op (not (or (eq s 'unregistered)
391 668dc8eb 2021-01-04 op (null s)))))))
392 af5ef7cd 2020-11-29 op
393 af5ef7cd 2020-11-29 op (defun vc-got-state (file)
394 af5ef7cd 2020-11-29 op "Return the current version control state of FILE. See `vc-state'."
395 af5ef7cd 2020-11-29 op (unless (file-directory-p file)
396 668dc8eb 2021-01-04 op ;; Manually calling got status and checking the result inline to
397 668dc8eb 2021-01-04 op ;; avoid building the data structure in vc-got--status.
398 668dc8eb 2021-01-04 op (with-temp-buffer
399 668dc8eb 2021-01-04 op (when (zerop (vc-got--call "status" file))
400 668dc8eb 2021-01-04 op (goto-char (point-min))
401 cf4e3ebe 2021-01-04 op (if (eobp)
402 cf4e3ebe 2021-01-04 op 'up-to-date
403 cf4e3ebe 2021-01-04 op (vc-got--parse-status-char (char-after)))))))
404 af5ef7cd 2020-11-29 op
405 af5ef7cd 2020-11-29 op (defun vc-got-dir-status-files (dir files update-function)
406 5b4a6b90 2021-01-04 op "Build the status for FILES in DIR.
407 5b4a6b90 2021-01-04 op The builded result is given to the callback UPDATE-FUNCTIONS. If
408 5b4a6b90 2021-01-04 op FILES is nil, consider all the files in DIR."
409 82289421 2020-01-02 op (let* ((fs (seq-filter (lambda (file)
410 82289421 2020-01-02 op (and (not (string= file ".."))
411 82289421 2020-01-02 op (not (string= file "."))
412 82289421 2020-01-02 op (not (string= file ".got"))))
413 82289421 2020-01-02 op (or files
414 82289421 2020-01-02 op (directory-files dir))))
415 668dc8eb 2021-01-04 op (res (vc-got--status nil dir files)))
416 82289421 2020-01-02 op (cl-loop for file in fs
417 668dc8eb 2021-01-04 op do (let ((s (unless (or (cdr (assoc file res #'string=))
418 8ed796d4 2021-01-04 op (file-directory-p file))
419 8ed796d4 2021-01-04 op (when (file-exists-p file)
420 82289421 2020-01-02 op ;; if file doesn't exists, it's a
421 82289421 2020-01-02 op ;; untracked file that was removed.
422 8ed796d4 2021-01-04 op (list file 'up-to-date nil)))))
423 82289421 2020-01-02 op (when s
424 82289421 2020-01-02 op (push s res)))
425 82289421 2020-01-02 op finally (funcall update-function res nil))))
426 af5ef7cd 2020-11-29 op
427 c27df03e 2020-01-03 op (defun vc-got-dir-extra-headers (dir)
428 c27df03e 2020-01-03 op "Return a string for the `vc-dir' buffer heading for directory DIR."
429 c27df03e 2020-01-03 op (concat (propertize "Repository : " 'face 'font-lock-type-face)
430 c27df03e 2020-01-03 op (vc-got--repo-root) "\n"
431 c27df03e 2020-01-03 op (propertize "Remote URL : " 'face 'font-lock-type-face)
432 c27df03e 2020-01-03 op (vc-got-repository-url dir) "\n"
433 c27df03e 2020-01-03 op (propertize "Branch : " 'face 'font-lock-type-face)
434 c27df03e 2020-01-03 op (vc-got--current-branch)))
435 2d83de2e 2021-01-05 op
436 2d83de2e 2021-01-05 op (defun vc-got-dir-printer (info)
437 2d83de2e 2021-01-05 op "Pretty-printer for the vc-dir-fileinfo structure INFO."
438 2d83de2e 2021-01-05 op (let* ((isdir (vc-dir-fileinfo->directory info))
439 2d83de2e 2021-01-05 op (state (if isdir "" (vc-dir-fileinfo->state info)))
440 2d83de2e 2021-01-05 op (stage-state (vc-dir-fileinfo->extra info))
441 2d83de2e 2021-01-05 op (filename (vc-dir-fileinfo->name info)))
442 2d83de2e 2021-01-05 op (insert
443 2d83de2e 2021-01-05 op (propertize
444 2d83de2e 2021-01-05 op (format "%c" (if (vc-dir-fileinfo->marked info) ?* ? ))
445 2d83de2e 2021-01-05 op 'face 'font-lock-type-face)
446 9e019413 2021-01-05 op " "
447 9e019413 2021-01-05 op (propertize
448 9e019413 2021-01-05 op (if stage-state
449 9e019413 2021-01-05 op (format "staged:%-6s" stage-state)
450 9e019413 2021-01-05 op (format "%-13s" ""))
451 9e019413 2021-01-05 op 'face (cond ((memq stage-state '(add edit)) 'font-lock-constant-face)
452 9e019413 2021-01-05 op ((eq stage-state 'remove) 'font-lock-warning-face)
453 9e019413 2021-01-05 op (t 'font-lock-variable-name-face)))
454 9e019413 2021-01-05 op " "
455 2d83de2e 2021-01-05 op (propertize
456 2d83de2e 2021-01-05 op (format "%-14s" state)
457 2d83de2e 2021-01-05 op 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
458 2d83de2e 2021-01-05 op ((memq state '(missing conflict)) 'font-lock-warning-face)
459 2d83de2e 2021-01-05 op ((eq state 'edited) 'font-lock-constant-face)
460 2d83de2e 2021-01-05 op (t 'font-lock-variable-name-face))
461 2d83de2e 2021-01-05 op 'mouse-face 'highlight)
462 2d83de2e 2021-01-05 op " "
463 2d83de2e 2021-01-05 op (propertize
464 2d83de2e 2021-01-05 op (format "%s" filename)
465 2d83de2e 2021-01-05 op 'face
466 2d83de2e 2021-01-05 op (if isdir 'font-lock-comment-delimiter-face 'font-lock-function-name-face)
467 2d83de2e 2021-01-05 op 'help-echo
468 2d83de2e 2021-01-05 op (if isdir
469 2d83de2e 2021-01-05 op "Directory\nVC operations can be applied to it\nmouse-3: Pop-up menu"
470 2d83de2e 2021-01-05 op "File\nmouse-3: Pop-up menu")
471 2d83de2e 2021-01-05 op 'mouse-face 'highlight
472 2d83de2e 2021-01-05 op 'keymap vc-dir-filename-mouse-map))))
473 a8466f02 2020-12-07 op
474 af5ef7cd 2020-11-29 op (defun vc-got-working-revision (file)
475 c0c9a339 2020-12-04 op "Return the id of the last commit that touched the FILE or \"0\" for a new (but added) file."
476 af5ef7cd 2020-11-29 op (or
477 af5ef7cd 2020-11-29 op (with-temp-buffer
478 518ede14 2020-12-05 op (when (vc-got--log file 1)
479 af5ef7cd 2020-11-29 op (let (start)
480 af5ef7cd 2020-11-29 op (goto-char (point-min))
481 af5ef7cd 2020-11-29 op (forward-line 1) ;skip the ----- line
482 af5ef7cd 2020-11-29 op (forward-word) ;skip "commit"
483 af5ef7cd 2020-11-29 op (forward-char) ;skip the space
484 af5ef7cd 2020-11-29 op (setq start (point)) ;store start of the SHA
485 af5ef7cd 2020-11-29 op (forward-word) ;goto SHA end
486 af5ef7cd 2020-11-29 op (buffer-substring start (point)))))
487 af5ef7cd 2020-11-29 op ;; special case: if this file is added but has no previous commits
488 af5ef7cd 2020-11-29 op ;; touching it, got log will fail (as expected), but we have to
489 af5ef7cd 2020-11-29 op ;; return "0".
490 af5ef7cd 2020-11-29 op (when (eq (vc-got-state file) 'added)
491 af5ef7cd 2020-11-29 op "0")))
492 af5ef7cd 2020-11-29 op
493 af5ef7cd 2020-11-29 op (defun vc-got-checkout-model (_files)
494 5b4a6b90 2021-01-04 op "Got uses an implicit checkout model for every file."
495 af5ef7cd 2020-11-29 op 'implicit)
496 af5ef7cd 2020-11-29 op
497 694534b4 2020-12-05 op (defun vc-got-mode-line-string (file)
498 694534b4 2020-12-05 op "Return the VC mode line string for FILE."
499 694534b4 2020-12-05 op (vc-got-with-worktree file
500 694534b4 2020-12-05 op (let ((def (vc-default-mode-line-string 'Got file)))
501 694534b4 2020-12-05 op (concat (substring def 0 4) (vc-got--current-branch)))))
502 694534b4 2020-12-05 op
503 23a0b465 2020-11-30 op
504 23a0b465 2020-11-30 op ;; state-changing functions
505 23a0b465 2020-11-30 op
506 23a0b465 2020-11-30 op (defun vc-got-create-repo (_backend)
507 23a0b465 2020-11-30 op (error "vc got: create-repo not implemented"))
508 23a0b465 2020-11-30 op
509 23a0b465 2020-11-30 op (defun vc-got-register (files &optional _comment)
510 23a0b465 2020-11-30 op "Register FILES, passing `vc-register-switches' to the backend command."
511 23a0b465 2020-11-30 op (vc-got--add files))
512 23a0b465 2020-11-30 op
513 9e805da8 2020-11-30 op (defalias 'vc-got-responsible-p #'vc-got-root)
514 23a0b465 2020-11-30 op
515 daae979d 2021-01-04 op ;; XXX: generally speaking, files cannot be nil. But we have to
516 daae979d 2021-01-04 op ;; handle that case too, because vc-got-stage-commit will call
517 ffa81a1d 2021-01-04 op ;; vc-got-checkin with fileset nil to commit the current staged hunks.
518 23a0b465 2020-11-30 op (defun vc-got-checkin (files comment &optional _rev)
519 23a0b465 2020-11-30 op "Commit FILES with COMMENT as commit message."
520 23a0b465 2020-11-30 op (with-temp-buffer
521 30dcedec 2020-12-05 op (apply #'vc-got--call "commit" "-m"
522 30dcedec 2020-12-05 op ;; emacs add ``Summary:'' at the start of the commit
523 30dcedec 2020-12-05 op ;; message. vc-git doesn't seem to treat this specially.
524 30dcedec 2020-12-05 op ;; Since it's annoying, remove it.
525 30dcedec 2020-12-05 op (string-remove-prefix "Summary: " comment)
526 30dcedec 2020-12-05 op files)))
527 23a0b465 2020-11-30 op
528 23a0b465 2020-11-30 op (defun vc-got-find-revision (file rev buffer)
529 c0c9a339 2020-12-04 op "Fill BUFFER with the content of FILE in the given revision REV."
530 23a0b465 2020-11-30 op (when-let (obj-id (assoc file (vc-got--tree rev file) #'string=))
531 23a0b465 2020-11-30 op (with-current-buffer buffer
532 23a0b465 2020-11-30 op (vc-got-with-worktree file
533 23a0b465 2020-11-30 op (vc-got--cat rev obj-id)))))
534 23a0b465 2020-11-30 op
535 55091167 2020-12-05 op (defun vc-got-find-ignore-file (file)
536 55091167 2020-12-05 op "Return the gitignore file that controls FILE."
537 55091167 2020-12-05 op (expand-file-name ".gitignore"
538 55091167 2020-12-05 op (vc-got-root file)))
539 55091167 2020-12-05 op
540 eb85ad27 2020-12-05 op (defun vc-got-checkout (_file &optional _rev)
541 eb85ad27 2020-12-05 op "Checkout revision REV of FILE. If REV is t, checkout from the head."
542 eb85ad27 2020-12-05 op (error "vc got: checkout not implemented"))
543 eb85ad27 2020-12-05 op
544 eb85ad27 2020-12-05 op (defun vc-got-revert (file &optional _content-done)
545 eb85ad27 2020-12-05 op "Revert FILE back to working revision."
546 eb85ad27 2020-12-05 op (vc-got--revert file))
547 eb85ad27 2020-12-05 op
548 eb85ad27 2020-12-05 op (defun vc-got-merge-branch ()
549 eb85ad27 2020-12-05 op "Prompt for a branch and integrate it into the current one."
550 eb85ad27 2020-12-05 op ;; XXX: be smart and try to "got rebase" if "got integrate" fails?
551 eb85ad27 2020-12-05 op (let* ((branches (cl-loop for (branch . commit) in (vc-got--list-branches)
552 eb85ad27 2020-12-05 op collect branch))
553 eb85ad27 2020-12-05 op (branch (completing-read "Merge from branch: " branches)))
554 eb85ad27 2020-12-05 op (when branch
555 eb85ad27 2020-12-05 op (vc-got--integrate branch))))
556 686eac9a 2020-12-07 op
557 686eac9a 2020-12-07 op (defun vc-got--push-pull (cmd op prompt root)
558 686eac9a 2020-12-07 op "Execute CMD OP, or prompt the user if PROMPT is non-nil.
559 686eac9a 2020-12-07 op ROOT is the worktree root."
560 686eac9a 2020-12-07 op (let ((buffer (format "*vc-got : %s*" (expand-file-name root))))
561 686eac9a 2020-12-07 op (when-let (cmd (if prompt
562 686eac9a 2020-12-07 op (split-string
563 686eac9a 2020-12-07 op (read-shell-command (format "%s %s command: " cmd op)
564 686eac9a 2020-12-07 op (format "%s %s" cmd op))
565 686eac9a 2020-12-07 op " " t)
566 686eac9a 2020-12-07 op (list cmd op)))
567 686eac9a 2020-12-07 op (apply #'vc-do-command buffer 0 (car cmd) nil (cdr cmd)))))
568 eb85ad27 2020-12-05 op
569 eb85ad27 2020-12-05 op (defun vc-got-pull (prompt)
570 eb85ad27 2020-12-05 op "Execute got pull, prompting the user for the full command if PROMPT is not nil."
571 e79563bd 2020-12-31 noreply (vc-got--push-pull vc-got-program "fetch" prompt (vc-got-root default-directory)))
572 686eac9a 2020-12-07 op
573 686eac9a 2020-12-07 op (defun vc-got-push (prompt)
574 686eac9a 2020-12-07 op "Run git push (not got!) in the repository dir.
575 686eac9a 2020-12-07 op If PROMPT is non-nil, prompt for the git command to run."
576 eb85ad27 2020-12-05 op (let* ((root (vc-got-root default-directory))
577 686eac9a 2020-12-07 op (default-directory (vc-got--repo-root)))
578 686eac9a 2020-12-07 op (vc-got--push-pull "git" "push" prompt root)))
579 eb85ad27 2020-12-05 op
580 eb85ad27 2020-12-05 op (defun vc-got-print-log (files buffer &optional _shortlog start-revision limit)
581 eb85ad27 2020-12-05 op "Insert the revision log for FILES into BUFFER.
582 eb85ad27 2020-12-05 op
583 eb85ad27 2020-12-05 op LIMIT limits the number of commits, optionally starting at START-REVISION."
584 eb85ad27 2020-12-05 op (with-current-buffer buffer
585 eb85ad27 2020-12-05 op ;; the *vc-diff* may be read only
586 4571b1fd 2020-12-05 op (let ((inhibit-read-only t))
587 eb85ad27 2020-12-05 op (cl-loop for file in files
588 4571b1fd 2020-12-05 op do (vc-got--log (file-relative-name file) limit start-revision)))))
589 eb85ad27 2020-12-05 op
590 9ad1eb5d 2020-12-07 op ;; XXX: this includes also the latest commit in REMOTE-LOCATION.
591 9ad1eb5d 2020-12-07 op (defun vc-got-log-outgoing (buffer remote-location)
592 9ad1eb5d 2020-12-07 op "Fill BUFFER with the diff between the local worktree branch and REMOTE-LOCATION."
593 9ad1eb5d 2020-12-07 op (vc-setup-buffer buffer)
594 9ad1eb5d 2020-12-07 op (let ((rl (if (or (not remote-location) (string-empty-p remote-location))
595 9ad1eb5d 2020-12-07 op (concat "origin/" (vc-got--current-branch))
596 9ad1eb5d 2020-12-07 op remote-location))
597 9ad1eb5d 2020-12-07 op (inhibit-read-only t))
598 9ad1eb5d 2020-12-07 op (with-current-buffer buffer
599 9ad1eb5d 2020-12-07 op (vc-got--log nil nil nil rl))))
600 6eda2f1f 2020-12-26 op
601 6eda2f1f 2020-12-26 op (defun vc-got-incoming (buffer remote-location)
602 6eda2f1f 2020-12-26 op "Fill BUFFER with the diff between the REMOTE-LOCATION and the local worktree branch."
603 6eda2f1f 2020-12-26 op (let ((rl (if (or (not remote-location) (string-empty-p remote-location))
604 6eda2f1f 2020-12-26 op (concat "origin/" (vc-got--current-branch))
605 6eda2f1f 2020-12-26 op remote-location))
606 6eda2f1f 2020-12-26 op (inhibit-read-only t))
607 6eda2f1f 2020-12-26 op (with-current-buffer buffer
608 6eda2f1f 2020-12-26 op (vc-got--log nil nil (vc-got--current-branch) rl))))
609 9ad1eb5d 2020-12-07 op
610 eb85ad27 2020-12-05 op (defun vc-got-log-search (buffer pattern)
611 eb85ad27 2020-12-05 op "Search commits for PATTERN and write the results found in BUFFER."
612 eb85ad27 2020-12-05 op (with-current-buffer buffer
613 eb85ad27 2020-12-05 op (let ((inhibit-read-only t))
614 9ad1eb5d 2020-12-07 op (vc-got--log nil nil nil nil pattern))))
615 eb85ad27 2020-12-05 op
616 eb85ad27 2020-12-05 op ;; TODO: async
617 f18d3e11 2020-12-05 op ;; TODO: return 0 or 1
618 eb85ad27 2020-12-05 op (defun vc-got-diff (files &optional rev1 rev2 buffer _async)
619 eb85ad27 2020-12-05 op "Insert into BUFFER (or *vc-diff*) the diff for FILES from REV1 to REV2."
620 f457868b 2020-12-07 op (let* ((buffer (get-buffer-create (or buffer "*vc-diff*")))
621 eb85ad27 2020-12-05 op (inhibit-read-only t))
622 eb85ad27 2020-12-05 op (with-current-buffer buffer
623 eb85ad27 2020-12-05 op (vc-got-with-worktree (car files)
624 eb85ad27 2020-12-05 op (cond ((and (null rev1)
625 eb85ad27 2020-12-05 op (null rev2))
626 986bd9a0 2020-12-27 op (dolist (file files)
627 986bd9a0 2020-12-27 op (vc-got--diff file)))
628 eb85ad27 2020-12-05 op (t (error "Not implemented")))))))
629 3f25d9ff 2020-01-02 noreply
630 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-command (file buf &optional rev)
631 67332bad 2021-01-05 op "Show annotated contents of FILE in buffer BUF. If given, use revision REV."
632 3f25d9ff 2020-01-02 noreply (let (process-file-side-effects)
633 3f25d9ff 2020-01-02 noreply (with-current-buffer buf
634 3f25d9ff 2020-01-02 noreply ;; FIXME: vc-ensure-vc-buffer won't recognise this buffer as managed
635 3f25d9ff 2020-01-02 noreply ;; by got unless vc-parent-buffer points to a buffer managed by got.
636 3f25d9ff 2020-01-02 noreply ;; investigate why this is needed.
637 3f25d9ff 2020-01-02 noreply (set (make-local-variable 'vc-parent-buffer) (find-file-noselect file))
638 3f25d9ff 2020-01-02 noreply (apply #'vc-got--call "blame" (if rev
639 3f25d9ff 2020-01-02 noreply (list "-c" rev file)
640 3f25d9ff 2020-01-02 noreply (list file))))))
641 3f25d9ff 2020-01-02 noreply
642 3f25d9ff 2020-01-02 noreply (defconst vc-got--annotate-re
643 3f25d9ff 2020-01-02 noreply (concat "^[0-9]\\{1,\\}) " ; line number followed by )
644 3f25d9ff 2020-01-02 noreply "\\([a-z0-9]+\\) " ; SHA-1 of commit
645 3f25d9ff 2020-01-02 noreply "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\) " ; year-mm-dd
646 3f25d9ff 2020-01-02 noreply "\\([^ ]\\)+ ") ; author
647 3f25d9ff 2020-01-02 noreply "Regexp to match annotation output lines.
648 3f25d9ff 2020-01-02 noreply
649 3f25d9ff 2020-01-02 noreply Provides capture groups for:
650 3f25d9ff 2020-01-02 noreply 1. revision id
651 3f25d9ff 2020-01-02 noreply 2. date of commit
652 3f25d9ff 2020-01-02 noreply 3. author of commit")
653 3f25d9ff 2020-01-02 noreply
654 3f25d9ff 2020-01-02 noreply (defconst vc-got--commit-re "^commit \\([a-z0-9]+\\)"
655 3f25d9ff 2020-01-02 noreply "Regexp to match commit lines.
656 3f25d9ff 2020-01-02 noreply
657 3f25d9ff 2020-01-02 noreply Provides capture group for the commit revision id.")
658 3f25d9ff 2020-01-02 noreply
659 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-time ()
660 3f25d9ff 2020-01-02 noreply "Return the time of the next line of annotation at or after point.
661 3f25d9ff 2020-01-02 noreply Value is returned as floating point fractional number of days."
662 3f25d9ff 2020-01-02 noreply (save-excursion
663 3f25d9ff 2020-01-02 noreply (beginning-of-line)
664 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--annotate-re)
665 3f25d9ff 2020-01-02 noreply (let ((str (match-string-no-properties 2)))
666 3f25d9ff 2020-01-02 noreply (vc-annotate-convert-time
667 3f25d9ff 2020-01-02 noreply (encode-time 0 0 0
668 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 8 10))
669 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 5 7))
670 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 0 4))))))))
671 eb85ad27 2020-12-05 op
672 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-extract-revision-at-line ()
673 67332bad 2021-01-05 op "Return revision corresponding to the current line or nil."
674 3f25d9ff 2020-01-02 noreply (save-excursion
675 3f25d9ff 2020-01-02 noreply (beginning-of-line)
676 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--annotate-re)
677 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1))))
678 3f25d9ff 2020-01-02 noreply
679 3f25d9ff 2020-01-02 noreply (defun vc-got-previous-revision (file rev)
680 3f25d9ff 2020-01-02 noreply "Return the revision number that precedes REV for FILE, or nil if no such revision exists."
681 3f25d9ff 2020-01-02 noreply (with-temp-buffer
682 3f25d9ff 2020-01-02 noreply (vc-got--log file 2 rev nil nil t)
683 3f25d9ff 2020-01-02 noreply (goto-char (point-min))
684 3f25d9ff 2020-01-02 noreply (keep-lines "^commit")
685 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--commit-re)
686 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1))))
687 3f25d9ff 2020-01-02 noreply
688 3f25d9ff 2020-01-02 noreply (defun vc-got-next-revision (file rev)
689 67332bad 2021-01-05 op "Return the revision number that follows REV for FILE, or nil if no such revision exists."
690 3f25d9ff 2020-01-02 noreply (with-temp-buffer
691 3f25d9ff 2020-01-02 noreply (vc-got--log file nil nil rev)
692 3f25d9ff 2020-01-02 noreply (keep-lines "^commit" (point-min) (point-max))
693 3f25d9ff 2020-01-02 noreply (goto-char (point-max))
694 3f25d9ff 2020-01-02 noreply (forward-line -1) ;; return from empty line to last actual commit
695 3f25d9ff 2020-01-02 noreply (unless (= (point) (point-min))
696 3f25d9ff 2020-01-02 noreply (forward-line -1)
697 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--commit-re)
698 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1)))))
699 3f25d9ff 2020-01-02 noreply
700 a96df0e8 2020-01-03 noreply (defun vc-got-delete-file (file)
701 a96df0e8 2020-01-03 noreply "Delete FILE locally and mark it deleted in work tree."
702 a96df0e8 2020-01-03 noreply (vc-got--remove file t))
703 a96df0e8 2020-01-03 noreply
704 7bb16f79 2020-01-03 op (defun vc-got-conflicted-files (dir)
705 7bb16f79 2020-01-03 op "Return the list of files with conflicts in directory DIR."
706 7bb16f79 2020-01-03 op (let* ((root (vc-got-root dir))
707 7bb16f79 2020-01-03 op (default-directory root)
708 7bb16f79 2020-01-03 op (process-file-side-effects))
709 7bb16f79 2020-01-03 op ;; for got it doesn't matter where we call "got status", it will
710 7bb16f79 2020-01-03 op ;; always report file paths from the root of the repo.
711 7bb16f79 2020-01-03 op (cl-loop with conflicts = nil
712 668dc8eb 2021-01-04 op for (file status _) in (vc-got--status "C" ".")
713 7bb16f79 2020-01-03 op do (when (and (eq status 'conflict)
714 7bb16f79 2020-01-03 op (file-in-directory-p file dir))
715 7bb16f79 2020-01-03 op (push file conflicts))
716 7bb16f79 2020-01-03 op finally return conflicts)))
717 7bb16f79 2020-01-03 op
718 8b635a9f 2020-01-03 op (defun vc-got-repository-url (_file &optional remote-name)
719 8b635a9f 2020-01-03 op "Return URL for REMOTE-NAME, or for \"origin\" if nil."
720 8b635a9f 2020-01-03 op (let* ((default-directory (vc-got--repo-root))
721 8b635a9f 2020-01-03 op (remote-name (or remote-name "origin"))
722 8b635a9f 2020-01-03 op (heading (concat "[remote \"" remote-name "\"]"))
723 f8a9db56 2020-01-03 op (conf (cond ((file-exists-p ".git/config")
724 f8a9db56 2020-01-03 op ".git/config")
725 f8a9db56 2020-01-03 op ((file-exists-p ".git")
726 f8a9db56 2020-01-03 op nil)
727 f8a9db56 2020-01-03 op ((file-exists-p "config")
728 f8a9db56 2020-01-03 op "config")))
729 8b635a9f 2020-01-03 op found)
730 8b635a9f 2020-01-03 op (with-temp-buffer
731 f8a9db56 2020-01-03 op (when conf
732 f8a9db56 2020-01-03 op (insert-file-contents conf)
733 f8a9db56 2020-01-03 op (goto-char (point-min))
734 f8a9db56 2020-01-03 op (when (search-forward heading nil t)
735 f8a9db56 2020-01-03 op (forward-line)
736 f8a9db56 2020-01-03 op (while (and (not found)
737 7a5ead65 2020-01-03 op (looking-at ".*=") ;too broad?
738 7a5ead65 2020-01-03 op (not (= (point) (point-max))))
739 f8a9db56 2020-01-03 op (when (looking-at ".*url = \\(.*\\)")
740 7a5ead65 2020-01-03 op (setq found (match-string-no-properties 1)))
741 7a5ead65 2020-01-03 op (forward-line))
742 f8a9db56 2020-01-03 op found)))))
743 8b635a9f 2020-01-03 op
744 2d83de2e 2021-01-05 op
745 2d83de2e 2021-01-05 op ;; hacks
746 2d83de2e 2021-01-05 op (defun vc-got-fix-dir-move-to-goal-column (fn)
747 2d83de2e 2021-01-05 op "Move the cursor on the file column.
748 2d83de2e 2021-01-05 op Adviced around vc-dir-move-to-goal-column because it hardcodes column 25."
749 2d83de2e 2021-01-05 op (if (not (vc-find-root default-directory ".got"))
750 2d83de2e 2021-01-05 op (funcall fn)
751 2d83de2e 2021-01-05 op (beginning-of-line)
752 2d83de2e 2021-01-05 op (unless (eolp)
753 9e019413 2021-01-05 op (forward-char 31))))
754 2d83de2e 2021-01-05 op (advice-add 'vc-dir-move-to-goal-column :around #'vc-got-fix-dir-move-to-goal-column)
755 2d83de2e 2021-01-05 op
756 af5ef7cd 2020-11-29 op (provide 'vc-got)
757 af5ef7cd 2020-11-29 op ;;; vc-got.el ends here