• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisiona5de1d88590dac1595b4177fc7eee8e14a866f63 (tree)
Time2019-10-10 05:15:04
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.1.2126: viminfo not sufficiently tested

Commit: https://github.com/vim/vim/commit/6bd1d7706766a7899904163e8fd55ea117fb1953
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 9 22:01:25 2019 +0200

patch 8.1.2126: viminfo not sufficiently tested
Problem: Viminfo not sufficiently tested.
Solution: Add more test cases. Clean up comments. (Yegappan Lakshmanan,
closes #5032)

Change Summary

Incremental Difference

diff -r 3050e95a3c73 -r a5de1d88590d src/search.c
--- a/src/search.c Tue Oct 08 23:30:05 2019 +0200
+++ b/src/search.c Wed Oct 09 22:15:04 2019 +0200
@@ -5783,12 +5783,18 @@
57835783 #endif
57845784
57855785 #ifdef FEAT_VIMINFO
5786+/*
5787+ * Return the last used search pattern at "idx".
5788+ */
57865789 spat_T *
57875790 get_spat(int idx)
57885791 {
57895792 return &spats[idx];
57905793 }
57915794
5795+/*
5796+ * Return the last used search pattern index.
5797+ */
57925798 int
57935799 get_spat_last_idx(void)
57945800 {
diff -r 3050e95a3c73 -r a5de1d88590d src/structs.h
--- a/src/structs.h Tue Oct 08 23:30:05 2019 +0200
+++ b/src/structs.h Wed Oct 09 22:15:04 2019 +0200
@@ -1134,18 +1134,6 @@
11341134 } vimconv_T;
11351135
11361136 /*
1137- * Structure used for reading from the viminfo file.
1138- */
1139-typedef struct
1140-{
1141- char_u *vir_line; // text of the current line
1142- FILE *vir_fd; // file descriptor
1143- vimconv_T vir_conv; // encoding conversion
1144- int vir_version; // viminfo version detected or -1
1145- garray_T vir_barlines; // lines starting with |
1146-} vir_T;
1147-
1148-/*
11491137 * Structure used for the command line history.
11501138 */
11511139 typedef struct hist_entry
diff -r 3050e95a3c73 -r a5de1d88590d src/testdir/test_viminfo.vim
--- a/src/testdir/test_viminfo.vim Tue Oct 08 23:30:05 2019 +0200
+++ b/src/testdir/test_viminfo.vim Wed Oct 09 22:15:04 2019 +0200
@@ -1,5 +1,7 @@
11 " Test for reading and writing .viminfo
22
3+source check.vim
4+
35 function Test_viminfo_read_and_write()
46 " First clear 'history', so that "hislen" is zero. Then set it again,
57 " simulating Vim starting up.
@@ -715,26 +717,78 @@
715717 rviminfo! Xviminfo
716718 call assert_equal(join(repeat(["sun is rising"], 200), "\n"), @r)
717719 call delete('Xviminfo')
720+ let @r = ''
718721 let &viminfo = save_viminfo
719722 endfunc
720723
721724 " Test for setting 'viminfofile' to NONE
722725 func Test_viminfofile_none()
726+ let save_vif = &viminfofile
723727 set viminfofile=NONE
724728 wviminfo Xviminfo
725729 call assert_false(filereadable('Xviminfo'))
726730 call writefile([''], 'Xviminfo')
727731 call assert_fails('rviminfo Xviminfo', 'E195:')
728732 call delete('Xviminfo')
733+ let &viminfofile = save_vif
729734 endfunc
730735
731-" Test for an unwritable 'viminfo' file
732-func Test_viminfo_readonly()
733- if !has('unix')
734- return
735- endif
736+" Test for an unwritable and unreadble 'viminfo' file
737+func Test_viminfo_perm()
738+ CheckUnix
736739 call writefile([''], 'Xviminfo')
737740 call setfperm('Xviminfo', 'r-x------')
738741 call assert_fails('wviminfo Xviminfo', 'E137:')
742+ call setfperm('Xviminfo', '--x------')
743+ call assert_fails('rviminfo Xviminfo', 'E195:')
739744 call delete('Xviminfo')
740745 endfunc
746+
747+" Test for writing to an existing viminfo file merges the file marks
748+func XTest_viminfo_marks_merge()
749+ let save_viminfo = &viminfo
750+ set viminfo&vim
751+ set viminfo^=%
752+ enew
753+ %argdelete
754+ %bwipe
755+
756+ call writefile(repeat(['editor'], 10), 'Xbufa')
757+ call writefile(repeat(['Vim'], 10), 'Xbufb')
758+
759+ " set marks in buffers
760+ call test_settime(10)
761+ edit Xbufa
762+ 4mark a
763+ wviminfo Xviminfo
764+ edit Xbufb
765+ 4mark b
766+ wviminfo Xviminfo
767+ %bwipe
768+
769+ " set marks in buffers again
770+ call test_settime(20)
771+ edit Xbufb
772+ 6mark b
773+ wviminfo Xviminfo
774+ edit Xbufa
775+ 6mark a
776+ wviminfo Xviminfo
777+ %bwipe
778+
779+ " Load the buffer and check the marks
780+ edit Xbufa
781+ rviminfo! Xviminfo
782+ call assert_equal(6, line("'a"))
783+ edit Xbufb
784+ rviminfo! Xviminfo
785+ call assert_equal(6, line("'b"))
786+
787+ " cleanup
788+ %bwipe
789+ call delete('Xviminfo')
790+ call delete('Xbufa')
791+ call delete('Xbufb')
792+ call test_settime(0)
793+ let &viminfo=save_viminfo
794+endfunc
diff -r 3050e95a3c73 -r a5de1d88590d src/version.c
--- a/src/version.c Tue Oct 08 23:30:05 2019 +0200
+++ b/src/version.c Wed Oct 09 22:15:04 2019 +0200
@@ -754,6 +754,8 @@
754754 static int included_patches[] =
755755 { /* Add new patch number below this line */
756756 /**/
757+ 2126,
758+/**/
757759 2125,
758760 /**/
759761 2124,
diff -r 3050e95a3c73 -r a5de1d88590d src/viminfo.c
--- a/src/viminfo.c Tue Oct 08 23:30:05 2019 +0200
+++ b/src/viminfo.c Wed Oct 09 22:15:04 2019 +0200
@@ -14,6 +14,18 @@
1414 #include "vim.h"
1515 #include "version.h"
1616
17+/*
18+ * Structure used for reading from the viminfo file.
19+ */
20+typedef struct
21+{
22+ char_u *vir_line; // text of the current line
23+ FILE *vir_fd; // file descriptor
24+ vimconv_T vir_conv; // encoding conversion
25+ int vir_version; // viminfo version detected or -1
26+ garray_T vir_barlines; // lines starting with |
27+} vir_T;
28+
1729 #if defined(FEAT_VIMINFO) || defined(PROTO)
1830
1931 static int viminfo_errcnt;
@@ -822,11 +834,9 @@
822834 if (num_saved > hislen)
823835 num_saved = hislen;
824836
825- /*
826- * Merge typed and viminfo history:
827- * round 1: history of typed commands.
828- * round 2: history from recently read viminfo.
829- */
837+ // Merge typed and viminfo history:
838+ // round 1: history of typed commands.
839+ // round 2: history from recently read viminfo.
830840 for (round = 1; round <= 2; ++round)
831841 {
832842 if (round == 1)
@@ -2671,16 +2681,14 @@
26712681 int i;
26722682 int read_next = TRUE;
26732683
2674- /*
2675- * The format is: |{bartype},{value},...
2676- * For a very long string:
2677- * |{bartype},>{length of "{text}{text2}"}
2678- * |<{text1}
2679- * |<{text2},{value}
2680- * For a long line not using a string
2681- * |{bartype},{lots of values},>
2682- * |<{value},{value}
2683- */
2684+ // The format is: |{bartype},{value},...
2685+ // For a very long string:
2686+ // |{bartype},>{length of "{text}{text2}"}
2687+ // |<{text1}
2688+ // |<{text2},{value}
2689+ // For a long line not using a string
2690+ // |{bartype},{lots of values},>
2691+ // |<{value},{value}
26842692 if (*p == '<')
26852693 {
26862694 // Continuation line of an unrecognized item.
@@ -3032,18 +3040,14 @@
30323040 }
30333041 else
30343042 {
3035- /*
3036- * There is an existing viminfo file. Create a temporary file to
3037- * write the new viminfo into, in the same directory as the
3038- * existing viminfo file, which will be renamed once all writing is
3039- * successful.
3040- */
3043+ // There is an existing viminfo file. Create a temporary file to
3044+ // write the new viminfo into, in the same directory as the
3045+ // existing viminfo file, which will be renamed once all writing is
3046+ // successful.
30413047 #ifdef UNIX
3042- /*
3043- * For Unix we check the owner of the file. It's not very nice to
3044- * overwrite a user's viminfo file after a "su root", with a
3045- * viminfo file that the user can't read.
3046- */
3048+ // For Unix we check the owner of the file. It's not very nice to
3049+ // overwrite a user's viminfo file after a "su root", with a
3050+ // viminfo file that the user can't read.
30473051 st_old.st_dev = (dev_t)0;
30483052 st_old.st_ino = 0;
30493053 st_old.st_mode = 0600;
@@ -3069,14 +3073,12 @@
30693073 hidden = mch_ishidden(fname);
30703074 #endif
30713075
3072- /*
3073- * Make tempname, find one that does not exist yet.
3074- * Beware of a race condition: If someone logs out and all Vim
3075- * instances exit at the same time a temp file might be created between
3076- * stat() and open(). Use mch_open() with O_EXCL to avoid that.
3077- * May try twice: Once normal and once with shortname set, just in
3078- * case somebody puts his viminfo file in an 8.3 filesystem.
3079- */
3076+ // Make tempname, find one that does not exist yet.
3077+ // Beware of a race condition: If someone logs out and all Vim
3078+ // instances exit at the same time a temp file might be created between
3079+ // stat() and open(). Use mch_open() with O_EXCL to avoid that.
3080+ // May try twice: Once normal and once with shortname set, just in
3081+ // case somebody puts his viminfo file in an 8.3 filesystem.
30803082 for (;;)
30813083 {
30823084 int next_char = 'z';
@@ -3098,30 +3100,24 @@
30983100 if (tempname == NULL) // out of memory
30993101 break;
31003102
3101- /*
3102- * Try a series of names. Change one character, just before
3103- * the extension. This should also work for an 8.3
3104- * file name, when after adding the extension it still is
3105- * the same file as the original.
3106- */
3103+ // Try a series of names. Change one character, just before
3104+ // the extension. This should also work for an 8.3
3105+ // file name, when after adding the extension it still is
3106+ // the same file as the original.
31073107 wp = tempname + STRLEN(tempname) - 5;
31083108 if (wp < gettail(tempname)) // empty file name?
31093109 wp = gettail(tempname);
31103110 for (;;)
31113111 {
3112- /*
3113- * Check if tempfile already exists. Never overwrite an
3114- * existing file!
3115- */
3112+ // Check if tempfile already exists. Never overwrite an
3113+ // existing file!
31163114 if (mch_stat((char *)tempname, &st_new) == 0)
31173115 {
31183116 #ifdef UNIX
3119- /*
3120- * Check if tempfile is same as original file. May happen
3121- * when modname() gave the same file back. E.g. silly
3122- * link, or file name-length reached. Try again with
3123- * shortname set.
3124- */
3117+ // Check if tempfile is same as original file. May happen
3118+ // when modname() gave the same file back. E.g. silly
3119+ // link, or file name-length reached. Try again with
3120+ // shortname set.
31253121 if (!shortname && st_new.st_dev == st_old.st_dev
31263122 && st_new.st_ino == st_old.st_ino)
31273123 {
@@ -3199,10 +3195,8 @@
31993195 {
32003196 stat_T tmp_st;
32013197
3202- /*
3203- * Make sure the original owner can read/write the tempfile and
3204- * otherwise preserve permissions, making sure the group matches.
3205- */
3198+ // Make sure the original owner can read/write the tempfile and
3199+ // otherwise preserve permissions, making sure the group matches.
32063200 if (mch_stat((char *)tempname, &tmp_st) >= 0)
32073201 {
32083202 if (st_old.st_uid != tmp_st.st_uid)
@@ -3222,9 +3216,7 @@
32223216 #endif
32233217 }
32243218
3225- /*
3226- * Check if the new viminfo file can be written to.
3227- */
3219+ // Check if the new viminfo file can be written to.
32283220 if (fp_out == NULL)
32293221 {
32303222 semsg(_("E138: Can't write viminfo file %s!"),
Show on old repository browser