Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Return a repository's age rather than a found flag
Diffstat (limited to 'source')
-rw-r--r--source/ui-repolist.c55
1 file changed, 14 insertions, 41 deletions
diff --git a/source/ui-repolist.c b/source/ui-repolist.c
index 6df70e4..d2552a6 100644
--- a/source/ui-repolist.c
+++ b/source/ui-repolist.c
@@ -77,7 +77,7 @@ static const char *tip_branch(const struct cgit_repo *repo, struct strbuf *head)
return branch ? branch : "master";
}
-static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
+static time_t get_repo_modtime(const struct cgit_repo *repo)
{
struct strbuf path = STRBUF_INIT;
struct strbuf head = STRBUF_INIT;
@@ -87,39 +87,30 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
// is kept in the repository itself so one page stats it only once.
struct cgit_repo *writable = (struct cgit_repo *)repo;
- if (repo->mtime != -1) {
- *mtime = repo->mtime;
- return 1;
- }
+ if (repo->mtime != -1)
+ return repo->mtime;
// A repository configured without a path has nothing on disk to date.
if (!repo->path) {
- *mtime = 0;
writable->mtime = 0;
return 0;
}
strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile);
- if (stat(path.buf, &st) == 0) {
- *mtime = read_agefile(path.buf);
- if (*mtime) {
- writable->mtime = *mtime;
- goto end;
- }
- }
+ writable->mtime = read_agefile(path.buf);
+ if (repo->mtime)
+ goto end;
branch = tip_branch(repo, &head);
strbuf_reset(&path);
strbuf_addf(&path, "%s/refs/heads/%s", repo->path, branch);
if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
+ writable->mtime = st.st_mtime;
goto end;
}
strbuf_reset(&path);
strbuf_addf(&path, "%s/packed-refs", repo->path);
if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
+ writable->mtime = st.st_mtime;
goto end;
}
@@ -127,26 +118,12 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
// every ref update.
strbuf_reset(&path);
strbuf_addf(&path, "%s/reftable/tables.list", repo->path);
- if (stat(path.buf, &st) == 0) {
- *mtime = st.st_mtime;
- writable->mtime = *mtime;
- goto end;
- }
-
- *mtime = 0;
- writable->mtime = *mtime;
+ if (stat(path.buf, &st) == 0)
+ writable->mtime = st.st_mtime;
end:
strbuf_release(&path);
strbuf_release(&head);
- return (writable->mtime != 0);
-}
-
-static void print_modtime(struct cgit_repo *repo)
-{
- time_t mtime;
-
- if (get_repo_modtime(repo, &mtime))
- cgit_print_age(mtime, 0, -1);
+ return repo->mtime;
}
static int matches_search(struct cgit_repo *repo)
@@ -269,7 +246,7 @@ static void print_repo_row(const char *currenturl, int sublevel)
html("</td>");
}
html("<td class='col-idle'>");
- print_modtime(ctx.repo);
+ cgit_print_age(get_repo_modtime(ctx.repo), 0, -1);
html("</td>");
if (ctx.cfg.enable_index_links) {
html("<td class='col-links'>");
@@ -340,11 +317,8 @@ static int cmp_idle(const void *a, const void *b)
{
const struct cgit_repo *r1 = a;
const struct cgit_repo *r2 = b;
- time_t t1, t2;
+ time_t t1 = get_repo_modtime(r1), t2 = get_repo_modtime(r2);
- t1 = t2 = 0;
- get_repo_modtime(r1, &t1);
- get_repo_modtime(r2, &t2);
// Only the sign is returned, because a 64-bit difference truncated
// into an int could come back with the wrong sign and leave the
// ordering inconsistent.
@@ -377,11 +351,10 @@ static int cmp_section(const void *a, const void *b)
*/
static void resolve_modtimes(void)
{
- time_t t;
int i;
for (i = 0; i < cgit_repolist.count; i++)
- get_repo_modtime(&cgit_repolist.repos[i], &t);
+ get_repo_modtime(&cgit_repolist.repos[i]);
}
static const struct sort_column sort_columns[] = {