Commit ff4bb25f1fc4f450c6c613b413e3c092f48d214d

Tracey Emery 2020-02-19T16:37:13

add new tags page and ability to navigate all tags

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
diff --git a/got-dist.txt b/got-dist.txt
index e34d1f0..039f973 100644
--- a/got-dist.txt
+++ b/got-dist.txt
@@ -27,6 +27,7 @@
 /gotweb/files/cgi-bin/gw_tmpl/index.tmpl
 /gotweb/files/cgi-bin/gw_tmpl/summry.tmpl
 /gotweb/files/cgi-bin/gw_tmpl/tag.tmpl
+/gotweb/files/cgi-bin/gw_tmpl/tags.tmpl
 /gotweb/files/cgi-bin/gw_tmpl/tree.tmpl
 /gotweb/files/htdocs
 /gotweb/files/htdocs/gotweb
diff --git a/gotweb/files/cgi-bin/gw_tmpl/tags.tmpl b/gotweb/files/cgi-bin/gw_tmpl/tags.tmpl
new file mode 100644
index 0000000..1281926
--- /dev/null
+++ b/gotweb/files/cgi-bin/gw_tmpl/tags.tmpl
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>@@title@@</title>
+		@@head@@
+	</head>
+	<body>
+	<div id="gw_body">
+		<div id="header">
+			@@header@@
+		</div>
+		<div id="site_path">
+			@@sitepath@@
+			@@search@@
+		</div>
+		<div id="content">
+			@@content@@
+		</div>
+		@@siteowner@@
+	</div>
+	</body>
+</html>
diff --git a/gotweb/files/htdocs/gotweb/gotweb.css b/gotweb/files/htdocs/gotweb/gotweb.css
index bc35b62..eb7e67f 100644
--- a/gotweb/files/htdocs/gotweb/gotweb.css
+++ b/gotweb/files/htdocs/gotweb/gotweb.css
@@ -733,32 +733,12 @@ body {
 	padding-bottom: 2px;
 	width: 80%;
 }
-#tag {
-	clear: left;
-	float: left;
-	margin-left: 20px;
-	margin-top: 20px;
-	margin-bottom: 20px;
-	font-family: monospace;
-}
 #tag_wrapper {
 	clear: left;
 	float: left;
 	width: 100%;
 }
-#tag_line {
-	clear: left;
-	float:left ;
-}
-
-/* tags.tmpl */
-
-#tags_wrapper {
-	clear: left;
-	float: left;
-	width: 100%;
-}
-#tags_age {
+#tag_age {
 	padding-left: 10px;
 	padding-top: 5px;
 	padding-bottom: 5px;
@@ -766,14 +746,14 @@ body {
 	width: 7.5em;
 	overflow: auto;
 }
-#tags {
+#tag {
 	float: left;
 	width: 8.5em;
 	font-style: italic;
 	padding-top: 5px;
 	padding-bottom: 5px;
 }
-#tags_name {
+#tag_name {
 	float: left;
 	padding-left: 10px;
 	padding-right: 10px;
@@ -803,6 +783,16 @@ body {
 	white-space: pre-wrap;
 }
 
+/* tags.tmpl */
+#tags_info {
+	clear: left;
+	float: left;
+	padding-left: 10px;
+	padding-top: 5px;
+	padding-bottom: 5px;
+}
+
+
 /* diff.tmpl */
 
 #diff_title_wrapper {
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 28bc103..0b4134e 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -132,7 +132,7 @@ enum gw_ref_tm {
 	TM_LONG,
 };
 
