diff options
author | Teddy Wing | 2021-05-30 23:34:06 +0200 |
---|---|---|
committer | Teddy Wing | 2021-05-30 23:34:06 +0200 |
commit | c88dc471fae44101a7029341a1c7311e105f8a72 (patch) | |
tree | ce37d91179a3770efe9df3d9c2ccb0afc6110b4b /src | |
parent | 94dc9d677ba0f25261f55b17f38b16a4b9d712af (diff) | |
download | reflectub-c88dc471fae44101a7029341a1c7311e105f8a72.tar.bz2 |
Set repository mtime to GitHub `updated_at` time
CGit reads the repository modification time from the following
locations, in order from top to bottom:
1. agefile
2. repo.git/refs/heads/{default_branch | "master"}
3. repo.git/packed-refs
(https://git.zx2c4.com/cgit/tree/ui-repolist.c?id=bd6f5683f6cde4212364354b3139c1d521f40f39#n35)
Update the `/refs/heads/{default_branch}` file mtime when cloning and
updating the repo to match the GitHub `updated_at` time.
This ensures that when mirroring old repositories, they don't appear at
the top of the CGit repository index list when sorting by age.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 9689d3c..bae2da8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ use anyhow::{self, Context}; +use chrono::DateTime; +use filetime; use sqlx; use tokio; @@ -10,9 +12,9 @@ use std::path::{Path, PathBuf}; #[tokio::main] async fn main() { - let repos = github::fetch_repos("teddywing").await.unwrap(); - - dbg!(&repos); + // let repos = github::fetch_repos("teddywing").await.unwrap(); + // + // dbg!(&repos); // git::mirror( // "https://github.com/teddywing/google-calendar-rsvp.git", @@ -22,6 +24,8 @@ async fn main() { // git::update( // Path::new("/tmp/grsvp"), // ).unwrap(); + + run().await.unwrap(); } async fn run() -> anyhow::Result<()> { @@ -129,6 +133,8 @@ fn mirror<P: AsRef<Path>>( ))?; } + update_mtime(&clone_path, &repo)?; + Ok(()) } @@ -145,5 +151,29 @@ fn update<P: AsRef<Path>>( git::update_description(&repo_path, remote_description)?; } + update_mtime(&repo_path, &updated_repo)?; + + Ok(()) +} + +fn update_mtime<P: AsRef<Path>>( + repo_path: P, + repo: &github::Repo, +) -> anyhow::Result<()> { + let default_branch_ref = repo_path + .as_ref() + .join("refs/heads") + .join(&repo.default_branch); + + let update_time = filetime::FileTime::from_system_time( + DateTime::parse_from_rfc3339(&repo.updated_at)?.into() + ); + + filetime::set_file_times(&default_branch_ref, update_time, update_time) + .with_context(|| format!( + "unable to set mtime on '{}'", + &default_branch_ref.display(), + ))?; + Ok(()) } |