REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 2.97 KB
Close
/opt/hc_python/lib64/python3.12/site-packages/pre_commit/commands/gc.py
Text
Base64
from __future__ import annotations import os.path from typing import Any import pre_commit.constants as C from pre_commit import output from pre_commit.clientlib import InvalidConfigError from pre_commit.clientlib import InvalidManifestError from pre_commit.clientlib import load_config from pre_commit.clientlib import load_manifest from pre_commit.clientlib import LOCAL from pre_commit.clientlib import META from pre_commit.store import Store from pre_commit.util import rmtree def _mark_used_repos( store: Store, all_repos: dict[tuple[str, str], str], unused_repos: set[tuple[str, str]], repo: dict[str, Any], ) -> None: if repo['repo'] == META: return elif repo['repo'] == LOCAL: for hook in repo['hooks']: deps = hook.get('additional_dependencies') unused_repos.discard(( store.db_repo_name(repo['repo'], deps), C.LOCAL_REPO_VERSION, )) else: key = (repo['repo'], repo['rev']) path = all_repos.get(key) # can't inspect manifest if it isn't cloned if path is None: return try: manifest = load_manifest(os.path.join(path, C.MANIFEST_FILE)) except InvalidManifestError: return else: unused_repos.discard(key) by_id = {hook['id']: hook for hook in manifest} for hook in repo['hooks']: if hook['id'] not in by_id: continue deps = hook.get( 'additional_dependencies', by_id[hook['id']]['additional_dependencies'], ) unused_repos.discard(( store.db_repo_name(repo['repo'], deps), repo['rev'], )) def _gc(store: Store) -> int: with store.exclusive_lock(), store.connect() as db: store._create_configs_table(db) repos = db.execute('SELECT repo, ref, path FROM repos').fetchall() all_repos = {(repo, ref): path for repo, ref, path in repos} unused_repos = set(all_repos) configs_rows = db.execute('SELECT path FROM configs').fetchall() configs = [path for path, in configs_rows] dead_configs = [] for config_path in configs: try: config = load_config(config_path) except InvalidConfigError: dead_configs.append(config_path) continue else: for repo in config['repos']: _mark_used_repos(store, all_repos, unused_repos, repo) paths = [(path,) for path in dead_configs] db.executemany('DELETE FROM configs WHERE path = ?', paths) db.executemany( 'DELETE FROM repos WHERE repo = ? and ref = ?', sorted(unused_repos), ) for k in unused_repos: rmtree(all_repos[k]) return len(unused_repos) def gc(store: Store) -> int: output.write_line(f'{_gc(store)} repo(s) removed.') return 0
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 1 × Files: 14
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
__pycache__
DIR
-
drwxr-xr-x
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
autoupdate.py
6.99 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
clean.py
429 B
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
gc.py
2.97 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
hazmat.py
2.51 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
hook_impl.py
9.20 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
init_templatedir.py
1.11 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
install_uninstall.py
5.22 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
migrate_config.py
4.07 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
run.py
13.83 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
sample_config.py
453 B
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
try_repo.py
2.52 KB
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
validate_config.py
371 B
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
validate_manifest.py
377 B
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__init__.py
0 B
lrw-r--r--
2025-12-03 08:02:54
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).