Compare commits

..

No commits in common. "00ecfaadea2c40cc62b7a43e246384329e6ddb98" and "ce2062d9e29bf165ba8a70bfc92ff3ab08338d53" have entirely different histories.

12 changed files with 47 additions and 184 deletions

View File

@ -87,7 +87,6 @@ install: all
$(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
$(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
$(INSTALL) -m 0644 cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js
$(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
$(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico
$(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt

45
cache.c
View File

@ -85,45 +85,40 @@ static int close_slot(struct cache_slot *slot)
/* Print the content of the active cache slot (but skip the key). */
static int print_slot(struct cache_slot *slot)
{
off_t off;
#ifdef HAVE_LINUX_SENDFILE
off_t size;
#endif
off_t start_off;
int ret;
off = slot->keylen + 1;
#ifdef HAVE_LINUX_SENDFILE
size = slot->cache_st.st_size;
start_off = slot->keylen + 1;
do {
ssize_t ret;
ret = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off);
ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off,
slot->cache_st.st_size - start_off);
if (ret < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
/* Fall back to read/write on EINVAL or ENOSYS */
if (errno == EINVAL || errno == ENOSYS)
break;
return errno;
}
if (off == size)
return 0;
return 0;
} while (1);
#endif
#else
ssize_t i, j;
if (lseek(slot->cache_fd, off, SEEK_SET) != off)
i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET);
if (i != slot->keylen + 1)
return errno;
do {
ssize_t ret;
ret = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
if (ret < 0)
return errno;
if (ret == 0)
return 0;
if (write_in_full(STDOUT_FILENO, slot->buf, ret) < 0)
return errno;
} while (1);
i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
if (i > 0)
j = xwrite(STDOUT_FILENO, slot->buf, i);
} while (i > 0 && j == i);
if (i < 0 || j != i)
return errno;
else
return 0;
#endif
}
/* Check if the slot has expired */

19
cgit.c
View File

@ -142,9 +142,7 @@ static void config_cb(const char *name, const char *value)
else if (!strcmp(name, "root-readme"))
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
string_list_append(&ctx.cfg.css, xstrdup(value));
else if (!strcmp(name, "js"))
string_list_append(&ctx.cfg.js, xstrdup(value));
ctx.cfg.css = xstrdup(value);
else if (!strcmp(name, "favicon"))
ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer"))
@ -239,11 +237,9 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.max_repodesc_len = atoi(value);
else if (!strcmp(name, "max-blob-size"))
ctx.cfg.max_blob_size = atoi(value);
else if (!strcmp(name, "max-repo-count")) {
else if (!strcmp(name, "max-repo-count"))
ctx.cfg.max_repo_count = atoi(value);
if (ctx.cfg.max_repo_count <= 0)
ctx.cfg.max_repo_count = INT_MAX;
} else if (!strcmp(name, "max-commit-count"))
else if (!strcmp(name, "max-commit-count"))
ctx.cfg.max_commit_count = atoi(value);
else if (!strcmp(name, "project-list"))
ctx.cfg.project_list = xstrdup(expand_macros(value));
@ -380,6 +376,7 @@ static void prepare_context(void)
ctx.cfg.case_sensitive_sort = 1;
ctx.cfg.branch_sort = 0;
ctx.cfg.commit_sort = 0;
ctx.cfg.css = "/cgit.css";
ctx.cfg.logo = "/cgit.png";
ctx.cfg.favicon = "/favicon.ico";
ctx.cfg.local_time = 0;
@ -510,11 +507,9 @@ static inline void parse_readme(const char *readme, char **filename, char **ref,
/* Check if the readme is tracked in the git repo. */
colon = strchr(readme, ':');
if (colon && strlen(colon) > 1) {
/* If it starts with a colon, we want to use head given
* from query or the default branch */
if (colon == readme && ctx.qry.head)
*ref = xstrdup(ctx.qry.head);
else if (colon == readme && repo->defbranch)
/* If it starts with a colon, we want to use
* the default branch */
if (colon == readme && repo->defbranch)
*ref = xstrdup(repo->defbranch);
else
*ref = xstrndup(readme, colon - readme);

View File

@ -363,10 +363,6 @@ div#cgit table.blame td.lines > div > pre {
top: 0;
}
div#cgit table.blame .oid {
font-size: 100%;
}
div#cgit table.bin-blob {
margin-top: 0.5em;
border: solid 1px black;

4
cgit.h
View File

@ -25,7 +25,6 @@
#include <utf8.h>
#include <notes.h>
#include <graph.h>
#include <inttypes.h>
/* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
#undef isgraph
@ -196,6 +195,7 @@ struct cgit_config {
char *cache_root;
char *clone_prefix;
char *clone_url;
char *css;
char *favicon;
char *footer;
char *head_include;
@ -206,7 +206,6 @@ struct cgit_config {
char *module_link;
char *project_list;
struct string_list readme;
struct string_list css;
char *robots;
char *root_title;
char *root_desc;
@ -265,7 +264,6 @@ struct cgit_config {
int branch_sort;
int commit_sort;
struct string_list mimetypes;
struct string_list js;
struct cgit_filter *about_filter;
struct cgit_filter *commit_filter;
struct cgit_filter *source_filter;

68
cgit.js
View File

@ -1,68 +0,0 @@
/* cgit.js: javacript functions for cgit
*
* Copyright (C) 2006-2018 cgit Development Team <cgit@lists.zx2c4.com>
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
(function () {
/* This follows the logic and suffixes used in ui-shared.c */
var age_classes = [ "age-mins", "age-hours", "age-days", "age-weeks", "age-months", "age-years" ];
var age_suffix = [ "min.", "hours", "days", "weeks", "months", "years", "years" ];
var age_next = [ 60, 3600, 24 * 3600, 7 * 24 * 3600, 30 * 24 * 3600, 365 * 24 * 3600, 365 * 24 * 3600 ];
var age_limit = [ 7200, 24 * 7200, 7 * 24 * 7200, 30 * 24 * 7200, 365 * 25 * 7200, 365 * 25 * 7200 ];
var update_next = [ 10, 5 * 60, 1800, 24 * 3600, 24 * 3600, 24 * 3600, 24 * 3600 ];
function render_age(e, age) {
var t, n;
for (n = 0; n < age_classes.length; n++)
if (age < age_limit[n])
break;
t = Math.round(age / age_next[n]) + " " + age_suffix[n];
if (e.textContent != t) {
e.textContent = t;
if (n == age_classes.length)
n--;
if (e.className != age_classes[n])
e.className = age_classes[n];
}
}
function aging() {
var n, next = 24 * 3600,
now_ut = Math.round((new Date().getTime() / 1000));
for (n = 0; n < age_classes.length; n++) {
var m, elems = document.getElementsByClassName(age_classes[n]);
if (elems.length && update_next[n] < next)
next = update_next[n];
for (m = 0; m < elems.length; m++) {
var age = now_ut - elems[m].getAttribute("data-ut");
render_age(elems[m], age);
}
}
/*
* We only need to come back when the age might have changed.
* Eg, if everything is counted in hours already, once per
* 5 minutes is accurate enough.
*/
window.setTimeout(aging, next * 1000);
}
document.addEventListener("DOMContentLoaded", function() {
/* we can do the aging on DOM content load since no layout dependency */
aging();
}, false);
})();

