From 604a455b39845f281afaa74836d2ff39fcba941d Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 20:59:21 +0100 Subject: [PATCH 1/2] feat: add command to update times manually --- help | 3 ++- update-time | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 update-time diff --git a/help b/help index 5b987ba..8fb0ba6 100755 --- a/help +++ b/help @@ -5,7 +5,7 @@ echo " $ ls list all repositories, marks hidden echo " $ new create new repository" echo " $ mirror [name] mirror remote repository" echo " $ upstream set repository to push to a given remote" -echo " $ sync push and pull all mirrored repositories" +echo " $ fetch-mirrors push and pull all mirrored repositories" echo " $ tree show file tree of repo at HEAD" echo " $ log show commit log of repo" echo " $ head change default branch of repository" @@ -14,5 +14,6 @@ echo " $ owner [owner] set or unset owner for repository" echo " $ group [group] set or unset group for repository" echo " $ page [page] set or unset homepage for repository" echo " $ pic [href] set or unset picture url for repository" +echo " $ update-time force update idle times for all repos" echo " $ show make repository public" echo " $ hide hide public repository" diff --git a/update-time b/update-time new file mode 100755 index 0000000..9e1d7b5 --- /dev/null +++ b/update-time @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import os +import subprocess +from pathlib import Path + +GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/") + +def update_time(repo: Path): + cmd = ["git", "for-each-ref", "--sort=-authordate", "--count=1", "--format='%(authordate:iso8601)'" ] + with open(repo / "info" / "web" / "last-modified", "w") as f: + subprocess.run(cmd, stdout=f) + +def run_on_all_repos(root: Path): + for element in os.listdir(root): + full_path = root / element + if element.startswith("."): + pass # ignore hidden files + elif element.endswith(".git"): + print(f"updating idle time for {element.replace('.git','')}") + update_time(full_path) + elif os.path.isdir(root / element): + run_on_all_repos(root / element) + +if __name__ == "__main__": + run_on_all_repos(GIT_ROOT) + From d1993254d3e474cde9323ef4f74d736661c99dc9 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 21:03:25 +0100 Subject: [PATCH 2/2] feat: update-time shows the times, also fix --- update-time | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/update-time b/update-time index 9e1d7b5..0c1f6c7 100755 --- a/update-time +++ b/update-time @@ -6,10 +6,13 @@ from pathlib import Path GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/") -def update_time(repo: Path): +def update_time(repo: Path) -> str: cmd = ["git", "for-each-ref", "--sort=-authordate", "--count=1", "--format='%(authordate:iso8601)'" ] + proc = subprocess.run(cmd, cwd=repo, stdout=subprocess.PIPE) + time = proc.stdout.decode().strip() with open(repo / "info" / "web" / "last-modified", "w") as f: - subprocess.run(cmd, stdout=f) + f.write(time) + return time def run_on_all_repos(root: Path): for element in os.listdir(root): @@ -17,8 +20,8 @@ def run_on_all_repos(root: Path): if element.startswith("."): pass # ignore hidden files elif element.endswith(".git"): - print(f"updating idle time for {element.replace('.git','')}") - update_time(full_path) + time = update_time(full_path) + print(f"last update for '{element.replace('.git','')}': {time}") elif os.path.isdir(root / element): run_on_all_repos(root / element)