summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h3
-rw-r--r--ui-commit.c10
-rw-r--r--ui-repolist.c35
-rw-r--r--ui-shared.c64
-rw-r--r--ui-tree.c33
5 files changed, 107 insertions, 38 deletions
diff --git a/cgit.h b/cgit.h
index b93e2e8..9a19c97 100644
--- a/cgit.h
+++ b/cgit.h
@@ -198,12 +198,15 @@ 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_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);
diff --git a/ui-commit.c b/ui-commit.c
index ed5384d..885f870 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -150,12 +150,13 @@ void cgit_print_commit(const char *hex)
struct commit *commit, *parent;
struct commitinfo *info;
struct commit_list *p;
unsigned char sha1[20];
char *query;
char *filename;
+ char *tmp;
int i;
if (get_sha1(hex, sha1)) {
cgit_print_error(fmt("Bad object id: %s", hex));
return;
}
@@ -178,16 +179,17 @@ void cgit_print_commit(const char *hex)
html_txt(info->committer);
html(" ");
html_txt(info->committer_email);
html("</td><td class='right'>");
cgit_print_date(info->committer_date, FMT_LONGDATE);
html("</td></tr>\n");
- html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
- query = fmt("h=%s", sha1_to_hex(commit->object.sha1));
- html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
- htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
+ html("<tr><th>tree</th><td colspan='2' class='sha1'>");
+ tmp = xstrdup(hex);
+ cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
+ cgit_query_head, tmp, NULL);
+ html("</td></tr>\n");
for (p = commit->parents; p ; p = p->next) {
parent = lookup_commit_reference(p->item->object.sha1);
if (!parent) {
html("<tr><td colspan='3'>");
cgit_print_error("Error reading parent commit");
html("</td></tr>");
diff --git a/ui-repolist.c b/ui-repolist.c
index e5c6c20..8ade91a 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -41,13 +41,12 @@ static void print_modtime(struct repoinfo *repo)
return;
cgit_print_age(s.st_mtime, -1, NULL);
}
void cgit_print_repolist(struct cacheitem *item)
{
- struct repoinfo *repo;
int i;
char *last_group = NULL;
cgit_print_docstart(cgit_root_title, item);
cgit_print_pageheader(cgit_root_title, 0);
@@ -62,42 +61,40 @@ void cgit_print_repolist(struct cacheitem *item)
"<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++) {
- repo = &cgit_repolist.repos[i];
- if ((last_group == NULL && repo->group != NULL) ||
- (last_group != NULL && repo->group == NULL) ||
- (last_group != NULL && repo->group!= NULL &&
- strcmp(repo->group, last_group))) {
+ 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(repo->group);
+ html_txt(cgit_repo->group);
html("</td></tr>");
- last_group = repo->group;
+ last_group = cgit_repo->group;
}
htmlf("<tr><td class='%s'>",
- repo->group ? "sublevel-repo" : "toplevel-repo");
- html_link_open(cgit_repourl(repo->url), repo->desc, NULL);
- html_txt(repo->name);
+ 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, repo->desc);
+ html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
html("</td><td>");
- html_txt(repo->owner);
+ html_txt(cgit_repo->owner);
html("</td><td>");
- print_modtime(repo);
+ print_modtime(cgit_repo);
html("</td><td>");
- html_link_open(cgit_repourl(repo->url),
+ html_link_open(cgit_repourl(cgit_repo->url),
"Summary", "button");
html("S</a>");
- html_link_open(cgit_pageurl(repo->name, "log", NULL),
+ html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
"Log", "button");
html("L</a>");
- html_link_open(cgit_pageurl(repo->name, "tree", NULL),
- "Files", "button");
- html("F</a>");
+ 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 aba93e8..9ab6409 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -84,12 +84,76 @@ char *cgit_currurl()
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 && 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)
{
char buf[64];
struct tm *time;
diff --git a/ui-tree.c b/ui-tree.c
index db0bef6..3b82374 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -52,45 +52,50 @@ static void print_object(const unsigned char *sha1, char *path)
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;
}
- 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_filemode(mode);
html("</td><td ");
if (S_ISDIRLNK(mode)) {
htmlf("class='ls-mod'><a href='");
html_attr(fmt(cgit_repo->module_link,
name,
sha1_to_hex(sha1)));
+ html("'>");
+ html_txt(name);
+ html("</a>");
} else if (S_ISDIR(mode)) {
- html("class='ls-dir'><a href='");
- html_attr(url);
+ html("class='ls-dir'>");
+ cgit_tree_link(name, NULL, NULL, cgit_query_head,
+ curr_rev, fullpath);
} else {
- html("class='ls-blob'><a href='");
- html_attr(url);
+ html("class='ls-blob'>");
+ cgit_tree_link(name, NULL, NULL, cgit_query_head,
+ curr_rev, fullpath);
}
- htmlf("'>%s</a></td>", name);
- htmlf("<td class='filesize'>%li</td>", size);
+ htmlf("</td><td class='filesize'>%li</td>", size);
html("<td class='links'><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);
@@ -147,17 +152,15 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
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));
- htmlf(" / <a href='");
- html_attr(url);
- html("'>");
- html_txt(xstrdup(pathname));
- html("</a>");
+ 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;