View File

@ -126,8 +126,7 @@ commit-sort::
css::
Url which specifies the css document to include in all cgit pages.
Default value: "/cgit.css". May be given multiple times, each
css URL path is added in the head section of the document in turn.
Default value: "/cgit.css".
email-filter::
Specifies a command which will be invoked to format names and email
@ -239,11 +238,6 @@ include::
Name of a configfile to include before the rest of the current config-
file is parsed. Default value: none. See also: "MACRO EXPANSION".
js::
Url which specifies the javascript script document to include in all cgit
pages. Default value: "/cgit.js". Setting this to an empty string will
disable generation of the link to this file in the head section.
local-time::
Flag which, if set to "1", makes cgit print commit and tag times in the
servers timezone. Default value: "0".
@ -275,8 +269,7 @@ max-message-length::
max-repo-count::
Specifies the number of entries to list per page on the repository
index page. The value "0" shows all repositories without limitation.
Default value: "50".
index page. Default value: "50".
max-repodesc-length::
Specifies the maximum number of repo description characters to display
@ -586,11 +579,11 @@ repo.readme::
verbatim as the "About" page for this repo. You may also specify a
git refspec by head or by hash by prepending the refspec followed by
a colon. For example, "master:docs/readme.mkd". If the value begins
with a colon, i.e. ":docs/readme.rst", the head giving in query or
the default branch of the repository will be used. Sharing any file
will expose that entire directory tree to the "/about/PATH" endpoints,
so be sure that there are no non-public files located in the same
directory as the readme file. Default value: <readme>.
with a colon, i.e. ":docs/readme.rst", the default branch of the
repository will be used. Sharing any file will expose that entire
directory tree to the "/about/PATH" endpoints, so be sure that there
are no non-public files located in the same directory as the readme
file. Default value: <readme>.
repo.section::
Override the current section name for this repository. Default value:

