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 af5ef7cd 2020-11-29 op ;; - dir-printer NOT IMPLEMENTED
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 6b6c8a78 2021-01-04 op (require 'vc-got-stage)
138 ba123905 2020-12-08 op
139 e79563bd 2020-12-31 noreply (defgroup vc-got nil
140 e79563bd 2020-12-31 noreply "VC GoT backend."
141 e79563bd 2020-12-31 noreply :group 'vc)
142 af5ef7cd 2020-11-29 op
143 e79563bd 2020-12-31 noreply (defcustom vc-got-program "got"
144 e79563bd 2020-12-31 noreply "Name of the Got executable (excluding any arguments)."
145 e79563bd 2020-12-31 noreply :type 'string
146 e79563bd 2020-12-31 noreply :group 'vc-got)
147 e79563bd 2020-12-31 noreply
148 12ca62f2 2020-12-26 op (defcustom vc-got-diff-switches t
149 12ca62f2 2020-12-26 op "String or list of strings specifying switches for Got diff under VC.
150 12ca62f2 2020-12-26 op If nil, use the value of `vc-diff-switches'. If t, use no switches."
151 12ca62f2 2020-12-26 op :type '(choice (const :tag "Unspecified" nil)
152 12ca62f2 2020-12-26 op (const :tag "None" t)
153 12ca62f2 2020-12-26 op (string :tag "Argument String")
154 e79563bd 2020-12-31 noreply (repeat :tag "Argument List" :value ("") string))
155 e79563bd 2020-12-31 noreply :group 'vc-got)
156 12ca62f2 2020-12-26 op
157 af5ef7cd 2020-11-29 op ;; helpers
158 f09d6359 2020-12-31 noreply (defun vc-got--program-version ()
159 f09d6359 2020-12-31 noreply "Returns the version string of used `Got' command."
160 f09d6359 2020-12-31 noreply (let (process-file-side-effects)
161 f09d6359 2020-12-31 noreply (with-temp-buffer
162 f09d6359 2020-12-31 noreply (vc-got--call "-V")
163 f09d6359 2020-12-31 noreply (substring (buffer-string) 4 -1))))
164 af5ef7cd 2020-11-29 op
165 af5ef7cd 2020-11-29 op (defun vc-got-root (file)
166 af5ef7cd 2020-11-29 op "Return the work tree root for FILE, or nil."
167 f6e414a6 2020-11-30 op (or (vc-file-getprop file 'got-root)
168 f6e414a6 2020-11-30 op (vc-file-setprop file 'got-root (vc-find-root file ".got"))))
169 af5ef7cd 2020-11-29 op
170 af5ef7cd 2020-11-29 op (defmacro vc-got-with-worktree (file &rest body)
171 af5ef7cd 2020-11-29 op "Evaluate BODY in the work tree directory of FILE."
172 af5ef7cd 2020-11-29 op (declare (indent defun))
173 af5ef7cd 2020-11-29 op `(when-let (default-directory (vc-got-root ,file))
174 af5ef7cd 2020-11-29 op ,@body))
175 686eac9a 2020-12-07 op
176 686eac9a 2020-12-07 op (defun vc-got--repo-root ()
177 686eac9a 2020-12-07 op "Return the path to the repository root.
178 686eac9a 2020-12-07 op Assume `default-directory' is inside a got worktree."
179 686eac9a 2020-12-07 op (vc-got-with-worktree default-directory
180 686eac9a 2020-12-07 op (with-temp-buffer
181 686eac9a 2020-12-07 op (insert-file-contents ".got/repository")
182 686eac9a 2020-12-07 op (string-trim (buffer-string) nil "\n"))))
183 af5ef7cd 2020-11-29 op
184 af5ef7cd 2020-11-29 op (defun vc-got--call (&rest args)
185 e79563bd 2020-12-31 noreply "Call `vc-got-program' in the `default-directory' with ARGS and put the output in the current buffer."
186 fab791a2 2020-01-03 op (apply #'process-file vc-got-program nil (current-buffer) nil
187 fab791a2 2020-01-03 op (cl-remove-if #'null (flatten-list args))))
188 af5ef7cd 2020-11-29 op
189 23a0b465 2020-11-30 op (defun vc-got--add (files)
190 23a0b465 2020-11-30 op "Add FILES to got, passing `vc-register-switches' to the command invocation."
191 23a0b465 2020-11-30 op (with-temp-buffer
192 23a0b465 2020-11-30 op (apply #'vc-got--call "add" (append vc-register-switches files))))
193 23a0b465 2020-11-30 op
194 0a66694e 2020-01-02 op (defun vc-got--log (&optional path limit start-commit stop-commit
195 0a66694e 2020-01-02 op search-pattern reverse)
196 23a0b465 2020-11-30 op "Execute the log command in the worktree of PATH.
197 518ede14 2020-12-05 op The output in the current buffer.
198 af5ef7cd 2020-11-29 op
199 23a0b465 2020-11-30 op LIMIT limits the maximum number of commit returned.
200 23a0b465 2020-11-30 op
201 518ede14 2020-12-05 op START-COMMIT: start traversing history at the specified commit.
202 9ad1eb5d 2020-12-07 op STOP-COMMIT: stop traversing history at the specified commit.
203 518ede14 2020-12-05 op SEARCH-PATTERN: limit to log messages matched by the regexp given.
204 0a66694e 2020-01-02 op REVERSE: display the log messages in reverse order.
205 518ede14 2020-12-05 op
206 23a0b465 2020-11-30 op Return nil if the command failed or if PATH isn't included in any
207 23a0b465 2020-11-30 op worktree."
208 0a66694e 2020-01-02 op (let (process-file-side-effects)
209 0a66694e 2020-01-02 op (vc-got-with-worktree (or path default-directory)
210 0a66694e 2020-01-02 op (zerop
211 fab791a2 2020-01-03 op (vc-got--call "log"
212 fab791a2 2020-01-03 op (when limit (list "-l" (format "%s" limit)))
213 fab791a2 2020-01-03 op (when start-commit (list "-c" start-commit))
214 fab791a2 2020-01-03 op (when stop-commit (list "-x" stop-commit))
215 fab791a2 2020-01-03 op (when search-pattern (list "-s" search-pattern))
216 fab791a2 2020-01-03 op (when reverse '("-R"))
217 fab791a2 2020-01-03 op path)))))
218 af5ef7cd 2020-11-29 op
219 af5ef7cd 2020-11-29 op (defun vc-got--status (dir-or-file &rest files)
220 af5ef7cd 2020-11-29 op "Return the output of ``got status''.
221 af5ef7cd 2020-11-29 op
222 af5ef7cd 2020-11-29 op DIR-OR-FILE can be either a directory or a file. If FILES is
223 af5ef7cd 2020-11-29 op given, return the status of those files, otherwise the status of
224 af5ef7cd 2020-11-29 op DIR-OR-FILE."
225 af5ef7cd 2020-11-29 op (vc-got-with-worktree dir-or-file
226 af5ef7cd 2020-11-29 op (with-temp-buffer
227 af5ef7cd 2020-11-29 op (if files
228 af5ef7cd 2020-11-29 op (apply #'vc-got--call "status" files)
229 af5ef7cd 2020-11-29 op (vc-got--call "status" dir-or-file))
230 af5ef7cd 2020-11-29 op (buffer-string))))
231 af5ef7cd 2020-11-29 op
232 af5ef7cd 2020-11-29 op (defun vc-got--parse-status-flag (flag)
233 af5ef7cd 2020-11-29 op "Parse FLAG, see `vc-state'."
234 af5ef7cd 2020-11-29 op ;; got outputs nothing if the file is up-to-date
235 af5ef7cd 2020-11-29 op (if (string-empty-p flag)
236 af5ef7cd 2020-11-29 op 'up-to-date
237 af5ef7cd 2020-11-29 op ;; trying to follow the order of the manpage
238 af5ef7cd 2020-11-29 op (cl-case (aref flag 0)
239 af5ef7cd 2020-11-29 op (?M 'edited)
240 af5ef7cd 2020-11-29 op (?A 'added)
241 af5ef7cd 2020-11-29 op (?D 'removed)
242 af5ef7cd 2020-11-29 op (?C 'conflict)
243 af5ef7cd 2020-11-29 op (?! 'missing)
244 af5ef7cd 2020-11-29 op (?~ 'edited) ;XXX: what does it means for a file to be ``obstructed''?
245 af5ef7cd 2020-11-29 op (?? 'unregistered)
246 af5ef7cd 2020-11-29 op (?m 'edited) ;modified file modes
247 af5ef7cd 2020-11-29 op (?N nil))))
248 af5ef7cd 2020-11-29 op
249 af5ef7cd 2020-11-29 op (defun vc-got--parse-status (output)
250 af5ef7cd 2020-11-29 op "Parse the OUTPUT of got status and return an alist of (FILE . STATUS)."
251 af5ef7cd 2020-11-29 op ;; XXX: the output of got is line-oriented and will break if
252 af5ef7cd 2020-11-29 op ;; filenames contains spaces or newlines.
253 af5ef7cd 2020-11-29 op (cl-loop for line in (split-string output "\n" t)
254 af5ef7cd 2020-11-29 op collect (cl-destructuring-bind (status file) (split-string line " " t " ")
255 af5ef7cd 2020-11-29 op `(,file . ,(vc-got--parse-status-flag status)))))
256 af5ef7cd 2020-11-29 op
257 23a0b465 2020-11-30 op (defun vc-got--tree-parse ()
258 23a0b465 2020-11-30 op "Parse into an alist the output of got tree -i in the current buffer."
259 23a0b465 2020-11-30 op (goto-char (point-min))
260 23a0b465 2020-11-30 op (cl-loop
261 23a0b465 2020-11-30 op until (= (point) (point-max))
262 23a0b465 2020-11-30 op collect (let* ((obj-start (point))
263 23a0b465 2020-11-30 op (_ (forward-word))
264 23a0b465 2020-11-30 op (obj (buffer-substring obj-start (point)))
265 23a0b465 2020-11-30 op (_ (forward-char)) ;skip the space
266 23a0b465 2020-11-30 op (filename-start (point))
267 23a0b465 2020-11-30 op (_ (move-end-of-line nil))
268 23a0b465 2020-11-30 op (filename (buffer-substring filename-start (point))))
269 23a0b465 2020-11-30 op ;; goto the start of the next line
270 23a0b465 2020-11-30 op (forward-line)
271 23a0b465 2020-11-30 op (move-beginning-of-line nil)
272 23a0b465 2020-11-30 op `(,filename . ,obj))))
273 23a0b465 2020-11-30 op
274 23a0b465 2020-11-30 op (defun vc-got--tree (commit path)
275 23a0b465 2020-11-30 op (vc-got-with-worktree path
276 23a0b465 2020-11-30 op (with-temp-buffer
277 23a0b465 2020-11-30 op (vc-got--call "tree" "-c" commit "-i" path)
278 23a0b465 2020-11-30 op (vc-got--tree-parse))))
279 23a0b465 2020-11-30 op
280 23a0b465 2020-11-30 op (defun vc-got--cat (commit obj-id)
281 23a0b465 2020-11-30 op "Execute got cat -c COMMIT OBJ-ID in the current buffer."
282 23a0b465 2020-11-30 op (vc-got--call "cat" "-c" commit obj-id))
283 eb85ad27 2020-12-05 op
284 eb85ad27 2020-12-05 op (defun vc-got--revert (&rest files)
285 eb85ad27 2020-12-05 op "Execute got revert FILES..."
286 eb85ad27 2020-12-05 op (vc-got-with-worktree (car files)
287 eb85ad27 2020-12-05 op (with-temp-buffer
288 eb85ad27 2020-12-05 op (apply #'vc-got--call "revert" files))))
289 eb85ad27 2020-12-05 op
290 eb85ad27 2020-12-05 op (defun vc-got--list-branches ()
291 eb85ad27 2020-12-05 op "Return an alist of (branch . commit)."
292 eb85ad27 2020-12-05 op (with-temp-buffer
293 eb85ad27 2020-12-05 op (when (zerop (vc-got--call "branch" "-l"))
294 eb85ad27 2020-12-05 op (goto-char (point-min))
295 eb85ad27 2020-12-05 op (cl-loop
296 eb85ad27 2020-12-05 op until (= (point) (point-max))
297 eb85ad27 2020-12-05 op ;; parse the `* $branchname: $commit', from the end
298 eb85ad27 2020-12-05 op collect (let* ((_ (move-end-of-line nil))
299 eb85ad27 2020-12-05 op (end-commit (point))
300 eb85ad27 2020-12-05 op (_ (backward-word))
301 eb85ad27 2020-12-05 op (start-commit (point))
302 eb85ad27 2020-12-05 op (_ (backward-char 2))
303 eb85ad27 2020-12-05 op (end-branchname (point))
304 eb85ad27 2020-12-05 op (_ (move-beginning-of-line nil))
305 eb85ad27 2020-12-05 op (_ (forward-char 2))
306 eb85ad27 2020-12-05 op (start-branchname (point))
307 eb85ad27 2020-12-05 op (branchname (buffer-substring start-branchname end-branchname))
308 eb85ad27 2020-12-05 op (commit (buffer-substring start-commit end-commit)))
309 eb85ad27 2020-12-05 op (forward-line)
310 eb85ad27 2020-12-05 op (move-beginning-of-line nil)
311 eb85ad27 2020-12-05 op `(,branchname . ,commit))))))
312 eb85ad27 2020-12-05 op
313 694534b4 2020-12-05 op (defun vc-got--current-branch ()
314 694534b4 2020-12-05 op "Return the current branch."
315 694534b4 2020-12-05 op (with-temp-buffer
316 694534b4 2020-12-05 op (when (zerop (vc-got--call "branch"))
317 694534b4 2020-12-05 op (string-trim (buffer-string) "" "\n"))))
318 eb85ad27 2020-12-05 op
319 eb85ad27 2020-12-05 op (defun vc-got--integrate (branch)
320 eb85ad27 2020-12-05 op "Integrate BRANCH into the current one."
321 eb85ad27 2020-12-05 op (with-temp-buffer
322 eb85ad27 2020-12-05 op (vc-got--call "integrate" branch)))
323 23a0b465 2020-11-30 op
324 eb85ad27 2020-12-05 op (defun vc-got--diff (&rest args)
325 eb85ad27 2020-12-05 op "Call got diff with ARGS. The result will be stored in the current buffer."
326 345290bf 2020-12-05 op (apply #'vc-got--call "diff"
327 12ca62f2 2020-12-26 op (append (vc-switches 'got 'diff)
328 12ca62f2 2020-12-26 op (mapcar #'file-relative-name args))))
329 6b6c8a78 2021-01-04 op
330 6b6c8a78 2021-01-04 op (defun vc-got--unstage (file-or-directory)
331 6b6c8a78 2021-01-04 op "Unstage all the staged hunks at or within FILE-OR-DIRECTORY.
332 6b6c8a78 2021-01-04 op If it's nil, unstage every staged changes across the entire work
333 6b6c8a78 2021-01-04 op tree."
334 6b6c8a78 2021-01-04 op (vc-got--call "unstage" file-or-directory))
335 a96df0e8 2020-01-03 noreply
336 a96df0e8 2020-01-03 noreply (defun vc-got--remove (file &optional force keep-local)
337 a96df0e8 2020-01-03 noreply "Internal helper to removing FILE from got."
338 a96df0e8 2020-01-03 noreply (vc-got-with-worktree (or file default-directory)
339 a96df0e8 2020-01-03 noreply (with-temp-buffer
340 a96df0e8 2020-01-03 noreply (vc-got--call "remove"
341 a96df0e8 2020-01-03 noreply (when force "-f")
342 a96df0e8 2020-01-03 noreply (when keep-local "-k")
343 a96df0e8 2020-01-03 noreply file))))
344 eb85ad27 2020-12-05 op
345 af5ef7cd 2020-11-29 op
346 af5ef7cd 2020-11-29 op ;; Backend properties
347 af5ef7cd 2020-11-29 op
348 af5ef7cd 2020-11-29 op (defun vc-got-revision-granularity ()
349 af5ef7cd 2020-11-29 op "Got has REPOSITORY granularity."
350 af5ef7cd 2020-11-29 op 'repository)
351 af5ef7cd 2020-11-29 op
352 af5ef7cd 2020-11-29 op ;; XXX: what this should do? The description is not entirely clear
353 af5ef7cd 2020-11-29 op (defun vc-got-update-on-retrieve-tag ()
354 af5ef7cd 2020-11-29 op nil)
355 af5ef7cd 2020-11-29 op
356 af5ef7cd 2020-11-29 op
357 af5ef7cd 2020-11-29 op ;; State-querying functions
358 af5ef7cd 2020-11-29 op
359 af5ef7cd 2020-11-29 op ;;;###autoload (defun vc-got-registered (file)
360 af5ef7cd 2020-11-29 op ;;;###autoload "Return non-nil if FILE is registered with got."
361 af5ef7cd 2020-11-29 op ;;;###autoload (when (vc-find-root file ".got")
362 af5ef7cd 2020-11-29 op ;;;###autoload (load "vc-got" nil t)
363 af5ef7cd 2020-11-29 op ;;;###autoload (vc-got-registered file)))
364 af5ef7cd 2020-11-29 op
365 af5ef7cd 2020-11-29 op (defun vc-got-registered (file)
366 af5ef7cd 2020-11-29 op "Return non-nil if FILE is registered with got."
367 af5ef7cd 2020-11-29 op (if (file-directory-p file)
368 af5ef7cd 2020-11-29 op nil ;got doesn't track directories
369 4093d2f9 2020-12-04 op (when (vc-find-root file ".got")
370 4093d2f9 2020-12-04 op (let ((status (vc-got--status file)))
371 4093d2f9 2020-12-04 op (not (or (string-prefix-p "?" status)
372 4093d2f9 2020-12-04 op (string-prefix-p "N" status)))))))
373 af5ef7cd 2020-11-29 op
374 af5ef7cd 2020-11-29 op (defun vc-got-state (file)
375 af5ef7cd 2020-11-29 op "Return the current version control state of FILE. See `vc-state'."
376 af5ef7cd 2020-11-29 op (unless (file-directory-p file)
377 af5ef7cd 2020-11-29 op (vc-got--parse-status-flag (vc-got--status file))))
378 af5ef7cd 2020-11-29 op
379 af5ef7cd 2020-11-29 op (defun vc-got-dir-status-files (dir files update-function)
380 82289421 2020-01-02 op (let* ((fs (seq-filter (lambda (file)
381 82289421 2020-01-02 op (and (not (string= file ".."))
382 82289421 2020-01-02 op (not (string= file "."))
383 82289421 2020-01-02 op (not (string= file ".got"))))
384 82289421 2020-01-02 op (or files
385 82289421 2020-01-02 op (directory-files dir))))
386 82289421 2020-01-02 op (stats (vc-got--parse-status (apply #'vc-got--status dir files)))
387 8ed796d4 2021-01-04 op (res (mapcar (lambda (x)
388 8ed796d4 2021-01-04 op (list (car x) (cdr x) nil))
389 8ed796d4 2021-01-04 op stats)))
390 82289421 2020-01-02 op (cl-loop for file in fs
391 8ed796d4 2021-01-04 op do (let ((s (unless (or (cdr (assoc file stats #'string=))
392 8ed796d4 2021-01-04 op (file-directory-p file))
393 8ed796d4 2021-01-04 op (when (file-exists-p file)
394 82289421 2020-01-02 op ;; if file doesn't exists, it's a
395 82289421 2020-01-02 op ;; untracked file that was removed.
396 8ed796d4 2021-01-04 op (list file 'up-to-date nil)))))
397 82289421 2020-01-02 op (when s
398 82289421 2020-01-02 op (push s res)))
399 82289421 2020-01-02 op finally (funcall update-function res nil))))
400 af5ef7cd 2020-11-29 op
401 c27df03e 2020-01-03 op (defun vc-got-dir-extra-headers (dir)
402 c27df03e 2020-01-03 op "Return a string for the `vc-dir' buffer heading for directory DIR."
403 c27df03e 2020-01-03 op (concat (propertize "Repository : " 'face 'font-lock-type-face)
404 c27df03e 2020-01-03 op (vc-got--repo-root) "\n"
405 c27df03e 2020-01-03 op (propertize "Remote URL : " 'face 'font-lock-type-face)
406 c27df03e 2020-01-03 op (vc-got-repository-url dir) "\n"
407 c27df03e 2020-01-03 op (propertize "Branch : " 'face 'font-lock-type-face)
408 c27df03e 2020-01-03 op (vc-got--current-branch)))
409 a8466f02 2020-12-07 op
410 af5ef7cd 2020-11-29 op (defun vc-got-working-revision (file)
411 c0c9a339 2020-12-04 op "Return the id of the last commit that touched the FILE or \"0\" for a new (but added) file."
412 af5ef7cd 2020-11-29 op (or
413 af5ef7cd 2020-11-29 op (with-temp-buffer
414 518ede14 2020-12-05 op (when (vc-got--log file 1)
415 af5ef7cd 2020-11-29 op (let (start)
416 af5ef7cd 2020-11-29 op (goto-char (point-min))
417 af5ef7cd 2020-11-29 op (forward-line 1) ;skip the ----- line
418 af5ef7cd 2020-11-29 op (forward-word) ;skip "commit"
419 af5ef7cd 2020-11-29 op (forward-char) ;skip the space
420 af5ef7cd 2020-11-29 op (setq start (point)) ;store start of the SHA
421 af5ef7cd 2020-11-29 op (forward-word) ;goto SHA end
422 af5ef7cd 2020-11-29 op (buffer-substring start (point)))))
423 af5ef7cd 2020-11-29 op ;; special case: if this file is added but has no previous commits
424 af5ef7cd 2020-11-29 op ;; touching it, got log will fail (as expected), but we have to
425 af5ef7cd 2020-11-29 op ;; return "0".
426 af5ef7cd 2020-11-29 op (when (eq (vc-got-state file) 'added)
427 af5ef7cd 2020-11-29 op "0")))
428 af5ef7cd 2020-11-29 op
429 af5ef7cd 2020-11-29 op (defun vc-got-checkout-model (_files)
430 af5ef7cd 2020-11-29 op 'implicit)
431 af5ef7cd 2020-11-29 op
432 694534b4 2020-12-05 op (defun vc-got-mode-line-string (file)
433 694534b4 2020-12-05 op "Return the VC mode line string for FILE."
434 694534b4 2020-12-05 op (vc-got-with-worktree file
435 694534b4 2020-12-05 op (let ((def (vc-default-mode-line-string 'Got file)))
436 694534b4 2020-12-05 op (concat (substring def 0 4) (vc-got--current-branch)))))
437 694534b4 2020-12-05 op
438 23a0b465 2020-11-30 op
439 23a0b465 2020-11-30 op ;; state-changing functions
440 23a0b465 2020-11-30 op
441 23a0b465 2020-11-30 op (defun vc-got-create-repo (_backend)
442 23a0b465 2020-11-30 op (error "vc got: create-repo not implemented"))
443 23a0b465 2020-11-30 op
444 23a0b465 2020-11-30 op (defun vc-got-register (files &optional _comment)
445 23a0b465 2020-11-30 op "Register FILES, passing `vc-register-switches' to the backend command."
446 23a0b465 2020-11-30 op (vc-got--add files))
447 23a0b465 2020-11-30 op
448 9e805da8 2020-11-30 op (defalias 'vc-got-responsible-p #'vc-got-root)
449 23a0b465 2020-11-30 op
450 23a0b465 2020-11-30 op (defun vc-got-checkin (files comment &optional _rev)
451 23a0b465 2020-11-30 op "Commit FILES with COMMENT as commit message."
452 23a0b465 2020-11-30 op (with-temp-buffer
453 30dcedec 2020-12-05 op (apply #'vc-got--call "commit" "-m"
454 30dcedec 2020-12-05 op ;; emacs add ``Summary:'' at the start of the commit
455 30dcedec 2020-12-05 op ;; message. vc-git doesn't seem to treat this specially.
456 30dcedec 2020-12-05 op ;; Since it's annoying, remove it.
457 30dcedec 2020-12-05 op (string-remove-prefix "Summary: " comment)
458 30dcedec 2020-12-05 op files)))
459 23a0b465 2020-11-30 op
460 23a0b465 2020-11-30 op (defun vc-got-find-revision (file rev buffer)
461 c0c9a339 2020-12-04 op "Fill BUFFER with the content of FILE in the given revision REV."
462 23a0b465 2020-11-30 op (when-let (obj-id (assoc file (vc-got--tree rev file) #'string=))
463 23a0b465 2020-11-30 op (with-current-buffer buffer
464 23a0b465 2020-11-30 op (vc-got-with-worktree file
465 23a0b465 2020-11-30 op (vc-got--cat rev obj-id)))))
466 23a0b465 2020-11-30 op
467 55091167 2020-12-05 op (defun vc-got-find-ignore-file (file)
468 55091167 2020-12-05 op "Return the gitignore file that controls FILE."
469 55091167 2020-12-05 op (expand-file-name ".gitignore"
470 55091167 2020-12-05 op (vc-got-root file)))
471 55091167 2020-12-05 op
472 eb85ad27 2020-12-05 op (defun vc-got-checkout (_file &optional _rev)
473 eb85ad27 2020-12-05 op "Checkout revision REV of FILE. If REV is t, checkout from the head."
474 eb85ad27 2020-12-05 op (error "vc got: checkout not implemented"))
475 eb85ad27 2020-12-05 op
476 eb85ad27 2020-12-05 op (defun vc-got-revert (file &optional _content-done)
477 eb85ad27 2020-12-05 op "Revert FILE back to working revision."
478 eb85ad27 2020-12-05 op (vc-got--revert file))
479 eb85ad27 2020-12-05 op
480 eb85ad27 2020-12-05 op (defun vc-got-merge-branch ()
481 eb85ad27 2020-12-05 op "Prompt for a branch and integrate it into the current one."
482 eb85ad27 2020-12-05 op ;; XXX: be smart and try to "got rebase" if "got integrate" fails?
483 eb85ad27 2020-12-05 op (let* ((branches (cl-loop for (branch . commit) in (vc-got--list-branches)
484 eb85ad27 2020-12-05 op collect branch))
485 eb85ad27 2020-12-05 op (branch (completing-read "Merge from branch: " branches)))
486 eb85ad27 2020-12-05 op (when branch
487 eb85ad27 2020-12-05 op (vc-got--integrate branch))))
488 686eac9a 2020-12-07 op
489 686eac9a 2020-12-07 op (defun vc-got--push-pull (cmd op prompt root)
490 686eac9a 2020-12-07 op "Execute CMD OP, or prompt the user if PROMPT is non-nil.
491 686eac9a 2020-12-07 op ROOT is the worktree root."
492 686eac9a 2020-12-07 op (let ((buffer (format "*vc-got : %s*" (expand-file-name root))))
493 686eac9a 2020-12-07 op (when-let (cmd (if prompt
494 686eac9a 2020-12-07 op (split-string
495 686eac9a 2020-12-07 op (read-shell-command (format "%s %s command: " cmd op)
496 686eac9a 2020-12-07 op (format "%s %s" cmd op))
497 686eac9a 2020-12-07 op " " t)
498 686eac9a 2020-12-07 op (list cmd op)))
499 686eac9a 2020-12-07 op (apply #'vc-do-command buffer 0 (car cmd) nil (cdr cmd)))))
500 eb85ad27 2020-12-05 op
501 eb85ad27 2020-12-05 op (defun vc-got-pull (prompt)
502 eb85ad27 2020-12-05 op "Execute got pull, prompting the user for the full command if PROMPT is not nil."
503 e79563bd 2020-12-31 noreply (vc-got--push-pull vc-got-program "fetch" prompt (vc-got-root default-directory)))
504 686eac9a 2020-12-07 op
505 686eac9a 2020-12-07 op (defun vc-got-push (prompt)
506 686eac9a 2020-12-07 op "Run git push (not got!) in the repository dir.
507 686eac9a 2020-12-07 op If PROMPT is non-nil, prompt for the git command to run."
508 eb85ad27 2020-12-05 op (let* ((root (vc-got-root default-directory))
509 686eac9a 2020-12-07 op (default-directory (vc-got--repo-root)))
510 686eac9a 2020-12-07 op (vc-got--push-pull "git" "push" prompt root)))
511 eb85ad27 2020-12-05 op
512 eb85ad27 2020-12-05 op (defun vc-got-print-log (files buffer &optional _shortlog start-revision limit)
513 eb85ad27 2020-12-05 op "Insert the revision log for FILES into BUFFER.
514 eb85ad27 2020-12-05 op
515 eb85ad27 2020-12-05 op LIMIT limits the number of commits, optionally starting at START-REVISION."
516 eb85ad27 2020-12-05 op (with-current-buffer buffer
517 eb85ad27 2020-12-05 op ;; the *vc-diff* may be read only
518 4571b1fd 2020-12-05 op (let ((inhibit-read-only t))
519 eb85ad27 2020-12-05 op (cl-loop for file in files
520 4571b1fd 2020-12-05 op do (vc-got--log (file-relative-name file) limit start-revision)))))
521 eb85ad27 2020-12-05 op
522 9ad1eb5d 2020-12-07 op ;; XXX: this includes also the latest commit in REMOTE-LOCATION.
523 9ad1eb5d 2020-12-07 op (defun vc-got-log-outgoing (buffer remote-location)
524 9ad1eb5d 2020-12-07 op "Fill BUFFER with the diff between the local worktree branch and REMOTE-LOCATION."
525 9ad1eb5d 2020-12-07 op (vc-setup-buffer buffer)
526 9ad1eb5d 2020-12-07 op (let ((rl (if (or (not remote-location) (string-empty-p remote-location))
527 9ad1eb5d 2020-12-07 op (concat "origin/" (vc-got--current-branch))
528 9ad1eb5d 2020-12-07 op remote-location))
529 9ad1eb5d 2020-12-07 op (inhibit-read-only t))
530 9ad1eb5d 2020-12-07 op (with-current-buffer buffer
531 9ad1eb5d 2020-12-07 op (vc-got--log nil nil nil rl))))
532 6eda2f1f 2020-12-26 op
533 6eda2f1f 2020-12-26 op (defun vc-got-incoming (buffer remote-location)
534 6eda2f1f 2020-12-26 op "Fill BUFFER with the diff between the REMOTE-LOCATION and the local worktree branch."
535 6eda2f1f 2020-12-26 op (let ((rl (if (or (not remote-location) (string-empty-p remote-location))
536 6eda2f1f 2020-12-26 op (concat "origin/" (vc-got--current-branch))
537 6eda2f1f 2020-12-26 op remote-location))
538 6eda2f1f 2020-12-26 op (inhibit-read-only t))
539 6eda2f1f 2020-12-26 op (with-current-buffer buffer
540 6eda2f1f 2020-12-26 op (vc-got--log nil nil (vc-got--current-branch) rl))))
541 9ad1eb5d 2020-12-07 op
542 eb85ad27 2020-12-05 op (defun vc-got-log-search (buffer pattern)
543 eb85ad27 2020-12-05 op "Search commits for PATTERN and write the results found in BUFFER."
544 eb85ad27 2020-12-05 op (with-current-buffer buffer
545 eb85ad27 2020-12-05 op (let ((inhibit-read-only t))
546 9ad1eb5d 2020-12-07 op (vc-got--log nil nil nil nil pattern))))
547 eb85ad27 2020-12-05 op
548 eb85ad27 2020-12-05 op ;; TODO: async
549 f18d3e11 2020-12-05 op ;; TODO: return 0 or 1
550 eb85ad27 2020-12-05 op (defun vc-got-diff (files &optional rev1 rev2 buffer _async)
551 eb85ad27 2020-12-05 op "Insert into BUFFER (or *vc-diff*) the diff for FILES from REV1 to REV2."
552 f457868b 2020-12-07 op (let* ((buffer (get-buffer-create (or buffer "*vc-diff*")))
553 eb85ad27 2020-12-05 op (inhibit-read-only t))
554 eb85ad27 2020-12-05 op (with-current-buffer buffer
555 eb85ad27 2020-12-05 op (vc-got-with-worktree (car files)
556 eb85ad27 2020-12-05 op (cond ((and (null rev1)
557 eb85ad27 2020-12-05 op (null rev2))
558 986bd9a0 2020-12-27 op (dolist (file files)
559 986bd9a0 2020-12-27 op (vc-got--diff file)))
560 eb85ad27 2020-12-05 op (t (error "Not implemented")))))))
561 3f25d9ff 2020-01-02 noreply
562 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-command (file buf &optional rev)
563 3f25d9ff 2020-01-02 noreply "Show annotated contents of FILE in buffer BUF. If given, use revision REV."
564 3f25d9ff 2020-01-02 noreply (let (process-file-side-effects)
565 3f25d9ff 2020-01-02 noreply (with-current-buffer buf
566 3f25d9ff 2020-01-02 noreply ;; FIXME: vc-ensure-vc-buffer won't recognise this buffer as managed
567 3f25d9ff 2020-01-02 noreply ;; by got unless vc-parent-buffer points to a buffer managed by got.
568 3f25d9ff 2020-01-02 noreply ;; investigate why this is needed.
569 3f25d9ff 2020-01-02 noreply (set (make-local-variable 'vc-parent-buffer) (find-file-noselect file))
570 3f25d9ff 2020-01-02 noreply (apply #'vc-got--call "blame" (if rev
571 3f25d9ff 2020-01-02 noreply (list "-c" rev file)
572 3f25d9ff 2020-01-02 noreply (list file))))))
573 3f25d9ff 2020-01-02 noreply
574 3f25d9ff 2020-01-02 noreply (defconst vc-got--annotate-re
575 3f25d9ff 2020-01-02 noreply (concat "^[0-9]\\{1,\\}) " ; line number followed by )
576 3f25d9ff 2020-01-02 noreply "\\([a-z0-9]+\\) " ; SHA-1 of commit
577 3f25d9ff 2020-01-02 noreply "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\) " ; year-mm-dd
578 3f25d9ff 2020-01-02 noreply "\\([^ ]\\)+ ") ; author
579 3f25d9ff 2020-01-02 noreply "Regexp to match annotation output lines.
580 3f25d9ff 2020-01-02 noreply
581 3f25d9ff 2020-01-02 noreply Provides capture groups for:
582 3f25d9ff 2020-01-02 noreply 1. revision id
583 3f25d9ff 2020-01-02 noreply 2. date of commit
584 3f25d9ff 2020-01-02 noreply 3. author of commit")
585 3f25d9ff 2020-01-02 noreply
586 3f25d9ff 2020-01-02 noreply (defconst vc-got--commit-re "^commit \\([a-z0-9]+\\)"
587 3f25d9ff 2020-01-02 noreply "Regexp to match commit lines.
588 3f25d9ff 2020-01-02 noreply
589 3f25d9ff 2020-01-02 noreply Provides capture group for the commit revision id.")
590 3f25d9ff 2020-01-02 noreply
591 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-time ()
592 3f25d9ff 2020-01-02 noreply "Return the time of the next line of annotation at or after point.
593 3f25d9ff 2020-01-02 noreply Value is returned as floating point fractional number of days."
594 3f25d9ff 2020-01-02 noreply (save-excursion
595 3f25d9ff 2020-01-02 noreply (beginning-of-line)
596 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--annotate-re)
597 3f25d9ff 2020-01-02 noreply (let ((str (match-string-no-properties 2)))
598 3f25d9ff 2020-01-02 noreply (vc-annotate-convert-time
599 3f25d9ff 2020-01-02 noreply (encode-time 0 0 0
600 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 8 10))
601 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 5 7))
602 3f25d9ff 2020-01-02 noreply (string-to-number (substring str 0 4))))))))
603 eb85ad27 2020-12-05 op
604 3f25d9ff 2020-01-02 noreply (defun vc-got-annotate-extract-revision-at-line ()
605 3f25d9ff 2020-01-02 noreply "Returns revision corresponding to the current line or nil."
606 3f25d9ff 2020-01-02 noreply (save-excursion
607 3f25d9ff 2020-01-02 noreply (beginning-of-line)
608 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--annotate-re)
609 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1))))
610 3f25d9ff 2020-01-02 noreply
611 3f25d9ff 2020-01-02 noreply (defun vc-got-previous-revision (file rev)
612 3f25d9ff 2020-01-02 noreply "Return the revision number that precedes REV for FILE, or nil if no such revision exists."
613 3f25d9ff 2020-01-02 noreply (with-temp-buffer
614 3f25d9ff 2020-01-02 noreply (vc-got--log file 2 rev nil nil t)
615 3f25d9ff 2020-01-02 noreply (goto-char (point-min))
616 3f25d9ff 2020-01-02 noreply (keep-lines "^commit")
617 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--commit-re)
618 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1))))
619 3f25d9ff 2020-01-02 noreply
620 3f25d9ff 2020-01-02 noreply (defun vc-got-next-revision (file rev)
621 3f25d9ff 2020-01-02 noreply "Return the revision number that follows REV for FILE, or nil
622 3f25d9ff 2020-01-02 noreply if no such revision exists."
623 3f25d9ff 2020-01-02 noreply (with-temp-buffer
624 3f25d9ff 2020-01-02 noreply (vc-got--log file nil nil rev)
625 3f25d9ff 2020-01-02 noreply (keep-lines "^commit" (point-min) (point-max))
626 3f25d9ff 2020-01-02 noreply (goto-char (point-max))
627 3f25d9ff 2020-01-02 noreply (forward-line -1) ;; return from empty line to last actual commit
628 3f25d9ff 2020-01-02 noreply (unless (= (point) (point-min))
629 3f25d9ff 2020-01-02 noreply (forward-line -1)
630 3f25d9ff 2020-01-02 noreply (when (looking-at vc-got--commit-re)
631 3f25d9ff 2020-01-02 noreply (match-string-no-properties 1)))))
632 3f25d9ff 2020-01-02 noreply
633 a96df0e8 2020-01-03 noreply (defun vc-got-delete-file (file)
634 a96df0e8 2020-01-03 noreply "Delete FILE locally and mark it deleted in work tree."
635 a96df0e8 2020-01-03 noreply (vc-got--remove file t))
636 a96df0e8 2020-01-03 noreply
637 7bb16f79 2020-01-03 op (defun vc-got-conflicted-files (dir)
638 7bb16f79 2020-01-03 op "Return the list of files with conflicts in directory DIR."
639 7bb16f79 2020-01-03 op (let* ((root (vc-got-root dir))
640 7bb16f79 2020-01-03 op (default-directory root)
641 7bb16f79 2020-01-03 op (process-file-side-effects))
642 7bb16f79 2020-01-03 op ;; for got it doesn't matter where we call "got status", it will
643 7bb16f79 2020-01-03 op ;; always report file paths from the root of the repo.
644 7bb16f79 2020-01-03 op (cl-loop with conflicts = nil
645 43c93a89 2021-01-04 op for (file . status) in (vc-got--parse-status
646 7bb16f79 2020-01-03 op (vc-got--status "."))
647 7bb16f79 2020-01-03 op do (when (and (eq status 'conflict)
648 7bb16f79 2020-01-03 op (file-in-directory-p file dir))
649 7bb16f79 2020-01-03 op (push file conflicts))
650 7bb16f79 2020-01-03 op finally return conflicts)))
651 7bb16f79 2020-01-03 op
652 8b635a9f 2020-01-03 op (defun vc-got-repository-url (_file &optional remote-name)
653 8b635a9f 2020-01-03 op "Return URL for REMOTE-NAME, or for \"origin\" if nil."
654 8b635a9f 2020-01-03 op (let* ((default-directory (vc-got--repo-root))
655 8b635a9f 2020-01-03 op (remote-name (or remote-name "origin"))
656 8b635a9f 2020-01-03 op (heading (concat "[remote \"" remote-name "\"]"))
657 f8a9db56 2020-01-03 op (conf (cond ((file-exists-p ".git/config")
658 f8a9db56 2020-01-03 op ".git/config")
659 f8a9db56 2020-01-03 op ((file-exists-p ".git")
660 f8a9db56 2020-01-03 op nil)
661 f8a9db56 2020-01-03 op ((file-exists-p "config")
662 f8a9db56 2020-01-03 op "config")))
663 8b635a9f 2020-01-03 op found)
664 8b635a9f 2020-01-03 op (with-temp-buffer
665 f8a9db56 2020-01-03 op (when conf
666 f8a9db56 2020-01-03 op (insert-file-contents conf)
667 f8a9db56 2020-01-03 op (goto-char (point-min))
668 f8a9db56 2020-01-03 op (when (search-forward heading nil t)
669 f8a9db56 2020-01-03 op (forward-line)
670 f8a9db56 2020-01-03 op (while (and (not found)
671 7a5ead65 2020-01-03 op (looking-at ".*=") ;too broad?
672 7a5ead65 2020-01-03 op (not (= (point) (point-max))))
673 f8a9db56 2020-01-03 op (when (looking-at ".*url = \\(.*\\)")
674 7a5ead65 2020-01-03 op (setq found (match-string-no-properties 1)))
675 7a5ead65 2020-01-03 op (forward-line))
676 f8a9db56 2020-01-03 op found)))))
677 8b635a9f 2020-01-03 op
678 af5ef7cd 2020-11-29 op (provide 'vc-got)
679 af5ef7cd 2020-11-29 op ;;; vc-got.el ends here