(defgroup reftex): Update home page url-link.
[bpt/emacs.git] / lisp / pcvs.el
index 34a93a1..1f2bad1 100644 (file)
@@ -1,7 +1,7 @@
 ;;; pcvs.el --- a front-end to CVS
 
 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;;   2000, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+;;   2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: (The PCL-CVS Trust) pcl-cvs@cyclic.com
 ;;     (Per Cederqvist) ceder@lysator.liu.se
@@ -467,7 +467,7 @@ If non-nil, NEW means to create a new buffer no matter what."
         (cvs-mode)
         (set (make-local-variable 'list-buffers-directory) buffer-name)
         ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
-        (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n" "")))
+        (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n\n" "\n" t)))
           (set (make-local-variable 'cvs-cookies) cookies)
           (add-hook 'kill-buffer-hook
                     (lambda ()
@@ -618,7 +618,6 @@ If non-nil, NEW means to create a new buffer no matter what."
         (str (car hf))
         (done "")
         (tin (ewoc-nth cvs-cookies 0)))
-    (if (eq (length str) 1) (setq str ""))
     ;; look for the first *real* fileinfo (to determine emptyness)
     (while
        (and tin
@@ -626,13 +625,17 @@ If non-nil, NEW means to create a new buffer no matter what."
                   '(MESSAGE DIRCHANGE)))
       (setq tin (ewoc-next cvs-cookies tin)))
     (if add
-       (setq str (concat "-- Running " cmd " ...\n" str))
+        (progn
+          ;; Remove the default empty line, if applicable.
+          (if (not (string-match "." str)) (setq str "\n"))
+          (setq str (concat "-- Running " cmd " ...\n" str)))
       (if (not (string-match
                (concat "^-- Running " (regexp-quote cmd) " \\.\\.\\.\n") str))
          (error "Internal PCL-CVS error while removing message")
        (setq str (replace-match "" t t str))
-       (if (zerop (length str)) (setq str "\n"))
-       (setq done (concat "-- last cmd: " cmd " --"))))
+        ;; Re-add the default empty line, if applicable.
+        (if (not (string-match "." str)) (setq str "\n\n"))
+       (setq done (concat "-- last cmd: " cmd " --\n"))))
     ;; set the new header and footer
     (ewoc-set-hf cvs-cookies
                 str (concat "\n--------------------- "
@@ -647,34 +650,38 @@ This is responsible for parsing the output from the cvs update when
 it is finished."
   (when (memq (process-status proc) '(signal exit))
     (let ((cvs-postproc (process-get proc 'cvs-postprocess))
-         (cvs-buf (process-get proc 'cvs-buffer)))
+         (cvs-buf (process-get proc 'cvs-buffer))
+          (procbuf (process-buffer proc)))
+      (unless (buffer-live-p cvs-buf) (setq cvs-buf nil))
+      (unless (buffer-live-p procbuf) (setq procbuf nil))
       ;; Since the buffer and mode line will show that the
       ;; process is dead, we can delete it now.  Otherwise it
       ;; will stay around until M-x list-processes.
       (process-put proc 'postprocess nil)
       (delete-process proc)
       ;; Don't do anything if the main buffer doesn't exist any more.
-      (when (buffer-live-p cvs-buf)
+      (when cvs-buf
        (with-current-buffer cvs-buf
          (cvs-update-header (process-get proc 'cvs-header) nil)
          (setq cvs-mode-line-process (symbol-name (process-status proc)))
          (force-mode-line-update)
          (when cvs-postproc
-           (if (null (buffer-live-p (process-buffer proc)))
+           (if (null procbuf)
                ;;(set-process-buffer proc nil)
                (error "cvs' process buffer was killed")
-             (with-current-buffer (process-buffer proc)
-               ;; do the postprocessing like parsing and such
-               (save-excursion (eval cvs-postproc))
-               ;; check whether something is left
-               (unless (get-buffer-process (current-buffer))
-                 ;; IIRC, we enable undo again once the process is finished
-                 ;; for cases where the output was inserted in *vc-diff* or
-                 ;; in a file-like buffer.  --Stef
-                 (buffer-enable-undo)
-                 (with-current-buffer cvs-buffer
-                   (message "CVS process has completed in %s"
-                            (buffer-name))))))))))))
+             (with-current-buffer procbuf
+               ;; Do the postprocessing like parsing and such.
+               (save-excursion (eval cvs-postproc)))))))
+      ;; Check whether something is left.
+      (when (and procbuf (not (get-buffer-process procbuf)))
+        (with-current-buffer procbuf
+          ;; IIRC, we enable undo again once the process is finished
+          ;; for cases where the output was inserted in *vc-diff* or
+          ;; in a file-like buffer.  --Stef
+          (buffer-enable-undo)
+          (with-current-buffer (or cvs-buf (current-buffer))
+            (message "CVS process has completed in %s"
+                     (buffer-name))))))))
 
 (defun cvs-parse-process (dcd &optional subdir old-fis)
   "Parse the output of a cvs process.
@@ -771,6 +778,7 @@ clear what alternative to use.
 For interactive use, use `" (symbol-name fun) "' instead.")
             ,interact
             ,@body)
+          (put ',fun-1 'definition-name ',fun)
           (defun ,fun ()
             ,(concat line1 "\nWrapper function that switches to a *cvs* buffer
 before calling the real function `" (symbol-name fun-1) "'.\n")
@@ -1171,7 +1179,7 @@ Full documentation is in the Texinfo file."
   (interactive)
   (if (eq last-command 'cvs-help)
       (describe-function 'cvs-mode)   ; would need minor-mode for log-edit-mode
-    (message
+    (message "%s"
      (substitute-command-keys
       "`\\[cvs-help]':help `\\[cvs-mode-add]':add `\\[cvs-mode-commit]':commit \
 `\\[cvs-mode-diff-map]':diff* `\\[cvs-mode-log]':log \
@@ -1478,11 +1486,16 @@ The POSTPROC specified there (typically `log-edit') is then called,
         (point))))))
 
 (defvar cvs-edit-log-revision)
-(defun cvs-mode-edit-log (rev &optional text)
+(defvar cvs-edit-log-files) (put 'cvs-edit-log-files 'permanent-local t)
+(defun cvs-mode-edit-log (file rev &optional text)
   "Edit the log message at point.
 This is best called from a `log-view-mode' buffer."
   (interactive
    (list
+    (or (cvs-mode! (lambda ()
+                     (car (cvs-mode-files nil nil
+                                          :read-only t :file t :noquery t))))
+        (read-string "File name: "))
     (or (cvs-mode! (lambda () (cvs-prefix-get 'cvs-branch-prefix)))
        (read-string "Revision to edit: "))
     (cvs-edit-log-text-at-point)))
@@ -1494,26 +1507,38 @@ This is best called from a `log-view-mode' buffer."
   (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
        (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
                      'log-edit)))
+    (with-current-buffer buf
+      ;; Set the filename before, so log-edit can correctly setup its
+      ;; log-edit-initial-files variable.
+      (set (make-local-variable 'cvs-edit-log-files) (list file)))
     (funcall setupfun 'cvs-do-edit-log nil 'cvs-edit-log-filelist buf)
     (when text (erase-buffer) (insert text))
     (set (make-local-variable 'cvs-edit-log-revision) rev)
-    (set (make-local-variable 'cvs-minor-wrap-function) 'cvs-edit-log-minor-wrap)
+    (set (make-local-variable 'cvs-minor-wrap-function)
+         'cvs-edit-log-minor-wrap)
     ;; (run-hooks 'cvs-mode-commit-hook)
     ))
 
 (defun cvs-edit-log-minor-wrap (buf f)
-  (let ((cvs-ignore-marks-modif (cvs-mode-mark-get-modif "commit")))
+  (let ((cvs-branch-prefix (with-current-buffer buf cvs-edit-log-revision))
+        (cvs-minor-current-files
+         (with-current-buffer buf cvs-edit-log-files))
+        ;; FIXME:  I need to force because the fileinfos are UNKNOWN
+        (cvs-force-command "/F"))
     (funcall f)))
 
 (defun cvs-edit-log-filelist ()
-  (cvs-mode-files nil nil :read-only t :file t :noquery t))
+  (if cvs-minor-wrap-function
+      (cvs-mode-files nil nil :read-only t :file t :noquery t)
+    cvs-edit-log-files))
 
 (defun cvs-do-edit-log (rev)
   "Do the actual commit, using the current buffer as the log message."
   (interactive (list cvs-edit-log-revision))
   (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
-    (cvs-mode!)
-    (cvs-mode-do "admin" (list (concat "-m" rev ":" msg)) nil)))
+    (cvs-mode!
+     (lambda ()
+       (cvs-mode-do "admin" (list (concat "-m" rev ":" msg)) nil)))))
 
 
 ;;;;
@@ -1700,16 +1725,22 @@ Signal an error if there is no backup file."
          (message "Retrieving revision %s..." rev)
          ;; Discard stderr output to work around the CVS+SSH+libc
          ;; problem when stdout and stderr are the same.
-         (let ((res (apply 'call-process cvs-program nil '(t nil) nil
-                           "-q" "update" "-p"
-                           ;; If `rev' is HEAD, don't pass it at all:
-                           ;; the default behavior is to get the head
-                           ;; of the current branch whereas "-r HEAD"
-                           ;; stupidly gives you the head of the trunk.
-                           (append (unless (equal rev "HEAD") (list "-r" rev))
-                                   (list file)))))
+         (let ((res
+                 (let ((coding-system-for-read 'binary))
+                   (apply 'call-process cvs-program nil '(t nil) nil
+                          "-q" "update" "-p"
+                          ;; If `rev' is HEAD, don't pass it at all:
+                          ;; the default behavior is to get the head
+                          ;; of the current branch whereas "-r HEAD"
+                          ;; stupidly gives you the head of the trunk.
+                          (append (unless (equal rev "HEAD") (list "-r" rev))
+                                  (list file))))))
            (when (and res (not (and (equal 0 res))))
              (error "Something went wrong retrieving revision %s: %s" rev res))
+            ;; Figure out the encoding used and decode the byte-sequence
+            ;; into a sequence of chars.
+            (decode-coding-inserted-region
+             (point-min) (point-max) file t nil nil t)
            (set-buffer-modified-p nil)
            (let ((buffer-file-name (expand-file-name file)))
              (after-find-file))
@@ -2258,7 +2289,7 @@ this file, or a list of arguments to send to the program."
   (interactive "DNew repository: ")
   (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
          (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
-                           " Change cvs-cvsroot anyhow?")))
+                           " Change cvs-cvsroot anyhow? ")))
       (setq cvs-cvsroot newroot)))
 
 ;;;;