Mercurial > emacs
comparison lisp/vc/vc-bzr.el @ 111679:33ed3cf8260b
Initial support for unified DVCS pull and merge.
* lisp/vc/vc-bzr.el (vc-bzr-admin-branchconf, vc-bzr-history): New vars.
(vc-bzr--branch-conf, vc-bzr-async-command, vc-bzr-pull)
(vc-bzr-merge-branch): New functions, implementing merge-branch
and pull operations.
* lisp/vc/vc.el (vc-merge): Use vc-BACKEND-merge-branch if available.
Accept optional prefix arg meaning to prompt for a command.
(vc-update): Use vc-BACKEND-pull if available. Accept optional
prefix arg meaning to prompt for a command.
(vc-pull): Alias for vc-update.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 22 Nov 2010 20:15:08 -0500 |
parents | 280c8ae2476d |
children | 411dce7ee068 |
comparison
equal
deleted
inserted
replaced
111678:3b6c0c4ef2bb | 111679:33ed3cf8260b |
---|---|
113 (concat vc-bzr-admin-dirname "/branch/format")) | 113 (concat vc-bzr-admin-dirname "/branch/format")) |
114 (defconst vc-bzr-admin-revhistory | 114 (defconst vc-bzr-admin-revhistory |
115 (concat vc-bzr-admin-dirname "/branch/revision-history")) | 115 (concat vc-bzr-admin-dirname "/branch/revision-history")) |
116 (defconst vc-bzr-admin-lastrev | 116 (defconst vc-bzr-admin-lastrev |
117 (concat vc-bzr-admin-dirname "/branch/last-revision")) | 117 (concat vc-bzr-admin-dirname "/branch/last-revision")) |
118 (defconst vc-bzr-admin-branchconf | |
119 (concat vc-bzr-admin-dirname "/branch/branch.conf")) | |
118 | 120 |
119 ;;;###autoload (defun vc-bzr-registered (file) | 121 ;;;###autoload (defun vc-bzr-registered (file) |
120 ;;;###autoload (if (vc-find-root file vc-bzr-admin-checkout-format-file) | 122 ;;;###autoload (if (vc-find-root file vc-bzr-admin-checkout-format-file) |
121 ;;;###autoload (progn | 123 ;;;###autoload (progn |
122 ;;;###autoload (load "vc-bzr") | 124 ;;;###autoload (load "vc-bzr") |
126 "Return the root directory of the bzr repository containing FILE." | 128 "Return the root directory of the bzr repository containing FILE." |
127 ;; Cache technique copied from vc-arch.el. | 129 ;; Cache technique copied from vc-arch.el. |
128 (or (vc-file-getprop file 'bzr-root) | 130 (or (vc-file-getprop file 'bzr-root) |
129 (let ((root (vc-find-root file vc-bzr-admin-checkout-format-file))) | 131 (let ((root (vc-find-root file vc-bzr-admin-checkout-format-file))) |
130 (when root (vc-file-setprop file 'bzr-root root))))) | 132 (when root (vc-file-setprop file 'bzr-root root))))) |
133 | |
134 (defun vc-bzr--branch-conf (file) | |
135 "Return the Bzr branch config for file FILE, as a string." | |
136 (with-temp-buffer | |
137 (insert-file-contents | |
138 (expand-file-name vc-bzr-admin-branchconf (vc-bzr-root file))) | |
139 (buffer-string))) | |
131 | 140 |
132 (require 'sha1) ;For sha1-program | 141 (require 'sha1) ;For sha1-program |
133 | 142 |
134 (defun vc-bzr-sha1 (file) | 143 (defun vc-bzr-sha1 (file) |
135 (with-temp-buffer | 144 (with-temp-buffer |
226 | 235 |
227 (defconst vc-bzr-state-words | 236 (defconst vc-bzr-state-words |
228 "added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown" | 237 "added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown" |
229 "Regexp matching file status words as reported in `bzr' output.") | 238 "Regexp matching file status words as reported in `bzr' output.") |
230 | 239 |
240 ;; History of Bzr commands. | |
241 (defvar vc-bzr-history nil) | |
242 | |
231 (defun vc-bzr-file-name-relative (filename) | 243 (defun vc-bzr-file-name-relative (filename) |
232 "Return file name FILENAME stripped of the initial Bzr repository path." | 244 "Return file name FILENAME stripped of the initial Bzr repository path." |
233 (lexical-let* | 245 (lexical-let* |
234 ((filename* (expand-file-name filename)) | 246 ((filename* (expand-file-name filename)) |
235 (rootdir (vc-bzr-root filename*))) | 247 (rootdir (vc-bzr-root filename*))) |
236 (when rootdir | 248 (when rootdir |
237 (file-relative-name filename* rootdir)))) | 249 (file-relative-name filename* rootdir)))) |
250 | |
251 (defun vc-bzr-async-command (command args) | |
252 "Run Bzr COMMAND asynchronously with ARGS, displaying the result. | |
253 Send the output to a buffer named \"*vc-bzr : NAME*\", where NAME | |
254 is the root of the current Bzr branch. Display the buffer in | |
255 some window, but don't select it." | |
256 ;; TODO: set up hyperlinks. | |
257 (let* ((dir default-directory) | |
258 (root (vc-bzr-root default-directory)) | |
259 (buffer (get-buffer-create (format "*vc-bzr : %s*" root)))) | |
260 (with-current-buffer buffer | |
261 (setq default-directory root) | |
262 (goto-char (point-max)) | |
263 (unless (eq (point) (point-min)) | |
264 (insert "\n")) | |
265 (insert "Running \"" vc-bzr-program " " command) | |
266 (dolist (arg args) | |
267 (insert " " arg)) | |
268 (insert "\"...\n") | |
269 ;; Run bzr in the original working directory. | |
270 (let ((default-directory dir)) | |
271 (apply 'vc-bzr-command command t 'async nil args))) | |
272 (display-buffer buffer))) | |
273 | |
274 (defun vc-bzr-pull (prompt) | |
275 "Pull changes into the current Bzr branch. | |
276 Normally, this runs \"bzr pull\". However, if the branch is a | |
277 bound branch, run \"bzr update\" instead. If there is no default | |
278 location from which to pull or update, or if PROMPT is non-nil, | |
279 prompt for the Bzr command to run." | |
280 (let* ((vc-bzr-program vc-bzr-program) | |
281 (branch-conf (vc-bzr--branch-conf default-directory)) | |
282 ;; Check whether the branch is bound. | |
283 (bound (string-match "^bound\\s-*=\\s-*True" branch-conf)) | |
284 ;; If we need to do a "bzr pull", check for a parent. If it | |
285 ;; does not exist, bzr will need a pull location. | |
286 (parent (unless bound | |
287 (string-match | |
288 "^parent_location\\s-*=\\s-*[^\n[:space:]]+" | |
289 branch-conf))) | |
290 (command (if bound "update" "pull")) | |
291 args buf) | |
292 ;; If necessary, prompt for the exact command. | |
293 (when (or prompt (not (or bound parent))) | |
294 (setq args (split-string | |
295 (read-shell-command | |
296 "Run Bzr (like this): " | |
297 (concat vc-bzr-program " " command) | |
298 'vc-bzr-history) | |
299 " " t)) | |
300 (setq vc-bzr-program (car args) | |
301 command (cadr args) | |
302 args (cddr args))) | |
303 (vc-bzr-async-command command args))) | |
304 | |
305 (defun vc-bzr-merge-branch (prompt) | |
306 "Merge another Bzr branch into the current one. | |
307 If a default merge source is defined (i.e. an upstream branch or | |
308 a previous merge source), this normally runs \"bzr merge --pull\". | |
309 If optional PROMPT is non-nil or no default merge source is | |
310 defined, prompt for the Bzr command to run." | |
311 (let* ((vc-bzr-program vc-bzr-program) | |
312 (command "merge") | |
313 (args '("--pull")) | |
314 command-string args buf) | |
315 (when (or prompt | |
316 ;; Prompt if there is no default merge source. | |
317 (null | |
318 (string-match | |
319 "^\\(parent_location\\|submit_branch\\)\\s-*=\\s-*[^\n[:space:]]+" | |
320 (vc-bzr--branch-conf default-directory)))) | |
321 (setq args (split-string | |
322 (read-shell-command | |
323 "Run Bzr (like this): " | |
324 (concat vc-bzr-program " " command " --pull") | |
325 'vc-bzr-history) | |
326 " " t)) | |
327 (setq vc-bzr-program (car args) | |
328 command (cadr args) | |
329 args (cddr args))) | |
330 (vc-bzr-async-command command args))) | |
238 | 331 |
239 (defun vc-bzr-status (file) | 332 (defun vc-bzr-status (file) |
240 "Return FILE status according to Bzr. | 333 "Return FILE status according to Bzr. |
241 Return value is a cons (STATUS . WARNING), where WARNING is a | 334 Return value is a cons (STATUS . WARNING), where WARNING is a |
242 string or nil, and STATUS is one of the symbols: `added', | 335 string or nil, and STATUS is one of the symbols: `added', |