From b2a3d31e8839b53a623b4c99124c2c637d0e3cbb Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 21 May 2008 08:17:54 +0200 Subject: Add atom-support This enables a page which generates atom feeds for the current branch and path, heavily inspired by the atom-support in gitweb. Signed-off-by: Lars Hjemli --- ui-atom.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 ui-atom.c (limited to 'ui-atom.c') diff --git a/ui-atom.c b/ui-atom.c new file mode 100644 index 0000000..a6ea3ee --- /dev/null +++ b/ui-atom.c @@ -0,0 +1,129 @@ +/* ui-atom.c: functions for atom feeds + * + * Copyright (C) 2008 Lars Hjemli + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + +#include "cgit.h" +#include "html.h" +#include "ui-shared.h" + +void add_entry(struct commit *commit, char *host) +{ + char delim = '&'; + char *hex; + char *mail, *t, *t2; + struct commitinfo *info; + + info = cgit_parse_commit(commit); + hex = sha1_to_hex(commit->object.sha1); + html("\n"); + html(""); + html_txt(info->subject); + html("\n"); + html(""); + cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); + html("\n"); + html("\n"); + if (info->author) { + html(""); + html_txt(info->author); + html("\n"); + } + if (info->author_email) { + mail = xstrdup(info->author_email); + t = strchr(mail, '<'); + if (t) + t++; + else + t = mail; + t2 = strchr(t, '>'); + if (t2) + *t2 = '\0'; + html(""); + html_txt(t); + html("\n"); + free(mail); + } + html("\n"); + html(""); + cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); + html("\n"); + if (host) { + html("\n"); + } + htmlf("%s\n", hex); + html("\n"); + html_txt(info->msg); + html("\n"); + html("\n"); + html("
\n"); + html("
\n");
+	html_txt(info->msg);
+	html("
\n"); + html("
\n"); + html("
\n"); + html("
\n"); + cgit_free_commitinfo(info); +} + + +void cgit_print_atom(char *tip, char *path, int max_count) +{ + char *host; + const char *argv[] = {NULL, tip, NULL, NULL, NULL}; + struct commit *commit; + struct rev_info rev; + int argc = 2; + + if (!tip) + argv[1] = ctx.qry.head; + + if (path) { + argv[argc++] = "--"; + argv[argc++] = path; + } + + init_revisions(&rev, NULL); + rev.abbrev = DEFAULT_ABBREV; + rev.commit_format = CMIT_FMT_DEFAULT; + rev.verbose_header = 1; + rev.show_root_diff = 0; + rev.max_count = max_count; + setup_revisions(argc, argv, &rev, NULL); + prepare_revision_walk(&rev); + + host = cgit_hosturl(); + ctx.page.mimetype = "text/xml"; + ctx.page.charset = "utf-8"; + cgit_print_http_headers(&ctx); + html("\n"); + html(""); + html_txt(ctx.repo->name); + html("\n"); + html(""); + html_txt(ctx.repo->desc); + html("\n"); + if (host) { + html("\n"); + } + while ((commit = get_revision(&rev)) != NULL) { + add_entry(commit, host); + free(commit->buffer); + commit->buffer = NULL; + free_commit_list(commit->parents); + commit->parents = NULL; + } + html("\n"); +} -- cgit v1.2.3-70-g09d2