summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c6
-rw-r--r--cgit.css10
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt2
-rw-r--r--cmd.c46
-rw-r--r--cmd.h3
-rw-r--r--shared.c1
-rw-r--r--ui-commit.c20
-rw-r--r--ui-commit.h2
-rw-r--r--ui-diff.c8
-rw-r--r--ui-log.c27
-rw-r--r--ui-patch.c6
-rw-r--r--ui-patch.h2
-rw-r--r--ui-refs.c2
-rw-r--r--ui-shared.c216
-rw-r--r--ui-shared.h70
-rw-r--r--ui-tree.c15
17 files changed, 274 insertions, 163 deletions
diff --git a/cgit.c b/cgit.c
index 38bc136..d4fcfa7 100644
--- a/cgit.c
+++ b/cgit.c
@@ -435,2 +435,8 @@ static void process_request(void *cbdata)
+ /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
+ * in-project path limit to be made available at ctx->qry.vpath.
+ * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
+ */
+ ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL;
+
if (cmd->want_repo && !ctx->repo) {
diff --git a/cgit.css b/cgit.css
index 6198403..6e47eb3 100644
--- a/cgit.css
+++ b/cgit.css
@@ -66,3 +66,3 @@ table#header td.sub {
table.tabs {
- /* border-bottom: solid 2px #ccc; */
+ border-bottom: solid 3px #ccc;
border-collapse: collapse;
@@ -104,2 +104,9 @@ table.tabs td.form select {
+div.path {
+ margin: 0px;
+ padding: 5px 2em 2px 2em;
+ color: #000;
+ background-color: #eee;
+}
+
div.content {
@@ -107,3 +114,2 @@ div.content {
padding: 2em;
- border-top: solid 3px #ccc;
border-bottom: solid 3px #ccc;
diff --git a/cgit.h b/cgit.h
index 8884f9e..80c3902 100644
--- a/cgit.h
+++ b/cgit.h
@@ -149,2 +149,3 @@ struct cgit_query {
int show_all;
+ char *vpath;
};
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 5c24381..a853522 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -446,3 +446,3 @@ snapshots=tar.gz tar.bz2 zip
-mimetype.git=image/git
+mimetype.gif=image/gif
mimetype.html=text/html
diff --git a/cmd.c b/cmd.c
index ad784fc..6dc9f5e 100644
--- a/cmd.c
+++ b/cmd.c
@@ -53,3 +53,3 @@ static void commit_fn(struct cgit_context *ctx)
{
- cgit_print_commit(ctx->qry.sha1);
+ cgit_print_commit(ctx->qry.sha1, ctx->qry.path);
}
@@ -92,3 +92,3 @@ static void patch_fn(struct cgit_context *ctx)
{
- cgit_print_patch(ctx->qry.sha1);
+ cgit_print_patch(ctx->qry.sha1, ctx->qry.path);
}
@@ -131,4 +131,4 @@ static void tree_fn(struct cgit_context *ctx)
-#define def_cmd(name, want_repo, want_layout) \
- {#name, name##_fn, want_repo, want_layout}
+#define def_cmd(name, want_repo, want_layout, want_vpath) \
+ {#name, name##_fn, want_repo, want_layout, want_vpath}
@@ -137,21 +137,21 @@ struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
static struct cgit_cmd cmds[] = {
- def_cmd(HEAD, 1, 0),
- def_cmd(atom, 1, 0),
- def_cmd(about, 0, 1),
- def_cmd(blob, 1, 0),
- def_cmd(commit, 1, 1),
- def_cmd(diff, 1, 1),
- def_cmd(info, 1, 0),
- def_cmd(log, 1, 1),
- def_cmd(ls_cache, 0, 0),
- def_cmd(objects, 1, 0),
- def_cmd(patch, 1, 0),
- def_cmd(plain, 1, 0),
- def_cmd(refs, 1, 1),
- def_cmd(repolist, 0, 0),
- def_cmd(snapshot, 1, 0),
- def_cmd(stats, 1, 1),
- def_cmd(summary, 1, 1),
- def_cmd(tag, 1, 1),
- def_cmd(tree, 1, 1),
+ def_cmd(HEAD, 1, 0, 0),
+ def_cmd(atom, 1, 0, 0),
+ def_cmd(about, 0, 1, 0),
+ def_cmd(blob, 1, 0, 0),
+ def_cmd(commit, 1, 1, 1),
+ def_cmd(diff, 1, 1, 1),
+ def_cmd(info, 1, 0, 0),
+ def_cmd(log, 1, 1, 1),
+ def_cmd(ls_cache, 0, 0, 0),
+ def_cmd(objects, 1, 0, 0),
+ def_cmd(patch, 1, 0, 1),
+ def_cmd(plain, 1, 0, 0),
+ def_cmd(refs, 1, 1, 0),
+ def_cmd(repolist, 0, 0, 0),
+ def_cmd(snapshot, 1, 0, 0),
+ def_cmd(stats, 1, 1, 1),
+ def_cmd(summary, 1, 1, 0),
+ def_cmd(tag, 1, 1, 0),
+ def_cmd(tree, 1, 1, 1),
};
diff --git a/cmd.h b/cmd.h
index ec9e691..8dc01bd 100644
--- a/cmd.h
+++ b/cmd.h
@@ -9,3 +9,4 @@ struct cgit_cmd {
unsigned int want_repo:1,
- want_layout:1;
+ want_layout:1,
+ want_vpath:1;
};
diff --git a/shared.c b/shared.c
index 8b3a045..58837dc 100644
--- a/shared.c
+++ b/shared.c
@@ -12,3 +12,2 @@ struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
-int cgit_cmd;
diff --git a/ui-commit.c b/ui-commit.c
index 41313b9..a11bc5f 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -14,3 +14,3 @@
-void cgit_print_commit(char *hex)
+void cgit_print_commit(char *hex, const char *prefix)
{
@@ -60,10 +60,10 @@ void cgit_print_commit(char *hex)
tmp = sha1_to_hex(commit->object.sha1);
- cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, 0);
+ cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
html(" (");
- cgit_patch_link("patch", NULL, NULL, NULL, tmp);
+ cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
html(") (");
if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
- cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, 1);
+ cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
else
- cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, 1);
+ cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
html(")</td></tr>\n");
@@ -73,2 +73,6 @@ void cgit_print_commit(char *hex)
ctx.qry.head, tmp, NULL);
+ if (prefix) {
+ html(" /");
+ cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
+ }
html("</td></tr>\n");
@@ -89,6 +93,6 @@ void cgit_print_commit(char *hex)
}
- cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, 0);
+ cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
html(" (");
cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
- sha1_to_hex(p->item->object.sha1), NULL, 0);
+ sha1_to_hex(p->item->object.sha1), prefix, 0);
html(")</td></tr>");
@@ -123,3 +127,3 @@ void cgit_print_commit(char *hex)
tmp = NULL;
- cgit_print_diff(ctx.qry.sha1, tmp, NULL);
+ cgit_print_diff(ctx.qry.sha1, tmp, prefix);
}
diff --git a/ui-commit.h b/ui-commit.h
index 40bcb31..8198b4b 100644
--- a/ui-commit.h
+++ b/ui-commit.h
@@ -3,3 +3,3 @@
-extern void cgit_print_commit(char *hex);
+extern void cgit_print_commit(char *hex, const char *prefix);
diff --git a/ui-diff.c b/ui-diff.c
index a92a768..fb836df 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -156,3 +156,3 @@ static void inspect_filepair(struct diff_filepair *pair)
void cgit_print_diffstat(const unsigned char *old_sha1,
- const unsigned char *new_sha1)
+ const unsigned char *new_sha1, const char *prefix)
{
@@ -163,2 +163,4 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
ctx.qry.sha2, NULL, 0);
+ if (prefix)
+ htmlf(" (limited to '%s')", prefix);
html("</div>");
@@ -166,3 +168,3 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
max_changes = 0;
- cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL);
+ cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix);
for(i = 0; i<files; i++)
@@ -340,3 +342,3 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
print_ssdiff_link();
- cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
+ cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
diff --git a/ui-log.c b/ui-log.c
index 0947604..bfbe436 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -48,4 +48,5 @@ void show_commit_decorations(struct commit *commit)
strncpy(buf, deco->name + 11, sizeof(buf) - 1);
- cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
- 0, NULL, NULL, ctx.qry.showmsg);
+ cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
+ ctx.qry.vpath, 0, NULL, NULL,
+ ctx.qry.showmsg);
}
@@ -62,4 +63,5 @@ void show_commit_decorations(struct commit *commit)
cgit_log_link(buf, NULL, "remote-deco", NULL,
- sha1_to_hex(commit->object.sha1), NULL,
- 0, NULL, NULL, ctx.qry.showmsg);
+ sha1_to_hex(commit->object.sha1),
+ ctx.qry.vpath, 0, NULL, NULL,
+ ctx.qry.showmsg);
}
@@ -68,3 +70,4 @@ void show_commit_decorations(struct commit *commit)
cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
- sha1_to_hex(commit->object.sha1), 0);
+ sha1_to_hex(commit->object.sha1),
+ ctx.qry.vpath, 0);
}
@@ -84,3 +87,3 @@ void print_commit(struct commit *commit)
tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
- tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
+ tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp);
html_link_open(tmp, NULL, NULL);
@@ -91,3 +94,3 @@ void print_commit(struct commit *commit)
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
- sha1_to_hex(commit->object.sha1), 0);
+ sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
show_commit_decorations(commit);
@@ -178,3 +181,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
NULL, ctx.qry.head, ctx.qry.sha1,
- ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
+ ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep,
ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
@@ -215,3 +218,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
- ctx.qry.sha1, ctx.qry.path,
+ ctx.qry.sha1, ctx.qry.vpath,
ofs - cnt, ctx.qry.grep,
@@ -222,3 +225,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
- ctx.qry.sha1, ctx.qry.path,
+ ctx.qry.sha1, ctx.qry.vpath,
ofs + cnt, ctx.qry.grep,
@@ -229,4 +232,4 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
html("<tr class='nohover'><td colspan='3'>");
- cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
- NULL, NULL, ctx.qry.showmsg);
+ cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL,
+ ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg);
html("</td></tr>\n");
diff --git a/ui-patch.c b/ui-patch.c
index 2a8f7a5..25dc9fe 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -79,3 +79,3 @@ static void filepair_cb(struct diff_filepair *pair)
-void cgit_print_patch(char *hex)
+void cgit_print_patch(char *hex, const char *prefix)
{
@@ -124,3 +124,5 @@ void cgit_print_patch(char *hex)
html("---\n");
- cgit_diff_tree(old_sha1, sha1, filepair_cb, NULL);
+ if (prefix)
+ htmlf("(limited to '%s')\n\n", prefix);
+ cgit_diff_tree(old_sha1, sha1, filepair_cb, prefix);
html("--\n");
diff --git a/ui-patch.h b/ui-patch.h
index 9f68212..1641cea 100644
--- a/ui-patch.h
+++ b/ui-patch.h
@@ -3,3 +3,3 @@
-extern void cgit_print_patch(char *hex);
+extern void cgit_print_patch(char *hex, const char *prefix);
diff --git a/ui-refs.c b/ui-refs.c
index 98738db..94ff6be 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -76,3 +76,3 @@ static int print_branch(struct refinfo *ref)
if (ref->object->type == OBJ_COMMIT) {
- cgit_commit_link(info->subject, NULL, NULL, name, NULL, 0);
+ cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0);
html("</td><td>");
diff --git a/ui-shared.c b/ui-shared.c
index 8827fff..e991799 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -29,3 +29,3 @@ static char *http_date(time_t t)
-void cgit_print_error(char *msg)
+void cgit_print_error(const char *msg)
{
@@ -135,3 +135,3 @@ char *cgit_currurl()
-static void site_url(char *page, char *search, int ofs)
+static void site_url(const char *page, const char *search, int ofs)
{
@@ -162,4 +162,4 @@ static void site_url(char *page, char *search, int ofs)
-static void site_link(char *page, char *name, char *title, char *class,
- char *search, int ofs)
+static void site_link(const char *page, const char *name, const char *title,
+ const char *class, const char *search, int ofs)
{
@@ -183,4 +183,4 @@ static void site_link(char *page, char *name, char *title, char *class,
-void cgit_index_link(char *name, char *title, char *class, char *pattern,
- int ofs)
+void cgit_index_link(const char *name, const char *title, const char *class,
+ const char *pattern, int ofs)
{
@@ -189,4 +189,4 @@ void cgit_index_link(char *name, char *title, char *class, char *pattern,
-static char *repolink(char *title, char *class, char *page, char *head,
- char *path)
+static char *repolink(const char *title, const char *class, const char *page,
+ const char *head, const char *path)
{
@@ -242,4 +242,5 @@ static char *repolink(char *title, char *class, char *page, char *head,
-static void reporevlink(char *page, char *name, char *title, char *class,
- char *head, char *rev, char *path)
+static void reporevlink(const char *page, const char *name, const char *title,
+ const char *class, const char *head, const char *rev,
+ const char *path)
{
@@ -258,3 +259,4 @@ static void reporevlink(char *page, char *name, char *title, char *class,
-void cgit_summary_link(char *name, char *title, char *class, char *head)
+void cgit_summary_link(const char *name, const char *title, const char *class,
+ const char *head)
{
@@ -263,4 +265,4 @@ void cgit_summary_link(char *name, char *title, char *class, char *head)
-void cgit_tag_link(char *name, char *title, char *class, char *head,
- char *rev)
+void cgit_tag_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev)
{
@@ -269,4 +271,4 @@ void cgit_tag_link(char *name, char *title, char *class, char *head,
-void cgit_tree_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_tree_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
@@ -275,4 +277,4 @@ void cgit_tree_link(char *name, char *title, char *class, char *head,
-void cgit_plain_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_plain_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
@@ -281,5 +283,5 @@ void cgit_plain_link(char *name, char *title, char *class, char *head,
-void cgit_log_link(char *name, char *title, char *class, char *head,
- char *rev, char *path, int ofs, char *grep, char *pattern,
- int showmsg)
+void cgit_log_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path,
+ int ofs, const char *grep, const char *pattern, int showmsg)
{
@@ -318,4 +320,5 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
-void cgit_commit_link(char *name, char *title, char *class, char *head,
- char *rev, int toggle_ssdiff)
+void cgit_commit_link(char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path,
+ int toggle_ssdiff)
{
@@ -330,3 +333,3 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
- delim = repolink(title, class, "commit", head, NULL);
+ delim = repolink(title, class, "commit", head, path);
if (rev && strcmp(rev, ctx.qry.head)) {
@@ -346,4 +349,4 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
-void cgit_refs_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_refs_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
@@ -352,4 +355,5 @@ void cgit_refs_link(char *name, char *title, char *class, char *head,
-void cgit_snapshot_link(char *name, char *title, char *class, char *head,
- char *rev, char *archivename)
+void cgit_snapshot_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev,
+ const char *archivename)
{
@@ -358,5 +362,5 @@ void cgit_snapshot_link(char *name, char *title, char *class, char *head,
-void cgit_diff_link(char *name, char *title, char *class, char *head,
- char *new_rev, char *old_rev, char *path,
- int toggle_ssdiff)
+void cgit_diff_link(const char *name, const char *title, const char *class,
+ const char *head, const char *new_rev, const char *old_rev,
+ const char *path, int toggle_ssdiff)
{
@@ -386,10 +390,10 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
-void cgit_patch_link(char *name, char *title, char *class, char *head,
- char *rev)
+void cgit_patch_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
- reporevlink("patch", name, title, class, head, rev, NULL);
+ reporevlink("patch", name, title, class, head, rev, path);
}
-void cgit_stats_link(char *name, char *title, char *class, char *head,
- char *path)
+void cgit_stats_link(const char *name, const char *title, const char *class,
+ const char *head, const char *path)
{
@@ -398,2 +402,60 @@ void cgit_stats_link(char *name, char *title, char *class, char *head,
+void cgit_self_link(char *name, const char *title, const char *class,
+ struct cgit_context *ctx)
+{
+ if (!strcmp(ctx->qry.page, "repolist"))
+ return cgit_index_link(name, title, class, ctx->qry.search,
+ ctx->qry.ofs);
+ else if (!strcmp(ctx->qry.page, "summary"))
+ return cgit_summary_link(name, title, class, ctx->qry.head);
+ else if (!strcmp(ctx->qry.page, "tag"))
+ return cgit_tag_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL);
+ else if (!strcmp(ctx->qry.page, "tree"))
+ return cgit_tree_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
+ else if (!strcmp(ctx->qry.page, "plain"))
+ return cgit_plain_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
+ else if (!strcmp(ctx->qry.page, "log"))
+ return cgit_log_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path, ctx->qry.ofs,
+ ctx->qry.grep, ctx->qry.search,
+ ctx->qry.showmsg);
+ else if (!strcmp(ctx->qry.page, "commit"))
+ return cgit_commit_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path, 0);
+ else if (!strcmp(ctx->qry.page, "patch"))
+ return cgit_patch_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
+ else if (!strcmp(ctx->qry.page, "refs"))
+ return cgit_refs_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
+ else if (!strcmp(ctx->qry.page, "snapshot"))
+ return cgit_snapshot_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
+ else if (!strcmp(ctx->qry.page, "diff"))
+ return cgit_diff_link(name, title, class, ctx->qry.head,
+ ctx->qry.sha1, ctx->qry.sha2,
+ ctx->qry.path, 0);
+ else if (!strcmp(ctx->qry.page, "stats"))
+ return cgit_stats_link(name, title, class, ctx->qry.head,
+ ctx->qry.path);
+
+ /* Don't known how to make link for this page */
+ repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
+ html("><!-- cgit_self_link() doesn't know how to make link for page '");
+ html_txt(ctx->qry.page);
+ html("' -->");
+ html_txt(name);
+ html("</a>");
+}
+
void cgit_object_link(struct object *obj)
@@ -407,3 +469,3 @@ void cgit_object_link(struct object *obj)
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
- ctx.qry.head, fullrev, 0);
+ ctx.qry.head, fullrev, NULL, 0);
return;
@@ -419,3 +481,3 @@ void cgit_object_link(struct object *obj)
-void cgit_print_date(time_t secs, char *format, int local_time)
+void cgit_print_date(time_t secs, const char *format, int local_time)
{
@@ -434,3 +496,3 @@ void cgit_print_date(time_t secs, char *format, int local_time)
-void cgit_print_age(time_t t, time_t max_relative, char *format)
+void cgit_print_age(time_t t, time_t max_relative, const char *format)
{
@@ -533,3 +595,3 @@ void cgit_print_docstart(struct cgit_context *ctx)
html_attr(cgit_hosturl());
- html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
+ html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath,
fmt("h=%s", ctx->qry.head)));
@@ -613,3 +675,4 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
-void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
+void cgit_add_hidden_formfields(int incl_head, int incl_search,
+ const char *page)
{
@@ -619,4 +682,4 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
url = fmt("%s/%s", ctx.qry.repo, page);
- if (ctx.qry.path)
- url = fmt("%s/%s", url, ctx.qry.path);
+ if (ctx.qry.vpath)
+ url = fmt("%s/%s", url, ctx.qry.vpath);
html_hidden("url", url);
@@ -643,7 +706,26 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
-const char *fallback_cmd = "repolist";
+static const char *hc(struct cgit_context *ctx, const char *page)
+{
+ return strcmp(ctx->qry.page, page) ? NULL : "active";
+}
-char *hc(struct cgit_cmd *cmd, const char *page)
+static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path)
{
- return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
+ char *old_path = ctx->qry.path;
+ char *p = path, *q, *end = path + strlen(path);
+
+ ctx->qry.path = NULL;
+ cgit_self_link("root", NULL, NULL, ctx);
+ ctx->qry.path = p = path;
+ while (p < end) {
+ if (!(q = strchr(p, '/')))
+ q = end;
+ *q = '\0';
+ html_txt("/");
+ cgit_self_link(p, NULL, NULL, ctx);
+ if (q < end)
+ *q = '/';
+ p = q + 1;
+ }
+ ctx->qry.path = old_path;
}
@@ -699,7 +781,2 @@ void cgit_print_pageheader(struct cgit_context *ctx)
{
- struct cgit_cmd *cmd = cgit_get_cmd(ctx);
-
- if (!cmd && ctx->repo)
- fallback_cmd = "summary";
-
html("<div id='cgit'>");
@@ -710,20 +787,21 @@ void cgit_print_pageheader(struct cgit_context *ctx)
if (ctx->repo) {
- cgit_summary_link("summary", NULL, hc(cmd, "summary"),
+ cgit_summary_link("summary", NULL, hc(ctx, "summary"),
ctx->qry.head);
- cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
- ctx->qry.sha1, NULL);
- cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
- NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
- cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
+ cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head,
ctx->qry.sha1, NULL);
- cgit_commit_link("commit", NULL, hc(cmd, "commit"),
- ctx->qry.head, ctx->qry.sha1, 0);
- cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
- ctx->qry.sha1, ctx->qry.sha2, NULL, 0);
+ cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head,
+ NULL, ctx->qry.vpath, 0, NULL, NULL,
+ ctx->qry.showmsg);
+ cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head,
+ ctx->qry.sha1, ctx->qry.vpath);
+ cgit_commit_link("commit", NULL, hc(ctx, "commit"),
+ ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0);
+ cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head,
+ ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0);
if (ctx->repo->max_stats)
- cgit_stats_link("stats", NULL, hc(cmd, "stats"),
- ctx->qry.head, NULL);
+ cgit_stats_link("stats", NULL, hc(ctx, "stats"),
+ ctx->qry.head, ctx->qry.vpath);
if (ctx->repo->readme)
reporevlink("about", "about", NULL,
- hc(cmd, "about"), ctx->qry.head, NULL,
+ hc(ctx, "about"), ctx->qry.head, NULL,
NULL);
@@ -733,3 +811,3 @@ void cgit_print_pageheader(struct cgit_context *ctx)
html_url_path(cgit_fileurl(ctx->qry.repo, "log",
- ctx->qry.path, NULL));
+ ctx->qry.vpath, NULL));
html("'>\n");
@@ -747,5 +825,5 @@ void cgit_print_pageheader(struct cgit_context *ctx)
} else {
- site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
+ site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0);
if (ctx->cfg.root_readme)
- site_link("about", "about", NULL, hc(cmd, "about"),
+ site_link("about", "about", NULL, hc(ctx, "about"),
NULL, 0);
@@ -762,2 +840,8 @@ void cgit_print_pageheader(struct cgit_context *ctx)
html("</td></tr></table>\n");
+ if (ctx->qry.vpath) {
+ html("<div class='path'>");
+ html("path: ");
+ cgit_print_path_crumbs(ctx, ctx->qry.vpath);
+ html("</div>");
+ }
html("<div class='content'>");
diff --git a/ui-shared.h b/ui-shared.h
index 9ebc1f9..3cc1258 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -12,32 +12,46 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
-extern void cgit_index_link(char *name, char *title, char *class,
- char *pattern, int ofs);
-extern void cgit_summary_link(char *name, char *title, char *class, char *head);
-extern void cgit_tag_link(char *name, char *title, char *class, char *head,
- char *rev);
-extern void cgit_tree_link(char *name, char *title, char *class, char *head,
- char *rev, char *path);
-extern void cgit_plain_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, int ofs, char *grep,
- char *pattern, int showmsg);
-extern void cgit_commit_link(char *name, char *title, char *class, char *head,
- char *rev, int toggle_ssdiff);
-extern void cgit_patch_link(char *name, char *title, char *class, char *head,
- char *rev);
-extern void cgit_refs_link(char *name, char *title, char *class, char *head,
- char *rev, char *path);
-extern void cgit_snapshot_link(char *name, char *title, char *class,
- char *head, char *rev, char *archivename);
-extern void cgit_diff_link(char *name, char *title, char *class, char *head,
- char *new_rev, char *old_rev, char *path,
+extern void cgit_index_link(const char *name, const char *title,
+ const char *class, const char *pattern, int ofs);
+extern void cgit_summary_link(const char *name, const char *title,
+ const char *class, const char *head);
+extern void cgit_tag_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev);
+extern void cgit_tree_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path);
+extern void cgit_plain_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path);
+extern void cgit_log_link(const char *name, const char *title,
+ const char *class, const char *head, const char *rev,
+ const char *path, int ofs, const char *grep,
+ const char *pattern, int showmsg);
+extern void cgit_commit_link(char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path,
int toggle_ssdiff);
-extern void cgit_stats_link(char *name, char *title, char *class, char *head,
- char *path);
+extern void cgit_patch_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path);
+extern void cgit_refs_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path);
+extern void cgit_snapshot_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *archivename);
+extern void cgit_diff_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *new_rev, const char *old_rev,
+ const char *path, int toggle_ssdiff);
+extern void cgit_stats_link(const char *name, const char *title,
+ const char *class, const char *head,
+ const char *path);
+extern void cgit_self_link(char *name, const char *title,
+ const char *class, struct cgit_context *ctx);
extern void cgit_object_link(struct object *obj);
-extern void cgit_print_error(char *msg);
-extern void cgit_print_date(time_t secs, char *format, int local_time);
-extern void cgit_print_age(time_t t, time_t max_relative, char *format);
+extern void cgit_print_error(const char *msg);
+extern void cgit_print_date(time_t secs, const char *format, int local_time);
+extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
extern void cgit_print_http_headers(struct cgit_context *ctx);
@@ -50,3 +64,3 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head,
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
- char *page);
+ const char *page);
#endif /* UI_SHARED_H */
diff --git a/ui-tree.c b/ui-tree.c
index 0ee38f2..75ec9cb 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -104,6 +104,6 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
- html(" (");
+ htmlf("blob: %s (", sha1_to_hex(sha1));
cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
curr_rev, path);
- htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
+ html(")\n");
@@ -227,3 +227,2 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
static char buffer[PATH_MAX];
- char *url;
@@ -232,8 +231,2 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
strcpy(buffer+baselen, pathname);
- url = cgit_pageurl(ctx.qry.repo, "tree",
- fmt("h=%s&amp;path=%s", curr_rev, buffer));
- html("/");
- cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head,
- curr_rev, buffer);
-
if (strcmp(match_path, buffer))
@@ -280,6 +273,2 @@ void cgit_print_tree(const char *rev, char *path)
- html("path: <a href='");
- html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev)));
- html("'>root</a>");
-
if (path == NULL) {