idle 是 cgit 中用来展示 repo 上一次更新的距今时间的。有些时候会出现 idle 不正确或者不展示的情况。
cgit 是如何计算 idle 的
cgit 中 repo 的 idle 是通过以下这个逻辑计算的
https://github.com/zx2c4/cgit/blob/09d24d7cd0b7e85633f2f43808b12871bb209d69/ui-repolist.c#L35
首先尝试获取 repo 对应的 modify time(修改时间):
- 如果在 repo 设置中直接定义了 mtime,那就会取这个值
- 如果 repo 定义了 agefile,就会读取 agefile 的 mtime
- 尝试读取 refs/heads/defbranch (defbranch 没有设置的话,默认是 master)
- 尝试读取 packed-refs 的 mtime
- 以上都不存在会返回 0(idle 为空)
然后根据 repo 的 modify time 计算相对当前时间的 idle。
解决 cgit 无法正确计算 idle 的问题
如果你的 repo 因为各种原因导致 cgit 无法正确计算 idle 的话,可以利用 cgit 会尝试读取 refs/heads/defbranch(master) 和 packed-refs 的逻辑,按照如下方法解决
如果你的 repo 的默认分支是 master
- 如果 refs/heads/master 不存在,就先创建这个文件,内容是 master 分支最后一次提交的 commit id
- 设置这个文件的 mtime 为最后一次提交的 commit time(可以使用
git log -1 --format=%ct master
获取)。
后续等你更新 master ref head 之后,idle 就能正确按照默认逻辑计算了。
如果你的 repo 的默认分支不是 master
由于 cgit 只会尝试读取 defbranch 或者 master 的 ref head mtime,假如你的默认分支不是 master,那么你就只能设置 defbranch 了,这样操作比较麻烦,也可以通过另一种方式临时解决。
那就是给你的 repo 的 packed-refs 设置最后一次 commit 的 commit time,这样同样可以让 cgit 正确计算出 idle。后续等你更新 ref head 之后,idle 就能正确按照默认逻辑计算了。
idle 计算错误一般出现在你是刚刚迁移到 cgit 的时候,虽然影响并不大,但是为了能正确展示每个 repo 的更新时间,还是有必要做一下修复的。