-enum gw_tags {
+enum gw_tags_type {
 	TAGBRIEF,
 	TAGFULL,
 };
@@ -228,6 +228,7 @@ static const struct got_error	*gw_briefs(struct gw_trans *);
 static const struct got_error	*gw_summary(struct gw_trans *);
 static const struct got_error	*gw_tree(struct gw_trans *);
 static const struct got_error	*gw_tag(struct gw_trans *);
+static const struct got_error	*gw_tags(struct gw_trans *);
 
 struct gw_query_action {
 	unsigned int		 func_id;
@@ -246,6 +247,7 @@ enum gw_query_actions {
 	GW_INDEX,
 	GW_SUMMARY,
 	GW_TAG,
+	GW_TAGS,
 	GW_TREE,
 };
 
@@ -259,6 +261,7 @@ static struct gw_query_action gw_query_funcs[] = {
 	{ GW_INDEX,	"index",	gw_index,	"gw_tmpl/index.tmpl" },
 	{ GW_SUMMARY,	"summary",	gw_summary,	"gw_tmpl/summry.tmpl" },
 	{ GW_TAG,	"tag",		gw_tag,		"gw_tmpl/tag.tmpl" },
+	{ GW_TAGS,	"tags",		gw_tags,	"gw_tmpl/tags.tmpl" },
 	{ GW_TREE,	"tree",		gw_tree,	"gw_tmpl/tree.tmpl" },
 };
 
@@ -551,6 +554,7 @@ gw_index(struct gw_trans *gw_trans)
 	struct gw_dir *gw_dir = NULL;
 	char *href_next = NULL, *href_prev = NULL, *href_summary = NULL;
 	char *href_briefs = NULL, *href_commits = NULL, *href_tree = NULL;
+	char *href_tags = NULL;
 	unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
 	enum kcgi_err kerr;
 
@@ -792,6 +796,27 @@ gw_index(struct gw_trans *gw_trans)
 		if (kerr != KCGI_OK)
 			goto done;
 
+
+		if (asprintf(&href_tags, "?path=%s&action=tags",
+		    gw_dir->name) == -1) {
+			error = got_error_from_errno("asprintf");
+			goto done;
+		}
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
+		    href_tags, KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_puts(gw_trans->gw_html_req, "tags");
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
+		if (kerr != KCGI_OK)
+			goto done;
+
+		kerr = khtml_puts(gw_trans->gw_html_req, " | ");
+		if (kerr != KCGI_OK)
+			goto done;
+
 		if (asprintf(&href_tree, "?path=%s&action=tree",
 		    gw_dir->name) == -1) {
 			error = got_error_from_errno("asprintf");
@@ -822,6 +847,8 @@ gw_index(struct gw_trans *gw_trans)
 		href_briefs = NULL;
 		free(href_commits);
 		href_commits = NULL;
+		free(href_tags);
+		href_tags = NULL;
 		free(href_tree);
 		href_tree = NULL;
 
@@ -911,6 +938,7 @@ done:
 	free(href_summary);
 	free(href_briefs);
 	free(href_commits);
+	free(href_tags);
 	free(href_tree);
 	if (error == NULL && kerr != KCGI_OK)
 		error = gw_kcgi_error(kerr);
@@ -1541,8 +1569,7 @@ gw_summary(struct gw_trans *gw_trans)
 	if (error)
 		goto done;
 
-	error = gw_output_repo_tags(gw_trans, NULL, D_MAXSLCOMMDISP,
-	    TAGBRIEF);
+	error = gw_tags(gw_trans);
 	if (error)
 		goto done;
 
@@ -1630,6 +1657,123 @@ done:
 }
 
 static const struct got_error *
+gw_tags(struct gw_trans *gw_trans)
+{
+	const struct got_error *error = NULL;
+	struct gw_header *header = NULL;
+	char *href_next = NULL, *href_prev = NULL;
+	enum kcgi_err kerr = KCGI_OK;
+
+	if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
+		return got_error_from_errno("pledge");
+
+	if ((header = gw_init_header()) == NULL)
+		return got_error_from_errno("malloc");
+
+	if (gw_trans->action != GW_SUMMARY) {
+		error = gw_apply_unveil(gw_trans->gw_dir->path);
+		if (error)
+			goto done;
+	}
+
+	error = gw_get_header(gw_trans, header, 1);
+	if (error)
+		goto done;
+
+	if (gw_trans->action == GW_SUMMARY) {
+		error = gw_output_repo_tags(gw_trans, header,
+		    D_MAXSLCOMMDISP, TAGBRIEF);
+		if (error)
+			goto done;
+	} else {
+		error = gw_output_repo_tags(gw_trans, header,
+		    gw_trans->gw_conf->got_max_commits_display, TAGBRIEF);
+		if (error)
+			goto done;
+	}
+
+	if (gw_trans->next_id || gw_trans->page > 0) {
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+		    KATTR_ID, "np_wrapper", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+		    KATTR_ID, "nav_prev", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+	}
+
+	if (gw_trans->page > 0 && gw_trans->prev_id) {
+		if (asprintf(&href_prev,
+		    "?path=%s&page=%d&action=tags&commit=%s&prev=%s",
+		    gw_trans->repo_name, gw_trans->page - 1,
+		    gw_trans->prev_id ? gw_trans->prev_id : "",
+		    gw_trans->prev_prev_id ?
+		    gw_trans->prev_prev_id : "") == -1) {
+			error = got_error_from_errno("asprintf");
+			goto done;
+		}
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
+		    KATTR_HREF, href_prev, KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
+		if (kerr != KCGI_OK)
+			goto done;
+	}
+
+	if (gw_trans->next_id || gw_trans->page > 0) {
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
+		if (kerr != KCGI_OK)
+			return gw_kcgi_error(kerr);
+	}
+
+	if (gw_trans->next_id) {
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+		    KATTR_ID, "nav_next", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		if (asprintf(&href_next,
+		    "?path=%s&page=%d&action=tags" \
+		    "&commit=%s&prev=%s&prev_prev=%s",
+		    gw_trans->repo_name, gw_trans->page + 1,
+		    gw_trans->next_id,
+		    gw_trans->next_prev_id ? gw_trans->next_prev_id : "",
+		    gw_trans->prev_id ?
+		    gw_trans->prev_id : "") == -1) {
+			error = got_error_from_errno("calloc");
+			goto done;
+		}
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
+		    KATTR_HREF, href_next, KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_puts(gw_trans->gw_html_req, "Next");
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
+		if (kerr != KCGI_OK)
+			goto done;
+	}
+
+	if (gw_trans->next_id || gw_trans->page > 0) {
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
+		if (kerr != KCGI_OK)
+			goto done;
+	}
+done:
+	gw_free_header(header);
+	free(href_next);
+	free(href_prev);
+	if (error == NULL && kerr != KCGI_OK)
+		error = gw_kcgi_error(kerr);
+	return error;
+}
+
+static const struct got_error *
 gw_tag(struct gw_trans *gw_trans)
 {
 	const struct got_error *error = NULL;
@@ -2824,7 +2968,8 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 	char *tag_commit0 = NULL, *href_tag = NULL, *href_briefs = NULL;
 	struct got_tag_object *tag = NULL;
 	enum kcgi_err kerr = KCGI_OK;
-	int summary_header_displayed = 0;
+	int summary_header_displayed = 0, start_tag = 0, chk_next = 0;
+	int prev_set = 0, tag_count = 0;
 
 	SIMPLEQ_INIT(&refs);
 
@@ -2882,6 +3027,32 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 		    strlen(id_str)) != 0)
 			continue;
 
+		if (tag_type == TAGBRIEF && gw_trans->commit_id &&
+		    start_tag == 0 && strncmp(id_str, header->commit_id,
+		    strlen(id_str)) != 0) {
+			continue;
+		} else {
+			start_tag = 1;
+		}
+
+		tag_count++;
+
+		if (prev_set == 0 && start_tag == 1) {
+			gw_trans->next_prev_id = strdup(id_str);
+			if (gw_trans->next_prev_id == NULL) {
+				error = got_error_from_errno("strdup");
+				goto done;
+			}
+			prev_set = 1;
+		}
+
+		if (chk_next) {
+			gw_trans->next_id = strdup(id_str);
+			if (gw_trans->next_id == NULL)
+				error = got_error_from_errno("strdup");
+			goto done;
+		}
+
 		if (commit) {
 			error = got_object_commit_get_logmsg(&tag_commit0,
 			    commit);
@@ -2934,11 +3105,11 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 			}
 
 			kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
-			    KATTR_ID, "tags_wrapper", KATTR__MAX);
+			    KATTR_ID, "tag_wrapper", KATTR__MAX);
 			if (kerr != KCGI_OK)
 				goto done;
 			kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
