From 604a455b39845f281afaa74836d2ff39fcba941d Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 20:59:21 +0100 Subject: [PATCH] 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) +