(Info-bookmark-make-cell): Fix up last change.
[bpt/emacs.git] / lisp / vc-bzr.el
CommitLineData
b6e0e86c
SM
1;;; vc-bzr.el --- VC backend for the bzr revision control system
2
f4d0cf23 3;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
b6e0e86c 4
b6e0e86c
SM
5;; Author: Dave Love <fx@gnu.org>, Riccardo Murri <riccardo.murri@gmail.com>
6;; Keywords: tools
7;; Created: Sept 2006
f4d0cf23 8;; Version: 2008-01-04 (Bzr revno 25)
b6e0e86c
SM
9;; URL: http://launchpad.net/vc-bzr
10
11;; This file is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
64be3a42 13;; the Free Software Foundation; either version 3, or (at your option)
b6e0e86c
SM
14;; any later version.
15
16;; This file is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
25
26
27;;; Commentary:
28
f4d0cf23
SM
29;; See <URL:http://bazaar-vcs.org/> concerning bzr. See
30;; <URL:http://launchpad.net/vc-bzr> for alternate development
31;; branches of `vc-bzr'.
b6e0e86c 32
f4d0cf23 33;; Load this library to register bzr support in VC.
77b5d458
SM
34
35;; Known bugs
36;; ==========
37
38;; When edititing a symlink and *both* the symlink and its target
39;; are bzr-versioned, `vc-bzr` presently runs `bzr status` on the
40;; symlink, thereby not detecting whether the actual contents
41;; (that is, the target contents) are changed.
42;; See https://bugs.launchpad.net/vc-bzr/+bug/116607
43
44;; For an up-to-date list of bugs, please see:
45;; https://bugs.launchpad.net/vc-bzr/+bugs
b6e0e86c
SM
46
47
48;;; Code:
49
50(eval-when-compile
37320a58 51 (require 'cl)
b6e0e86c
SM
52 (require 'vc)) ; for vc-exec-after
53
360cf7bc
SM
54;; Clear up the cache to force vc-call to check again and discover
55;; new functions when we reload this file.
4211679b 56(put 'Bzr 'vc-functions nil)
360cf7bc 57
b6e0e86c
SM
58(defgroup vc-bzr nil
59 "VC bzr backend."
fba500b6 60 :version "22.2"
b6e0e86c
SM
61 :group 'vc)
62
63(defcustom vc-bzr-program "bzr"
37320a58 64 "Name of the bzr command (excluding any arguments)."
b6e0e86c
SM
65 :group 'vc-bzr
66 :type 'string)
67
b6e0e86c 68(defcustom vc-bzr-diff-switches nil
37320a58 69 "String/list of strings specifying extra switches for bzr diff under VC."
b6e0e86c
SM
70 :type '(choice (const :tag "None" nil)
71 (string :tag "Argument String")
72 (repeat :tag "Argument List" :value ("") string))
73 :group 'vc-bzr)
74
f4d0cf23
SM
75(defcustom vc-bzr-log-switches nil
76 "String/list of strings specifying extra switches for `bzr log' under VC."
77 :type '(choice (const :tag "None" nil)
78 (string :tag "Argument String")
79 (repeat :tag "Argument List" :value ("") string))
80 :group 'vc-bzr)
81
37320a58
SM
82;; since v0.9, bzr supports removing the progress indicators
83;; by setting environment variable BZR_PROGRESS_BAR to "none".
8cdd17b4 84(defun vc-bzr-command (bzr-command buffer okstatus file-or-list &rest args)
37320a58 85 "Wrapper round `vc-do-command' using `vc-bzr-program' as COMMAND.
f4d0cf23
SM
86Invoke the bzr command adding `BZR_PROGRESS_BAR=none' and
87`LC_MESSAGES=C' to the environment."
37320a58
SM
88 (let ((process-environment
89 (list* "BZR_PROGRESS_BAR=none" ; Suppress progress output (bzr >=0.9)
f4d0cf23 90 "LC_MESSAGES=C" ; Force English output
a460c94c 91 process-environment)))
37320a58 92 (apply 'vc-do-command buffer okstatus vc-bzr-program
f4d0cf23 93 file-or-list bzr-command args)))
b6e0e86c 94
37320a58
SM
95
96;;;###autoload
f4d0cf23 97(defconst vc-bzr-admin-dirname ".bzr"
b6e6e09a 98 "Name of the directory containing Bzr repository status files.")
a460c94c 99;;;###autoload
b6e6e09a
SM
100(defconst vc-bzr-admin-checkout-format-file
101 (concat vc-bzr-admin-dirname "/checkout/format"))
a460c94c 102(defconst vc-bzr-admin-dirstate
b6e6e09a
SM
103 (concat vc-bzr-admin-dirname "/checkout/dirstate"))
104(defconst vc-bzr-admin-branch-format-file
105 (concat vc-bzr-admin-dirname "/branch/format"))
a460c94c 106(defconst vc-bzr-admin-revhistory
b6e6e09a 107 (concat vc-bzr-admin-dirname "/branch/revision-history"))
12451866
RF
108(defconst vc-bzr-admin-lastrev
109 (concat vc-bzr-admin-dirname "/branch/last-revision"))
37320a58
SM
110
111;;;###autoload (defun vc-bzr-registered (file)
b6e6e09a 112;;;###autoload (if (vc-find-root file vc-bzr-admin-checkout-format-file)
37320a58
SM
113;;;###autoload (progn
114;;;###autoload (load "vc-bzr")
115;;;###autoload (vc-bzr-registered file))))
b6e0e86c 116
a460c94c
SM
117(defun vc-bzr-root (file)
118 "Return the root directory of the bzr repository containing FILE."
119 ;; Cache technique copied from vc-arch.el.
120 (or (vc-file-getprop file 'bzr-root)
b38f5e6f
DN
121 (let ((root (vc-find-root file vc-bzr-admin-checkout-format-file)))
122 (when root (vc-file-setprop file 'bzr-root root)))))
b6e0e86c
SM
123
124(defun vc-bzr-registered (file)
a460c94c
SM
125 "Return non-nil if FILE is registered with bzr.
126
127For speed, this function tries first to parse Bzr internal file
128`checkout/dirstate', but it may fail if Bzr internal file format
129has changed. As a safeguard, the `checkout/dirstate' file is
130only parsed if it contains the string `#bazaar dirstate flat
131format 3' in the first line.
132
133If the `checkout/dirstate' file cannot be parsed, fall back to
134running `vc-bzr-state'."
fba500b6
SM
135 (lexical-let ((root (vc-bzr-root file)))
136 (when root ; Short cut.
137 ;; This looks at internal files. May break if they change
138 ;; their format.
139 (lexical-let ((dirstate (expand-file-name vc-bzr-admin-dirstate root)))
140 (if (not (file-readable-p dirstate))
141 (vc-bzr-state file) ; Expensive.
142 (with-temp-buffer
143 (insert-file-contents dirstate)
144 (goto-char (point-min))
145 (if (not (looking-at "#bazaar dirstate flat format 3"))
146 (vc-bzr-state file) ; Some other unknown format?
147 (let* ((relfile (file-relative-name file root))
148 (reldir (file-name-directory relfile)))
149 (re-search-forward
150 (concat "^\0"
151 (if reldir (regexp-quote (directory-file-name reldir)))
152 "\0"
153 (regexp-quote (file-name-nondirectory relfile))
154 "\0")
155 nil t)))))))))
77b5d458
SM
156
157(defconst vc-bzr-state-words
33e5d7d4 158 "added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown"
77b5d458
SM
159 "Regexp matching file status words as reported in `bzr' output.")
160
b6e6e09a
SM
161(defun vc-bzr-file-name-relative (filename)
162 "Return file name FILENAME stripped of the initial Bzr repository path."
163 (lexical-let*
164 ((filename* (expand-file-name filename))
f4d0cf23 165 (rootdir (vc-bzr-root filename*)))
6e98ad29 166 (when rootdir
b6e6e09a
SM
167 (file-relative-name filename* rootdir))))
168
33e5d7d4
SM
169(defun vc-bzr-status (file)
170 "Return FILE status according to Bzr.
171Return value is a cons (STATUS . WARNING), where WARNING is a
fba500b6
SM
172string or nil, and STATUS is one of the symbols: `added',
173`ignored', `kindchanged', `modified', `removed', `renamed', `unknown',
33e5d7d4
SM
174which directly correspond to `bzr status' output, or 'unchanged
175for files whose copy in the working tree is identical to the one
176in the branch repository, or nil for files that are not
177registered with Bzr.
178
179If any error occurred in running `bzr status', then return nil."
77b5d458 180 (with-temp-buffer
fba500b6
SM
181 (let ((ret (condition-case nil
182 (vc-bzr-command "status" t 0 file)
183 (file-error nil))) ; vc-bzr-program not found.
184 (status 'unchanged))
185 ;; the only secure status indication in `bzr status' output
186 ;; is a couple of lines following the pattern::
187 ;; | <status>:
188 ;; | <file name>
189 ;; if the file is up-to-date, we get no status report from `bzr',
190 ;; so if the regexp search for the above pattern fails, we consider
191 ;; the file to be up-to-date.
192 (goto-char (point-min))
193 (when (re-search-forward
194 ;; bzr prints paths relative to the repository root.
195 (concat "^\\(" vc-bzr-state-words "\\):[ \t\n]+"
196 (regexp-quote (vc-bzr-file-name-relative file))
f4d0cf23
SM
197 ;; Bzr appends a '/' to directory names and
198 ;; '*' to executable files
199 (if (file-directory-p file) "/?" "\\*?")
fba500b6
SM
200 "[ \t\n]*$")
201 nil t)
6e98ad29 202 (lexical-let ((statusword (match-string 1)))
fba500b6
SM
203 ;; Erase the status text that matched.
204 (delete-region (match-beginning 0) (match-end 0))
33e5d7d4 205 (setq status
f4d0cf23 206 (intern (replace-regexp-in-string " " "" statusword)))))
fba500b6
SM
207 (when status
208 (goto-char (point-min))
209 (skip-chars-forward " \n\t") ;Throw away spaces.
210 (cons status
211 ;; "bzr" will output warnings and informational messages to
212 ;; stderr; due to Emacs' `vc-do-command' (and, it seems,
213 ;; `start-process' itself) limitations, we cannot catch stderr
214 ;; and stdout into different buffers. So, if there's anything
215 ;; left in the buffer after removing the above status
216 ;; keywords, let us just presume that any other message from
217 ;; "bzr" is a user warning, and display it.
218 (unless (eobp) (buffer-substring (point) (point-max))))))))
a0e5e075 219
33e5d7d4
SM
220(defun vc-bzr-state (file)
221 (lexical-let ((result (vc-bzr-status file)))
222 (when (consp result)
223 (if (cdr result)
224 (message "Warnings in `bzr' output: %s" (cdr result)))
225 (cdr (assq (car result)
226 '((added . edited)
fba500b6 227 (kindchanged . edited)
33e5d7d4
SM
228 (renamed . edited)
229 (modified . edited)
230 (removed . edited)
231 (ignored . nil)
232 (unknown . nil)
233 (unchanged . up-to-date)))))))
b6e0e86c
SM
234
235(defun vc-bzr-workfile-unchanged-p (file)
33e5d7d4 236 (eq 'unchanged (car (vc-bzr-status file))))
b6e0e86c 237
ac3f4c6f 238(defun vc-bzr-working-revision (file)
a460c94c
SM
239 (lexical-let*
240 ((rootdir (vc-bzr-root file))
6e98ad29
SM
241 (branch-format-file (expand-file-name vc-bzr-admin-branch-format-file
242 rootdir))
243 (revhistory-file (expand-file-name vc-bzr-admin-revhistory rootdir))
244 (lastrev-file (expand-file-name vc-bzr-admin-lastrev rootdir)))
245 ;; This looks at internal files to avoid forking a bzr process.
246 ;; May break if they change their format.
a460c94c 247 (if (file-exists-p branch-format-file)
fba500b6 248 (with-temp-buffer
a460c94c
SM
249 (insert-file-contents branch-format-file)
250 (goto-char (point-min))
251 (cond
252 ((or
253 (looking-at "Bazaar-NG branch, format 0.0.4")
254 (looking-at "Bazaar-NG branch format 5"))
255 ;; count lines in .bzr/branch/revision-history
fba500b6 256 (insert-file-contents revhistory-file)
a460c94c
SM
257 (number-to-string (count-lines (line-end-position) (point-max))))
258 ((looking-at "Bazaar Branch Format 6 (bzr 0.15)")
259 ;; revno is the first number in .bzr/branch/last-revision
260 (insert-file-contents lastrev-file)
a460c94c
SM
261 (if (re-search-forward "[0-9]+" nil t)
262 (buffer-substring (match-beginning 0) (match-end 0))))))
263 ;; fallback to calling "bzr revno"
b6e6e09a 264 (lexical-let*
a460c94c
SM
265 ((result (vc-bzr-command-discarding-stderr
266 vc-bzr-program "revno" file))
b6e6e09a
SM
267 (exitcode (car result))
268 (output (cdr result)))
269 (cond
270 ((eq exitcode 0) (substring output 0 -1))
271 (t nil))))))
b6e0e86c
SM
272
273(defun vc-bzr-checkout-model (file)
274 'implicit)
275
a6ea7ffc 276(defun vc-bzr-create-repo ()
4211679b 277 "Create a new Bzr repository."
a6ea7ffc
DN
278 (vc-bzr-command "init" nil 0 nil))
279
25a4ea6d 280(defun vc-bzr-init-revision (&optional file)
f4d0cf23
SM
281 "Always return nil, as Bzr cannot register explicit versions."
282 nil)
283
8cdd17b4 284(defun vc-bzr-register (files &optional rev comment)
b6e0e86c
SM
285 "Register FILE under bzr.
286Signal an error unless REV is nil.
287COMMENT is ignored."
5b5afd50 288 (if rev (error "Can't register explicit revision with bzr"))
8cdd17b4 289 (vc-bzr-command "add" nil 0 files))
b6e0e86c
SM
290
291;; Could run `bzr status' in the directory and see if it succeeds, but
292;; that's relatively expensive.
b6e6e09a 293(defalias 'vc-bzr-responsible-p 'vc-bzr-root
b6e0e86c
SM
294 "Return non-nil if FILE is (potentially) controlled by bzr.
295The criterion is that there is a `.bzr' directory in the same
37320a58 296or a superior directory.")
b6e0e86c
SM
297
298(defun vc-bzr-could-register (file)
299 "Return non-nil if FILE could be registered under bzr."
300 (and (vc-bzr-responsible-p file) ; shortcut
301 (condition-case ()
302 (with-temp-buffer
303 (vc-bzr-command "add" t 0 file "--dry-run")
304 ;; The command succeeds with no output if file is
305 ;; registered (in bzr 0.8).
360cf7bc 306 (goto-char (point-min))
b6e0e86c
SM
307 (looking-at "added "))
308 (error))))
309
310(defun vc-bzr-unregister (file)
311 "Unregister FILE from bzr."
f4d0cf23 312 (vc-bzr-command "remove" nil 0 file "--keep"))
b6e0e86c 313
8cdd17b4 314(defun vc-bzr-checkin (files rev comment)
b6e0e86c
SM
315 "Check FILE in to bzr with log message COMMENT.
316REV non-nil gets an error."
5b5afd50 317 (if rev (error "Can't check in a specific revision with bzr"))
8cdd17b4 318 (vc-bzr-command "commit" nil 0 files "-m" comment))
b6e0e86c 319
f4d0cf23
SM
320(defun vc-bzr-find-version (file rev buffer)
321 "Fetch version REV of file FILE and put it into BUFFER."
322 (with-current-buffer buffer
323 (if (and rev (stringp rev) (not (string= rev "")))
324 (vc-bzr-command "cat" t 0 file "-r" rev)
325 (vc-bzr-command "cat" t 0 file))))
326
b6e0e86c
SM
327(defun vc-bzr-checkout (file &optional editable rev destfile)
328 "Checkout revision REV of FILE from bzr to DESTFILE.
329EDITABLE is ignored."
330 (unless destfile
331 (setq destfile (vc-version-backup-file-name file rev)))
332 (let ((coding-system-for-read 'binary)
333 (coding-system-for-write 'binary))
fba500b6 334 (with-temp-file destfile
f4d0cf23 335 (if (and rev (stringp rev) (not (string= rev "")))
fba500b6
SM
336 (vc-bzr-command "cat" t 0 file "-r" rev)
337 (vc-bzr-command "cat" t 0 file)))))
b6e0e86c
SM
338
339(defun vc-bzr-revert (file &optional contents-done)
340 (unless contents-done
33e5d7d4 341 (with-temp-buffer (vc-bzr-command "revert" t 0 file))))
b6e0e86c 342
37320a58
SM
343(defvar log-view-message-re)
344(defvar log-view-file-re)
345(defvar log-view-font-lock-keywords)
346(defvar log-view-current-tag-function)
347
348(define-derived-mode vc-bzr-log-view-mode log-view-mode "Bzr-Log-View"
349 (remove-hook 'log-view-mode-hook 'vc-bzr-log-view-mode) ;Deactivate the hack.
b6e0e86c
SM
350 (require 'add-log)
351 ;; Don't have file markers, so use impossible regexp.
352 (set (make-local-variable 'log-view-file-re) "\\'\\`")
37320a58
SM
353 (set (make-local-variable 'log-view-message-re)
354 "^ *-+\n *\\(?:revno: \\([0-9]+\\)\\|merged: .+\\)")
b6e0e86c 355 (set (make-local-variable 'log-view-font-lock-keywords)
37320a58
SM
356 ;; log-view-font-lock-keywords is careful to use the buffer-local
357 ;; value of log-view-message-re only since Emacs-23.
358 (append `((,log-view-message-re . 'log-view-message-face))
359 ;; log-view-font-lock-keywords
360 '(("^ *committer: \
5ec05779 361\\([^<(]+?\\)[ ]*[(<]\\([[:alnum:]_.+-]+@[[:alnum:]_.-]+\\)[>)]"
37320a58
SM
362 (1 'change-log-name)
363 (2 'change-log-email))
364 ("^ *timestamp: \\(.*\\)" (1 'change-log-date-face))))))
b6e0e86c 365
8cdd17b4
ER
366(defun vc-bzr-print-log (files &optional buffer) ; get buffer arg in Emacs 22
367 "Get bzr change log for FILES into specified BUFFER."
f4d0cf23
SM
368 ;; FIXME: `vc-bzr-command' runs `bzr log' with `LC_MESSAGES=C', so
369 ;; the log display may not what the user wants - but I see no other
370 ;; way of getting the above regexps working.
371 (apply 'vc-bzr-command "log" buffer 0 files
372 (if (stringp vc-bzr-log-switches)
373 (list vc-bzr-log-switches)
374 vc-bzr-log-switches))
37320a58
SM
375 ;; FIXME: Until Emacs-23, VC was missing a hook to sort out the mode for
376 ;; the buffer, or at least set the regexps right.
377 (unless (fboundp 'vc-default-log-view-mode)
378 (add-hook 'log-view-mode-hook 'vc-bzr-log-view-mode)))
b6e0e86c 379
5b5afd50
ER
380(defun vc-bzr-show-log-entry (revision)
381 "Find entry for patch name REVISION in bzr change log buffer."
b6e0e86c
SM
382 (goto-char (point-min))
383 (let (case-fold-search)
5b5afd50 384 (if (re-search-forward (concat "^-+\nrevno: " revision "$") nil t)
b6e0e86c
SM
385 (beginning-of-line 0)
386 (goto-char (point-min)))))
387
b6e0e86c
SM
388(autoload 'vc-diff-switches-list "vc" nil nil t)
389
8cdd17b4 390(defun vc-bzr-diff (files &optional rev1 rev2 buffer)
b6e0e86c 391 "VC bzr backend for diff."
f4d0cf23 392 ;; `bzr diff' exits with code 1 if diff is non-empty
59ce725a
MB
393 (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files
394 "--diff-options" (mapconcat 'identity
395 (vc-diff-switches-list bzr)
396 " ")
397 (list "-r" (format "%s..%s"
398 (or rev1 "revno:-1")
399 (or rev2 "")))))
b6e0e86c 400
b6e0e86c 401
5b5afd50
ER
402;; FIXME: vc-{next,previous}-revision need fixing in vc.el to deal with
403;; straight integer revisions.
b6e0e86c
SM
404
405(defun vc-bzr-delete-file (file)
406 "Delete FILE and delete it in the bzr repository."
407 (condition-case ()
408 (delete-file file)
409 (file-error nil))
410 (vc-bzr-command "remove" nil 0 file))
411
412(defun vc-bzr-rename-file (old new)
413 "Rename file from OLD to NEW using `bzr mv'."
414 (vc-bzr-command "mv" nil 0 new old))
415
416(defvar vc-bzr-annotation-table nil
417 "Internal use.")
418(make-variable-buffer-local 'vc-bzr-annotation-table)
419
5b5afd50 420(defun vc-bzr-annotate-command (file buffer &optional revision)
b6e0e86c
SM
421 "Prepare BUFFER for `vc-annotate' on FILE.
422Each line is tagged with the revision number, which has a `help-echo'
423property containing author and date information."
6e98ad29 424 (apply #'vc-bzr-command "annotate" buffer 0 file "--long" "--all"
5b5afd50 425 (if revision (list "-r" revision)))
b6e0e86c
SM
426 (with-current-buffer buffer
427 ;; Store the tags for the annotated source lines in a hash table
428 ;; to allow saving space by sharing the text properties.
429 (setq vc-bzr-annotation-table (make-hash-table :test 'equal))
430 (goto-char (point-min))
6e98ad29 431 (while (re-search-forward "^\\( *[0-9]+\\) +\\(.+\\) +\\([0-9]\\{8\\}\\) |"
b6e0e86c
SM
432 nil t)
433 (let* ((rev (match-string 1))
434 (author (match-string 2))
435 (date (match-string 3))
436 (key (match-string 0))
437 (tag (gethash key vc-bzr-annotation-table)))
438 (unless tag
b6e0e86c
SM
439 (setq tag (propertize rev 'help-echo (concat "Author: " author
440 ", date: " date)
441 'mouse-face 'highlight))
442 (puthash key tag vc-bzr-annotation-table))
443 (replace-match "")
444 (insert tag " |")))))
445
b6e0e86c
SM
446(defun vc-bzr-annotate-time ()
447 (when (re-search-forward "^ *[0-9]+ |" nil t)
448 (let ((prop (get-text-property (line-beginning-position) 'help-echo)))
449 (string-match "[0-9]+\\'" prop)
450 (vc-annotate-convert-time
451 (encode-time 0 0 0
452 (string-to-number (substring (match-string 0 prop) 6 8))
453 (string-to-number (substring (match-string 0 prop) 4 6))
454 (string-to-number (substring (match-string 0 prop) 0 4))
455 )))))
456
457(defun vc-bzr-annotate-extract-revision-at-line ()
458 "Return revision for current line of annoation buffer, or nil.
459Return nil if current line isn't annotated."
460 (save-excursion
461 (beginning-of-line)
462 (if (looking-at " *\\([0-9]+\\) | ")
463 (match-string-no-properties 1))))
464
a460c94c
SM
465(defun vc-bzr-command-discarding-stderr (command &rest args)
466 "Execute shell command COMMAND (with ARGS); return its output and exitcode.
b6e6e09a
SM
467Return value is a cons (EXITCODE . OUTPUT), where EXITCODE is
468the (numerical) exit code of the process, and OUTPUT is a string
469containing whatever the process sent to its standard output
470stream. Standard error output is discarded."
471 (with-temp-buffer
a460c94c 472 (cons
33e5d7d4 473 (apply #'call-process command nil (list (current-buffer) nil) nil args)
b6e6e09a 474 (buffer-substring (point-min) (point-max)))))
b6e0e86c
SM
475
476;; TODO: it would be nice to mark the conflicted files in VC Dired,
477;; and implement a command to run ediff and `bzr resolve' once the
478;; changes have been merged.
479(defun vc-bzr-dir-state (dir &optional localp)
cdce374a 480 "Find the VC state of all files in DIR and its subdirectories.
b6e0e86c 481Optional argument LOCALP is always ignored."
37320a58
SM
482 (let ((bzr-root-directory (vc-bzr-root dir))
483 (at-start t)
484 current-bzr-state current-vc-state)
485 ;; Check that DIR is a bzr repository.
486 (unless (file-name-absolute-p bzr-root-directory)
b6e0e86c
SM
487 (error "Cannot find bzr repository for directory `%s'" dir))
488 ;; `bzr ls --versioned' lists all versioned files;
489 ;; assume they are up-to-date, unless we are given
490 ;; evidence of the contrary.
37320a58 491 (setq at-start t)
b6e0e86c 492 (with-temp-buffer
18e1f249 493 (buffer-disable-undo) ;; Because these buffers can get huge
cdce374a 494 (vc-bzr-command "ls" t 0 nil "--versioned")
b6e0e86c 495 (goto-char (point-min))
37320a58 496 (while (or at-start
b6e0e86c 497 (eq 0 (forward-line)))
37320a58 498 (setq at-start nil)
b6e0e86c
SM
499 (let ((file (expand-file-name
500 (buffer-substring-no-properties
501 (line-beginning-position) (line-end-position))
502 bzr-root-directory)))
f4d0cf23
SM
503 ;; files are up-to-date unless they appear in the `bzr
504 ;; status' output below
b6e0e86c
SM
505 (vc-file-setprop file 'vc-state 'up-to-date)
506 ;; XXX: is this correct? what happens if one
507 ;; mixes different SCMs in the same dir?
f4d0cf23
SM
508 ;; Anyway, we're looking at the output of `bzr ls --versioned',
509 ;; so we know these files are registered with Bzr.
4211679b 510 (vc-file-setprop file 'vc-backend 'Bzr))))
b6e0e86c 511 ;; `bzr status' reports on added/modified/renamed and unknown/ignored files
37320a58 512 (setq at-start t)
b6e0e86c 513 (with-temp-buffer
77b5d458 514 (vc-bzr-command "status" t 0 nil)
b6e0e86c 515 (goto-char (point-min))
37320a58 516 (while (or at-start
b6e0e86c 517 (eq 0 (forward-line)))
37320a58 518 (setq at-start nil)
b6e0e86c
SM
519 (cond
520 ((looking-at "^added")
484c1b1f 521 (setq current-vc-state 'added)
37320a58 522 (setq current-bzr-state 'added))
33e5d7d4
SM
523 ((looking-at "^kind changed")
524 (setq current-vc-state 'edited)
fba500b6 525 (setq current-bzr-state 'kindchanged))
b6e0e86c 526 ((looking-at "^modified")
37320a58
SM
527 (setq current-vc-state 'edited)
528 (setq current-bzr-state 'modified))
b6e0e86c 529 ((looking-at "^renamed")
37320a58
SM
530 (setq current-vc-state 'edited)
531 (setq current-bzr-state 'renamed))
722f037f
ER
532 ((looking-at "^ignored")
533 (setq current-vc-state 'ignored)
534 (setq current-bzr-state 'not-versioned))
535 ((looking-at "^unknown")
536 (setq current-vc-state 'unregistered)
37320a58 537 (setq current-bzr-state 'not-versioned))
b6e0e86c
SM
538 ((looking-at " ")
539 ;; file names are indented by two spaces
540 (when current-vc-state
541 (let ((file (expand-file-name
542 (buffer-substring-no-properties
543 (match-end 0) (line-end-position))
544 bzr-root-directory)))
545 (vc-file-setprop file 'vc-state current-vc-state)
546 (vc-file-setprop file 'vc-bzr-state current-bzr-state)
547 (when (eq 'added current-bzr-state)
ac3f4c6f 548 (vc-file-setprop file 'vc-working-revision "0"))))
b6e0e86c
SM
549 (when (eq 'not-versioned current-bzr-state)
550 (let ((file (expand-file-name
551 (buffer-substring-no-properties
552 (match-end 0) (line-end-position))
553 bzr-root-directory)))
554 (vc-file-setprop file 'vc-backend 'none)
555 (vc-file-setprop file 'vc-state nil))))
556 (t
557 ;; skip this part of `bzr status' output
37320a58
SM
558 (setq current-vc-state nil)
559 (setq current-bzr-state nil)))))))
b6e0e86c
SM
560
561(defun vc-bzr-dired-state-info (file)
562 "Bzr-specific version of `vc-dired-state-info'."
563 (if (eq 'edited (vc-state file))
f4d0cf23
SM
564 (concat "(" (symbol-name (or (vc-file-getprop file 'vc-bzr-state)
565 'edited)) ")")
566 ;; else fall back to default vc.el representation
567 (vc-default-dired-state-info 'Bzr file)))
b6e0e86c 568
b6e0e86c 569(eval-after-load "vc"
b6e6e09a 570 '(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t))
b6e0e86c 571
b6e0e86c
SM
572(provide 'vc-bzr)
573;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06
574;;; vc-bzr.el ends here