(vc-bzr-admin-dirstate): Rename from `...-dirname'.
[bpt/emacs.git] / lisp / vc-bzr.el
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
13 ;; Version: 2007-05-24
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 3, 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
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.
43
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
56
57
58 ;;; Code:
59
60 (eval-when-compile
61 (require 'cl)
62 (require 'vc)) ; for vc-exec-after
63
64 ;; Clear up the cache to force vc-call to check again and discover
65 ;; new functions when we reload this file.
66 (put 'BZR 'vc-functions nil)
67
68 (defgroup vc-bzr nil
69 "VC bzr backend."
70 ;; :version "22"
71 :group 'vc)
72
73 (defcustom vc-bzr-program "bzr"
74 "Name of the bzr command (excluding any arguments)."
75 :group 'vc-bzr
76 :type 'string)
77
78 ;; Fixme: there's probably no call for this.
79 (defcustom vc-bzr-program-args nil
80 "List of global arguments to pass to `vc-bzr-program'."
81 :group 'vc-bzr
82 :type '(repeat string))
83
84 (defcustom vc-bzr-diff-switches nil
85 "String/list of strings specifying extra switches for bzr diff under VC."
86 :type '(choice (const :tag "None" nil)
87 (string :tag "Argument String")
88 (repeat :tag "Argument List" :value ("") string))
89 :group 'vc-bzr)
90
91 ;; since v0.9, bzr supports removing the progress indicators
92 ;; by setting environment variable BZR_PROGRESS_BAR to "none".
93 (defun vc-bzr-command (bzr-command buffer okstatus file-or-list &rest args)
94 "Wrapper round `vc-do-command' using `vc-bzr-program' as COMMAND.
95 Invoke the bzr command adding `BZR_PROGRESS_BAR=none' to the environment."
96 (let ((process-environment
97 (list* "BZR_PROGRESS_BAR=none" ; Suppress progress output (bzr >=0.9)
98 "LC_ALL=C" ; Force English output
99 process-environment))
100 ;; bzr may attempt some kind of user interaction if its stdin/stdout
101 ;; is connected to a PTY; therefore, ask Emacs to use a pipe to
102 ;; communicate with it.
103 ;; This is redundant because vc-do-command does it already. --Stef
104 (process-connection-type nil))
105 (apply 'vc-do-command buffer okstatus vc-bzr-program
106 file-or-list bzr-command (append vc-bzr-program-args args))))
107
108 ;;;###autoload
109 (defconst vc-bzr-admin-dirstate ".bzr/checkout/dirstate") ; "_bzr" on w32??
110
111 ;;;###autoload (defun vc-bzr-registered (file)
112 ;;;###autoload (if (vc-find-root file vc-bzr-admin-dirstate)
113 ;;;###autoload (progn
114 ;;;###autoload (load "vc-bzr")
115 ;;;###autoload (vc-bzr-registered file))))
116 (defun vc-bzr-root-dir (file)
117 "Return the root directory in the hierarchy above FILE.
118 Return nil if there isn't one."
119 (vc-find-root file vc-bzr-admin-dirstate))
120
121 (defun vc-bzr-registered (file)
122 "Return non-nil if FILE is registered with bzr."
123 (let ((root (vc-bzr-root-dir file)))
124 (and root ; Short cut.
125 ;; This looks at internal files. May break if they change
126 ;; their format.
127 (with-temp-buffer
128 (insert-file-contents
129 (expand-file-name vc-bzr-admin-dirstate root))
130 (goto-char (point-min))
131 (let* ((relfile (file-relative-name file root))
132 (reldir (file-name-directory relfile)))
133 (re-search-forward
134 (concat "^