comparison lisp/vc-hooks.el @ 12884:f47248851f26

(vc-fetch-master-properties): Recognize cvs status "Unresolved Conflict". (vc-locking-user): Count cvs status `unresolved-conflict' as "locked". (vc-checkout-model): New property and access function (still simplistic). (vc-after-save-hook): New function. (vc-mode-line): When the file is locked by somebody else, make the buffer read-only. (Formerly this was only done for root.) Don't write-protect the buffer if the file is unlocked. Instead, install vc-after-save-hook, which "locks" the file when modifications are saved.
author André Spiegel <spiegel@gnu.org>
date Fri, 18 Aug 1995 20:22:53 +0000
parents 3afd71d56015
children 22f47b2375c1
comparison
equal deleted inserted replaced
12883:c281a02dbb9f 12884:f47248851f26
317 (vc-file-setprop file 'vc-cvs-status 'locally-modified)) 317 (vc-file-setprop file 'vc-cvs-status 'locally-modified))
318 ((string-match "Needs Merge" status) 318 ((string-match "Needs Merge" status)
319 (vc-file-setprop file 'vc-cvs-status 'needs-merge)) 319 (vc-file-setprop file 'vc-cvs-status 'needs-merge))
320 ((string-match "Needs Checkout" status) 320 ((string-match "Needs Checkout" status)
321 (vc-file-setprop file 'vc-cvs-status 'needs-checkout)) 321 (vc-file-setprop file 'vc-cvs-status 'needs-checkout))
322 ((string-match "Unresolved Conflict" status)
323 (vc-file-setprop file 'vc-cvs-status 'unresolved-conflict))
322 (t (vc-file-setprop file 'vc-cvs-status nil)))))) 324 (t (vc-file-setprop file 'vc-cvs-status nil))))))
323 (if (get-buffer "*vc-info*") 325 (if (get-buffer "*vc-info*")
324 (kill-buffer (get-buffer "*vc-info*"))))) 326 (kill-buffer (get-buffer "*vc-info*")))))
325 327
326 ;;; Functions that determine property values, by examining the 328 ;;; Functions that determine property values, by examining the
445 (if name-and-type 447 (if name-and-type
446 (progn 448 (progn
447 (vc-file-setprop file 'vc-name (car name-and-type)) 449 (vc-file-setprop file 'vc-name (car name-and-type))
448 (vc-file-setprop file 'vc-backend (cdr name-and-type)))))))) 450 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
449 451
452 (defun vc-checkout-model (file)
453 ;; Return `manual' if the user has to type C-x C-q to check out FILE.
454 ;; Return `automatic' if the file can be modified without locking it first.
455 ;; Simplistic version, only returns the default for each backend.
456 (cond ((vc-file-getprop file 'vc-checkout-model))
457 ((vc-file-setprop file 'vc-checkout-model
458 (cond ((eq (vc-backend file) 'SCCS) 'manual)
459 ((eq (vc-backend file) 'RCS) 'manual)
460 ((eq (vc-backend file) 'CVS) 'automatic))))))
461
450 ;;; properties indicating the locking state 462 ;;; properties indicating the locking state
451 463
452 (defun vc-cvs-status (file) 464 (defun vc-cvs-status (file)
453 ;; Return the cvs status of FILE 465 ;; Return the cvs status of FILE
454 ;; (Status field in output of "cvs status") 466 ;; (Status field in output of "cvs status")
493 ;; otherwise, infer the property... 505 ;; otherwise, infer the property...
494 (cond 506 (cond
495 ;; in the CVS case, check the status 507 ;; in the CVS case, check the status
496 ((eq (vc-backend file) 'CVS) 508 ((eq (vc-backend file) 'CVS)
497 (if (and (not (eq (vc-cvs-status file) 'locally-modified)) 509 (if (and (not (eq (vc-cvs-status file) 'locally-modified))
498 (not (eq (vc-cvs-status file) 'needs-merge))) 510 (not (eq (vc-cvs-status file) 'needs-merge))
511 (not (eq (vc-cvs-status file) 'unresolved-conflict)))
499 (vc-file-setprop file 'vc-locking-user 'none) 512 (vc-file-setprop file 'vc-locking-user 'none)
500 ;; The expression below should return the username of the owner 513 ;; The expression below should return the username of the owner
501 ;; of the file. It doesn't. It returns the username if it is 514 ;; of the file. It doesn't. It returns the username if it is
502 ;; you, or otherwise the UID of the owner of the file. The 515 ;; you, or otherwise the UID of the owner of the file. The
503 ;; return value from this function is only used by 516 ;; return value from this function is only used by
720 (if (vc-backend (buffer-file-name)) 733 (if (vc-backend (buffer-file-name))
721 (vc-next-action verbose) 734 (vc-next-action verbose)
722 (toggle-read-only))) 735 (toggle-read-only)))
723 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only) 736 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
724 737
738 (defun vc-after-save-hook ()
739 ;; Mark the file in the current buffer as "locked" by the user.
740 (remove-hook 'after-save-hook 'vc-after-save-hook t)
741 (vc-file-setprop (buffer-file-name) 'vc-locking-user (user-login-name))
742 (vc-mode-line (buffer-file-name)))
743
725 (defun vc-mode-line (file &optional label) 744 (defun vc-mode-line (file &optional label)
726 "Set `vc-mode' to display type of version control for FILE. 745 "Set `vc-mode' to display type of version control for FILE.
727 The value is set in the current buffer, which should be the buffer 746 The value is set in the current buffer, which should be the buffer
728 visiting FILE. Second optional arg LABEL is put in place of version 747 visiting FILE. Second optional arg LABEL is put in place of version
729 control system name." 748 control system name."
733 (and vc-type 752 (and vc-type
734 (concat " " (or label (symbol-name vc-type)) 753 (concat " " (or label (symbol-name vc-type))
735 (and vc-display-status (vc-status file))))) 754 (and vc-display-status (vc-status file)))))
736 (and vc-type 755 (and vc-type
737 (equal file (buffer-file-name)) 756 (equal file (buffer-file-name))
738 ;; Make the buffer read-only if the file is not locked 757 (if (vc-locking-user file)
739 ;; (or unchanged, in the CVS case). 758 ;; If the file is locked by some other user, make
740 (if (not (vc-locking-user file)) 759 ;; the buffer read-only. Like this, even root
741 (setq buffer-read-only t)) 760 ;; cannot modify a file without locking it first.
742 ;; Even root shouldn't modify a registered file without 761 (if (not (string= (user-login-name) (vc-locking-user file)))
743 ;; locking it first. 762 (setq buffer-read-only t))
744 (not buffer-read-only) 763 ;; If the file is not locked, and vc-checkout-model is
745 (zerop (user-uid)) 764 ;; `automatic', install a hook that will make the file
746 (not (equal (user-login-name) (vc-locking-user file))) 765 ;; "locked" when the buffer is saved.
747 (setq buffer-read-only t)) 766 (cond ((eq (vc-checkout-model file) 'automatic)
767 (make-local-variable 'after-save-hook)
768 (make-local-hook 'after-save-hook)
769 (add-hook 'after-save-hook 'vc-after-save-hook t)))))
748 (force-mode-line-update) 770 (force-mode-line-update)
749 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18 771 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
750 vc-type)) 772 vc-type))
751 773
752 (defun vc-status (file) 774 (defun vc-status (file)