--------------------------------------------
On Sun, 1/8/17, vim-dev ML <[email protected]> wrote:

 Subject: Re: [vim/vim] bug in persistent undo -- `:earlier 100d` undoes one 
change instead of all (#1254)
 To: "vim/vim" <[email protected]>
 Cc: "vim-dev ML" <[email protected]>, "Your activity" 
<[email protected]>
 Date: Sunday, January 8, 2017, 4:06 AM
 
 2016-11-17 16:49 GMT+03:00 Bram
 Moolenaar <[email protected]>:
 
 >
 
 > Christian Brabandt wrote:
 
 >
 
 >> I am quite sure it happens here in undo.c
 
 >>
 
 >> 2390 if (dosec)
 
 >> 2391 val = (long)(uhp->uh_time - starttime);
 
 >>
 
 >> val will get a negative value, because starttime is
 less than the time of
 
 >> the undo header. Then this condition here will only
 get hit once:
 
 >>
 
 >>
 
 >> 2403 if ((step < 0 ? uhp->uh_seq <=
 curbuf->b_u_seq_cur
 
 >> 2404 : uhp->uh_seq > curbuf->b_u_seq_cur)
 
 >> 2405 && ((dosec && val == closest)
 
 >> 2406 ? (step < 0
 
 >> 2407 ? uhp->uh_seq < closest_seq
 
 >> 2408 : uhp->uh_seq > closest_seq)
 
 >> 2409 : closest == closest_start
 
 >> 2410 || (val > target
 
 >> 2411 ? (closest > target
 
 >> 2412 ? val - target <= closest - target
 
 >> 2413 : val - target <= target - closest)
 
 >> 2414 : (closest > target
 
 >> 2415 ? target - val <= closest - target
 
 >> 2416 : target - val <= target - closest))))
 
 >> 2417 {
 
 >> 2418 closest = val;
 
 >> 2419 closest_seq = uhp->uh_seq;
 
 >> 2420 }
 
 >>
 
 >> This will only hit the first time, because only at
 the beginning closest
 
 >> == closest_start, but after the next iteration, it
 will never hit again.
 
 >>
 
 >> I think this patch will fix it, but I am not sure:
 
 >>
 
 >> ```patch
 
 >> diff --git a/src/undo.c b/src/undo.c
 
 >> index 57c3c20..07c5d3c 100644
 
 >> --- a/src/undo.c
 
 >> +++ b/src/undo.c
 
 >> @@ -2406,7 +2406,7 @@ undo_time(
 
 >> ? (step < 0
 
 >> ? uhp->uh_seq < closest_seq
 
 >> : uhp->uh_seq > closest_seq)
 
 >> - : closest == closest_start
 
 >> + : closest == closest_start || closest < 0
 
 >> || (val > target
 
 >> ? (closest > target
 
 >> ? val - target <= closest - target
 
 >> ```
 
 >>
 
 >> That condition is really hard to understand, I
 stared on it for about
 
 >> an hour and even now I am not quite sure I
 completly understand it..
 
 >
 
 > I tried to write a test for this, but it passes without
 the fix:
 
 >
 
 > func Test_undofile_earlier()
 
 > " Issue #1254
 
 > new Xfile
 
 > call feedkeys("ione\<Esc>",
 'xt')
 
 > set ul=100
 
 > call feedkeys("otwo\<Esc>",
 'xt')
 
 > set ul=100
 
 > call feedkeys("othree\<Esc>",
 'xt')
 
 > set ul=100
 
 > w
 
 > wundo Xundofile
 
 > bwipe!
 
 > new Xfile
 
 > rundo Xundofile
 
 > earlier 1m
 
 > call assert_equal('', getline(1))
 
 > bwipe!
 
 > call delete('Xfile')
 
 > call delete('Xundofile')
 
 > endfunc
 
 >
 
 > And indeed, if I try the reproduce steps without
 exiting Vim then it
 
 > works as expected. So it seems that something gets
 reset when
 
 > restarting Vim, but not when reading the undo file.
 
 
 
 This is one of the reasons Neovim tests prefer to restart
 Neovim
 
 another time even during a single test rather then try to
 smash more
 
 then one test (note: not even a test module) in a single
 Neovim
 
 instance: you never know which state that is significant to
 the test
 
 was left from the previous test, additionally state may be
 just
 
 impossible to restore. Even if this makes tests an order of
 magnitude
 
 faster this is not worth the chance that dirty state will
 make the
 
 tests incorrect (also Neovim test suite does not require
 “sleep to
 
 avoid the xterm title being messed up”).
 
 
 
 >
 
 > --
 
 > `The Guide says there is an art to flying,' said
 Ford, `or at least a
 
 > knack. The knack lies in learning how to throw yourself
 at the ground
 
 > and miss.' He smiled weakly.
 
 > -- Douglas Adams, "The Hitchhiker's Guide to
 the Galaxy"
 
 >
 
 > /// Bram Moolenaar -- [email protected] --
 http://www.Moolenaar.net \\\
 
 > /// sponsor Vim, vote for features --
 http://www.Vim.org/sponsor/ \\\
 
 > \\\ an exciting new programming language --
 http://www.Zimbu.org ///
 
 > \\\ help me help AIDS victims --
 http://ICCF-Holland.org ///
 
 >
 
 > —
 
 > You are receiving this because you are subscribed to
 this thread.
 
 > Reply to this email directly, view it on GitHub
 
 >
 
 > --
 
 > --
 
 > You received this message from the "vim_dev"
 maillist.
 
 > Do not top-post! Type your reply below the text you are
 replying to.
 
 > For more information, visit
 http://www.vim.org/maillist.php
 
 >
 
 > ---
 
 > You received this message because you are subscribed to
 the Google Groups
 
 > "vim_dev" group.
 
 > To unsubscribe from this group and stop receiving
 emails from it, send an
 
 > email to [email protected].
 
 > For more options, visit
 https://groups.google.com/d/optout.
 
 
 
 —
 You are receiving this because you are subscribed to this
 thread.
 Reply to this email directly, view
 it on GitHub
 
 
   
   
 
  
 
 
  
 
 
 
 -- 
 
 -- 
 
 You received this message from the "vim_dev"
 maillist.
 
 Do not top-post! Type your reply below the text you are
 replying to.
 
 For more information, visit http://www.vim.org/maillist.php
 
 
 
 --- 
 
 You received this message because you are subscribed to the
 Google Groups "vim_dev" group.
 
 To unsubscribe from this group and stop receiving emails
 from it, send an email to [email protected].
 
 For more options, visit https://groups.google.com/d/optout.
 sadar  anul 1944 s-a profilat ca hotarator pentru destinul Romaniei  pe fondul 
cresterii nemultumirii populare  al aruncarii Romaniei in sfera de influenta 
sovietica  al intensificarii contactelor diplomatice pentru identificarea unor 
cai sigure de iesire din conflictul mondial.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui