Tuesday, May 31, 2011

Re: Restore file from undo

diff --git a/src/ex_cmds.h b/src/ex_cmds.h
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -788,7 +788,7 @@
EX(CMD_rubyfile, "rubyfile", ex_rubyfile,
RANGE|FILE1|NEEDARG|CMDWIN),
EX(CMD_rundo, "rundo", ex_rundo,
- NEEDARG|EXTRA|XFILE),
+ BANG|NEEDARG|EXTRA|XFILE),
EX(CMD_rviminfo, "rviminfo", ex_viminfo,
BANG|FILE1|TRLBAR|CMDWIN),
EX(CMD_substitute, "substitute", do_sub,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -8551,7 +8551,7 @@
char_u hash[UNDO_HASH_SIZE];

u_compute_hash(hash);
- u_read_undo(eap->arg, hash, NULL);
+ u_read_undo(eap->arg, hash, NULL, eap->forceit);
}
#endif

diff --git a/src/fileio.c b/src/fileio.c
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2616,7 +2616,7 @@
char_u hash[UNDO_HASH_SIZE];

sha256_finish(&sha_ctx, hash);
- u_read_undo(NULL, hash, fname);
+ u_read_undo(NULL, hash, fname, FALSE);
}
#endif

diff --git a/src/proto/undo.pro b/src/proto/undo.pro
--- a/src/proto/undo.pro
+++ b/src/proto/undo.pro
@@ -9,7 +9,7 @@
void u_compute_hash __ARGS((char_u *hash));
char_u *u_get_undo_file_name __ARGS((char_u *buf_ffname, int reading));
void u_write_undo __ARGS((char_u *name, int forceit, buf_T *buf, char_u *hash));
-void u_read_undo __ARGS((char_u *name, char_u *hash, char_u *orig_name));
+void u_read_undo __ARGS((char_u *name, char_u *hash, char_u *orig_name, int force));
void u_undo __ARGS((int count));
void u_redo __ARGS((int count));
void undo_time __ARGS((long step, int sec, int file, int absolute));
diff --git a/src/undo.c b/src/undo.c
--- a/src/undo.c
+++ b/src/undo.c
@@ -1555,10 +1555,11 @@
* "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
*/
void
-u_read_undo(name, hash, orig_name)
+u_read_undo(name, hash, orig_name, force)
char_u *name;
char_u *hash;
char_u *orig_name;
+ int force; /* :rundo! */
{
char_u *file_name;
FILE *fp;
@@ -1675,8 +1676,9 @@
goto error;
}
line_count = (linenr_T)get4c(fp);
- if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0
+ if ((memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0
|| line_count != curbuf->b_ml.ml_line_count)
+ && !force)
{
if (p_verbose > 0 || name != NULL)
{On Tue, May 31, 2011 1:50 pm, Vsevolod Velichko wrote:
> Christian, thanks for your answer.
> Yes, all the files I've lost were created from scratch, so I suppose,
> that undofile contains all the file history (undolevels=1000 should be
> sufficient for every file).

Ok then here is a patch. It allows to use :rundo! to let vim read in any
undo file. You need to create a new empty file with more lines, than your
original file had, e.g. 1000 empty lines. Then do :rundo! original_file.un~
and you can move through the undo history using g- and g+ or using
the :earlier :later commands.
The histwin or gundo plugin may also come useful to see your different
undo branches.

regards,
Christian

--
You received this message from the "vim_use" 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

No comments:

Post a Comment