Commit fba500b6 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

Don't fiddle with vc-handled-backend.

(vc-bzr-registered): Don't redundantly protect against
file-error.  Actually use the format-specific code.
(vc-bzr-buffer-nonblank-p): Remove.
(vc-bzr-status): Change `kindchange' -> `kindchanged'.
parent 37e47941
2007-08-15 Stefan Monnier <monnier@iro.umontreal.ca>
* vc-bzr.el: Don't fiddle with vc-handled-backend.
(vc-bzr-registered): Don't redundantly protect against
file-error. Actually use the format-specific code.
(vc-bzr-buffer-nonblank-p): Remove.
(vc-bzr-status): Change `kindchange' -> `kindchanged'.
2007-08-15 Glenn Morris <rgm@gnu.org> 2007-08-15 Glenn Morris <rgm@gnu.org>
   
* mail/undigest.el (rmail-digest-parse-rfc1153sloppy): Be even * mail/undigest.el (rmail-digest-parse-rfc1153sloppy): Be even
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
(defgroup vc-bzr nil (defgroup vc-bzr nil
"VC bzr backend." "VC bzr backend."
;; :version "22" :version "22.2"
:group 'vc) :group 'vc)
(defcustom vc-bzr-program "bzr" (defcustom vc-bzr-program "bzr"
...@@ -130,38 +130,27 @@ format 3' in the first line. ...@@ -130,38 +130,27 @@ format 3' in the first line.
If the `checkout/dirstate' file cannot be parsed, fall back to If the `checkout/dirstate' file cannot be parsed, fall back to
running `vc-bzr-state'." running `vc-bzr-state'."
(condition-case nil (lexical-let ((root (vc-bzr-root file)))
(lexical-let ((root (vc-bzr-root file))) (when root ; Short cut.
(and root ; Short cut. ;; This looks at internal files. May break if they change
;; This looks at internal files. May break if they change ;; their format.
;; their format. (lexical-let ((dirstate (expand-file-name vc-bzr-admin-dirstate root)))
(lexical-let (if (not (file-readable-p dirstate))
((dirstate-file (expand-file-name vc-bzr-admin-dirstate root))) (vc-bzr-state file) ; Expensive.
(if (file-exists-p dirstate-file) (with-temp-buffer
(with-temp-buffer (insert-file-contents dirstate)
(insert-file-contents dirstate-file) (goto-char (point-min))
(goto-char (point-min)) (if (not (looking-at "#bazaar dirstate flat format 3"))
(when (looking-at "#bazaar dirstate flat format 3") (vc-bzr-state file) ; Some other unknown format?
(let* ((relfile (file-relative-name file root)) (let* ((relfile (file-relative-name file root))
(reldir (file-name-directory relfile))) (reldir (file-name-directory relfile)))
(re-search-forward (re-search-forward
(concat "^\0" (concat "^\0"
(if reldir (regexp-quote (directory-file-name reldir))) (if reldir (regexp-quote (directory-file-name reldir)))
"\0" "\0"
(regexp-quote (file-name-nondirectory relfile)) (regexp-quote (file-name-nondirectory relfile))
"\0") "\0")
nil t)))) nil t)))))))))
t))
(vc-bzr-state file))) ; Expensive.
(file-error nil))) ; vc-bzr-program not found
(defun vc-bzr-buffer-nonblank-p (&optional buffer)
"Return non-nil if BUFFER contains any non-blank characters."
(or (> (buffer-size buffer) 0)
(save-excursion
(set-buffer (or buffer (current-buffer)))
(goto-char (point-min))
(re-search-forward "[^ \t\n]" (point-max) t))))
(defconst vc-bzr-state-words (defconst vc-bzr-state-words
"added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown" "added\\|ignored\\|kind changed\\|modified\\|removed\\|renamed\\|unknown"
...@@ -180,61 +169,53 @@ running `vc-bzr-state'." ...@@ -180,61 +169,53 @@ running `vc-bzr-state'."
(defun vc-bzr-status (file) (defun vc-bzr-status (file)
"Return FILE status according to Bzr. "Return FILE status according to Bzr.
Return value is a cons (STATUS . WARNING), where WARNING is a Return value is a cons (STATUS . WARNING), where WARNING is a
string or nil, and STATUS is one of the symbols: 'added, string or nil, and STATUS is one of the symbols: `added',
'ignored, 'kindchange, 'modified, 'removed, 'renamed, 'unknown, `ignored', `kindchanged', `modified', `removed', `renamed', `unknown',
which directly correspond to `bzr status' output, or 'unchanged which directly correspond to `bzr status' output, or 'unchanged
for files whose copy in the working tree is identical to the one for files whose copy in the working tree is identical to the one
in the branch repository, or nil for files that are not in the branch repository, or nil for files that are not
registered with Bzr. registered with Bzr.
If any error occurred in running `bzr status', then return nil." If any error occurred in running `bzr status', then return nil."
(condition-case nil
(with-temp-buffer (with-temp-buffer
(let ((ret (vc-bzr-command "status" t 0 file)) (let ((ret (condition-case nil
(status 'unchanged)) (vc-bzr-command "status" t 0 file)
;; the only secure status indication in `bzr status' output (file-error nil))) ; vc-bzr-program not found.
;; is a couple of lines following the pattern:: (status 'unchanged))
;; | <status>: ;; the only secure status indication in `bzr status' output
;; | <file name> ;; is a couple of lines following the pattern::
;; if the file is up-to-date, we get no status report from `bzr', ;; | <status>:
;; so if the regexp search for the above pattern fails, we consider ;; | <file name>
;; the file to be up-to-date. ;; if the file is up-to-date, we get no status report from `bzr',
(goto-char (point-min)) ;; so if the regexp search for the above pattern fails, we consider
(when ;; the file to be up-to-date.
(re-search-forward (goto-char (point-min))
;; bzr prints paths relative to the repository root (when (re-search-forward
(concat "^\\(" vc-bzr-state-words "\\):[ \t\n]+" ;; bzr prints paths relative to the repository root.
(regexp-quote (vc-bzr-file-name-relative file)) (concat "^\\(" vc-bzr-state-words "\\):[ \t\n]+"
(if (file-directory-p file) "/?" "") (regexp-quote (vc-bzr-file-name-relative file))
"[ \t\n]*$") (if (file-directory-p file) "/?" "")
(point-max) t) "[ \t\n]*$")
(let ((start (match-beginning 0)) nil t)
(end (match-end 0))) (let ((status (match-string 1)))
(goto-char start) ;; Erase the status text that matched.
(delete-region (match-beginning 0) (match-end 0))
(setq status (setq status
(cond (and (equal ret 0) ; Seems redundant. --Stef
((not (equal ret 0)) nil) (intern (replace-regexp-in-string " " ""
((looking-at "added") 'added) status))))))
((looking-at "kind changed") 'kindchange) (when status
((looking-at "renamed") 'renamed) (goto-char (point-min))
((looking-at "modified") 'modified) (skip-chars-forward " \n\t") ;Throw away spaces.
((looking-at "removed") 'removed) (cons status
((looking-at "ignored") 'ignored) ;; "bzr" will output warnings and informational messages to
((looking-at "unknown") 'unknown))) ;; stderr; due to Emacs' `vc-do-command' (and, it seems,
;; erase the status text that matched ;; `start-process' itself) limitations, we cannot catch stderr
(delete-region start end))) ;; and stdout into different buffers. So, if there's anything
(if status ;; left in the buffer after removing the above status
(cons status ;; keywords, let us just presume that any other message from
;; "bzr" will output warnings and informational messages to ;; "bzr" is a user warning, and display it.
;; stderr; due to Emacs' `vc-do-command' (and, it seems, (unless (eobp) (buffer-substring (point) (point-max))))))))
;; `start-process' itself) limitations, we cannot catch stderr
;; and stdout into different buffers. So, if there's anything
;; left in the buffer after removing the above status
;; keywords, let us just presume that any other message from
;; "bzr" is a user warning, and display it.
(if (vc-bzr-buffer-nonblank-p)
(buffer-substring (point-min) (point-max)))))))
(file-error nil))) ; vc-bzr-program not found
(defun vc-bzr-state (file) (defun vc-bzr-state (file)
(lexical-let ((result (vc-bzr-status file))) (lexical-let ((result (vc-bzr-status file)))
...@@ -243,7 +224,7 @@ If any error occurred in running `bzr status', then return nil." ...@@ -243,7 +224,7 @@ If any error occurred in running `bzr status', then return nil."
(message "Warnings in `bzr' output: %s" (cdr result))) (message "Warnings in `bzr' output: %s" (cdr result)))
(cdr (assq (car result) (cdr (assq (car result)
'((added . edited) '((added . edited)
(kindchange . edited) (kindchanged . edited)
(renamed . edited) (renamed . edited)
(modified . edited) (modified . edited)
(removed . edited) (removed . edited)
...@@ -264,7 +245,7 @@ If any error occurred in running `bzr status', then return nil." ...@@ -264,7 +245,7 @@ If any error occurred in running `bzr status', then return nil."
;; bzr process. This looks at internal files. May break if they ;; bzr process. This looks at internal files. May break if they
;; change their format. ;; change their format.
(if (file-exists-p branch-format-file) (if (file-exists-p branch-format-file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents branch-format-file) (insert-file-contents branch-format-file)
(goto-char (point-min)) (goto-char (point-min))
(cond (cond
...@@ -272,7 +253,7 @@ If any error occurred in running `bzr status', then return nil." ...@@ -272,7 +253,7 @@ If any error occurred in running `bzr status', then return nil."
(looking-at "Bazaar-NG branch, format 0.0.4") (looking-at "Bazaar-NG branch, format 0.0.4")
(looking-at "Bazaar-NG branch format 5")) (looking-at "Bazaar-NG branch format 5"))
;; count lines in .bzr/branch/revision-history ;; count lines in .bzr/branch/revision-history
(insert-file-contents revhistory-file) (insert-file-contents revhistory-file)
(number-to-string (count-lines (line-end-position) (point-max)))) (number-to-string (count-lines (line-end-position) (point-max))))
((looking-at "Bazaar Branch Format 6 (bzr 0.15)") ((looking-at "Bazaar Branch Format 6 (bzr 0.15)")
;; revno is the first number in .bzr/branch/last-revision ;; revno is the first number in .bzr/branch/last-revision
...@@ -340,10 +321,10 @@ EDITABLE is ignored." ...@@ -340,10 +321,10 @@ EDITABLE is ignored."
(setq destfile (vc-version-backup-file-name file rev))) (setq destfile (vc-version-backup-file-name file rev)))
(let ((coding-system-for-read 'binary) (let ((coding-system-for-read 'binary)
(coding-system-for-write 'binary)) (coding-system-for-write 'binary))
(with-temp-file destfile (with-temp-file destfile
(if rev (if rev
(vc-bzr-command "cat" t 0 file "-r" rev) (vc-bzr-command "cat" t 0 file "-r" rev)
(vc-bzr-command "cat" t 0 file))))) (vc-bzr-command "cat" t 0 file)))))
(defun vc-bzr-revert (file &optional contents-done) (defun vc-bzr-revert (file &optional contents-done)
(unless contents-done (unless contents-done
...@@ -376,7 +357,6 @@ EDITABLE is ignored." ...@@ -376,7 +357,6 @@ EDITABLE is ignored."
"Get bzr change log for FILES into specified BUFFER." "Get bzr change log for FILES into specified BUFFER."
;; Fixme: This might need the locale fixing up if things like `revno' ;; Fixme: This might need the locale fixing up if things like `revno'
;; got localized, but certainly it shouldn't use LC_ALL=C. ;; got localized, but certainly it shouldn't use LC_ALL=C.
;; NB. Can't be async -- see `vc-bzr-post-command-function'.
(vc-bzr-command "log" buffer 0 files) (vc-bzr-command "log" buffer 0 files)
;; FIXME: Until Emacs-23, VC was missing a hook to sort out the mode for ;; FIXME: Until Emacs-23, VC was missing a hook to sort out the mode for
;; the buffer, or at least set the regexps right. ;; the buffer, or at least set the regexps right.
...@@ -400,7 +380,6 @@ EDITABLE is ignored." ...@@ -400,7 +380,6 @@ EDITABLE is ignored."
(setq rev1 nil)) (setq rev1 nil))
(if (and (not rev1) rev2) (if (and (not rev1) rev2)
(setq rev1 working)) (setq rev1 working))
;; NB. Can't be async -- see `vc-bzr-post-command-function'.
;; bzr diff produces condition code 1 for some reason. ;; bzr diff produces condition code 1 for some reason.
(apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files (apply #'vc-bzr-command "diff" (or buffer "*vc-diff*") 1 files
"--diff-options" (mapconcat 'identity (vc-diff-switches-list bzr) "--diff-options" (mapconcat 'identity (vc-diff-switches-list bzr)
...@@ -462,11 +441,11 @@ property containing author and date information." ...@@ -462,11 +441,11 @@ property containing author and date information."
;; Definition from Emacs 22 ;; Definition from Emacs 22
(unless (fboundp 'vc-annotate-convert-time) (unless (fboundp 'vc-annotate-convert-time)
(defun vc-annotate-convert-time (time) (defun vc-annotate-convert-time (time)
"Convert a time value to a floating-point number of days. "Convert a time value to a floating-point number of days.
The argument TIME is a list as returned by `current-time' or The argument TIME is a list as returned by `current-time' or
`encode-time', only the first two elements of that list are considered." `encode-time', only the first two elements of that list are considered."
(/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))) (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600)))
(defun vc-bzr-annotate-time () (defun vc-bzr-annotate-time ()
(when (re-search-forward "^ *[0-9]+ |" nil t) (when (re-search-forward "^ *[0-9]+ |" nil t)
...@@ -548,7 +527,7 @@ Optional argument LOCALP is always ignored." ...@@ -548,7 +527,7 @@ Optional argument LOCALP is always ignored."
(setq current-bzr-state 'added)) (setq current-bzr-state 'added))
((looking-at "^kind changed") ((looking-at "^kind changed")
(setq current-vc-state 'edited) (setq current-vc-state 'edited)
(setq current-bzr-state 'kindchange)) (setq current-bzr-state 'kindchanged))
((looking-at "^modified") ((looking-at "^modified")
(setq current-vc-state 'edited) (setq current-vc-state 'edited)
(setq current-bzr-state 'modified)) (setq current-bzr-state 'modified))
...@@ -590,17 +569,9 @@ Optional argument LOCALP is always ignored." ...@@ -590,17 +569,9 @@ Optional argument LOCALP is always ignored."
;; else fall back to default vc representation ;; else fall back to default vc representation
(vc-default-dired-state-info 'Bzr file))))) (vc-default-dired-state-info 'Bzr file)))))
;; In case of just `(load "vc-bzr")', but that's probably the wrong
;; way to do it.
(add-to-list 'vc-handled-backends 'Bzr)
(eval-after-load "vc" (eval-after-load "vc"
'(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t)) '(add-to-list 'vc-directory-exclusion-list vc-bzr-admin-dirname t))
(defconst vc-bzr-unload-hook
(lambda ()
(setq vc-handled-backends (delq 'Bzr vc-handled-backends))
(remove-hook 'vc-post-command-functions 'vc-bzr-post-command-function)))
(provide 'vc-bzr) (provide 'vc-bzr)
;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06 ;; arch-tag: 8101bad8-4e92-4e7d-85ae-d8e08b4e7c06
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment