diff options
author | Teddy Wing | 2021-06-23 23:52:19 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-23 23:52:19 +0200 |
commit | 1aaef56e5b3c3f4ba6e479c809bd77bc585c716b (patch) | |
tree | 01cb5f145c73015bad6f5e7dc3920e5acc5f78f7 | |
parent | 5de391101d72f0d2239a69073b08861641d9c878 (diff) | |
download | reflectub-1aaef56e5b3c3f4ba6e479c809bd77bc585c716b.tar.bz2 |
update_mtime(): Set the mtime to the repo's `pushed_at` time
Use `pushed_at` instead of `updated_at`. This mtime is used to sort
repositories on CGit's repository index page. Prevent things like GitHub
stars from changing the sort order. The sort should instead be
influenced by repository changes.
-rw-r--r-- | src/github.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 16 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/github.rs b/src/github.rs index 5289a0d..a3bb74e 100644 --- a/src/github.rs +++ b/src/github.rs @@ -47,6 +47,7 @@ pub struct Repo { pub default_branch: String, pub size: u64, pub updated_at: String, + pub pushed_at: String, } impl Repo { diff --git a/src/main.rs b/src/main.rs index a888883..a776070 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,7 +122,7 @@ fn run() -> Result<(), MultiError> { default_branch: "master".to_owned(), size: 48, updated_at: "2013-01-12T09:09:38Z".to_owned(), - // pushed_at: "2012-09-23T17:45:14Z".to_owned(), + pushed_at: "2012-09-23T17:45:14Z".to_owned(), }, github::Repo { id: 158463778, @@ -135,7 +135,7 @@ fn run() -> Result<(), MultiError> { default_branch: "master".to_owned(), size: 17, updated_at: "2018-11-20T23:44:31Z".to_owned(), - // pushed_at: "2018-11-20T23:44:29Z".to_owned(), + pushed_at: "2018-11-20T23:44:29Z".to_owned(), }, ]; @@ -309,16 +309,20 @@ fn update<P: AsRef<Path>>( Ok(()) } -/// Set the mtime of the repository to GitHub's `updated_at` time. +/// Set the mtime of the repository to GitHub's `pushed_at` time. /// /// Used for CGit "age" sorting. fn update_mtime<P: AsRef<Path>>( repo_path: P, repo: &github::Repo, ) -> anyhow::Result<()> { - // TODO: Use `pushed_at` instead of `updated_at` to set the mtime. let update_time = filetime::FileTime::from_system_time( - DateTime::parse_from_rfc3339(&repo.updated_at)?.into() + DateTime::parse_from_rfc3339(&repo.pushed_at) + .with_context(|| format!( + "unable to parse update time from '{}'", + &repo.pushed_at, + ))? + .into() ); let default_branch_ref = repo_path @@ -349,7 +353,7 @@ fn update_mtime<P: AsRef<Path>>( Err(e) if e.kind() == io::ErrorKind::NotFound => { // In the absence of a 'packed-refs' file, create a CGit // agefile and add the update time to it. - Ok(set_agefile_time(&repo_path, &repo.updated_at)?) + Ok(set_agefile_time(&repo_path, &repo.pushed_at)?) }, Err(e) => Err(e), } |