From 544aefa17839c3eeb45a4a1d1e18f7fbe3665285 Mon Sep 17 00:00:00 2001 From: jez Date: Fri, 27 May 2011 08:16:09 +0000 Subject: [PATCH] Errors should not equal length of string. Otherwise a match is always possible. --- autojump | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/autojump b/autojump index 928b5b5..74b0cd9 100755 --- a/autojump +++ b/autojump @@ -126,14 +126,22 @@ def find_matches(dirs, patterns, result_list, ignore_case, approx, max_matches): for path, count in dirs: if len(one_error_paths) >= max_matches: break - errors = sum(approximatch(pattern, match_string) - for pattern, match_string in get_pattern_and_match(patterns, path)) + total_errors = 0 + bad_match = False + for pattern, match_string in get_pattern_and_match(patterns, path): + errors = approximatch(pattern, match_string) + if errors >= len(pattern) or errors >= len(match_string): + bad_match = True + break + total_errors += errors + if bad_match: + continue #Verify that the path exists #(useful in the case of external drives, for example) - if errors <= 2 and os.path.exists(path): - if errors == 1: + if total_errors <= 2 and os.path.exists(path): + if total_errors == 1: uniqadd(one_error_paths, path) - elif errors == 2: + elif total_errors == 2: uniqadd(two_error_paths, path) result_list.extend(one_error_paths) result_list.extend(two_error_paths[:max_matches-len(one_error_paths)])