-			    KATTR_ID, "tags_age", KATTR__MAX);
+			    KATTR_ID, "tag_age", KATTR__MAX);
 			if (kerr != KCGI_OK)
 				goto done;
 			error = gw_get_time_str(&age, tagger_time, TM_DIFF);
@@ -2952,7 +3123,7 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 			if (kerr != KCGI_OK)
 				goto done;
 			kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
-			    KATTR_ID, "tags", KATTR__MAX);
+			    KATTR_ID, "tag", KATTR__MAX);
 			if (kerr != KCGI_OK)
 				goto done;
 			kerr = khtml_puts(gw_trans->gw_html_req, refname);
@@ -2962,7 +3133,7 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 			if (kerr != KCGI_OK)
 				goto done;
 			kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
-			    KATTR_ID, "tags_name", KATTR__MAX);
+			    KATTR_ID, "tag_name", KATTR__MAX);
 			if (kerr != KCGI_OK)
 				goto done;
 			if (asprintf(&href_tag, "?path=%s&action=tag&commit=%s",
@@ -3115,7 +3286,7 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 			goto done;
 
 		if (limit && --limit == 0)
-			break;
+			chk_next = 1;
 
 		if (tag)
 			got_object_tag_close(tag);
@@ -3133,6 +3304,37 @@ gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
 		free(href_commits);
 		href_commits = NULL;
 	}
+	if (tag_count == 0) {
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
+		    "summary_tags_title_wrapper", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
+		    "summary_tags_title", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_puts(gw_trans->gw_html_req, "Tags");
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
+		    "summary_tags_content", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
+		    "tags_info", KATTR__MAX);
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khttp_puts(gw_trans->gw_req,
+		    "There are no tags for this repo.");
+		if (kerr != KCGI_OK)
+			goto done;
+		kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
+		if (kerr != KCGI_OK)
+			goto done;
+	}
 done:
 	if (tag)
 		got_object_tag_close(tag);