summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--ui-repolist.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index 312a7ee..436a774 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -28,21 +28,30 @@ time_t read_agefile(char *path)
28 return 0; 28 return 0;
29} 29}
30 30
31static void print_modtime(struct cgit_repo *repo) 31static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
32{ 32{
33 char *path; 33 char *path;
34 struct stat s; 34 struct stat s;
35 35
36 path = fmt("%s/%s", repo->path, ctx.cfg.agefile); 36 path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
37 if (stat(path, &s) == 0) { 37 if (stat(path, &s) == 0) {
38 cgit_print_age(read_agefile(path), -1, NULL); 38 *mtime = read_agefile(path);
39 return; 39 return 1;
40 } 40 }
41 41
42 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); 42 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
43 if (stat(path, &s) != 0) 43 if (stat(path, &s) == 0) {
44 return; 44 *mtime = s.st_mtime;
45 cgit_print_age(s.st_mtime, -1, NULL); 45 return 1;
46 }
47 return 0;
48}
49
50static void print_modtime(struct cgit_repo *repo)
51{
52 time_t t;
53 if (get_repo_modtime(repo, &t))
54 cgit_print_age(t, -1, NULL);
46} 55}
47 56
48int is_match(struct cgit_repo *repo) 57int is_match(struct cgit_repo *repo)
@@ -96,28 +105,11 @@ static int cgit_reposort_modtime(const void *a, const void *b)
96{ 105{
97 const struct cgit_repo *r1 = a; 106 const struct cgit_repo *r1 = a;
98 const struct cgit_repo *r2 = b; 107 const struct cgit_repo *r2 = b;
99 char *path;
100 struct stat s;
101 time_t t1, t2; 108 time_t t1, t2;
102 path = fmt("%s/%s", r1->path, ctx.cfg.agefile);
103 if (stat(path, &s) == 0) {
104 t1 = read_agefile(path);
105 } else {
106 path = fmt("%s/refs/heads/%s", r1->path, r1->defbranch);
107 if (stat(path, &s) != 0)
108 return 0;
109 t1 =s.st_mtime;
110 }
111 109
112 path = fmt("%s/%s", r2->path, ctx.cfg.agefile); 110 t1 = t2 = 0;
113 if (stat(path, &s) == 0) { 111 get_repo_modtime(r1, &t1);
114 t2 = read_agefile(path); 112 get_repo_modtime(r2, &t2);
115 } else {
116 path = fmt("%s/refs/heads/%s", r2->path, r2->defbranch);
117 if (stat(path, &s) != 0)
118 return 0;
119 t2 =s.st_mtime;
120 }
121 return t2-t1; 113 return t2-t1;
122} 114}
123 115