2007-08-19 Michael Kifer <kifer@cs.stonybrook.edu>
[emacs.git] / lisp / vc-bzr.el
blob20a9ca9b2fbfb8e31b58c15c134bcb32326885ec
1 ;;; vc-bzr.el --- VC backend for the bzr revision control system
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc.
5 ;; Author: Dave Love <fx@gnu.org>, Riccardo Murri <riccardo.murri@gmail.com>
6 ;; Keywords: tools
7 ;; Created: Sept 2006
8 ;; Version: 2007-08-03
9 ;; URL: http://launchpad.net/vc-bzr
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
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
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.
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.
27 ;;; Commentary:
29 ;; See <URL:http://bazaar-vcs.org/> concerning bzr.
31 ;; Load this library to register bzr support in VC. It covers basic VC
32 ;; functionality, but was only lightly exercised with a few Emacs/bzr
33 ;; version combinations, namely those current on the authors' PCs.
34 ;; See various Fixmes below.
37 ;; Known bugs
38 ;; ==========
40 ;; When edititing a symlink and *both* the symlink and its target
41 ;; are bzr-versioned, `vc-bzr` presently runs `bzr status` on the
42 ;; symlink, thereby not detecting whether the actual contents
43 ;; (that is, the target contents) are changed.
44 ;; See https://bugs.launchpad.net/vc-bzr/+bug/116607
46 ;; For an up-to-date list of bugs, please see:
47 ;; https://bugs.launchpad.net/vc-bzr/+bugs
50 ;;; Code:
52 (eval-when-compile
53 (require 'cl)
54 (require 'vc)) ; for vc-exec-after
56 ;; Clear up the cache to force vc-call to check again and discover
57 ;; new functions when we reload this file.
58 (put 'Bzr 'vc-functions nil)
60 (defgroup vc-bzr nil
61 "VC bzr backend."
62 ;; :version "22"
63 :group 'vc)
65 (defcustom vc-bzr-program "bzr"
66 "Name of the bzr command (excluding any arguments)."
67 :group 'vc-bzr
68 :type 'string)
70 ;; Fixme: there's probably no call for this.
71 (defcustom vc-bzr-program-args nil
72 "List of global arguments to pass to `vc-bzr-program'."
73 :group 'vc-bzr
74 :type '(repeat string))
76 (defcustom vc-bzr-diff-switches nil
77 "String/list of strings specifying extra switches for bzr diff under VC."
78 :type '(choice (const :tag "None" nil)
79 (string :tag "Argument String")
80 (repeat :tag "Argument List" :value ("") string))
81 :group 'vc-bzr)
83 ;; since v0.9, bzr supports removing the progress indicators
84 ;; by setting environment variable BZR_PROGRESS_BAR to "none".
85 (defun vc-bzr-command (bzr-command buffer okstatus file-or-list &rest args)
86 "Wrapper round `vc-do-command' using `vc-bzr-program' as COMMAND.
87 Invoke the bzr command adding `BZR_PROGRESS_BAR=none' to the environment."
88 (let ((process-environment
89 (list* "BZR_PROGRESS_BAR=none" ; Suppress progress output (bzr >=0.9)
90 "LC_ALL=C" ; Force English output
91 process-environment)))
92 (apply 'vc-do-command buffer okstatus vc-bzr-program
93 file-or-list bzr-command (append vc-bzr-program-args args))))
96 ;;;###autoload
97 (defconst vc-bzr-admin-dirname ".bzr" ; FIXME: "_bzr" on w32?
98 "Name of the directory containing Bzr repository status files.")
99 ;;;###autoload
100 (defconst vc-bzr-admin-checkout-format-file
101 (concat vc-bzr-admin-dirname "/checkout/format"))
102 (defconst vc-bzr-admin-dirstate
103 (concat vc-bzr-admin-dirname "/checkout/dirstate"))
104 (defconst vc-bzr-admin-branch-format-file
105 (concat vc-bzr-admin-dirname "/branch/format"))
106 (defconst vc-bzr-admin-revhistory
107 (concat vc-bzr-admin-dirname "/branch/revision-history"))
109 ;;;###autoload (defun vc-bzr-registered (file)
110 ;;;###autoload (if (vc-find-root file vc-bzr-admin-checkout-format-file)
111 ;;;###autoload (progn
112 ;;;###autoload (load "vc-bzr")
113 ;;;###autoload (vc-bzr-registered file))))
115 (defun vc-bzr-root (file)
116 "Return the root directory of the bzr repository containing FILE."
117 ;; Cache technique copied from vc-arch.el.
118 (or (vc-file-getprop file 'bzr-root)
119 (vc-file-setprop
120 file 'bzr-root
121 (vc-find-root file vc-bzr-admin-checkout-format-file))))
123 (defun vc-bzr-registered (file)
124 "Return non-nil if FILE is registered with bzr.
126 For speed, this function tries first to parse Bzr internal file
127 `checkout/dirstate', but it may fail if Bzr internal file format
128 has changed. As a safeguard, the `checkout/dirstate' file is
129 only parsed if it contains the string `#bazaar dirstate flat
130 format 3' in the first line.
132 If the `checkout/dirstate' file cannot be parsed, fall back to
133 running `vc-bzr-state'."
134 (condition-case nil
135 (lexical-let ((root (vc-bzr-root file)))
136 (and root ; Short cut.
137 ;; This looks at internal files. May break if they change
138 ;; their format.
139 (lexical-let
140 ((dirstate-file (expand-file-name vc-bzr-admin-dirstate root)))
141 (if (file-exists-p dirstate-file)
142 (with-temp-buffer
143 (insert-file-contents dirstate-file)
144 (goto-char (point-min))
145 (when (looking-at "#bazaar dirstate flat format 3")
146 (let* ((relfile (file-relative-name file root))
147 (reldir (file-name-directory relfile)))
148 (re-search-forward
149 (concat "^\0"
150 (if reldir (regexp-quote (directory-file-name reldir)))
151 "\0"
152 (regexp-quote (file-name-nondirectory relfile))
153 "\0")
154 nil t))))
156 (vc-bzr-state file))) ; Expensive.
157 (file-error nil))) ; vc-bzr-program not found
159 (defun vc-bzr-buffer-nonblank-p (&optional buffer)
160 "Return non-nil if BUFFER contains any non-blank characters."
161 (or (> (buffer-size buffer) 0)
162 (save-excursion
163 (set-buffer (or buffer (current-buffer)))
164 (goto-char (point-min))
165 (re-search-forward "[^ \t\n]" (point-max) t))))
167 (defconst vc-bzr-state-words
168 "added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown"
169 "Regexp matching file status words as reported in `bzr' output.")
171 (defun vc-bzr-file-name-relative (filename)
172 "Return file name FILENAME stripped of the initial Bzr repository path."
173 (lexical-let*
174 ((filename* (expand-file-name filename))
175 (rootdir (vc-bzr-root (file-name-directory filename*))))
176 (and rootdir
177 (file-relative-name filename* rootdir))))
179 ;; FIXME: Also get this in a non-registered sub-directory.
180 ;; It already works for me. -- Riccardo
181 (defun vc-bzr-status (file)
182 "Return FILE status according to Bzr.
183 Return value is a cons (STATUS . WARNING), where WARNING is a
184 string or nil, and STATUS is one of the symbols: 'added,
185 'ignored, 'kindchange, 'modified, 'removed, 'renamed, 'unknown,
186 which directly correspond to `bzr status' output, or 'unchanged
187 for files whose copy in the working tree is identical to the one
188 in the branch repository, or nil for files that are not
189 registered with Bzr.
191 If any error occurred in running `bzr status', then return nil."
192 (condition-case nil
193 (with-temp-buffer
194 (let ((ret (vc-bzr-command "status" t 0 file))
195 (status 'unchanged))
196 ;; the only secure status indication in `bzr status' output
197 ;; is a couple of lines following the pattern::
198 ;; | <status>:
199 ;; | <file name>
200 ;; if the file is up-to-date, we get no status report from `bzr',
201 ;; so if the regexp search for the above pattern fails, we consider
202 ;; the file to be up-to-date.
203 (goto-char (point-min))
204 (when
205 (re-search-forward
206 ;; bzr prints paths relative to the repository root
207 (concat "^\\(" vc-bzr-state-words "\\):[ \t\n]+"
208 (regexp-quote (vc-bzr-file-name-relative file))
209 (if (file-directory-p file) "/?" "")
210 "[ \t\n]*$")
211 (point-max) t)
212 (let ((start (match-beginning 0))
213 (end (match-end 0)))
214 (goto-char start)
215 (setq status
216 (cond
217 ((not (equal ret 0)) nil)
218 ((looking-at "added") 'added)
219 ((looking-at "kind changed") 'kindchange)
220 ((looking-at "renamed") 'renamed)
221 ((looking-at "modified") 'modified)
222 ((looking-at "removed") 'removed)
223 ((looking-at "ignored") 'ignored)
224 ((looking-at "unknown") 'unknown)))
225 ;; erase the status text that matched
226 (delete-region start end)))
227 (if status
228 (cons status
229 ;; "bzr" will output warnings and informational messages to
230 ;; stderr; due to Emacs' `vc-do-command' (and, it seems,
231 ;; `start-process' itself) limitations, we cannot catch stderr
232 ;; and stdout into different buffers. So, if there's anything
233 ;; left in the buffer after removing the above status
234 ;; keywords, let us just presume that any other message from
235 ;; "bzr" is a user warning, and display it.
236 (if (vc-bzr-buffer-nonblank-p)
237 (buffer-substring (point-min) (point-max)))))))
238 (file-error nil))) ; vc-bzr-program not found
240 (defun vc-bzr-state (file)
241 (lexical-let ((result (vc-bzr-status file)))
242 (when (consp result)
243 (if (cdr result)
244 (message "Warnings in `bzr' output: %s" (cdr result)))
245 (cdr (assq (car result)
246 '((added . edited)
247 (kindchange . edited)
248 (renamed . edited)
249 (modified . edited)
250 (removed . edited)
251 (ignored . nil)
252 (unknown . nil)
253 (unchanged . up-to-date)))))))
255 (defun vc-bzr-workfile-unchanged-p (file)
256 (eq 'unchanged (car (vc-bzr-status file))))
258 (defun vc-bzr-workfile-version (file)
259 (lexical-let*
260 ((rootdir (vc-bzr-root file))
261 (branch-format-file (concat rootdir "/" vc-bzr-admin-branch-format-file))
262 (revhistory-file (concat rootdir "/" vc-bzr-admin-revhistory))
263 (lastrev-file (concat rootdir "/" "branch/last-revision")))
264 ;; Count lines in .bzr/branch/revision-history to avoid forking a
265 ;; bzr process. This looks at internal files. May break if they
266 ;; change their format.
267 (if (file-exists-p branch-format-file)
268 (with-temp-buffer
269 (insert-file-contents branch-format-file)
270 (goto-char (point-min))
271 (cond
272 ((or
273 (looking-at "Bazaar-NG branch, format 0.0.4")
274 (looking-at "Bazaar-NG branch format 5"))
275 ;; count lines in .bzr/branch/revision-history
276 (insert-file-contents revhistory-file)
277 (number-to-string (count-lines (line-end-position) (point-max))))
278 ((looking-at "Bazaar Branch Format 6 (bzr 0.15)")
279 ;; revno is the first number in .bzr/branch/last-revision
280 (insert-file-contents lastrev-file)
281 (goto-char (line-end-position))
282 (if (re-search-forward "[0-9]+" nil t)
283 (buffer-substring (match-beginning 0) (match-end 0))))))
284 ;; fallback to calling "bzr revno"
285 (lexical-let*
286 ((result (vc-bzr-command-discarding-stderr
287 vc-bzr-program "revno" file))
288 (exitcode (car result))
289 (output (cdr result)))
290 (cond
291 ((eq exitcode 0) (substring output 0 -1))
292 (t nil))))))
294 (defun vc-bzr-checkout-model (file)
295 'implicit)
297 (defun vc-bzr-create-repo ()
298 "Create a new Bzr repository."
299 (vc-bzr-command "init" nil 0 nil))
301 (defun vc-bzr-register (files &optional rev comment)
302 "Register FILE under bzr.
303 Signal an error unless REV is nil.
304 COMMENT is ignored."
305 (if rev (error "Can't register explicit version with bzr"))
306 (vc-bzr-command "add" nil 0 files))
308 ;; Could run `bzr status' in the directory and see if it succeeds, but
309 ;; that's relatively expensive.
310 (defalias 'vc-bzr-responsible-p 'vc-bzr-root
311 "Return non-nil if FILE is (potentially) controlled by bzr.
312 The criterion is that there is a `.bzr' directory in the same
313 or a superior directory.")
315 (defun vc-bzr-could-register (file)
316 "Return non-nil if FILE could be registered under bzr."
317 (and (vc-bzr-responsible-p file) ; shortcut
318 (condition-case ()
319 (with-temp-buffer
320 (vc-bzr-command "add" t 0 file "--dry-run")
321 ;; The command succeeds with no output if file is
322 ;; registered (in bzr 0.8).
323 (goto-char (point-min))
324 (looking-at "added "))
325 (error))))
327 (defun vc-bzr-unregister (file)
328 "Unregister FILE from bzr."
329 (vc-bzr-command "remove" nil 0 file))
331 (defun vc-bzr-checkin (files rev comment)
332 "Check FILE in to bzr with log message COMMENT.
333 REV non-nil gets an error."
334 (if rev (error "Can't check in a specific version with bzr"))
335 (vc-bzr-command "commit" nil 0 files "-m" comment))
337 (defun vc-bzr-checkout (file &optional editable rev destfile)
338 "Checkout revision REV of FILE from bzr to DESTFILE.
339 EDITABLE is ignored."
340 (unless destfile
341 (setq destfile (vc-version-backup-file-name file rev)))
342 (let ((coding-system-for-read 'binary)
343 (coding-system-for-write 'binary))
344 (with-temp-file destfile
345 (if rev
346 (vc-bzr-command "cat" t 0 file "-r" rev)
347 (vc-bzr-command "cat" t 0 file)))))
349 (defun vc-bzr-revert (file &optional contents-done)
350 (unless contents-done
351 (with-temp-buffer (vc-bzr-command "revert" t 0 file))))
353 (defvar log-view-message-re)
354 (defvar log-view-file-re)
355 (defvar log-view-font-lock-keywords)
356 (defvar log-view-current-tag-function)
358 (define-derived-mode vc-bzr-log-view-mode log-view-mode "Bzr-Log-View"
359 (remove-hook 'log-view-mode-hook 'vc-bzr-log-view-mode) ;Deactivate the hack.
360 (require 'add-log)
361 ;; Don't have file markers, so use impossible regexp.
362 (set (make-local-variable 'log-view-file-re) "\\'\\`")
363 (set (make-local-variable 'log-view-message-re)
364 "^ *-+\n *\\(?:revno: \\([0-9]+\\)\\|merged: .+\\)")
365 (set (make-local-variable 'log-view-font-lock-keywords)
366 ;; log-view-font-lock-keywords is careful to use the buffer-local
367 ;; value of log-view-message-re only since Emacs-23.
368 (append `((,log-view-message-re . 'log-view-message-face))
369 ;; log-view-font-lock-keywords
370 '(("^ *committer: \
371 \\([^<(]+?\\)[ ]*[(<]\\([[:alnum:]_.+-]+@[[:alnum:]_.-]+\\)[>)]"
372 (1 'change-log-name)
373 (2 'change-log-email))
374 ("^ *timestamp: \\(.*\\)" (1 'change-log-date-face))))))
376 (defun vc-bzr-print-log (files &optional buffer) ; get buffer arg in Emacs 22
377 "Get bzr change log for FILES into specified BUFFER."
378 ;; Fixme: This might need the locale fixing up if things like `revno'
379 ;; got localized, but certainly it shouldn't use LC_ALL=C.
380 ;; NB. Can't be async -- see `vc-bzr-post-command-function'.
381 (vc-bzr-command "log" buffer 0 files)
382 ;; FIXME: Until Emacs-23, VC was missing a hook to sort out the mode for
383 ;; the buffer, or at least set the regexps right.
384 (unless (fboundp 'vc-default-log-view-mode)
385 (add-hook 'log-view-mode-hook 'vc-bzr-log-view-mode)))
387 (defun vc-bzr-show-log-entry (version)
388 "Find entry for patch name VERSION in bzr change log buffer."
389 (goto-char (point-min))
390 (let (case-fold-search)
391 (if (re-search-forward (concat "^-+\nrevno: " version "$") nil t)
392 (beginning-of-line 0)
393 (goto-char (point-min)))))
395 (autoload 'vc-diff-switches-list "vc" nil nil t)
397 (defun vc-bzr-diff (files &optional rev1 rev2 buffer)
398 "VC bzr backend for diff."
399 (let ((working (vc-workfile-version (if (consp files) (car files) files))))
400 (if (and (equal rev1 working) (not rev2))
401 (setq rev1 nil))
402 (if (and (not rev1) rev2)
403 (setq rev1 working))
404 ;; NB. Can't be async -- see `vc-bzr-post-command-function'.
405 ;; bzr diff produces condition code 1 for some reason.
406 (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files
407 "--diff-options" (mapconcat 'identity (vc-diff-switches-list bzr)
408 " ")
409 (when rev1
410 (if rev2
411 (list "-r" (format "%s..%s" rev1 rev2))
412 (list "-r" rev1))))))
414 (defalias 'vc-bzr-diff-tree 'vc-bzr-diff)
417 ;; FIXME: vc-{next,previous}-version need fixing in vc.el to deal with
418 ;; straight integer versions.
420 (defun vc-bzr-delete-file (file)
421 "Delete FILE and delete it in the bzr repository."
422 (condition-case ()
423 (delete-file file)
424 (file-error nil))
425 (vc-bzr-command "remove" nil 0 file))
427 (defun vc-bzr-rename-file (old new)
428 "Rename file from OLD to NEW using `bzr mv'."
429 (vc-bzr-command "mv" nil 0 new old))
431 (defvar vc-bzr-annotation-table nil
432 "Internal use.")
433 (make-variable-buffer-local 'vc-bzr-annotation-table)
435 (defun vc-bzr-annotate-command (file buffer &optional version)
436 "Prepare BUFFER for `vc-annotate' on FILE.
437 Each line is tagged with the revision number, which has a `help-echo'
438 property containing author and date information."
439 (apply #'vc-bzr-command "annotate" buffer 0 file "-l" "--all"
440 (if version (list "-r" version)))
441 (with-current-buffer buffer
442 ;; Store the tags for the annotated source lines in a hash table
443 ;; to allow saving space by sharing the text properties.
444 (setq vc-bzr-annotation-table (make-hash-table :test 'equal))
445 (goto-char (point-min))
446 (while (re-search-forward "^\\( *[0-9]+\\) \\(.+\\) +\\([0-9]\\{8\\}\\) |"
447 nil t)
448 (let* ((rev (match-string 1))
449 (author (match-string 2))
450 (date (match-string 3))
451 (key (match-string 0))
452 (tag (gethash key vc-bzr-annotation-table)))
453 (unless tag
454 (save-match-data
455 (string-match " +\\'" author)
456 (setq author (substring author 0 (match-beginning 0))))
457 (setq tag (propertize rev 'help-echo (concat "Author: " author
458 ", date: " date)
459 'mouse-face 'highlight))
460 (puthash key tag vc-bzr-annotation-table))
461 (replace-match "")
462 (insert tag " |")))))
464 ;; Definition from Emacs 22
465 (unless (fboundp 'vc-annotate-convert-time)
466 (defun vc-annotate-convert-time (time)
467 "Convert a time value to a floating-point number of days.
468 The argument TIME is a list as returned by `current-time' or
469 `encode-time', only the first two elements of that list are considered."
470 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600)))
472 (defun vc-bzr-annotate-time ()
473 (when (re-search-forward "^ *[0-9]+ |" nil t)
474 (let ((prop (get-text-property (line-beginning-position) 'help-echo)))
475 (string-match "[0-9]+\\'" prop)
476 (vc-annotate-convert-time
477 (encode-time 0 0 0
478 (string-to-number (substring (match-string 0 prop) 6 8))
479 (string-to-number (substring (match-string 0 prop) 4 6))
480 (string-to-number (substring (match-string 0 prop) 0 4))
481 )))))
483 (defun vc-bzr-annotate-extract-revision-at-line ()
484 "Return revision for current line of annoation buffer, or nil.
485 Return nil if current line isn't annotated."
486 (save-excursion
487 (beginning-of-line)
488 (if (looking-at " *\\([0-9]+\\) | ")
489 (match-string-no-properties 1))))
491 ;; Not needed for Emacs 22
492 (defun vc-bzr-annotate-difference (point)
493 (let ((next-time (vc-bzr-annotate-time)))
494 (if next-time
495 (- (vc-annotate-convert-time (current-time)) next-time))))
497 (defun vc-bzr-command-discarding-stderr (command &rest args)
498 "Execute shell command COMMAND (with ARGS); return its output and exitcode.
499 Return value is a cons (EXITCODE . OUTPUT), where EXITCODE is
500 the (numerical) exit code of the process, and OUTPUT is a string
501 containing whatever the process sent to its standard output
502 stream. Standard error output is discarded."
503 (with-temp-buffer
504 (cons
505 (apply #'call-process command nil (list (current-buffer) nil) nil args)
506 (buffer-substring (point-min) (point-max)))))
508 ;; TODO: it would be nice to mark the conflicted files in VC Dired,
509 ;; and implement a command to run ediff and `bzr resolve' once the
510 ;; changes have been merged.
511 (defun vc-bzr-dir-state (dir &optional localp)
512 "Find the VC state of all files in DIR.
513 Optional argument LOCALP is always ignored."
514 (let ((bzr-root-directory (vc-bzr-root dir))
515 (at-start t)
516 current-bzr-state current-vc-state)
517 ;; Check that DIR is a bzr repository.
518 (unless (file-name-absolute-p bzr-root-directory)
519 (error "Cannot find bzr repository for directory `%s'" dir))
520 ;; `bzr ls --versioned' lists all versioned files;
521 ;; assume they are up-to-date, unless we are given
522 ;; evidence of the contrary.
523 (setq at-start t)
524 (with-temp-buffer
525 (vc-bzr-command "ls" t 0 nil "--versioned" "--non-recursive")
526 (goto-char (point-min))
527 (while (or at-start
528 (eq 0 (forward-line)))
529 (setq at-start nil)
530 (let ((file (expand-file-name
531 (buffer-substring-no-properties
532 (line-beginning-position) (line-end-position))
533 bzr-root-directory)))
534 (vc-file-setprop file 'vc-state 'up-to-date)
535 ;; XXX: is this correct? what happens if one
536 ;; mixes different SCMs in the same dir?
537 (vc-file-setprop file 'vc-backend 'Bzr))))
538 ;; `bzr status' reports on added/modified/renamed and unknown/ignored files
539 (setq at-start t)
540 (with-temp-buffer
541 (vc-bzr-command "status" t 0 nil)
542 (goto-char (point-min))
543 (while (or at-start
544 (eq 0 (forward-line)))
545 (setq at-start nil)
546 (cond
547 ((looking-at "^added")
548 (setq current-vc-state 'edited)
549 (setq current-bzr-state 'added))
550 ((looking-at "^kind changed")
551 (setq current-vc-state 'edited)
552 (setq current-bzr-state 'kindchange))
553 ((looking-at "^modified")
554 (setq current-vc-state 'edited)
555 (setq current-bzr-state 'modified))
556 ((looking-at "^renamed")
557 (setq current-vc-state 'edited)
558 (setq current-bzr-state 'renamed))
559 ((looking-at "^\\(unknown\\|ignored\\)")
560 (setq current-vc-state nil)
561 (setq current-bzr-state 'not-versioned))
562 ((looking-at " ")
563 ;; file names are indented by two spaces
564 (when current-vc-state
565 (let ((file (expand-file-name
566 (buffer-substring-no-properties
567 (match-end 0) (line-end-position))
568 bzr-root-directory)))
569 (vc-file-setprop file 'vc-state current-vc-state)
570 (vc-file-setprop file 'vc-bzr-state current-bzr-state)
571 (when (eq 'added current-bzr-state)
572 (vc-file-setprop file 'vc-workfile-version "0"))))
573 (when (eq 'not-versioned current-bzr-state)
574 (let ((file (expand-file-name
575 (buffer-substring-no-properties
576 (match-end 0) (line-end-position))
577 bzr-root-directory)))
578 (vc-file-setprop file 'vc-backend 'none)
579 (vc-file-setprop file 'vc-state nil))))
581 ;; skip this part of `bzr status' output
582 (setq current-vc-state nil)
583 (setq current-bzr-state nil)))))))
585 (defun vc-bzr-dired-state-info (file)
586 "Bzr-specific version of `vc-dired-state-info'."
587 (if (eq 'edited (vc-state file))
588 (let ((bzr-state (vc-file-getprop file 'vc-bzr-state)))
589 (if bzr-state
590 (concat "(" (symbol-name bzr-state) ")")
591 ;; else fall back to default vc representation
592 (vc-default-dired-state-info 'Bzr file)))))
594 ;; In case of just `(load "vc-bzr")', but that's probably the wrong
595 ;; way to do it.
596 (add-to-list 'vc-handled-backends 'Bzr)
598 (eval-after-load "vc"
599 '(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t))
601 (defconst vc-bzr-unload-hook
602 (lambda ()
603 (setq vc-handled-backends (delq 'Bzr vc-handled-backends))
604 (remove-hook 'vc-post-command-functions 'vc-bzr-post-command-function)))
606 (provide 'vc-bzr)
607 ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06
608 ;;; vc-bzr.el ends here