On Fri, Aug 13, 2010 at 3:33 AM, Bram Moolenaar <[email protected]> wrote:
>
> Nazri Ramliy wrote:
>
>> This is a regression introduced by my own patch previously
>> (7ce8b24450dc: Improvements for
>> ":find" completion. (Nazri Ramliy)).
>>
>> Attached patch fixes the regression and add tests to test73 to catch the bug.
>>
>> The test runs fine on unix, but fails on msvc vim.  I'll investigate
>> it later. Sorry I'm in a bit of a hurry
>> I'll look into cleaning up the patch and making the test successfull
>> on msvc vim soon.
>
> Thanks.
>
> I noticed a few memory leaks and fixed them.
>
> I changed the STRNCMP() to fnamencmp().  That might fix the problem on
> MS-Windows.
>
> I moved a few C99 style declarations to start of code block.

Thanks the fixes. Sorry, the patch was made in a hurry.

>
> That's an awful lot of problems...  I'll spend some more time on this
> tomorrow.

I've spent some time looking over the changes and made a few more fixes.

Instead of one big patch I'm attaching 7 small patches with the hope
that they are easier for you to review. These are on top of the latest
changeset at the moment (20e83abf88b1).

0001: Make test73 pass on msvc-vim

0002: Call uniquefy_paths only when there are candidates.

0003: I noticed that the "is_in_curdir" check only works correctly for
      file, not directory.  The must be some condition that will fail
      the find completion due to this but I can't think of any at the
      moment.

0004: Delete an "#if defined(MSWIN) || defined(MSDOS)" conditional.
      I think it is not really needed there because "cutoff" points to a
      filename produced by globpath and the directory separators should
      have already been normalized to the platform's path separator.

0005: Add a failing test to test73 to show a peculiar behavior of
      shorten_fname() on windows when used for the shortening the
      filename.  This test runs fine on unix, but fails on msvc-vim.

0006: Work around shorten_fname()'s behavior on windows.  With this
      change test73 runs successfully.

0007: Remove irrelevant comment.

nazri.

-- 
You received this message from the "vim_dev" 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
From 5a7b0e0229f97e9cc430e94efd1363ebec4b5fa4 Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 12:39:48 +0800
Subject: [PATCH 1/6] Make test73 pass on msvc vim

---
 src/misc1.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 432d36c..64c7620 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9470,13 +9470,7 @@ uniquefy_paths(gap, pattern)
 	char_u	    *path_cutoff;
 
 	len = (int)STRLEN(path);
-	while (dir_end > path &&
-# if defined(MSWIN) || defined(MSDOS)
-		*dir_end != '/'
-#else
-		!vim_ispathsep(*dir_end)
-#endif
-		)
+	while (dir_end > path && !vim_ispathsep(*dir_end))
 	    mb_ptr_back(path, dir_end);
 	is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0
 					     && curdir[dir_end - path] == NUL;
-- 
1.7.2.1.6.g61bf12

From 2736d3512a49bfc97021ceed4a6223e209046e56 Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 12:32:36 +0800
Subject: [PATCH 2/6] find completion: Shorten candidates only when they exist.

---
 src/misc1.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 64c7620..968acfa 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9820,7 +9820,7 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags)
 	}
 
 #if defined(FEAT_SEARCHPATH)
-	if (flags & EW_PATH)
+	if (ga.ga_len && flags & EW_PATH)
 	    uniquefy_paths(&ga, p);
 #endif
 	if (p != pat[i])
-- 
1.7.2.1.6.g61bf12

From 6e2ff12b7679e5971138e647c717641c615fe0b3 Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 12:41:11 +0800
Subject: [PATCH 3/6] Find completion: Fix for shortening directory names.

