Loading hooks/copyright.py +15 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ import os import re import sys import time from functools import lru_cache from pathlib import Path from subprocess import DEVNULL from subprocess import PIPE from subprocess import run from typing import Dict Loading Loading @@ -93,6 +95,16 @@ def split_paths(paths: bytes) -> Iterator[Path]: return (Path(p.decode()) for p in paths.split(b'\x00') if p != b'') @lru_cache(1) def has_commits() -> bool: """ Return whether the repository has any commits yet """ cmd = ['git', 'rev-parse', '--verify', '-q', 'HEAD'] proc = run(cmd, stdout=DEVNULL) return proc.returncode == 0 def cli_parser() -> argparse.ArgumentParser: """ Return an argparse parser Loading Loading @@ -120,6 +132,7 @@ def main() -> None: year = time.strftime('%Y') years = {path: year for path in paths if path.is_file()} if has_commits(): years.update(get_file_years(paths)) years.update((path, year) for path in get_changed(paths)) Loading Loading
hooks/copyright.py +15 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ import os import re import sys import time from functools import lru_cache from pathlib import Path from subprocess import DEVNULL from subprocess import PIPE from subprocess import run from typing import Dict Loading Loading @@ -93,6 +95,16 @@ def split_paths(paths: bytes) -> Iterator[Path]: return (Path(p.decode()) for p in paths.split(b'\x00') if p != b'') @lru_cache(1) def has_commits() -> bool: """ Return whether the repository has any commits yet """ cmd = ['git', 'rev-parse', '--verify', '-q', 'HEAD'] proc = run(cmd, stdout=DEVNULL) return proc.returncode == 0 def cli_parser() -> argparse.ArgumentParser: """ Return an argparse parser Loading Loading @@ -120,6 +132,7 @@ def main() -> None: year = time.strftime('%Y') years = {path: year for path in paths if path.is_file()} if has_commits(): years.update(get_file_years(paths)) years.update((path, year) for path in get_changed(paths)) Loading