Mercurial > vim
comparison src/undo.c @ 2235:4ba83ae8d505 vim73
Do not write an undo file if there is nothing to undo.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 30 May 2010 17:17:42 +0200 |
parents | 3b241fd8d7c0 |
children | dc2e5ec0500d |
comparison
equal
deleted
inserted
replaced
2234:3b241fd8d7c0 | 2235:4ba83ae8d505 |
---|---|
996 { | 996 { |
997 file_name = u_get_undo_file_name(buf->b_ffname, FALSE); | 997 file_name = u_get_undo_file_name(buf->b_ffname, FALSE); |
998 if (file_name == NULL) | 998 if (file_name == NULL) |
999 { | 999 { |
1000 if (p_verbose > 0) | 1000 if (p_verbose > 0) |
1001 smsg((char_u *)_("Cannot write undo file in any directory in 'undodir'")); | 1001 { |
1002 verbose_enter(); | |
1003 smsg((char_u *) | |
1004 _("Cannot write undo file in any directory in 'undodir'")); | |
1005 verbose_leave(); | |
1006 } | |
1002 return; | 1007 return; |
1003 } | 1008 } |
1004 } | 1009 } |
1005 else | 1010 else |
1006 file_name = name; | 1011 file_name = name; |
1038 /* Check we can read it and it's an undo file. */ | 1043 /* Check we can read it and it's an undo file. */ |
1039 fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0); | 1044 fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0); |
1040 if (fd < 0) | 1045 if (fd < 0) |
1041 { | 1046 { |
1042 if (name != NULL || p_verbose > 0) | 1047 if (name != NULL || p_verbose > 0) |
1043 smsg((char_u *)_("Will not overwrite with undo file, cannot read: %s"), | 1048 { |
1049 if (name == NULL) | |
1050 verbose_enter(); | |
1051 smsg((char_u *) | |
1052 _("Will not overwrite with undo file, cannot read: %s"), | |
1044 file_name); | 1053 file_name); |
1054 if (name == NULL) | |
1055 verbose_leave(); | |
1056 } | |
1045 goto theend; | 1057 goto theend; |
1046 } | 1058 } |
1047 else | 1059 else |
1048 { | 1060 { |
1049 char_u buf[UF_START_MAGIC_LEN]; | 1061 char_u buf[UF_START_MAGIC_LEN]; |
1053 close(fd); | 1065 close(fd); |
1054 if (len < UF_START_MAGIC_LEN | 1066 if (len < UF_START_MAGIC_LEN |
1055 || memcmp(buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) | 1067 || memcmp(buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) |
1056 { | 1068 { |
1057 if (name != NULL || p_verbose > 0) | 1069 if (name != NULL || p_verbose > 0) |
1070 { | |
1071 if (name == NULL) | |
1072 verbose_enter(); | |
1058 smsg((char_u *)_("Will not overwrite, this is not an undo file: %s"), | 1073 smsg((char_u *)_("Will not overwrite, this is not an undo file: %s"), |
1059 file_name); | 1074 file_name); |
1075 if (name == NULL) | |
1076 verbose_leave(); | |
1077 } | |
1060 goto theend; | 1078 goto theend; |
1061 } | 1079 } |
1062 } | 1080 } |
1063 } | 1081 } |
1064 mch_remove(file_name); | 1082 mch_remove(file_name); |
1083 } | |
1084 | |
1085 /* If there is no undo information at all, quit here after deleting any | |
1086 * existing undo file. */ | |
1087 if (buf->b_u_numhead == 0) | |
1088 { | |
1089 if (p_verbose > 0) | |
1090 verb_msg((char_u *)_("Skipping undo file write, noting to undo")); | |
1091 goto theend; | |
1065 } | 1092 } |
1066 | 1093 |
1067 fd = mch_open((char *)file_name, | 1094 fd = mch_open((char *)file_name, |
1068 O_CREAT|O_EXTRA|O_WRONLY|O_EXCL|O_NOFOLLOW, perm); | 1095 O_CREAT|O_EXTRA|O_WRONLY|O_EXCL|O_NOFOLLOW, perm); |
1069 if (fd < 0) | 1096 if (fd < 0) |
1071 EMSG2(_(e_not_open), file_name); | 1098 EMSG2(_(e_not_open), file_name); |
1072 goto theend; | 1099 goto theend; |
1073 } | 1100 } |
1074 (void)mch_setperm(file_name, perm); | 1101 (void)mch_setperm(file_name, perm); |
1075 if (p_verbose > 0) | 1102 if (p_verbose > 0) |
1103 { | |
1104 verbose_enter(); | |
1076 smsg((char_u *)_("Writing undo file: %s"), file_name); | 1105 smsg((char_u *)_("Writing undo file: %s"), file_name); |
1106 verbose_leave(); | |
1107 } | |
1077 | 1108 |
1078 #ifdef U_DEBUG | 1109 #ifdef U_DEBUG |
1079 /* Check if there already is a problem before writing. */ | 1110 /* Check there is no problem in undo info before writing. */ |
1080 u_check(FALSE); | 1111 u_check(FALSE); |
1081 #endif | 1112 #endif |
1082 | 1113 |
1083 #ifdef UNIX | 1114 #ifdef UNIX |
1084 /* | 1115 /* |
1288 } | 1319 } |
1289 else | 1320 else |
1290 file_name = name; | 1321 file_name = name; |
1291 | 1322 |
1292 if (p_verbose > 0) | 1323 if (p_verbose > 0) |
1324 { | |
1325 verbose_enter(); | |
1293 smsg((char_u *)_("Reading undo file: %s"), file_name); | 1326 smsg((char_u *)_("Reading undo file: %s"), file_name); |
1327 verbose_leave(); | |
1328 } | |
1294 fp = mch_fopen((char *)file_name, "r"); | 1329 fp = mch_fopen((char *)file_name, "r"); |
1295 if (fp == NULL) | 1330 if (fp == NULL) |
1296 { | 1331 { |
1297 if (name != NULL || p_verbose > 0) | 1332 if (name != NULL || p_verbose > 0) |
1298 EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name); | 1333 EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name); |
1324 if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 | 1359 if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 |
1325 || line_count != curbuf->b_ml.ml_line_count) | 1360 || line_count != curbuf->b_ml.ml_line_count) |
1326 { | 1361 { |
1327 if (p_verbose > 0 || name != NULL) | 1362 if (p_verbose > 0 || name != NULL) |
1328 { | 1363 { |
1329 verbose_enter(); | 1364 if (name == NULL) |
1365 verbose_enter(); | |
1330 give_warning((char_u *)_("File contents changed, cannot use undo info"), TRUE); | 1366 give_warning((char_u *)_("File contents changed, cannot use undo info"), TRUE); |
1331 verbose_leave(); | 1367 if (name == NULL) |
1368 verbose_leave(); | |
1332 } | 1369 } |
1333 goto error; | 1370 goto error; |
1334 } | 1371 } |
1335 | 1372 |
1336 /* Begin undo data for U */ | 1373 /* Begin undo data for U */ |