about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJune McEnroe2021-06-08 20:21:10 +0000
committerJune McEnroe2022-02-13 12:13:58 -0500
commit20f0352d9be4d6159ef665140d27ed8de76c0c91 (patch)
treeadde7fbfa5f1217025f1525ad7bab09f5d0cdf5a
parentMerge up to git v2.32.0 (diff)
downloadcgit-20f0352d9be4d6159ef665140d27ed8de76c0c91.tar.gz
cgit-20f0352d9be4d6159ef665140d27ed8de76c0c91.zip
Generate valid Atom feeds
Fixes several RFC 4287 violations:

> 4.1.1. The "atom:feed" Element
>    o  atom:feed elements MUST contain exactly one atom:id element.
>    o  atom:feed elements SHOULD contain one atom:link element with a rel
>       attribute value of "self".  This is the preferred URI for
>       retrieving Atom Feed Documents representing this Atom feed.
>    o  atom:feed elements MUST contain exactly one atom:updated element.

An atom:id element is generated from cgit_currentfullurl(), and an
atom:link element with a rel attribute of "self" is generated with
the same URL. An atom:updated element is generated from the date
of the first commit in the revision walk.

> 4.1.2.  The "atom:entry" Element
>    o  atom:entry elements MUST NOT contain more than one atom:content
>       element.

The second atom:content element with the type of "xhtml" is removed.

> 4.2.6.  The "atom:id" Element
>    Its content MUST be an IRI, as defined by [RFC3987].  Note that the
>    definition of "IRI" excludes relative references.  Though the IRI
>    might use a dereferencable scheme, Atom Processors MUST NOT assume it
>    can be dereferenced.

The atom:id elements for commits now use URNs in the "sha1" or
"sha256" namespaces. Although these are not registered URN namespaces,
they see use in the wild, for instance as part of magnet URIs.
-rw-r--r--ui-atom.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/ui-atom.c b/ui-atom.c index 1056f36..8329e01 100644 --- a/ui-atom.c +++ b/ui-atom.c
@@ -67,17 +67,12 @@ static void add_entry(struct commit *commit, const char *host)
67 html("'/>\n"); 67 html("'/>\n");
68 free(pageurl); 68 free(pageurl);
69 } 69 }
70 htmlf("<id>%s</id>\n", hex); 70 html("<id>");
71 html_txtf("urn:%s:%s", the_hash_algo->name, hex);
72 html("</id>\n");
71 html("<content type='text'>\n"); 73 html("<content type='text'>\n");
72 html_txt(info->msg); 74 html_txt(info->msg);
73 html("</content>\n"); 75 html("</content>\n");
74 html("<content type='xhtml'>\n");
75 html("<div xmlns='http://www.w3.org/1999/xhtml'>\n");
76 html("<pre>\n");
77 html_txt(info->msg);
78 html("</pre>\n");
79 html("</div>\n");
80 html("</content>\n");
81 html("</entry>\n"); 76 html("</entry>\n");
82 cgit_free_commitinfo(info); 77 cgit_free_commitinfo(info);
83} 78}
@@ -90,6 +85,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
90 struct commit *commit; 85 struct commit *commit;
91 struct rev_info rev; 86 struct rev_info rev;
92 int argc = 2; 87 int argc = 2;
88 int first = 1;
93 89
94 if (ctx.qry.show_all) 90 if (ctx.qry.show_all)
95 argv[1] = "--all"; 91 argv[1] = "--all";
@@ -130,15 +126,28 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
130 html_txt(ctx.repo->desc); 126 html_txt(ctx.repo->desc);
131 html("</subtitle>\n"); 127 html("</subtitle>\n");
132 if (host) { 128 if (host) {
129 char *fullurl = cgit_currentfullurl();
133 char *repourl = cgit_repourl(ctx.repo->url); 130 char *repourl = cgit_repourl(ctx.repo->url);
131 html("<id>");
132 html_txtf("%s%s%s", cgit_httpscheme(), host, fullurl);
133 html("</id>\n");
134 html("<link rel='self' href='");
135 html_attrf("%s%s%s", cgit_httpscheme(), host, fullurl);
136 html("'/>\n");
134 html("<link rel='alternate' type='text/html' href='"); 137 html("<link rel='alternate' type='text/html' href='");
135 html(cgit_httpscheme()); 138 html_attrf("%s%s%s", cgit_httpscheme(), host, repourl);
136 html_attr(host);
137 html_attr(repourl);
138 html("'/>\n"); 139 html("'/>\n");
140 free(fullurl);
139 free(repourl); 141 free(repourl);
140 } 142 }
141 while ((commit = get_revision(&rev)) != NULL) { 143 while ((commit = get_revision(&rev)) != NULL) {
144 if (first) {
145 html("<updated>");
146 html_txt(show_date(commit->date, 0,
147 date_mode_from_type(DATE_ISO8601_STRICT)));
148 html("</updated>\n");
149 first = 0;
150 }
142 add_entry(commit, host); 151 add_entry(commit, host);
143 free_commit_buffer(the_repository->parsed_objects, commit); 152 free_commit_buffer(the_repository->parsed_objects, commit);
144 free_commit_list(commit->parents); 153 free_commit_list(commit->parents);