36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import os
|
|
from collections import Counter
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
from subprocess import check_output
|
|
|
|
|
|
@lru_cache()
|
|
def _counter(commit: str, unique: bool, to_counter: bool) -> Counter | set:
|
|
check_output(["git", "checkout", commit], text=True)
|
|
if unique:
|
|
all_lines = set()
|
|
else:
|
|
all_lines = Counter()
|
|
for path in Path.cwd().rglob(os.getenv("SRCPATTERN", "./src/**/*.rs")):
|
|
lines = path.read_bytes().splitlines()
|
|
lines = (line.strip() for line in lines)
|
|
lines = (line for line in lines if line)
|
|
all_lines.update(lines)
|
|
if isinstance(all_lines, set) and to_counter:
|
|
return Counter(all_lines)
|
|
else:
|
|
return all_lines
|
|
|
|
|
|
def set_(commit: str) -> set:
|
|
all_lines = _counter(commit, True, False)
|
|
assert isinstance(all_lines, set)
|
|
return all_lines
|
|
|
|
|
|
def counter(commit: str, unique: bool) -> Counter:
|
|
all_lines = _counter(commit, unique, True)
|
|
assert isinstance(all_lines, Counter)
|
|
return all_lines
|