-rw-r--r-- | ui-repolist.c | 6 |
1 files changed, 0 insertions, 6 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index 0a0b6ca..2c98668 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,142 +1,136 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | /* This is needed for strcasestr to be defined by <string.h> */ | ||
10 | #define _GNU_SOURCE 1 | ||
11 | #include <string.h> | ||
12 | |||
13 | #include <time.h> | ||
14 | |||
15 | #include "cgit.h" | 9 | #include "cgit.h" |
16 | #include "html.h" | 10 | #include "html.h" |
17 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
18 | 12 | ||
19 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
20 | { | 14 | { |
21 | time_t result; | 15 | time_t result; |
22 | size_t size; | 16 | size_t size; |
23 | char *buf; | 17 | char *buf; |
24 | static char buf2[64]; | 18 | static char buf2[64]; |
25 | 19 | ||
26 | if (readfile(path, &buf, &size)) | 20 | if (readfile(path, &buf, &size)) |
27 | return -1; | 21 | return -1; |
28 | 22 | ||
29 | if (parse_date(buf, buf2, sizeof(buf2))) | 23 | if (parse_date(buf, buf2, sizeof(buf2))) |
30 | result = strtoul(buf2, NULL, 10); | 24 | result = strtoul(buf2, NULL, 10); |
31 | else | 25 | else |
32 | result = 0; | 26 | result = 0; |
33 | free(buf); | 27 | free(buf); |
34 | return result; | 28 | return result; |
35 | } | 29 | } |
36 | 30 | ||
37 | static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) | 31 | static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) |
38 | { | 32 | { |
39 | char *path; | 33 | char *path; |
40 | struct stat s; | 34 | struct stat s; |
41 | struct cgit_repo *r = (struct cgit_repo *)repo; | 35 | struct cgit_repo *r = (struct cgit_repo *)repo; |
42 | 36 | ||
43 | if (repo->mtime != -1) { | 37 | if (repo->mtime != -1) { |
44 | *mtime = repo->mtime; | 38 | *mtime = repo->mtime; |
45 | return 1; | 39 | return 1; |
46 | } | 40 | } |
47 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 41 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
48 | if (stat(path, &s) == 0) { | 42 | if (stat(path, &s) == 0) { |
49 | *mtime = read_agefile(path); | 43 | *mtime = read_agefile(path); |
50 | r->mtime = *mtime; | 44 | r->mtime = *mtime; |
51 | return 1; | 45 | return 1; |
52 | } | 46 | } |
53 | 47 | ||
54 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 48 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
55 | if (stat(path, &s) == 0) | 49 | if (stat(path, &s) == 0) |
56 | *mtime = s.st_mtime; | 50 | *mtime = s.st_mtime; |
57 | else | 51 | else |
58 | *mtime = 0; | 52 | *mtime = 0; |
59 | 53 | ||
60 | r->mtime = *mtime; | 54 | r->mtime = *mtime; |
61 | return (r->mtime != 0); | 55 | return (r->mtime != 0); |
62 | } | 56 | } |
63 | 57 | ||
64 | static void print_modtime(struct cgit_repo *repo) | 58 | static void print_modtime(struct cgit_repo *repo) |
65 | { | 59 | { |
66 | time_t t; | 60 | time_t t; |
67 | if (get_repo_modtime(repo, &t)) | 61 | if (get_repo_modtime(repo, &t)) |
68 | cgit_print_age(t, -1, NULL); | 62 | cgit_print_age(t, -1, NULL); |
69 | } | 63 | } |
70 | 64 | ||
71 | int is_match(struct cgit_repo *repo) | 65 | int is_match(struct cgit_repo *repo) |
72 | { | 66 | { |
73 | if (!ctx.qry.search) | 67 | if (!ctx.qry.search) |
74 | return 1; | 68 | return 1; |
75 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) | 69 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) |
76 | return 1; | 70 | return 1; |
77 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) | 71 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) |
78 | return 1; | 72 | return 1; |
79 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) | 73 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) |
80 | return 1; | 74 | return 1; |
81 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) | 75 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) |
82 | return 1; | 76 | return 1; |
83 | return 0; | 77 | return 0; |
84 | } | 78 | } |
85 | 79 | ||
86 | int is_in_url(struct cgit_repo *repo) | 80 | int is_in_url(struct cgit_repo *repo) |
87 | { | 81 | { |
88 | if (!ctx.qry.url) | 82 | if (!ctx.qry.url) |
89 | return 1; | 83 | return 1; |
90 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) | 84 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) |
91 | return 1; | 85 | return 1; |
92 | return 0; | 86 | return 0; |
93 | } | 87 | } |
94 | 88 | ||
95 | void print_sort_header(const char *title, const char *sort) | 89 | void print_sort_header(const char *title, const char *sort) |
96 | { | 90 | { |
97 | htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort); | 91 | htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort); |
98 | if (ctx.qry.search) { | 92 | if (ctx.qry.search) { |
99 | html("&q="); | 93 | html("&q="); |
100 | html_url_arg(ctx.qry.search); | 94 | html_url_arg(ctx.qry.search); |
101 | } | 95 | } |
102 | htmlf("'>%s</a></th>", title); | 96 | htmlf("'>%s</a></th>", title); |
103 | } | 97 | } |
104 | 98 | ||
105 | void print_header(int columns) | 99 | void print_header(int columns) |
106 | { | 100 | { |
107 | html("<tr class='nohover'>"); | 101 | html("<tr class='nohover'>"); |
108 | print_sort_header("Name", "name"); | 102 | print_sort_header("Name", "name"); |
109 | print_sort_header("Description", "desc"); | 103 | print_sort_header("Description", "desc"); |
110 | print_sort_header("Owner", "owner"); | 104 | print_sort_header("Owner", "owner"); |
111 | print_sort_header("Idle", "idle"); | 105 | print_sort_header("Idle", "idle"); |
112 | if (ctx.cfg.enable_index_links) | 106 | if (ctx.cfg.enable_index_links) |
113 | html("<th class='left'>Links</th>"); | 107 | html("<th class='left'>Links</th>"); |
114 | html("</tr>\n"); | 108 | html("</tr>\n"); |
115 | } | 109 | } |
116 | 110 | ||
117 | 111 | ||
118 | void print_pager(int items, int pagelen, char *search) | 112 | void print_pager(int items, int pagelen, char *search) |
119 | { | 113 | { |
120 | int i; | 114 | int i; |
121 | html("<div class='pager'>"); | 115 | html("<div class='pager'>"); |
122 | for(i = 0; i * pagelen < items; i++) | 116 | for(i = 0; i * pagelen < items; i++) |
123 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, | 117 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, |
124 | search, i * pagelen); | 118 | search, i * pagelen); |
125 | html("</div>"); | 119 | html("</div>"); |
126 | } | 120 | } |
127 | 121 | ||
128 | static int cmp(const char *s1, const char *s2) | 122 | static int cmp(const char *s1, const char *s2) |
129 | { | 123 | { |
130 | if (s1 && s2) | 124 | if (s1 && s2) |
131 | return strcmp(s1, s2); | 125 | return strcmp(s1, s2); |
132 | if (s1 && !s2) | 126 | if (s1 && !s2) |
133 | return -1; | 127 | return -1; |
134 | if (s2 && !s1) | 128 | if (s2 && !s1) |
135 | return 1; | 129 | return 1; |
136 | return 0; | 130 | return 0; |
137 | } | 131 | } |
138 | 132 | ||
139 | static int sort_section(const void *a, const void *b) | 133 | static int sort_section(const void *a, const void *b) |
140 | { | 134 | { |
141 | const struct cgit_repo *r1 = a; | 135 | const struct cgit_repo *r1 = a; |
142 | const struct cgit_repo *r2 = b; | 136 | const struct cgit_repo *r2 = b; |