Skip to content

Commit f092e32

Browse files
committed
Improve debugging
1 parent 67ddd73 commit f092e32

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pathspec/gitignore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ def _match_file(
150150

151151
if pattern.include and dir_mark:
152152
out_include = pattern.include
153+
out_index = index
153154
out_priority = priority
154155
elif priority >= out_priority:
155156
out_include = pattern.include
157+
out_index = index
156158
out_priority = priority
157159

158160
return out_include, out_index

tests/util.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module provides utility functions shared by tests.
33
"""
44

5+
import itertools
56
import os
67
import os.path
78
import pathlib
@@ -32,6 +33,10 @@ def debug_results(spec: PathSpec, results: Iterable[CheckResult[str]]) -> str:
3233
"""
3334
patterns = cast(list[RegexPattern], spec.patterns)
3435

36+
pattern_table = []
37+
for index, pattern in enumerate(patterns, 1):
38+
pattern_table.append((f"{index}:{pattern.pattern}", repr(pattern.regex.pattern)))
39+
3540
result_table = []
3641
for result in results:
3742
if result.index is not None:
@@ -42,18 +47,19 @@ def debug_results(spec: PathSpec, results: Iterable[CheckResult[str]]) -> str:
4247

4348
result_table.sort(key=lambda r: r[1])
4449

45-
first_max_len = max((len(__row[0]) for __row in result_table), default=0)
50+
first_max_len = max((
51+
len(__row[0]) for __row in itertools.chain(pattern_table, result_table)
52+
), default=0)
4653
first_width = min(first_max_len, 20)
4754

55+
pattern_lines = []
56+
for row in pattern_table:
57+
pattern_lines.append(f" {row[0]:<{first_width}} {row[1]}")
58+
4859
result_lines = []
4960
for row in result_table:
5061
result_lines.append(f" {row[0]:<{first_width}} {row[1]}")
5162

52-
pattern_lines = []
53-
for index, pattern in enumerate(patterns, 1):
54-
first_col = f"{index}:{pattern.pattern}"
55-
pattern_lines.append(f" {first_col:<{first_width}} {pattern.regex.pattern!r}")
56-
5763
return "\n".join([
5864
"\n",
5965
" DEBUG ".center(32, "-"),

0 commit comments

Comments
 (0)