aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-17 16:25:19 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-18 17:00:26 -0800
commit43e1c0a2bf0898a23950c740de9fcba2991f1aaf (patch)
treea05a6c85a4e64391eb3aad2d03fd3d85de442943
parent99e18d9cef17a9e5ef3b0cefc88c2f8f54c38bf5 (diff)
Remove some newly dead code
out_suggested_cdpath is no longer required from is_potential_path
-rw-r--r--src/fish_tests.cpp23
-rw-r--r--src/highlight.cpp123
-rw-r--r--src/highlight.h2
3 files changed, 20 insertions, 128 deletions
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp
index cd1c0b60..9be273e6 100644
--- a/src/fish_tests.cpp
+++ b/src/fish_tests.cpp
@@ -1929,25 +1929,24 @@ static void test_is_potential_path()
const wcstring wd = L"/tmp/is_potential_path_test/";
const wcstring_list_t wds(1, wd);
- wcstring tmp;
- do_test(is_potential_path(L"al", wds, PATH_REQUIRE_DIR, &tmp) && tmp == L"alpha/");
- do_test(is_potential_path(L"alpha/", wds, PATH_REQUIRE_DIR, &tmp) && tmp == L"alpha/");
+ do_test(is_potential_path(L"al", wds, PATH_REQUIRE_DIR));
+ do_test(is_potential_path(L"alpha/", wds, PATH_REQUIRE_DIR));
do_test(is_potential_path(L"aard", wds, 0));
- do_test(! is_potential_path(L"balpha/", wds, PATH_REQUIRE_DIR, &tmp));
- do_test(! is_potential_path(L"aard", wds, PATH_REQUIRE_DIR, &tmp));
- do_test(! is_potential_path(L"aarde", wds, PATH_REQUIRE_DIR, &tmp));
- do_test(! is_potential_path(L"aarde", wds, 0, &tmp));
+ do_test(! is_potential_path(L"balpha/", wds, PATH_REQUIRE_DIR));
+ do_test(! is_potential_path(L"aard", wds, PATH_REQUIRE_DIR));
+ do_test(! is_potential_path(L"aarde", wds, PATH_REQUIRE_DIR));
+ do_test(! is_potential_path(L"aarde", wds, 0));
do_test(is_potential_path(L"/tmp/is_potential_path_test/aardvark", wds, 0));
- do_test(is_potential_path(L"/tmp/is_potential_path_test/al", wds, PATH_REQUIRE_DIR, &tmp) && tmp == L"/tmp/is_potential_path_test/alpha/");
+ do_test(is_potential_path(L"/tmp/is_potential_path_test/al", wds, PATH_REQUIRE_DIR));
do_test(is_potential_path(L"/tmp/is_potential_path_test/aardv", wds, 0));
- do_test(! is_potential_path(L"/tmp/is_potential_path_test/aardvark", wds, PATH_REQUIRE_DIR, &tmp));
- do_test(! is_potential_path(L"/tmp/is_potential_path_test/al/", wds, 0, &tmp));
- do_test(! is_potential_path(L"/tmp/is_potential_path_test/ar", wds, 0, &tmp));
+ do_test(! is_potential_path(L"/tmp/is_potential_path_test/aardvark", wds, PATH_REQUIRE_DIR));
+ do_test(! is_potential_path(L"/tmp/is_potential_path_test/al/", wds, 0));
+ do_test(! is_potential_path(L"/tmp/is_potential_path_test/ar", wds, 0));
- do_test(is_potential_path(L"/usr", wds, PATH_REQUIRE_DIR, &tmp) && tmp == L"/usr/");
+ do_test(is_potential_path(L"/usr", wds, PATH_REQUIRE_DIR));
}
diff --git a/src/highlight.cpp b/src/highlight.cpp
index da40bfda..90426803 100644
--- a/src/highlight.cpp
+++ b/src/highlight.cpp
@@ -91,72 +91,13 @@ bool fs_is_case_insensitive(const wcstring &path, int fd, case_sensitivity_cache
return result;
}
-/* Given a start point as an absolute path, for any directory that has exactly one non-hidden entity in it which is itself a directory, return that. The result is a relative path. For example, if start_point is '/usr' we may return 'local/bin'.
-
- The result does not have a leading slash, but does have a trailing slash if non-empty. */
-static wcstring descend_unique_hierarchy(const wcstring &start_point)
-{
- assert(! start_point.empty() && start_point.at(0) == L'/');
-
- wcstring unique_hierarchy;
- wcstring abs_unique_hierarchy = start_point;
-
- bool stop_descent = false;
- DIR *dir;
- while (!stop_descent && (dir = wopendir(abs_unique_hierarchy)))
- {
- /* We keep track of the single unique_entry entry. If we get more than one, it's not unique and we stop the descent. */
- wcstring unique_entry;
-
- bool child_is_dir;
- wcstring child_entry;
- while (wreaddir_resolving(dir, abs_unique_hierarchy, child_entry, &child_is_dir))
- {
- if (child_entry.empty() || child_entry.at(0) == L'.')
- {
- /* Either hidden, or . and .. entries. Skip them. */
- continue;
- }
- else if (child_is_dir && unique_entry.empty())
- {
- /* First candidate */
- unique_entry = child_entry;
- }
- else
- {
- /* We either have two or more candidates, or the child is not a directory. We're done. */
- stop_descent = true;
- break;
- }
- }
-
- /* We stop if we got two or more entries; also stop if we got zero. */
- if (unique_entry.empty())
- {
- stop_descent = true;
- }
-
- if (! stop_descent)
- {
- /* We have an entry in the unique hierarchy! */
- append_path_component(unique_hierarchy, unique_entry);
- unique_hierarchy.push_back(L'/');
-
- append_path_component(abs_unique_hierarchy, unique_entry);
- abs_unique_hierarchy.push_back(L'/');
- }
- closedir(dir);
- }
- return unique_hierarchy;
-}
-
/* Tests whether the specified string cpath is the prefix of anything we could cd to. directories is a list of possible parent directories (typically either the working directory, or the cdpath). This does I/O!
Hack: if out_suggested_cdpath is not NULL, it returns the autosuggestion for cd. This descends the deepest unique directory hierarchy.
We expect the path to already be unescaped.
*/
-bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_list_t &directories, path_flags_t flags, wcstring *out_suggested_cdpath)
+bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_list_t &directories, path_flags_t flags)
{
ASSERT_IS_BACKGROUND_THREAD();
@@ -231,12 +172,6 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
if (0 == wstat(abs_path, &buf) && S_ISDIR(buf.st_mode))
{
result = true;
- /* Return the path suffix, not the whole absolute path */
- if (out_suggested_cdpath)
- {
- out_suggested_cdpath->assign(clean_potential_path_fragment);
- append_path_component(*out_suggested_cdpath, descend_unique_hierarchy(abs_path));
- }
}
}
else
@@ -256,7 +191,6 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
const bool do_case_insensitive = fs_is_case_insensitive(dir_name, dirfd(dir), case_sensitivity_cache);
wcstring matched_file;
- bool match_is_case_insensitive = false;
// We opened the dir_name; look for a string where the base name prefixes it
// Don't ask for the is_dir value unless we care, because it can cause extra filesystem access
@@ -270,59 +204,18 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
continue;
}
- if (string_prefixes_string(filename_fragment, ent))
+ if (string_prefixes_string(filename_fragment, ent) ||
+ (do_case_insensitive && string_prefixes_string_case_insensitive(filename_fragment, ent)))
{
- // We matched, case-sensitive. This is as good as it gets.
+ // We matched
matched_file = ent;
- match_is_case_insensitive = false;
break;
}
- else if (do_case_insensitive && string_prefixes_string_case_insensitive(filename_fragment, ent))
- {
- // Case insensitive match.
- // If we want to return a suggestion, we keep going in hopes of getting a case-sensitive match, which is better (#2672)
- // If we don't care about the suggestion, we're done
- matched_file = ent;
- match_is_case_insensitive = true;
- if (out_suggested_cdpath == NULL)
- {
- // Early out
- break;
- }
- }
}
closedir(dir);
-
- /* Can't have a case insensitive match unless we're doing that */
- assert(do_case_insensitive || ! match_is_case_insensitive);
-
+
/* We succeeded if we found a match */
result = ! matched_file.empty();
-
- if (out_suggested_cdpath != NULL)
- {
- /* We want to return the path in the same "form" as it was given, preserving all magic, etc. Take the given path, get its basename. Append that to the output if the basename actually prefixes the path (which it won't if the given path contains no slashes), and isn't a slash (so we don't duplicate slashes). Then append the directory entry. */
-
- wcstring suggestion;
- const wcstring path_base = wdirname(potential_path_fragment);
- if (string_prefixes_string(path_base, potential_path_fragment) ||
- (do_case_insensitive && string_prefixes_string_case_insensitive(path_base, potential_path_fragment)))
- {
- suggestion.append(path_base);
- }
- append_path_component(suggestion, ent);
-
- /* A trailing '/' makes autosuggestion a bit nicer and is needed for the singles traversal */
- suggestion.push_back(L'/');
-
- /* Now descend the deepest unique hierarchy we have. */
- wcstring start_point = dir_name;
- append_path_component(start_point, ent);
- append_path_component(suggestion, descend_unique_hierarchy(start_point));
-
- /* Return our computed suggestion */
- out_suggested_cdpath->swap(suggestion);
- }
}
}
}
@@ -332,7 +225,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
/* Given a string, return whether it prefixes a path that we could cd into. Return that path in out_path. Expects path to be unescaped. */
-static bool is_potential_cd_path(const wcstring &path, const wcstring &working_directory, path_flags_t flags, wcstring *out_path)
+static bool is_potential_cd_path(const wcstring &path, const wcstring &working_directory, path_flags_t flags)
{
wcstring_list_t directories;
@@ -359,7 +252,7 @@ static bool is_potential_cd_path(const wcstring &path, const wcstring &working_d
}
/* Call is_potential_path with all of these directories */
- bool result = is_potential_path(path, directories, flags | PATH_REQUIRE_DIR, out_path);
+ bool result = is_potential_path(path, directories, flags | PATH_REQUIRE_DIR);
return result;
}
@@ -1074,7 +967,7 @@ void highlighter_t::color_arguments(const parse_node_t &list_node)
if (expand_one(param, EXPAND_SKIP_CMDSUBST))
{
bool is_help = string_prefixes_string(param, L"--help") || string_prefixes_string(param, L"-h");
- if (! is_help && this->io_ok && ! is_potential_cd_path(param, working_directory, PATH_EXPAND_TILDE, NULL))
+ if (! is_help && this->io_ok && ! is_potential_cd_path(param, working_directory, PATH_EXPAND_TILDE))
{
this->color_node(*child, highlight_spec_error);
}
diff --git a/src/highlight.h b/src/highlight.h
index 22021ba1..161b4b73 100644
--- a/src/highlight.h
+++ b/src/highlight.h
@@ -126,7 +126,7 @@ enum
PATH_EXPAND_TILDE = 1 << 1
};
typedef unsigned int path_flags_t;
-bool is_potential_path(const wcstring &const_path, const wcstring_list_t &directories, path_flags_t flags, wcstring *out_suggested_cdpath = NULL);
+bool is_potential_path(const wcstring &const_path, const wcstring_list_t &directories, path_flags_t flags);
#endif