unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* avoiding revert-buffer after vc-checkin
@ 2007-07-18  5:47 Dan Nicolaescu
  2007-07-18 18:53 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Nicolaescu @ 2007-07-18  5:47 UTC (permalink / raw)
  To: emacs-devel


After a vc-checkin the corresponding buffer is reverted, which is not
so convenient because the undo information is lost. 

One way to avoid the revert is to check if the buffer and the file on
disk are identical. One way to do that is to compare the md5
checksums.

I wrote a patch that does that almost a year ago, I never fully
verified it if it works correctly, and I don't think I'll touch it
again anytime soon. So I thought I'd throw it over the fence and maybe
it will inspire someone to pick it up and solve this problem
properly. Pretty please :-)

Index: vc.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/vc.el,v
retrieving revision 1.433
diff -c -3 -p -c -r1.433 vc.el
*** vc.el       17 Jul 2007 04:47:57 -0000      1.433
--- vc.el       18 Jul 2007 05:10:40 -0000
*** 1530,1536 ****
    (and (string= buffer-file-name file)
         (if keep
           (progn
!            (vc-revert-buffer1 t noquery)
               ;; TODO: Adjusting view mode might no longer be necessary
               ;; after RMS change to files.el of 1999-08-08.  Investigate
               ;; this when we install the new VC.
--- 1530,1542 ----
    (and (string= buffer-file-name file)
         (if keep
           (progn
!            (if (string=
!                 (substring (shell-command-to-string 
!                             (concat "md5sum " (expand-file-namefile))) 0 32)
!                 (md5 (current-buffer)))
!                (message "not reverting")
!              (message "reverting :-(")
!              (vc-revert-buffer1 t noquery))
               ;; TODO: Adjusting view mode might no longer be necessary
               ;; after RMS change to files.el of 1999-08-08.  Investigate
               ;; this when we install the new VC.


The reason the md5sum command is used is because `md5' cannot take a
file argument.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: avoiding revert-buffer after vc-checkin
  2007-07-18  5:47 avoiding revert-buffer after vc-checkin Dan Nicolaescu
@ 2007-07-18 18:53 ` Stefan Monnier
  2007-07-18 21:21   ` David Kastrup
  2007-07-19 21:21   ` Richard Stallman
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2007-07-18 18:53 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: emacs-devel

> After a vc-checkin the corresponding buffer is reverted, which is not
> so convenient because the undo information is lost. 

Indeed.  My own take on this problem is to change revert-buffer so that it
doesn't throw away the undo info.

I understand that some people find this idea completely unacceptable, so
maybe a good compromise is to just provide a way to tell revert-buffer not
to throw away the undo info, and then use it in vc.el.


        Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: avoiding revert-buffer after vc-checkin
  2007-07-18 18:53 ` Stefan Monnier
@ 2007-07-18 21:21   ` David Kastrup
  2007-07-19  2:57     ` Stefan Monnier
  2007-07-19 21:21   ` Richard Stallman
  1 sibling, 1 reply; 5+ messages in thread
From: David Kastrup @ 2007-07-18 21:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Dan Nicolaescu, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> After a vc-checkin the corresponding buffer is reverted, which is not
>> so convenient because the undo information is lost. 
>
> Indeed.  My own take on this problem is to change revert-buffer so that it
> doesn't throw away the undo info.

Revert-buffer throws away the undo info because usually after
revert-buffer the undo-info is useless.

> I understand that some people find this idea completely
> unacceptable, so maybe a good compromise is to just provide a way to
> tell revert-buffer not to throw away the undo info, and then use it
> in vc.el.

And how will you cater for CVS having replaced $Id: ...$ strings and
similar?  How do you know which offsets to apply to the undo info in
order to compensate for that?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: avoiding revert-buffer after vc-checkin
  2007-07-18 21:21   ` David Kastrup
@ 2007-07-19  2:57     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2007-07-19  2:57 UTC (permalink / raw)
  To: David Kastrup; +Cc: Dan Nicolaescu, emacs-devel

>> Indeed.  My own take on this problem is to change revert-buffer so that it
>> doesn't throw away the undo info.

> Revert-buffer throws away the undo info because usually after
> revert-buffer the undo-info is useless.

In my use pattern, the undo info is rarely useless after revert buffer.
Of course, the revert-buffer operation itself adds undo entries
corresponding to the changes it made.

>> I understand that some people find this idea completely
>> unacceptable, so maybe a good compromise is to just provide a way to
>> tell revert-buffer not to throw away the undo info, and then use it
>> in vc.el.

> And how will you cater for CVS having replaced $Id: ...$ strings and
> similar?  How do you know which offsets to apply to the undo info in
> order to compensate for that?

I don't need to: the usual C code takes care of that.  All I did was change
insert-file-contents so that it doesn't explicitly throw away the undo info
that is otherwise correctly computed by the underlying primitives.


        Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: avoiding revert-buffer after vc-checkin
  2007-07-18 18:53 ` Stefan Monnier
  2007-07-18 21:21   ` David Kastrup
@ 2007-07-19 21:21   ` Richard Stallman
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Stallman @ 2007-07-19 21:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: dann, emacs-devel

    I understand that some people find this idea completely unacceptable, so
    maybe a good compromise is to just provide a way to tell revert-buffer not
    to throw away the undo info, and then use it in vc.el.

There is nothing magic about the undo data structure.  It is easy to
preserve it, by binding buffer-undo-list.  But if you want this to
work right, you should also make undo records for any text changes
made by reverting.

It would not be terribly hard to compare the file with the buffer
contents, find what the differences will be, then revert, then
construct new undo entries for those differences.  It could write the
buffer to a temp file, then use diff to localize the changes.  If the
changes in the diff output make sense, it can construct undo entries.

Want to implement it?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-07-19 21:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18  5:47 avoiding revert-buffer after vc-checkin Dan Nicolaescu
2007-07-18 18:53 ` Stefan Monnier
2007-07-18 21:21   ` David Kastrup
2007-07-19  2:57     ` Stefan Monnier
2007-07-19 21:21   ` Richard Stallman

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).