summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui-repolist.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index 59a4fbb..77e6387 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -6,12 +6,15 @@
* (see COPYING for full license text)
*/
+#include <linux/limits.h>
+#include <stdio.h>
+#include <string.h>
#define USE_THE_REPOSITORY_VARIABLE
-#include "ui-repolist.h"
#include "cgit.h"
#include "html.h"
#include "lang.h"
+#include "ui-repolist.h"
#include "ui-shared.h"
static time_t read_agefile(const char *path) {
@@ -34,6 +37,36 @@ static time_t read_agefile(const char *path) {
return result;
}
+time_t get_default_branch(const char *gitdir) {
+ char head_path[PATH_MAX];
+ char ref_path[PATH_MAX];
+ FILE *f;
+ char buf[256];
+ struct stat s;
+
+ snprintf(head_path, sizeof(head_path), "%sHEAD", gitdir);
+
+ f = fopen(head_path, "r");
+ if (!f)
+ return 0;
+
+ if (!fgets(buf, sizeof(buf), f))
+ return 0;
+
+ fclose(f);
+
+ if (strncmp("ref: ", buf, 5) != 0)
+ return 0;
+ char *ref = buf + 5;
+ ref[strcspn(ref, "\n")] = '\0';
+
+ snprintf(ref_path, sizeof(ref_path), "%s%s", gitdir, ref);
+ if (stat(ref_path, &s) == 0) {
+ return s.st_mtime;
+ }
+ return 0;
+}
+
static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) {
struct strbuf path = STRBUF_INIT;
struct stat s;
@@ -68,9 +101,8 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) {
r->mtime = *mtime;
goto end;
}
+ *mtime = get_default_branch(r->path);
- *mtime = 0;
- r->mtime = *mtime;
end:
strbuf_release(&path);
return (r->mtime != 0);