From 5bb0fa6a35b1d54bacad8b2189a6af36a1a7bbaf Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Tue, 9 Dec 2025 20:02:30 +0200 Subject: [PATCH] change highlight style and allow to hide repos from list --- git/config.py | 33 +++++++++++++++++++++++++++------ git/repository.py | 5 ++++- highlight.py | 2 +- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/git/config.py b/git/config.py index 8343102..41cb97c 100644 --- a/git/config.py +++ b/git/config.py @@ -2,20 +2,41 @@ import pygit2 as git def get_repo_owner(repo_path: str) -> str | None: - """Return lipasto.owner from repo config, None when missing or on error.""" - try: - repo = git.Repository(str(repo_path)) - except git.GitError: + config = _load_repo_config(repo_path) + if not config: return None try: - config = repo.config + return config["lipasto.owner"] + except KeyError: + return None except git.GitError: return None + +def is_repo_hidden(repo_path: str) -> bool: + config = _load_repo_config(repo_path) + if not config: + return False + try: - return config["lipasto.owner"] + raw_value = config["lipasto.hidden"] except KeyError: + return False + except git.GitError: + return False + + return str(raw_value).strip().lower() == "true" + + +def _load_repo_config(repo_path: str): + try: + repo = git.Repository(str(repo_path)) + except git.GitError: return None + + try: + return repo.config except git.GitError: return None + diff --git a/git/repository.py b/git/repository.py index 7c5c113..2032011 100644 --- a/git/repository.py +++ b/git/repository.py @@ -1,7 +1,7 @@ from pathlib import Path import pygit2 as git -from .config import get_repo_owner +from .config import get_repo_owner, is_repo_hidden # scans given path for bare git repos and list their names and paths @@ -23,6 +23,9 @@ def get_bare_repos(path): if not repo or not repo.is_bare: continue + if is_repo_hidden(item): + continue + description = _read_description(item / "description") owner = get_repo_owner(item) repos.append( diff --git a/highlight.py b/highlight.py index 8bab634..c6eaa8a 100644 --- a/highlight.py +++ b/highlight.py @@ -6,7 +6,7 @@ from pygments.lexers import guess_lexer from pygments.lexers import guess_lexer_for_filename from pygments.util import ClassNotFound -STYLE = "sas" +STYLE = "default" # reference: https://git.kernel.org/pub/scm/infra/cgit.git/tree/filters/syntax-highlighting.py?id=dbaee2672be14374acb17266477c19294c6155f3 -- 2.47.3