summaryrefslogtreecommitdiffabout
path: root/cgit.c
Side-by-side diff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index 110face..7f14016 100644
--- a/cgit.c
+++ b/cgit.c
@@ -372,137 +372,137 @@ static void cgit_print_log(const char *tip, int ofs, int cnt)
rev.verbose_header = 1;
rev.show_root_diff = 0;
setup_revisions(2, argv, &rev, NULL);
prepare_revision_walk(&rev);
html("<h2>Log</h2>");
html("<table class='list'>");
html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n");
while ((commit = get_revision(&rev)) != NULL && n++ < 100) {
cgit_print_commit_shortlog(commit);
free(commit->buffer);
commit->buffer = NULL;
free_commit_list(commit->parents);
commit->parents = NULL;
}
html("</table>\n");
}
static void cgit_print_repo_summary()
{
html("<h2>");
html_txt("Repo summary page");
html("</h2>");
cgit_print_branches();
}
static void cgit_print_object(char *hex)
{
unsigned char sha1[20];
//struct object *object;
char type[20];
unsigned char *buf;
unsigned long size;
if (get_sha1_hex(hex, sha1)){
htmlf(cgit_error, "Bad hex value");
return;
}
if (sha1_object_info(sha1, type, NULL)){
htmlf(cgit_error, "Bad object name");
return;
}
buf = read_sha1_file(sha1, type, &size);
if (!buf) {
htmlf(cgit_error, "Error reading object");
return;
}
buf[size] = '\0';
html("<h2>Object view</h2>");
htmlf("sha1=%s<br/>type=%s<br/>size=%i<br/>", hex, type, size);
html("<pre>");
html_txt(buf);
html("</pre>");
}
static void cgit_print_repo_page()
{
if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) ||
cgit_read_config("info/cgit", cgit_repo_config_cb)) {
char *title = fmt("%s - %s", cgit_root_title, "Bad request");
cgit_print_docstart(title);
cgit_print_pageheader(title);
htmlf(cgit_lib_error, "Unable to scan repository",
strerror(errno));
cgit_print_docend();
return;
}
setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1);
char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc);
cgit_print_docstart(title);
cgit_print_pageheader(title);
if (!cgit_query_page)
cgit_print_repo_summary();
else if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, 0, 100);
} else if (!strcmp(cgit_query_page, "view")) {
cgit_print_object(cgit_query_sha1);
}
cgit_print_docend();
}
static void cgit_fill_cache(struct cacheitem *item)
{
htmlfd = item->fd;
item->st.st_mtime = time(NULL);
if (cgit_query_repo)
cgit_print_repo_page();
else
cgit_print_repolist();
}
static void cgit_refresh_cache(struct cacheitem *item)
{
+ cache_prepare(item);
top:
- if (!cache_lookup(item)) {
- if (cache_lock(item)) {
- cgit_fill_cache(item);
- cache_unlock(item);
- } else {
+ if (!cache_exist(item)) {
+ if (!cache_lock(item)) {
sched_yield();
goto top;
}
- } else if (cache_expired(item)) {
- if (cache_lock(item)) {
+ if (!cache_exist(item))
cgit_fill_cache(item);
- cache_unlock(item);
- }
+ cache_unlock(item);
+ } else if (cache_expired(item) && cache_lock(item)) {
+ if (cache_expired(item))
+ cgit_fill_cache(item);
+ cache_unlock(item);
}
}
static void cgit_print_cache(struct cacheitem *item)
{
static char buf[4096];
ssize_t i;
int fd = open(item->name, O_RDONLY);
if (fd<0)
die("Unable to open cached file %s", item->name);
while((i=read(fd, buf, sizeof(buf))) > 0)
write(STDOUT_FILENO, buf, i);
close(fd);
}
int main(int argc, const char **argv)
{
cgit_read_config("/etc/cgitrc", cgit_global_config_cb);
cgit_querystring = xstrdup(getenv("QUERY_STRING"));
cgit_parse_query(cgit_querystring, cgit_querystring_cb);
cgit_refresh_cache(&cacheitem);
cgit_print_cache(&cacheitem);
return 0;
}