summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 657e8af..64ee79c 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -98,89 +98,101 @@ static char *repolink(char *title, char *class, char *page, char *head,
98 html_attr(title); 98 html_attr(title);
99 html("'"); 99 html("'");
100 } 100 }
101 if (class) { 101 if (class) {
102 html(" class='"); 102 html(" class='");
103 html_attr(class); 103 html_attr(class);
104 html("'"); 104 html("'");
105 } 105 }
106 html(" href='"); 106 html(" href='");
107 if (cgit_virtual_root) { 107 if (cgit_virtual_root) {
108 html_attr(cgit_virtual_root); 108 html_attr(cgit_virtual_root);
109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
110 html("/"); 110 html("/");
111 html_attr(cgit_repo->url); 111 html_attr(cgit_repo->url);
112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
113 html("/"); 113 html("/");
114 html(page); 114 html(page);
115 html("/"); 115 html("/");
116 if (path) 116 if (path)
117 html_attr(path); 117 html_attr(path);
118 } else { 118 } else {
119 html(cgit_script_name); 119 html(cgit_script_name);
120 html("?url="); 120 html("?url=");
121 html_attr(cgit_repo->url); 121 html_attr(cgit_repo->url);
122 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 122 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
123 html("/"); 123 html("/");
124 html(page); 124 html(page);
125 html("/"); 125 html("/");
126 if (path) 126 if (path)
127 html_attr(path); 127 html_attr(path);
128 delim = "&"; 128 delim = "&";
129 } 129 }
130 if (head && strcmp(head, cgit_query_head)) { 130 if (head && strcmp(head, cgit_repo->defbranch)) {
131 html(delim); 131 html(delim);
132 html("h="); 132 html("h=");
133 html_attr(head); 133 html_attr(head);
134 delim = "&"; 134 delim = "&";
135 } 135 }
136 return fmt("%s", delim); 136 return fmt("%s", delim);
137} 137}
138 138
139void cgit_tree_link(char *name, char *title, char *class, char *head, 139static char *reporevlink(char *page, char *name, char *title, char *class,
140 char *rev, char *path) 140 char *head, char *rev, char *path)
141{ 141{
142 char *delim; 142 char *delim;
143 143
144 delim = repolink(title, class, "tree", head, path); 144 delim = repolink(title, class, page, head, path);
145 if (rev && strcmp(rev, cgit_query_head)) { 145 if (rev && strcmp(rev, cgit_query_head)) {
146 html(delim); 146 html(delim);
147 html("id="); 147 html("id=");
148 html_attr(rev); 148 html_attr(rev);
149 } 149 }
150 html("'>"); 150 html("'>");
151 html_txt(name); 151 html_txt(name);
152 html("</a>"); 152 html("</a>");
153} 153}
154 154
155void cgit_tree_link(char *name, char *title, char *class, char *head,
156 char *rev, char *path)
157{
158 reporevlink("tree", name, title, class, head, rev, path);
159}
160
161void cgit_log_link(char *name, char *title, char *class, char *head,
162 char *rev, char *path)
163{
164 reporevlink("log", name, title, class, head, rev, path);
165}
166
155void cgit_print_date(time_t secs, char *format) 167void cgit_print_date(time_t secs, char *format)
156{ 168{
157 char buf[64]; 169 char buf[64];
158 struct tm *time; 170 struct tm *time;
159 171
160 time = gmtime(&secs); 172 time = gmtime(&secs);
161 strftime(buf, sizeof(buf)-1, format, time); 173 strftime(buf, sizeof(buf)-1, format, time);
162 html_txt(buf); 174 html_txt(buf);
163} 175}
164 176
165void cgit_print_age(time_t t, time_t max_relative, char *format) 177void cgit_print_age(time_t t, time_t max_relative, char *format)
166{ 178{
167 time_t now, secs; 179 time_t now, secs;
168 180
169 time(&now); 181 time(&now);
170 secs = now - t; 182 secs = now - t;
171 183
172 if (secs > max_relative && max_relative >= 0) { 184 if (secs > max_relative && max_relative >= 0) {
173 cgit_print_date(t, format); 185 cgit_print_date(t, format);
174 return; 186 return;
175 } 187 }
176 188
177 if (secs < TM_HOUR * 2) { 189 if (secs < TM_HOUR * 2) {
178 htmlf("<span class='age-mins'>%.0f min.</span>", 190 htmlf("<span class='age-mins'>%.0f min.</span>",
179 secs * 1.0 / TM_MIN); 191 secs * 1.0 / TM_MIN);
180 return; 192 return;
181 } 193 }
182 if (secs < TM_DAY * 2) { 194 if (secs < TM_DAY * 2) {
183 htmlf("<span class='age-hours'>%.0f hours</span>", 195 htmlf("<span class='age-hours'>%.0f hours</span>",
184 secs * 1.0 / TM_HOUR); 196 secs * 1.0 / TM_HOUR);
185 return; 197 return;
186 } 198 }