unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@gnu.org>
To: Glenn Morris <rgm@gnu.org>
Cc: Jonathan Kamens <jik@kamens.us>, 11490@debbugs.gnu.org
Subject: bug#11490: vc-next-action overwrites changes in non-checked-out RCS file
Date: Sat, 5 Jan 2013 09:35:56 +0000 (UTC)	[thread overview]
Message-ID: <87mwthp9dd.fsf@gnu.org> (raw)
In-Reply-To: <50E64D8D.1010201@kamens.us> (Jonathan Kamens's message of "Thu,  03 Jan 2013 22:33:33 -0500")

Jonathan Kamens <jik@kamens.us> writes:

> Please read the WHOLE LIST OF COMMANDS I SENT in my test case.
>
> I made the file writable in that list only to modify it. If you read
> the whole list of commands, you will see that I make it unwritable
> again before editing it with emacs. And that's exactly the problem...
> if the file isn't writable, emacs assumes that it's not checked out
> and not modified it and checks it out when you hit C-x v v,
> overwriting the changes in it.

OK, so the original bug is fixed by changing `vc-mistrust-permissions'
to t, indeed.

As for the problem Glenn just pointed out, it arises because VC caches
the state of the file when it is first visited (via vc-state-refresh).
The following patch (against trunk) should fix this, but I haven't had
time to give it much testing yet.


=== modified file 'lisp/vc/vc-hooks.el'
*** lisp/vc/vc-hooks.el	2013-01-02 16:13:04 +0000
--- lisp/vc/vc-hooks.el	2013-04-02 09:23:22 +0000
***************
*** 703,719 ****
    ;; the state to 'edited and redisplay the mode line.
    (let* ((file buffer-file-name)
           (backend (vc-backend file)))
!     (and backend
! 	 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
! 			 (nth 5 (file-attributes file)))
! 		  ;; File has been saved in the same second in which
! 		  ;; it was checked out.  Clear the checkout-time
! 		  ;; to avoid confusion.
! 		  (vc-file-setprop file 'vc-checkout-time nil))
! 	     t)
!          (eq (vc-checkout-model backend (list file)) 'implicit)
!          (vc-state-refresh file backend)
! 	 (vc-mode-line file backend))
      ;; Try to avoid unnecessary work, a *vc-dir* buffer is
      ;; present if this is true.
      (when vc-dir-buffers
--- 703,723 ----
    ;; the state to 'edited and redisplay the mode line.
    (let* ((file buffer-file-name)
           (backend (vc-backend file)))
!     (when backend
!       (if (eq (vc-checkout-model backend (list file)) 'implicit)
! 	  (progn
! 	    ;; If the file was saved in the same second in which it
! 	    ;; was checked out, clear the checkout-time to avoid
! 	    ;; confusion.
! 	    (if (equal (vc-file-getprop file 'vc-checkout-time)
! 		       (nth 5 (file-attributes file)))
! 		(vc-file-setprop file 'vc-checkout-time nil))
! 	    (if (vc-state-refresh file backend)
! 		(vc-mode-line file backend)))
! 	;; If we saved an unlocked file on a locking based VCS, that
! 	;; file is not longer up-to-date.
! 	(if (eq (vc-file-getprop file 'vc-state) 'up-to-date)
! 	    (vc-file-setprop file 'vc-state nil))))
      ;; Try to avoid unnecessary work, a *vc-dir* buffer is
      ;; present if this is true.
      (when vc-dir-buffers

=== modified file 'lisp/vc/vc.el'
*** lisp/vc/vc.el	2013-01-02 16:13:04 +0000
--- lisp/vc/vc.el	2013-04-02 09:30:28 +0000
***************
*** 1072,1077 ****
--- 1072,1087 ----
           ;; among all the `files'.
  	 (model (nth 4 vc-fileset)))
  
+     ;; If a buffer has unsaved changes, a checkout would discard them.
+     (when (and (not (eq model 'implicit))
+ 	       (eq state 'up-to-date))
+       (let ((files files)
+ 	    buffer)
+ 	(while files
+ 	  (setq buffer (get-file-buffer (car files)))
+ 	  (and buffer (buffer-modified-p buffer)
+ 	       (setq state 'unlocked-changes files nil)))))
+ 
      ;; Do the right thing
      (cond
       ((eq state 'missing)






      reply	other threads:[~2013-01-05  9:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-16 19:29 bug#11490: vc-next-action overwrites changes in non-checked-out RCS file Jonathan Kamens
2012-05-16 20:12 ` Glenn Morris
2012-05-17  1:17   ` Jonathan Kamens
2012-05-18  0:45     ` Glenn Morris
2012-05-18 14:38       ` Jonathan Kamens
2012-05-22  3:57         ` Glenn Morris
2013-01-04  2:57           ` Chong Yidong
2013-01-04  3:11             ` Glenn Morris
2013-01-04  3:17               ` Jonathan Kamens
2013-01-04  3:21                 ` Glenn Morris
2013-01-04  3:33                   ` Jonathan Kamens
2013-01-05  9:35                     ` Chong Yidong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mwthp9dd.fsf@gnu.org \
    --to=cyd@gnu.org \
    --cc=11490@debbugs.gnu.org \
    --cc=jik@kamens.us \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).