---
 src/misc1.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 968acfa..0f9f90a 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9465,10 +9465,20 @@ uniquefy_paths(gap, pattern)
     {
 	char_u	    *path = fnames[i];
 	int	    is_in_curdir;
-	char_u	    *dir_end = gettail(path);
+	char_u	    *dir_end;
 	char_u	    *pathsep_p;
 	char_u	    *path_cutoff;
 
+
+	dir_end = gettail(path);
+	/*
+	 * path might be a directory, in which case *dir_end is NUL.
+	 * Point it to the letter before the last path separator.
+	 */
+	if (*dir_end == NUL)
+	    for (dir_end--; dir_end > path && vim_ispathsep(*dir_end);)
+	      mb_ptr_back(path, dir_end);
+
 	len = (int)STRLEN(path);
 	while (dir_end > path && !vim_ispathsep(*dir_end))
 	    mb_ptr_back(path, dir_end);
-- 
1.7.2.1.6.g61bf12

From a995da65a456d0a7a5bfd6ab774289a01a255e0b Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 13:07:45 +0800
Subject: [PATCH 4/6] Remove redundant #if-#else-#endif

---
 src/misc1.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 0f9f90a..6abd098 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9388,13 +9388,7 @@ get_path_cutoff(fname, gap)
 
     /* Skip to the file or directory name */
     if (cutoff != NULL)
-	while (
-# if defined(MSWIN) || defined(MSDOS)
-		*cutoff == '/'
-#else
-		vim_ispathsep(*cutoff)
-#endif
-	      )
+	while (vim_ispathsep(*cutoff))
 	    mb_ptr_adv(cutoff);
 
     return cutoff;
-- 
1.7.2.1.6.g61bf12

From 1c442861c2d390e1f9675ce19a775809e0f8a74f Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 15:49:52 +0800
Subject: [PATCH 5/6] test73: Add check for correct handling of shorten_fname()'s behavior on windows

---
 src/testdir/test73.in |    6 +++++-
 src/testdir/test73.ok |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/testdir/test73.in b/src/testdir/test73.in
index 4186590..712e123 100644
--- a/src/testdir/test73.in
+++ b/src/testdir/test73.in
@@ -146,8 +146,12 @@ SVoyager 2:w
 :exec "w >> " . test_out
 :find voyager		
 :exec "w >> " . test_out
-:cd ..
+:" Check for correct handling of shorten_fname()'s behavior on windows
+:exec "cd " . cwd . "/Xfind/in"
+:find file	
+:exec "w >>" . test_out
 :q
+:exec "cd " . cwd
 :call DeleteDirectory("Xfind")
 :qa!
 ENDTEST
diff --git a/src/testdir/test73.ok b/src/testdir/test73.ok
index a54e5f4..4dd48fb 100644
--- a/src/testdir/test73.ok
+++ b/src/testdir/test73.ok
@@ -15,3 +15,4 @@ Voyager 2
 Voyager 1
 Voyager 1
 Voyager 2
+Jimmy Hoffa
-- 
1.7.2.1.6.g61bf12

From c7a9ba1ba1c4d5c395614c2f9f34f9a943208e01 Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 15:48:12 +0800
Subject: [PATCH 6/6] Work around for shorten_fname()'s behavior on windows

---
 src/misc1.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 6abd098..5941111 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9515,7 +9515,19 @@ uniquefy_paths(gap, pattern)
 	     *	    c:\file.txt		  c:\		.\file.txt
 	     */
 	    short_name = shorten_fname(path, curdir);
-	    if (short_name != NULL && short_name > path + 1)
+	    if (short_name != NULL && short_name > path + 1
+#if defined(MSWIN) || defined(MSDOS)
+		    /*
+		     * On windows,
+		     *
+		     *	    shorten_fname("c:\a\a.txt", "c:\a\b")
+		     *
+		     * returns "\a\a.txt", which is not really the short
+		     * name, hence:
+		     */
+		    && !vim_ispathsep(*short_name)
+#endif
+		)
 	    {
 		STRCPY(path, ".");
 		add_pathsep(path);
-- 
1.7.2.1.6.g61bf12

From 285ae72491f04e421b2113bd0a849c73d41597c2 Mon Sep 17 00:00:00 2001
From: Nazri Ramliy <[email protected]>
Date: Fri, 13 Aug 2010 16:08:41 +0800
Subject: [PATCH 7/7] Remove irrelevant comment.

---
 src/misc1.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 5941111..46c97a5 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9545,16 +9545,10 @@ uniquefy_paths(gap, pattern)
 	if (path == NULL)
 	    continue;
 	/*
-	 * If the file is in the current directory,
-	 * and it is not unique,
+	 * If the {filename} is not unique,
 	 * reduce it to ./{filename}
 	 *	  FIXME ^ Is this portable?
 	 * else reduce it to {filename}
-	 *
-	 * Note: If the full filename is /curdir/foo/bar/{filename}, we don't
-	 * want to shorten it to ./foo/bar/{filename} yet because 'path' might
-	 * contain ". / * *", in which case the shortened filename could be
-	 * shorter than ./foo/bar/{filename}.
 	 */
 	short_name = shorten_fname(path, curdir);
 	if (short_name == NULL)
-- 
1.7.2.1.6.g61bf12

Raspunde prin e-mail lui