summaryrefslogtreecommitdiff
path: root/src/undo.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2010-05-30 17:17:42 +0200
committerBram Moolenaar <Bram@vim.org>2010-05-30 17:17:42 +0200
commit504a82173c607f50801e90f8001bb2f1c13fecf9 (patch)
treeeb5b03ee5c053560c88ea7738c5b556ddf798b7b /src/undo.c
parent8f1f629d853d8c4de8bacf69fda769ce791fadb2 (diff)
downloadvim-git-504a82173c607f50801e90f8001bb2f1c13fecf9.tar.gz
Do not write an undo file if there is nothing to undo.
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/undo.c b/src/undo.c
index cb51c996c..88c030565 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -998,7 +998,12 @@ u_write_undo(name, forceit, buf, hash)
if (file_name == NULL)
{
if (p_verbose > 0)
- smsg((char_u *)_("Cannot write undo file in any directory in 'undodir'"));
+ {
+ verbose_enter();
+ smsg((char_u *)
+ _("Cannot write undo file in any directory in 'undodir'"));
+ verbose_leave();
+ }
return;
}
}
@@ -1040,8 +1045,15 @@ u_write_undo(name, forceit, buf, hash)
if (fd < 0)
{
if (name != NULL || p_verbose > 0)
- smsg((char_u *)_("Will not overwrite with undo file, cannot read: %s"),
+ {
+ if (name == NULL)
+ verbose_enter();
+ smsg((char_u *)
+ _("Will not overwrite with undo file, cannot read: %s"),
file_name);
+ if (name == NULL)
+ verbose_leave();
+ }
goto theend;
}
else
@@ -1055,8 +1067,14 @@ u_write_undo(name, forceit, buf, hash)
|| memcmp(buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
{
if (name != NULL || p_verbose > 0)
+ {
+ if (name == NULL)
+ verbose_enter();
smsg((char_u *)_("Will not overwrite, this is not an undo file: %s"),
file_name);
+ if (name == NULL)
+ verbose_leave();
+ }
goto theend;
}
}
@@ -1064,6 +1082,15 @@ u_write_undo(name, forceit, buf, hash)
mch_remove(file_name);
}
+ /* If there is no undo information at all, quit here after deleting any
+ * existing undo file. */
+ if (buf->b_u_numhead == 0)
+ {
+ if (p_verbose > 0)
+ verb_msg((char_u *)_("Skipping undo file write, noting to undo"));
+ goto theend;
+ }
+
fd = mch_open((char *)file_name,
O_CREAT|O_EXTRA|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0)
@@ -1073,10 +1100,14 @@ u_write_undo(name, forceit, buf, hash)
}
(void)mch_setperm(file_name, perm);
if (p_verbose > 0)
+ {
+ verbose_enter();
smsg((char_u *)_("Writing undo file: %s"), file_name);
+ verbose_leave();
+ }
#ifdef U_DEBUG
- /* Check if there already is a problem before writing. */
+ /* Check there is no problem in undo info before writing. */
u_check(FALSE);
#endif
@@ -1290,7 +1321,11 @@ u_read_undo(name, hash)
file_name = name;
if (p_verbose > 0)
+ {
+ verbose_enter();
smsg((char_u *)_("Reading undo file: %s"), file_name);
+ verbose_leave();
+ }
fp = mch_fopen((char *)file_name, "r");
if (fp == NULL)
{
@@ -1326,9 +1361,11 @@ u_read_undo(name, hash)
{
if (p_verbose > 0 || name != NULL)
{
- verbose_enter();
+ if (name == NULL)
+ verbose_enter();
give_warning((char_u *)_("File contents changed, cannot use undo info"), TRUE);
- verbose_leave();
+ if (name == NULL)
+ verbose_leave();
}
goto error;
}