Skip to content

Commit cbd4de4

Browse files
committed
patch 8.0.0149: :earlier does not work after reading the undo file
Problem: ":earlier" and ":later" do not work after startup or reading the undo file. Solution: Use absolute time stamps instead of relative to the Vim start time. (Christian Brabandt, Pavel Juhas, closes #1300, closes #1254)
1 parent c6aa475 commit cbd4de4

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/testdir/test_undo.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,31 @@ func Test_insert_expr()
235235

236236
close!
237237
endfunc
238+
239+
func Test_undofile_earlier()
240+
" Issue #1254
241+
" create undofile with timestamps older than Vim startup time.
242+
let t0 = localtime() - 43200
243+
call test_settime(t0)
244+
new Xfile
245+
call feedkeys("ione\<Esc>", 'xt')
246+
set ul=100
247+
call test_settime(t0 + 1)
248+
call feedkeys("otwo\<Esc>", 'xt')
249+
set ul=100
250+
call test_settime(t0 + 2)
251+
call feedkeys("othree\<Esc>", 'xt')
252+
set ul=100
253+
w
254+
wundo Xundofile
255+
bwipe!
256+
" restore normal timestamps.
257+
call test_settime(0)
258+
new Xfile
259+
rundo Xundofile
260+
earlier 1d
261+
call assert_equal('', getline(1))
262+
bwipe!
263+
call delete('Xfile')
264+
call delete('Xundofile')
265+
endfunc

src/undo.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,10 +2298,8 @@ undo_time(
22982298
}
22992299
else
23002300
{
2301-
/* When doing computations with time_t subtract starttime, because
2302-
* time_t converted to a long may result in a wrong number. */
23032301
if (dosec)
2304-
target = (long)(curbuf->b_u_time_cur - starttime) + step;
2302+
target = (long)(curbuf->b_u_time_cur) + step;
23052303
else if (dofile)
23062304
{
23072305
if (step < 0)
@@ -2350,7 +2348,7 @@ undo_time(
23502348
else
23512349
{
23522350
if (dosec)
2353-
closest = (long)(vim_time() - starttime + 1);
2351+
closest = (long)(vim_time() + 1);
23542352
else if (dofile)
23552353
closest = curbuf->b_u_save_nr_last + 2;
23562354
else
@@ -2388,7 +2386,7 @@ undo_time(
23882386
{
23892387
uhp->uh_walk = mark;
23902388
if (dosec)
2391-
val = (long)(uhp->uh_time - starttime);
2389+
val = (long)(uhp->uh_time);
23922390
else if (dofile)
23932391
val = uhp->uh_save_nr;
23942392
else

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
149,
767769
/**/
768770
148,
769771
/**/

0 commit comments

Comments
 (0)