Commit | Line | Data |
---|---|---|
b6e0e86c SM |
1 | ;;; vc-bzr.el --- VC backend for the bzr revision control system |
2 | ||
3 | ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. | |
4 | ||
5 | ;; NOTE: THIS IS A MODIFIED VERSION OF Dave Love's vc-bzr.el, | |
6 | ;; which you can find at: http://www.loveshack.ukfsn.org/emacs/vc-bzr.el | |
7 | ;; I could not get in touch with Dave Love by email, so | |
8 | ;; I am releasing my changes separately. -- Riccardo | |
9 | ||
10 | ;; Author: Dave Love <fx@gnu.org>, Riccardo Murri <riccardo.murri@gmail.com> | |
11 | ;; Keywords: tools | |
12 | ;; Created: Sept 2006 | |
77b5d458 | 13 | ;; Version: 2007-05-24 |
b6e0e86c SM |
14 | ;; URL: http://launchpad.net/vc-bzr |
15 | ||
16 | ;; This file is free software; you can redistribute it and/or modify | |
17 | ;; it under the terms of the GNU General Public License as published by | |
18 | ;; the Free Software Foundation; either version 2, or (at your option) | |
19 | ;; any later version. | |
20 | ||
21 | ;; This file is distributed in the hope that it will be useful, | |
22 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | ;; GNU General Public License for more details. | |
25 | ||
26 | ;; You should have received a copy of the GNU General Public License | |
27 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
28 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
29 | ;; Boston, MA 02110-1301, USA. | |
30 | ||
31 | ||
32 | ;;; Commentary: | |
33 | ||
34 | ;; NOTE: THIS IS A MODIFIED VERSION OF Dave Love's vc-bzr.el, | |
35 | ;; which you can find at: http://www.loveshack.ukfsn.org/emacs/vc-bzr.el | |
36 | ||
37 | ;; See <URL:http://bazaar-vcs.org/> concerning bzr. | |
38 | ||
77b5d458 SM |
39 | ;; Load this library to register bzr support in VC. It covers basic VC |
40 | ;; functionality, but was only lightly exercised with a few Emacs/bzr | |
41 | ;; version combinations, namely those current on the authors' PCs. | |
42 | ;; See various Fixmes below. | |
b6e0e86c | 43 | |
77b5d458 SM |
44 | |
45 | ;; Known bugs | |
46 | ;; ========== | |
47 | ||
48 | ;; When edititing a symlink and *both* the symlink and its target | |
49 | ;; are bzr-versioned, `vc-bzr` presently runs `bzr status` on the | |
50 | ;; symlink, thereby not detecting whether the actual contents | |
51 | ;; (that is, the target contents) are changed. | |
52 | ;; See https://bugs.launchpad.net/vc-bzr/+bug/116607 | |
53 | ||
54 | ;; For an up-to-date list of bugs, please see: | |
55 | ;; https://bugs.launchpad.net/vc-bzr/+bugs | |
b6e0e86c SM |
56 | |
57 | ||
58 | ;;; Code: | |
59 | ||
60 | (eval-when-compile | |
37320a58 | 61 | (require 'cl) |
b6e0e86c SM |
62 | (require 'vc)) ; for vc-exec-after |
63 | ||
64 | (defgroup vc-bzr nil | |
65 | "VC bzr backend." | |
66 | ;; :version "22" | |
67 | :group 'vc) | |
68 | ||
69 | (defcustom vc-bzr-program "bzr" | |
37320a58 | 70 | "Name of the bzr command (excluding any arguments)." |
b6e0e86c SM |
71 | :group 'vc-bzr |
72 | :type 'string) | |
73 | ||
74 | ;; Fixme: there's probably no call for this. | |
75 | (defcustom vc-bzr-program-args nil | |
37320a58 | 76 | "List of global arguments to pass to `vc-bzr-program'." |
b6e0e86c SM |
77 | :group 'vc-bzr |
78 | :type '(repeat string)) | |
79 | ||
80 | (defcustom vc-bzr-diff-switches nil | |
37320a58 | 81 | "String/list of strings specifying extra switches for bzr diff under VC." |
b6e0e86c SM |
82 | :type '(choice (const :tag "None" nil) |
83 | (string :tag "Argument String") | |
84 | (repeat :tag "Argument List" :value ("") string)) | |
85 | :group 'vc-bzr) | |
86 | ||
87 | (defvar vc-bzr-version nil | |
88 | "Internal use.") | |
89 | ||
90 | ;; Could be used for compatibility checks if bzr changes. | |
91 | (defun vc-bzr-version () | |
92 | "Return a three-numeric element list with components of the bzr version. | |
93 | This is of the form (X Y Z) for revision X.Y.Z. The elements are zero | |
94 | if running `vc-bzr-program' doesn't produce the expected output." | |
37320a58 SM |
95 | (or vc-bzr-version |
96 | (setq vc-bzr-version | |
97 | (let ((s (shell-command-to-string | |
98 | (concat (shell-quote-argument vc-bzr-program) | |
99 | " --version")))) | |
100 | (if (string-match "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" s) | |
101 | (list (string-to-number (match-string 1 s)) | |
102 | (string-to-number (match-string 2 s)) | |
103 | (string-to-number (match-string 3 s))) | |
104 | '(0 0 0)))))) | |
b6e0e86c SM |
105 | |
106 | (defun vc-bzr-at-least-version (vers) | |
107 | "Return t if the bzr command reports being a least version VERS. | |
108 | First argument VERS is a list of the form (X Y Z), as returned by `vc-bzr-version'." | |
109 | (version-list-<= vers (vc-bzr-version))) | |
110 | ||
37320a58 SM |
111 | ;; since v0.9, bzr supports removing the progress indicators |
112 | ;; by setting environment variable BZR_PROGRESS_BAR to "none". | |
113 | (defun vc-bzr-command (bzr-command buffer okstatus file &rest args) | |
114 | "Wrapper round `vc-do-command' using `vc-bzr-program' as COMMAND. | |
b6e0e86c | 115 | Invoke the bzr command adding `BZR_PROGRESS_BAR=none' to the environment." |
37320a58 SM |
116 | (let ((process-environment |
117 | (list* "BZR_PROGRESS_BAR=none" ; Suppress progress output (bzr >=0.9) | |
118 | "LC_ALL=C" ; Force English output | |
119 | process-environment)) | |
120 | ;; bzr may attempt some kind of user interaction if its stdin/stdout | |
121 | ;; is connected to a PTY; therefore, ask Emacs to use a pipe to | |
122 | ;; communicate with it. | |
123 | ;; This is redundant because vc-do-command does it already. --Stef | |
124 | (process-connection-type nil)) | |
125 | (apply 'vc-do-command buffer okstatus vc-bzr-program | |
126 | file bzr-command (append vc-bzr-program-args args)))) | |
b6e0e86c | 127 | |
37320a58 SM |
128 | (unless (vc-bzr-at-least-version '(0 9)) |
129 | ;; For older versions, we fall back to washing the log buffer | |
b6e0e86c | 130 | ;; when all output has been gathered. |
b6e0e86c SM |
131 | (defun vc-bzr-post-command-function (command file flags) |
132 | "`vc-post-command-functions' function to remove progress messages." | |
133 | ;; Note that using this requires that the vc command is run | |
134 | ;; synchronously. Otherwise, the ^Ms in the leading progress | |
135 | ;; message on stdout cause the stream to be interpreted as having | |
136 | ;; DOS line endings, losing the ^Ms, so the search fails. I don't | |
137 | ;; know how this works under Windows. | |
138 | (when (equal command vc-bzr-program) | |
139 | (save-excursion | |
140 | (goto-char (point-min)) | |
141 | (if (looking-at "^\\(\r.*\r\\)[^\r]+$") | |
142 | (replace-match "" nil nil nil 1))) | |
143 | (save-excursion | |
144 | (goto-char (point-min)) | |
145 | ;; This is inserted by bzr 0.11 `log', at least | |
146 | (while (looking-at "read knit.*\n") | |
147 | (replace-match ""))))) | |
148 | ||
37320a58 SM |
149 | (add-hook 'vc-post-command-functions 'vc-bzr-post-command-function)) |
150 | ||
151 | ;;;###autoload | |
152 | (defconst vc-bzr-admin-dirname ".bzr") ; FIXME: "_bzr" on w32? | |
153 | ||
154 | ;;;###autoload (defun vc-bzr-registered (file) | |
155 | ;;;###autoload (if (vc-find-root file vc-bzr-admin-dirname) | |
156 | ;;;###autoload (progn | |
157 | ;;;###autoload (load "vc-bzr") | |
158 | ;;;###autoload (vc-bzr-registered file)))) | |
b6e0e86c | 159 | |
37320a58 SM |
160 | (defun vc-bzr-root-dir (file) |
161 | "Return the root directory in the hierarchy above FILE. | |
b6e0e86c | 162 | Return nil if there isn't one." |
37320a58 | 163 | (vc-find-root file vc-bzr-admin-dirname)) |
b6e0e86c SM |
164 | |
165 | (defun vc-bzr-registered (file) | |
166 | "Return non-nil if FILE is registered with bzr." | |
37320a58 SM |
167 | (if (vc-bzr-root-dir file) ; Short cut. |
168 | (vc-bzr-state file))) ; Expensive. | |
b6e0e86c | 169 | |
77b5d458 SM |
170 | (defun vc-bzr-buffer-nonblank-p (&optional buffer) |
171 | "Return non-nil if BUFFER contains any non-blank characters." | |
172 | (or (> (buffer-size buffer) 0) | |
b6e0e86c | 173 | (save-excursion |
77b5d458 SM |
174 | (set-buffer (or buffer (current-buffer))) |
175 | (goto-char (point-min)) | |
176 | (re-search-forward "[^ \t\n]" (point-max) t)))) | |
177 | ||
178 | (defconst vc-bzr-state-words | |
179 | "added\\|ignored\\|modified\\|removed\\|renamed\\|unknown" | |
180 | "Regexp matching file status words as reported in `bzr' output.") | |
181 | ||
182 | ;; FIXME: Also get this in a non-registered sub-directory. | |
183 | (defun vc-bzr-state (file) | |
184 | (with-temp-buffer | |
185 | (cd (file-name-directory file)) | |
186 | (let ((ret (vc-bzr-command "status" t 255 file)) | |
187 | (state 'up-to-date)) | |
188 | ;; the only secure status indication in `bzr status' output | |
189 | ;; is a couple of lines following the pattern:: | |
190 | ;; | <status>: | |
191 | ;; | <file name> | |
192 | ;; if the file is up-to-date, we get no status report from `bzr', | |
193 | ;; so if the regexp search for the above pattern fails, we consider | |
194 | ;; the file to be up-to-date. | |
195 | (goto-char (point-min)) | |
196 | (when | |
197 | (re-search-forward | |
198 | (concat "^\\(" vc-bzr-state-words "\\):[ \t\n]+" | |
199 | (file-name-nondirectory file) "[ \t\n]*$") | |
200 | (point-max) t) | |
201 | (let ((start (match-beginning 0)) | |
202 | (end (match-end 0))) | |
203 | (goto-char start) | |
204 | (setq state | |
205 | (cond | |
206 | ((not (equal ret 0)) nil) | |
207 | ((looking-at "added\\|renamed\\|modified\\|removed") 'edited) | |
208 | ((looking-at "unknown\\|ignored") nil))) | |
209 | ;; erase the status text that matched | |
210 | (delete-region start end))) | |
211 | (when (vc-bzr-buffer-nonblank-p) | |
212 | ;; "bzr" will output some warnings and informational messages | |
213 | ;; to the user to stderr; due to Emacs' `vc-do-command' (and, | |
214 | ;; it seems, `start-process' itself), we cannot catch stderr | |
215 | ;; and stdout into different buffers. So, if there's anything | |
216 | ;; left in the buffer after removing the above status | |
217 | ;; keywords, let us just presume that any other message from | |
218 | ;; "bzr" is a user warning, and display it. | |
219 | (message "Warnings in `bzr' output: %s" | |
220 | (buffer-substring (point-min) (point-max)))) | |
b6e0e86c SM |
221 | (when state |
222 | (vc-file-setprop file 'vc-workfile-version | |
223 | (vc-bzr-workfile-version file)) | |
224 | (vc-file-setprop file 'vc-state state)) | |
225 | state))) | |
226 | ||
227 | (defun vc-bzr-workfile-unchanged-p (file) | |
228 | (eq 'up-to-date (vc-bzr-state file))) | |
229 | ||
230 | (defun vc-bzr-workfile-version (file) | |
231 | (with-temp-buffer | |
232 | (vc-bzr-command "revno" t 0 file) | |
233 | (goto-char 1) | |
234 | (buffer-substring 1 (line-end-position)))) | |
235 | ||
236 | (defun vc-bzr-checkout-model (file) | |
237 | 'implicit) | |
238 | ||
239 | (defun vc-bzr-register (file &optional rev comment) | |
240 | "Register FILE under bzr. | |
241 | Signal an error unless REV is nil. | |
242 | COMMENT is ignored." | |
243 | (if rev (error "Can't register explicit version with bzr")) | |
244 | (vc-bzr-command "add" nil 0 file)) | |
245 | ||
246 | ;; Could run `bzr status' in the directory and see if it succeeds, but | |
247 | ;; that's relatively expensive. | |
37320a58 | 248 | (defalias 'vc-bzr-responsible-p 'vc-bzr-root-dir |
b6e0e86c SM |
249 | "Return non-nil if FILE is (potentially) controlled by bzr. |
250 | The criterion is that there is a `.bzr' directory in the same | |
37320a58 | 251 | or a superior directory.") |
b6e0e86c SM |
252 | |
253 | (defun vc-bzr-could-register (file) | |
254 | "Return non-nil if FILE could be registered under bzr." | |
255 | (and (vc-bzr-responsible-p file) ; shortcut | |
256 | (condition-case () | |
257 | (with-temp-buffer | |
258 | (vc-bzr-command "add" t 0 file "--dry-run") | |
259 | ;; The command succeeds with no output if file is | |
260 | ;; registered (in bzr 0.8). | |
261 | (goto-char 1) | |
262 | (looking-at "added ")) | |
263 | (error)))) | |
264 | ||
265 | (defun vc-bzr-unregister (file) | |
266 | "Unregister FILE from bzr." | |
267 | (vc-bzr-command "remove" nil 0 file)) | |
268 | ||
269 | (defun vc-bzr-checkin (file rev comment) | |
270 | "Check FILE in to bzr with log message COMMENT. | |
271 | REV non-nil gets an error." | |
272 | (if rev (error "Can't check in a specific version with bzr")) | |
273 | (vc-bzr-command "commit" nil 0 file "-m" comment)) | |
274 | ||
275 | (defun vc-bzr-checkout (file &optional editable rev destfile) | |
276 | "Checkout revision REV of FILE from bzr to DESTFILE. | |
277 | EDITABLE is ignored." | |
278 | (unless destfile | |
279 | (setq destfile (vc-version-backup-file-name file rev))) | |
280 | (let ((coding-system-for-read 'binary) | |
281 | (coding-system-for-write 'binary)) | |
282 | (with-temp-file destfile | |
283 | (if rev | |
284 | (vc-bzr-command "cat" t 0 file "-r" rev) | |
285 | (vc-bzr-command "cat" t 0 file))))) | |
286 | ||
287 | (defun vc-bzr-revert (file &optional contents-done) | |
288 | (unless contents-done | |
289 | (with-temp-buffer (vc-bzr-command "revert" t 'async file)))) | |
290 | ||
37320a58 SM |
291 | (defvar log-view-message-re) |
292 | (defvar log-view-file-re) | |
293 | (defvar log-view-font-lock-keywords) | |
294 | (defvar log-view-current-tag-function) | |
295 | ||
296 | (define-derived-mode vc-bzr-log-view-mode log-view-mode "Bzr-Log-View" | |
297 | (remove-hook 'log-view-mode-hook 'vc-bzr-log-view-mode) ;Deactivate the hack. | |
b6e0e86c SM |
298 | (require 'add-log) |
299 | ;; Don't have file markers, so use impossible regexp. | |
300 | (set (make-local-variable 'log-view-file-re) "\\'\\`") | |
37320a58 SM |
301 | (set (make-local-variable 'log-view-message-re) |
302 | "^ *-+\n *\\(?:revno: \\([0-9]+\\)\\|merged: .+\\)") | |
b6e0e86c | 303 | (set (make-local-variable 'log-view-font-lock-keywords) |
37320a58 SM |
304 | ;; log-view-font-lock-keywords is careful to use the buffer-local |
305 | ;; value of log-view-message-re only since Emacs-23. | |
306 | (append `((,log-view-message-re . 'log-view-message-face)) | |
307 | ;; log-view-font-lock-keywords | |
308 | '(("^ *committer: \ | |
5ec05779 | 309 | \\([^<(]+?\\)[ ]*[(<]\\([[:alnum:]_.+-]+@[[:alnum:]_.-]+\\)[>)]" |
37320a58 SM |
310 | (1 'change-log-name) |
311 | (2 'change-log-email)) | |
312 | ("^ *timestamp: \\(.*\\)" (1 'change-log-date-face)))))) | |
b6e0e86c SM |
313 | |
314 | (defun vc-bzr-print-log (file &optional buffer) ; get buffer arg in Emacs 22 | |
315 | "Get bzr change log for FILE into specified BUFFER." | |
b6e0e86c SM |
316 | ;; Fixme: This might need the locale fixing up if things like `revno' |
317 | ;; got localized, but certainly it shouldn't use LC_ALL=C. | |
318 | ;; NB. Can't be async -- see `vc-bzr-post-command-function'. | |
319 | (vc-bzr-command "log" buffer 0 file) | |
37320a58 SM |
320 | ;; FIXME: Until Emacs-23, VC was missing a hook to sort out the mode for |
321 | ;; the buffer, or at least set the regexps right. | |
322 | (unless (fboundp 'vc-default-log-view-mode) | |
323 | (add-hook 'log-view-mode-hook 'vc-bzr-log-view-mode))) | |
b6e0e86c SM |
324 | |
325 | (defun vc-bzr-show-log-entry (version) | |
326 | "Find entry for patch name VERSION in bzr change log buffer." | |
327 | (goto-char (point-min)) | |
328 | (let (case-fold-search) | |
329 | (if (re-search-forward (concat "^-+\nrevno: " version "$") nil t) | |
330 | (beginning-of-line 0) | |
331 | (goto-char (point-min))))) | |
332 | ||
333 | ;; Fixem: vc-bzr-wash-log | |
334 | ||
335 | (autoload 'vc-diff-switches-list "vc" nil nil t) | |
336 | ||
337 | (defun vc-bzr-diff (file &optional rev1 rev2 buffer) | |
338 | "VC bzr backend for diff." | |
339 | (let ((working (vc-workfile-version file))) | |
340 | (if (and (equal rev1 working) (not rev2)) | |
341 | (setq rev1 nil)) | |
342 | (if (and (not rev1) rev2) | |
343 | (setq rev1 working)) | |
344 | ;; NB. Can't be async -- see `vc-bzr-post-command-function'. | |
345 | ;; bzr diff produces condition code 1 for some reason. | |
346 | (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 file | |
347 | "--diff-options" (mapconcat 'identity (vc-diff-switches-list bzr) | |
348 | " ") | |
349 | (when rev1 | |
350 | (if rev2 | |
351 | (list "-r" (format "%s..%s" rev1 rev2)) | |
352 | (list "-r" rev1)))))) | |
353 | ||
354 | (defalias 'vc-bzr-diff-tree 'vc-bzr-diff) | |
355 | ||
356 | ;; Fixme: implement vc-bzr-dir-state, vc-bzr-dired-state-info | |
357 | ||
358 | ;; Fixme: vc-{next,previous}-version need fixing in vc.el to deal with | |
359 | ;; straight integer versions. | |
360 | ||
361 | (defun vc-bzr-delete-file (file) | |
362 | "Delete FILE and delete it in the bzr repository." | |
363 | (condition-case () | |
364 | (delete-file file) | |
365 | (file-error nil)) | |
366 | (vc-bzr-command "remove" nil 0 file)) | |
367 | ||
368 | (defun vc-bzr-rename-file (old new) | |
369 | "Rename file from OLD to NEW using `bzr mv'." | |
370 | (vc-bzr-command "mv" nil 0 new old)) | |
371 | ||
372 | (defvar vc-bzr-annotation-table nil | |
373 | "Internal use.") | |
374 | (make-variable-buffer-local 'vc-bzr-annotation-table) | |
375 | ||
376 | (defun vc-bzr-annotate-command (file buffer &optional version) | |
377 | "Prepare BUFFER for `vc-annotate' on FILE. | |
378 | Each line is tagged with the revision number, which has a `help-echo' | |
379 | property containing author and date information." | |
380 | (apply #'vc-bzr-command "annotate" buffer 0 file "-l" "--all" | |
381 | (if version (list "-r" version))) | |
382 | (with-current-buffer buffer | |
383 | ;; Store the tags for the annotated source lines in a hash table | |
384 | ;; to allow saving space by sharing the text properties. | |
385 | (setq vc-bzr-annotation-table (make-hash-table :test 'equal)) | |
386 | (goto-char (point-min)) | |
387 | (while (re-search-forward "^\\( *[0-9]+\\) \\(.+\\) +\\([0-9]\\{8\\}\\) |" | |
388 | nil t) | |
389 | (let* ((rev (match-string 1)) | |
390 | (author (match-string 2)) | |
391 | (date (match-string 3)) | |
392 | (key (match-string 0)) | |
393 | (tag (gethash key vc-bzr-annotation-table))) | |
394 | (unless tag | |
395 | (save-match-data | |
396 | (string-match " +\\'" author) | |
397 | (setq author (substring author 0 (match-beginning 0)))) | |
398 | (setq tag (propertize rev 'help-echo (concat "Author: " author | |
399 | ", date: " date) | |
400 | 'mouse-face 'highlight)) | |
401 | (puthash key tag vc-bzr-annotation-table)) | |
402 | (replace-match "") | |
403 | (insert tag " |"))))) | |
404 | ||
405 | ;; Definition from Emacs 22 | |
406 | (unless (fboundp 'vc-annotate-convert-time) | |
407 | (defun vc-annotate-convert-time (time) | |
408 | "Convert a time value to a floating-point number of days. | |
409 | The argument TIME is a list as returned by `current-time' or | |
410 | `encode-time', only the first two elements of that list are considered." | |
411 | (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))) | |
412 | ||
413 | (defun vc-bzr-annotate-time () | |
414 | (when (re-search-forward "^ *[0-9]+ |" nil t) | |
415 | (let ((prop (get-text-property (line-beginning-position) 'help-echo))) | |
416 | (string-match "[0-9]+\\'" prop) | |
417 | (vc-annotate-convert-time | |
418 | (encode-time 0 0 0 | |
419 | (string-to-number (substring (match-string 0 prop) 6 8)) | |
420 | (string-to-number (substring (match-string 0 prop) 4 6)) | |
421 | (string-to-number (substring (match-string 0 prop) 0 4)) | |
422 | ))))) | |
423 | ||
424 | (defun vc-bzr-annotate-extract-revision-at-line () | |
425 | "Return revision for current line of annoation buffer, or nil. | |
426 | Return nil if current line isn't annotated." | |
427 | (save-excursion | |
428 | (beginning-of-line) | |
429 | (if (looking-at " *\\([0-9]+\\) | ") | |
430 | (match-string-no-properties 1)))) | |
431 | ||
432 | ;; Not needed for Emacs 22 | |
433 | (defun vc-bzr-annotate-difference (point) | |
434 | (let ((next-time (vc-bzr-annotate-time))) | |
435 | (if next-time | |
436 | (- (vc-annotate-convert-time (current-time)) next-time)))) | |
437 | ||
438 | ;; FIXME: `bzr root' will return the real path to the repository root, | |
439 | ;; that is, it can differ from the buffer's current directory name | |
440 | ;; if there are any symbolic links. | |
441 | (defun vc-bzr-root (dir) | |
442 | "Return the root directory of the bzr repository containing DIR." | |
b32ce4c3 MY |
443 | ;; Cache technique copied from vc-arch.el. |
444 | (or (vc-file-getprop dir 'bzr-root) | |
445 | (vc-file-setprop | |
446 | dir 'bzr-root | |
447 | (substring | |
448 | (shell-command-to-string (concat vc-bzr-program " root " dir)) 0 -1)))) | |
b6e0e86c SM |
449 | |
450 | ;; TODO: it would be nice to mark the conflicted files in VC Dired, | |
451 | ;; and implement a command to run ediff and `bzr resolve' once the | |
452 | ;; changes have been merged. | |
453 | (defun vc-bzr-dir-state (dir &optional localp) | |
454 | "Find the VC state of all files in DIR. | |
455 | Optional argument LOCALP is always ignored." | |
37320a58 SM |
456 | (let ((bzr-root-directory (vc-bzr-root dir)) |
457 | (at-start t) | |
458 | current-bzr-state current-vc-state) | |
459 | ;; Check that DIR is a bzr repository. | |
460 | (unless (file-name-absolute-p bzr-root-directory) | |
b6e0e86c SM |
461 | (error "Cannot find bzr repository for directory `%s'" dir)) |
462 | ;; `bzr ls --versioned' lists all versioned files; | |
463 | ;; assume they are up-to-date, unless we are given | |
464 | ;; evidence of the contrary. | |
37320a58 | 465 | (setq at-start t) |
b6e0e86c | 466 | (with-temp-buffer |
37320a58 | 467 | (vc-bzr-command "ls" t 0 nil "--versioned" "--non-recursive") |
b6e0e86c | 468 | (goto-char (point-min)) |
37320a58 | 469 | (while (or at-start |
b6e0e86c | 470 | (eq 0 (forward-line))) |
37320a58 | 471 | (setq at-start nil) |
b6e0e86c SM |
472 | (let ((file (expand-file-name |
473 | (buffer-substring-no-properties | |
474 | (line-beginning-position) (line-end-position)) | |
475 | bzr-root-directory))) | |
476 | (vc-file-setprop file 'vc-state 'up-to-date) | |
477 | ;; XXX: is this correct? what happens if one | |
478 | ;; mixes different SCMs in the same dir? | |
479 | (vc-file-setprop file 'vc-backend 'BZR)))) | |
480 | ;; `bzr status' reports on added/modified/renamed and unknown/ignored files | |
37320a58 | 481 | (setq at-start t) |
b6e0e86c | 482 | (with-temp-buffer |
77b5d458 | 483 | (vc-bzr-command "status" t 0 nil) |
b6e0e86c | 484 | (goto-char (point-min)) |
37320a58 | 485 | (while (or at-start |
b6e0e86c | 486 | (eq 0 (forward-line))) |
37320a58 | 487 | (setq at-start nil) |
b6e0e86c SM |
488 | (cond |
489 | ((looking-at "^added") | |
37320a58 SM |
490 | (setq current-vc-state 'edited) |
491 | (setq current-bzr-state 'added)) | |
b6e0e86c | 492 | ((looking-at "^modified") |
37320a58 SM |
493 | (setq current-vc-state 'edited) |
494 | (setq current-bzr-state 'modified)) | |
b6e0e86c | 495 | ((looking-at "^renamed") |
37320a58 SM |
496 | (setq current-vc-state 'edited) |
497 | (setq current-bzr-state 'renamed)) | |
b6e0e86c | 498 | ((looking-at "^\\(unknown\\|ignored\\)") |
37320a58 SM |
499 | (setq current-vc-state nil) |
500 | (setq current-bzr-state 'not-versioned)) | |
b6e0e86c SM |
501 | ((looking-at " ") |
502 | ;; file names are indented by two spaces | |
503 | (when current-vc-state | |
504 | (let ((file (expand-file-name | |
505 | (buffer-substring-no-properties | |
506 | (match-end 0) (line-end-position)) | |
507 | bzr-root-directory))) | |
508 | (vc-file-setprop file 'vc-state current-vc-state) | |
509 | (vc-file-setprop file 'vc-bzr-state current-bzr-state) | |
510 | (when (eq 'added current-bzr-state) | |
511 | (vc-file-setprop file 'vc-workfile-version "0")))) | |
512 | (when (eq 'not-versioned current-bzr-state) | |
513 | (let ((file (expand-file-name | |
514 | (buffer-substring-no-properties | |
515 | (match-end 0) (line-end-position)) | |
516 | bzr-root-directory))) | |
517 | (vc-file-setprop file 'vc-backend 'none) | |
518 | (vc-file-setprop file 'vc-state nil)))) | |
519 | (t | |
520 | ;; skip this part of `bzr status' output | |
37320a58 SM |
521 | (setq current-vc-state nil) |
522 | (setq current-bzr-state nil))))))) | |
b6e0e86c SM |
523 | |
524 | (defun vc-bzr-dired-state-info (file) | |
525 | "Bzr-specific version of `vc-dired-state-info'." | |
526 | (if (eq 'edited (vc-state file)) | |
527 | (let ((bzr-state (vc-file-getprop file 'vc-bzr-state))) | |
528 | (if bzr-state | |
529 | (concat "(" (symbol-name bzr-state) ")") | |
530 | ;; else fall back to default vc representation | |
531 | (vc-default-dired-state-info 'BZR file))))) | |
532 | ||
533 | ;; In case of just `(load "vc-bzr")', but that's probably the wrong | |
534 | ;; way to do it. | |
535 | (add-to-list 'vc-handled-backends 'BZR) | |
536 | ||
537 | (eval-after-load "vc" | |
538 | '(add-to-list 'vc-directory-exclusion-list ".bzr" t)) | |
539 | ||
540 | (defconst vc-bzr-unload-hook | |
541 | (lambda () | |
542 | (setq vc-handled-backends (delq 'BZR vc-handled-backends)) | |
543 | (remove-hook 'vc-post-command-functions 'vc-bzr-post-command-function))) | |
544 | ||
545 | (provide 'vc-bzr) | |
546 | ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06 | |
547 | ;;; vc-bzr.el ends here |