summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h2
-rw-r--r--ui-repolist.c4
-rw-r--r--ui-shared.c20
-rw-r--r--ui-summary.c6
-rw-r--r--ui-tree.c12
5 files changed, 24 insertions, 20 deletions
diff --git a/cgit.h b/cgit.h
index 9a19c97..b2f6361 100644
--- a/cgit.h
+++ b/cgit.h
@@ -142,88 +142,90 @@ extern char *cgit_query_search;
extern char *cgit_query_head;
extern char *cgit_query_sha1;
extern char *cgit_query_sha2;
extern char *cgit_query_path;
extern char *cgit_query_name;
extern int cgit_query_ofs;
extern int htmlfd;
extern int cgit_get_cmd_index(const char *cmd);
extern struct repoinfo *cgit_get_repoinfo(const char *url);
extern void cgit_global_config_cb(const char *name, const char *value);
extern void cgit_repo_config_cb(const char *name, const char *value);
extern void cgit_querystring_cb(const char *name, const char *value);
extern int chk_zero(int result, char *msg);
extern int chk_positive(int result, char *msg);
extern int hextoint(char c);
extern void *cgit_free_commitinfo(struct commitinfo *info);
extern int cgit_diff_files(const unsigned char *old_sha1,
const unsigned char *new_sha1,
linediff_fn fn);
extern void cgit_diff_tree(const unsigned char *old_sha1,
const unsigned char *new_sha1,
filepair_fn fn);
extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
extern char *fmt(const char *format,...);
extern void html(const char *txt);
extern void htmlf(const char *format,...);
extern void html_txt(char *txt);
extern void html_ntxt(int len, char *txt);
extern void html_attr(char *txt);
extern void html_hidden(char *name, char *value);
extern void html_link_open(char *url, char *title, char *class);
extern void html_link_close(void);
extern void html_filemode(unsigned short mode);
extern int html_include(const char *filename);
extern int cgit_read_config(const char *filename, configfn fn);
extern int cgit_parse_query(char *txt, configfn fn);
extern struct commitinfo *cgit_parse_commit(struct commit *commit);
extern struct taginfo *cgit_parse_tag(struct tag *tag);
extern void cgit_parse_url(const char *url);
extern char *cache_safe_filename(const char *unsafe);
extern int cache_lock(struct cacheitem *item);
extern int cache_unlock(struct cacheitem *item);
extern int cache_cancel_lock(struct cacheitem *item);
extern int cache_exist(struct cacheitem *item);
extern int cache_expired(struct cacheitem *item);
extern char *cgit_repourl(const char *reponame);
extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
+extern void cgit_log_link(char *name, char *title, char *class, char *head,
+ char *rev, char *path);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(time_t secs, char *format);
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
extern void cgit_print_docstart(char *title, struct cacheitem *item);
extern void cgit_print_docend();
extern void cgit_print_pageheader(char *title, int show_search);
extern void cgit_print_snapshot_start(const char *mimetype,
const char *filename,
struct cacheitem *item);
extern void cgit_print_repolist(struct cacheitem *item);
extern void cgit_print_summary();
extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
extern void cgit_print_tree(const char *rev, char *path);
extern void cgit_print_commit(const char *hex);
extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex,
char *path);
extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
const char *format, const char *prefix,
const char *filename);
#endif /* CGIT_H */
diff --git a/ui-repolist.c b/ui-repolist.c
index 8ade91a..2018dab 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -28,73 +28,71 @@ time_t read_agefile(char *path)
static void print_modtime(struct repoinfo *repo)
{
char *path;
struct stat s;
path = fmt("%s/%s", repo->path, cgit_agefile);
if (stat(path, &s) == 0) {
cgit_print_age(read_agefile(path), -1, NULL);
return;
}
path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
if (stat(path, &s) != 0)
return;
cgit_print_age(s.st_mtime, -1, NULL);
}
void cgit_print_repolist(struct cacheitem *item)
{
int i;
char *last_group = NULL;
cgit_print_docstart(cgit_root_title, item);
cgit_print_pageheader(cgit_root_title, 0);
html("<table class='list nowrap'>");
if (cgit_index_header) {
html("<tr class='nohover'><td colspan='5' class='include-block'>");
html_include(cgit_index_header);
html("</td></tr>");
}
html("<tr class='nohover'>"
"<th class='left'>Name</th>"
"<th class='left'>Description</th>"
"<th class='left'>Owner</th>"
"<th class='left'>Idle</th>"
"<th>Links</th></tr>\n");
for (i=0; i<cgit_repolist.count; i++) {
cgit_repo = &cgit_repolist.repos[i];
if ((last_group == NULL && cgit_repo->group != NULL) ||
(last_group != NULL && cgit_repo->group == NULL) ||
(last_group != NULL && cgit_repo->group != NULL &&
strcmp(cgit_repo->group, last_group))) {
html("<tr class='nohover'><td colspan='4' class='repogroup'>");
html_txt(cgit_repo->group);
html("</td></tr>");
last_group = cgit_repo->group;
}
htmlf("<tr><td class='%s'>",
cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
html_txt(cgit_repo->name);
html_link_close();
html("</td><td>");
html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
html("</td><td>");
html_txt(cgit_repo->owner);
html("</td><td>");
print_modtime(cgit_repo);
html("</td><td>");
html_link_open(cgit_repourl(cgit_repo->url),
"Summary", "button");
html("S</a>");
- html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
- "Log", "button");
- html("L</a>");
+ cgit_log_link("L", "Log", "button", NULL, NULL, NULL);
cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
html("</td></tr>\n");
}
html("</table>");
cgit_print_docend();
}
diff --git a/ui-shared.c b/ui-shared.c
index 657e8af..64ee79c 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -66,153 +66,165 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
pagename, query);
else
return fmt("%s/%s/%s/", cgit_virtual_root, reponame,
pagename);
} else {
if (query)
return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
else
return fmt("?r=%s&amp;p=%s", reponame, pagename);
}
}
char *cgit_currurl()
{
if (!cgit_virtual_root)
return cgit_script_name;
else if (cgit_query_page)
return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
else if (cgit_query_repo)
return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
else
return fmt("%s/", cgit_virtual_root);
}
static char *repolink(char *title, char *class, char *page, char *head,
char *path)
{
char *delim = "?";
html("<a");
if (title) {
html(" title='");
html_attr(title);
html("'");
}
if (class) {
html(" class='");
html_attr(class);
html("'");
}
html(" href='");
if (cgit_virtual_root) {
html_attr(cgit_virtual_root);
if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
html("/");
html_attr(cgit_repo->url);
if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
html("/");
html(page);
html("/");
if (path)
html_attr(path);
} else {
html(cgit_script_name);
html("?url=");
html_attr(cgit_repo->url);
if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
html("/");
html(page);
html("/");
if (path)
html_attr(path);
delim = "&amp;";
}
- if (head && strcmp(head, cgit_query_head)) {
+ if (head && strcmp(head, cgit_repo->defbranch)) {
html(delim);
html("h=");
html_attr(head);
delim = "&amp;";
}
return fmt("%s", delim);
}
-void cgit_tree_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+static char *reporevlink(char *page, char *name, char *title, char *class,
+ char *head, char *rev, char *path)
{
char *delim;
- delim = repolink(title, class, "tree", head, path);
+ delim = repolink(title, class, page, head, path);
if (rev && strcmp(rev, cgit_query_head)) {
html(delim);
html("id=");
html_attr(rev);
}
html("'>");
html_txt(name);
html("</a>");
}
+void cgit_tree_link(char *name, char *title, char *class, char *head,
+ char *rev, char *path)
+{
+ reporevlink("tree", name, title, class, head, rev, path);
+}
+
+void cgit_log_link(char *name, char *title, char *class, char *head,
+ char *rev, char *path)
+{
+ reporevlink("log", name, title, class, head, rev, path);
+}
+
void cgit_print_date(time_t secs, char *format)
{
char buf[64];
struct tm *time;
time = gmtime(&secs);
strftime(buf, sizeof(buf)-1, format, time);
html_txt(buf);
}
void cgit_print_age(time_t t, time_t max_relative, char *format)
{
time_t now, secs;
time(&now);
secs = now - t;
if (secs > max_relative && max_relative >= 0) {
cgit_print_date(t, format);
return;
}
if (secs < TM_HOUR * 2) {
htmlf("<span class='age-mins'>%.0f min.</span>",
secs * 1.0 / TM_MIN);
return;
}
if (secs < TM_DAY * 2) {
htmlf("<span class='age-hours'>%.0f hours</span>",
secs * 1.0 / TM_HOUR);
return;
}
if (secs < TM_WEEK * 2) {
htmlf("<span class='age-days'>%.0f days</span>",
secs * 1.0 / TM_DAY);
return;
}
if (secs < TM_MONTH * 2) {
htmlf("<span class='age-weeks'>%.0f weeks</span>",
secs * 1.0 / TM_WEEK);
return;
}
if (secs < TM_YEAR * 2) {
htmlf("<span class='age-months'>%.0f months</span>",
secs * 1.0 / TM_MONTH);
return;
}
htmlf("<span class='age-years'>%.0f years</span>",
secs * 1.0 / TM_YEAR);
}
void cgit_print_docstart(char *title, struct cacheitem *item)
{
html("Content-Type: text/html; charset=utf-8\n");
htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
htmlf("Expires: %s\n", http_date(item->st.st_mtime +
ttl_seconds(item->ttl)));
html("\n");
html(cgit_doctype);
html("<html>\n");
html("<head>\n");
html("<title>");
html_txt(title);
html("</title>\n");
diff --git a/ui-summary.c b/ui-summary.c
index 4bda4c2..29b76e3 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,96 +1,92 @@
/* ui-summary.c: functions for generating repo summary page
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
static int header;
static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
struct commit *commit;
struct commitinfo *info;
char buf[256], *url;
strncpy(buf, refname, sizeof(buf));
commit = lookup_commit(sha1);
// object is not really parsed at this point, because of some fallout
// from previous calls to git functions in cgit_print_log()
commit->object.parsed = 0;
if (commit && !parse_commit(commit)){
info = cgit_parse_commit(commit);
html("<tr><td>");
- url = cgit_pageurl(cgit_query_repo, "log",
- fmt("h=%s", refname));
- html_link_open(url, NULL, NULL);
- html_txt(buf);
- html_link_close();
+ cgit_log_link(refname, NULL, NULL, refname, NULL, NULL);
html("</td><td>");
cgit_print_age(commit->date, -1, NULL);
html("</td><td>");
html_txt(info->author);
html("</td><td>");
url = cgit_pageurl(cgit_query_repo, "commit",
fmt("h=%s", sha1_to_hex(sha1)));
html_link_open(url, NULL, NULL);
html_ntxt(cgit_max_msg_len, info->subject);
html_link_close();
html("</td></tr>\n");
cgit_free_commitinfo(info);
} else {
html("<tr><td>");
html_txt(buf);
html("</td><td colspan='3'>");
htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
html("</td></tr>\n");
}
return 0;
}
static void cgit_print_object_ref(struct object *obj)
{
char *page, *arg, *url;
if (obj->type == OBJ_COMMIT) {
page = "commit";
arg = "h";
} else if (obj->type == OBJ_TREE) {
page = "tree";
arg = "id";
} else {
page = "view";
arg = "id";
}
url = cgit_pageurl(cgit_query_repo, page,
fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
html_link_open(url, NULL, NULL);
htmlf("%s %s", typename(obj->type),
sha1_to_hex(obj->sha1));
html_link_close();
}
static void print_tag_header()
{
html("<tr class='nohover'><th class='left'>Tag</th>"
"<th class='left'>Age</th>"
"<th class='left'>Author</th>"
"<th class='left'>Reference</th></tr>\n");
header = 1;
}
static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
struct tag *tag;
struct taginfo *info;
struct object *obj;
char buf[256], *url;
strncpy(buf, refname, sizeof(buf));
diff --git a/ui-tree.c b/ui-tree.c
index d503bee..e16b638 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -31,136 +31,132 @@ static void print_object(const unsigned char *sha1, char *path)
sha1_to_hex(sha1)));
return;
}
html("<table class='blob'>\n");
idx = 0;
start = 0;
lineno = 0;
while(idx < size) {
if (buf[idx] == '\n') {
buf[idx] = '\0';
htmlf("<tr><td class='no'>%d</td><td class='txt'>",
++lineno);
html_txt(buf + start);
html("</td></tr>\n");
start = idx + 1;
}
idx++;
}
html("</table>\n");
}
static int ls_item(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned int mode, int stage)
{
char *name;
char *fullpath;
enum object_type type;
unsigned long size = 0;
char *url, *qry;
name = xstrdup(pathname);
fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
cgit_query_path ? "/" : "", name);
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
name,
sha1_to_hex(sha1));
return 0;
}
html("<tr><td class='ls-mode'>");
html_filemode(mode);
html("</td><td>");
if (S_ISDIRLNK(mode)) {
htmlf("<a class='ls-mod' href='");
html_attr(fmt(cgit_repo->module_link,
name,
sha1_to_hex(sha1)));
html("'>");
html_txt(name);
html("</a>");
} else if (S_ISDIR(mode)) {
cgit_tree_link(name, NULL, "ls-dir", cgit_query_head,
curr_rev, fullpath);
} else {
cgit_tree_link(name, NULL, "ls-blob", cgit_query_head,
curr_rev, fullpath);
}
htmlf("</td><td class='ls-size'>%li</td>", size);
- html("<td><a href='");
- qry = fmt("h=%s&amp;path=%s%s%s", curr_rev,
- cgit_query_path ? cgit_query_path : "",
- cgit_query_path ? "/" : "", pathname);
- url = cgit_pageurl(cgit_query_repo, "log", qry);
- html_attr(url);
- html("' title='Log' class='button'>L</a></td>");
- html("</tr>\n");
+ html("<td>");
+ cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev,
+ fullpath);
+ html("</td></tr>\n");
free(name);
return 0;
}
static void ls_head()
{
html("<table class='list'>\n");
html("<tr class='nohover'>");
html("<th class='left'>Mode</th>");
html("<th class='left'>Name</th>");
html("<th class='right'>Size</th>");
html("<th/>");
html("</tr>\n");
header = 1;
}
static void ls_tail()
{
if (!header)
return;
html("</table>\n");
header = 0;
}
static void ls_tree(const unsigned char *sha1, char *path)
{
struct tree *tree;
tree = parse_tree_indirect(sha1);
if (!tree) {
cgit_print_error(fmt("Not a tree object: %s",
sha1_to_hex(sha1)));
return;
}
ls_head();
read_tree_recursive(tree, "", 0, 1, NULL, ls_item);
ls_tail();
}
static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned mode, int stage)
{
static int state;
static char buffer[PATH_MAX];
char *url;
if (state == 0) {
memcpy(buffer, base, baselen);
strcpy(buffer+baselen, pathname);
url = cgit_pageurl(cgit_query_repo, "tree",
fmt("h=%s&amp;path=%s", curr_rev, buffer));
html("/");
cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
curr_rev, buffer);
if (strcmp(match_path, buffer))
return READ_TREE_RECURSIVE;
if (S_ISDIR(mode)) {
state = 1;
ls_head();
return READ_TREE_RECURSIVE;