View File

@ -149,7 +149,8 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
first = false;
}
add_entry(commit, host);
release_commit_memory(the_repository->parsed_objects, commit);
free_commit_buffer(the_repository->parsed_objects, commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
html("</feed>\n");

View File

@ -54,15 +54,6 @@ static void emit_blame_entry_hash(struct blame_entry *ent)
html("</span>");
free(detail);
if (!parse_commit(suspect->commit) && suspect->commit->parents) {
struct commit *parent = suspect->commit->parents->item;
html(" ");
cgit_blame_link("^", "Blame the previous revision", NULL,
ctx.qry.head, oid_to_hex(&parent->object.oid),
suspect->path);
}
while (line++ < ent->num_lines)
html("\n");
}

View File

@ -489,7 +489,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) {
if (show_commit(commit, &rev))
i++;
release_commit_memory(the_repository->parsed_objects, commit);
free_commit_buffer(the_repository->parsed_objects, commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
@ -510,7 +511,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
i++;
print_commit(commit, &rev);
}
release_commit_memory(the_repository->parsed_objects, commit);
free_commit_buffer(the_repository->parsed_objects, commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
if (pager) {

View File

@ -673,7 +673,7 @@ const struct date_mode *cgit_date_mode(enum date_mode_type type)
static void print_rel_date(time_t t, int tz, double value,
const char *class, const char *suffix)
{
htmlf("<span class='%s' data-ut='%" PRIu64 "' title='", class, (uint64_t)t);
htmlf("<span class='%s' title='", class);
html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
htmlf("'>%.0f %s</span>", value, suffix);
}
@ -768,38 +768,6 @@ static void print_rel_vcs_link(const char *url)
html(" Git repository'/>\n");
}
static int emit_css_link(struct string_list_item *s, void *arg)
{
/* Do not emit anything if css= is specified. */
if (s && *s->string == '\0')
return 0;
html("<link rel='stylesheet' type='text/css' href='");
if (s)
html_attr(s->string);
else
html_attr((const char *)arg);
html("'/>\n");
return 0;
}
static int emit_js_link(struct string_list_item *s, void *arg)
{
/* Do not emit anything if js= is specified. */
if (s && *s->string == '\0')
return 0;
html("<script type='text/javascript' src='");
if (s)
html_attr(s->string);
else
html_attr((const char *)arg);
html("'></script>\n");
return 0;
}
void cgit_print_docstart(void)
{
char *host = cgit_hosturl();
@ -819,17 +787,9 @@ void cgit_print_docstart(void)
htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
if (ctx.cfg.robots && *ctx.cfg.robots)
htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
if (ctx.cfg.css.items)
for_each_string_list(&ctx.cfg.css, emit_css_link, NULL);
else
emit_css_link(NULL, "/cgit.css");
if (ctx.cfg.js.items)
for_each_string_list(&ctx.cfg.js, emit_js_link, NULL);
else
emit_js_link(NULL, "/cgit.js");
html("<link rel='stylesheet' type='text/css' href='");
html_attr(ctx.cfg.css);
html("'/>\n");
if (ctx.cfg.favicon) {
html("<link rel='shortcut icon' href='");
html_attr(ctx.cfg.favicon);

View File

@ -241,7 +241,8 @@ static struct string_list collect_stats(const struct cgit_period *period)
memset(&authors, 0, sizeof(authors));
while ((commit = get_revision(&rev)) != NULL) {
add_commit(&authors, commit, period);
release_commit_memory(the_repository->parsed_objects, commit);
free_commit_buffer(the_repository->parsed_objects, commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
return authors;