Add and use cgit_tree_link()

This creates a new function used to generate links to 'tree' page and uses
the function everywhere a link to the 'tree' page is generated.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
This commit is contained in:
Lars Hjemli 2007-06-17 01:23:08 +02:00
والد f91b9696a3
کامیت 44947bfcdc
5فایلهای تغییر یافته به همراه107 افزوده شده و 38 حذف شده

3
cgit.h
مشاهده پرونده

@ -201,6 +201,9 @@ extern char *cgit_repourl(const char *reponame);
extern char *cgit_pageurl(const char *reponame, const char *pagename, extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query); const char *query);
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_print_error(char *msg); extern void cgit_print_error(char *msg);
extern void cgit_print_date(time_t secs, char *format); 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_age(time_t t, time_t max_relative, char *format);

مشاهده پرونده

@ -153,6 +153,7 @@ void cgit_print_commit(const char *hex)
unsigned char sha1[20]; unsigned char sha1[20];
char *query; char *query;
char *filename; char *filename;
char *tmp;
int i; int i;
if (get_sha1(hex, sha1)) { if (get_sha1(hex, sha1)) {
@ -181,10 +182,11 @@ void cgit_print_commit(const char *hex)
html("</td><td class='right'>"); html("</td><td class='right'>");
cgit_print_date(info->committer_date, FMT_LONGDATE); cgit_print_date(info->committer_date, FMT_LONGDATE);
html("</td></tr>\n"); html("</td></tr>\n");
html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); html("<tr><th>tree</th><td colspan='2' class='sha1'>");
query = fmt("h=%s", sha1_to_hex(commit->object.sha1)); tmp = xstrdup(hex);
html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); cgit_query_head, tmp, NULL);
html("</td></tr>\n");
for (p = commit->parents; p ; p = p->next) { for (p = commit->parents; p ; p = p->next) {
parent = lookup_commit_reference(p->item->object.sha1); parent = lookup_commit_reference(p->item->object.sha1);
if (!parent) { if (!parent) {

مشاهده پرونده

@ -44,7 +44,6 @@ static void print_modtime(struct repoinfo *repo)
void cgit_print_repolist(struct cacheitem *item) void cgit_print_repolist(struct cacheitem *item)
{ {
struct repoinfo *repo;
int i; int i;
char *last_group = NULL; char *last_group = NULL;
@ -65,37 +64,35 @@ void cgit_print_repolist(struct cacheitem *item)
"<th>Links</th></tr>\n"); "<th>Links</th></tr>\n");
for (i=0; i<cgit_repolist.count; i++) { for (i=0; i<cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i]; cgit_repo = &cgit_repolist.repos[i];
if ((last_group == NULL && repo->group != NULL) || if ((last_group == NULL && cgit_repo->group != NULL) ||
(last_group != NULL && repo->group == NULL) || (last_group != NULL && cgit_repo->group == NULL) ||
(last_group != NULL && repo->group!= NULL && (last_group != NULL && cgit_repo->group != NULL &&
strcmp(repo->group, last_group))) { strcmp(cgit_repo->group, last_group))) {
html("<tr class='nohover'><td colspan='4' class='repogroup'>"); html("<tr class='nohover'><td colspan='4' class='repogroup'>");
html_txt(repo->group); html_txt(cgit_repo->group);
html("</td></tr>"); html("</td></tr>");
last_group = repo->group; last_group = cgit_repo->group;
} }
htmlf("<tr><td class='%s'>", htmlf("<tr><td class='%s'>",
repo->group ? "sublevel-repo" : "toplevel-repo"); cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
html_link_open(cgit_repourl(repo->url), repo->desc, NULL); html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
html_txt(repo->name); html_txt(cgit_repo->name);
html_link_close(); html_link_close();
html("</td><td>"); html("</td><td>");
html_ntxt(cgit_max_repodesc_len, repo->desc); html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
html("</td><td>"); html("</td><td>");
html_txt(repo->owner); html_txt(cgit_repo->owner);
html("</td><td>"); html("</td><td>");
print_modtime(repo); print_modtime(cgit_repo);
html("</td><td>"); html("</td><td>");
html_link_open(cgit_repourl(repo->url), html_link_open(cgit_repourl(cgit_repo->url),
"Summary", "button"); "Summary", "button");
html("S</a>"); html("S</a>");
html_link_open(cgit_pageurl(repo->name, "log", NULL), html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
"Log", "button"); "Log", "button");
html("L</a>"); html("L</a>");
html_link_open(cgit_pageurl(repo->name, "tree", NULL), cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
"Files", "button");
html("F</a>");
html("</td></tr>\n"); html("</td></tr>\n");
} }
html("</table>"); html("</table>");

مشاهده پرونده

@ -87,6 +87,70 @@ char *cgit_currurl()
return fmt("%s/", cgit_virtual_root); 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 && head != cgit_query_head) {
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)
{
char *delim;
delim = repolink(title, class, "tree", head, path);
if (rev && rev != cgit_query_head) {
html(delim);
html("id=");
html_attr(rev);
}
html("'>");
html_txt(name);
html("</a>");
}
void cgit_print_date(time_t secs, char *format) void cgit_print_date(time_t secs, char *format)
{ {

مشاهده پرونده

@ -55,11 +55,15 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned int mode, int stage) const char *pathname, unsigned int mode, int stage)
{ {
char *name; char *name;
char *fullpath;
enum object_type type; enum object_type type;
unsigned long size = 0; unsigned long size = 0;
char *url, *qry; char *url, *qry;
name = xstrdup(pathname); name = xstrdup(pathname);
fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
cgit_query_path ? "/" : "", name);
type = sha1_object_info(sha1, &size); type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
@ -67,10 +71,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
sha1_to_hex(sha1)); sha1_to_hex(sha1));
return 0; return 0;
} }
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, "tree", qry);
html("<tr><td class='filemode'>"); html("<tr><td class='filemode'>");
html_filemode(mode); html_filemode(mode);
html("</td><td "); html("</td><td ");
@ -79,15 +80,19 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
html_attr(fmt(cgit_repo->module_link, html_attr(fmt(cgit_repo->module_link,
name, name,
sha1_to_hex(sha1))); sha1_to_hex(sha1)));
html("'>");
html_txt(name);
html("</a>");
} else if (S_ISDIR(mode)) { } else if (S_ISDIR(mode)) {
html("class='ls-dir'><a href='"); html("class='ls-dir'>");
html_attr(url); cgit_tree_link(name, NULL, NULL, cgit_query_head,
curr_rev, fullpath);
} else { } else {
html("class='ls-blob'><a href='"); html("class='ls-blob'>");
html_attr(url); cgit_tree_link(name, NULL, NULL, cgit_query_head,
curr_rev, fullpath);
} }
htmlf("'>%s</a></td>", name); htmlf("</td><td class='filesize'>%li</td>", size);
htmlf("<td class='filesize'>%li</td>", size);
html("<td class='links'><a href='"); html("<td class='links'><a href='");
qry = fmt("h=%s&amp;path=%s%s%s", curr_rev, qry = fmt("h=%s&amp;path=%s%s%s", curr_rev,
@ -150,11 +155,9 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
strcpy(buffer+baselen, pathname); strcpy(buffer+baselen, pathname);
url = cgit_pageurl(cgit_query_repo, "tree", url = cgit_pageurl(cgit_query_repo, "tree",
fmt("h=%s&amp;path=%s", curr_rev, buffer)); fmt("h=%s&amp;path=%s", curr_rev, buffer));
htmlf(" / <a href='"); html("/");
html_attr(url); cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
html("'>"); curr_rev, buffer);
html_txt(xstrdup(pathname));
html("</a>");
if (strcmp(match_path, buffer)) if (strcmp(match_path, buffer))
return READ_TREE_RECURSIVE; return READ_TREE_RECURSIVE;