Skip to content

Commit 1263a94

Browse files
committed
refactor: extract _show_at_revision to reduce cognitive complexity
1 parent e1adb06 commit 1263a94

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/treemapper/diffctx/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ def _looks_binary(content: str) -> bool:
8080
return bool(_BINARY_CTRL_RE.search(content[:8192]))
8181

8282

83+
def _show_at_revision(root_dir: Path, rev: str, rel: Path, batch_reader: CatFileBatch | None) -> str:
84+
if batch_reader is not None:
85+
return batch_reader.get(rev, rel)
86+
return show_file_at_revision(root_dir, rev, rel)
87+
88+
8389
def _read_file_content(
8490
file_path: Path,
8591
root_dir: Path,
@@ -98,10 +104,7 @@ def _read_file_content(
98104

99105
for rev in preferred_revs:
100106
try:
101-
if batch_reader is not None:
102-
content = batch_reader.get(rev, rel)
103-
else:
104-
content = show_file_at_revision(root_dir, rev, rel)
107+
content = _show_at_revision(root_dir, rev, rel, batch_reader)
105108
if _looks_binary(content):
106109
return None
107110
return content

0 commit comments

Comments
 (0)