Skip to content

Commit e1f744e

Browse files
committed
Avoid additional work handling the common prefix of paths
1 parent e8d859d commit e1f744e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

easybuild/tools/filetools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,14 @@ def search_file(paths, query, short=False, ignore_dirs=None, silent=False, filen
10271027
path_hits = sorted(path_hits, key=natural_keys)
10281028

10291029
if path_hits:
1030-
common_prefix = det_common_path_prefix(path_hits)
1031-
if not terse and short and common_prefix is not None and len(common_prefix) > len(var) * 2:
1032-
var_defs.append((var, common_prefix))
1033-
hits.extend([os.path.join('$%s' % var, fn[len(common_prefix) + 1:]) for fn in path_hits])
1034-
else:
1035-
hits.extend(path_hits)
1030+
if not terse and short:
1031+
common_prefix = det_common_path_prefix(path_hits)
1032+
if common_prefix is not None and len(common_prefix) > len(var) * 2:
1033+
var_defs.append((var, common_prefix))
1034+
var_spec = '$' + var
1035+
# Replace the common prefix by var_spec
1036+
path_hits = (var_spec + fn[len(common_prefix):] for fn in path_hits)
1037+
hits.extend(path_hits)
10361038

10371039
return var_defs, hits
10381040

0 commit comments

Comments
 (0)