summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-01-11 23:46:17 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-01-11 23:46:17 (UTC)
commit5cd2bf7e7f3f3daf6107cd3a269bad78e342de70 (patch) (side-by-side diff)
tree7ce9368e94b39114e772c279f741bd8106f611d2
parent2c2047ff67a1e0053f95776e5079e432f69cea54 (diff)
downloadcgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.zip
cgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.tar.gz
cgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.tar.bz2
WIP: add paths/backlinks to tree/blobview
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h3
-rw-r--r--shared.c3
-rw-r--r--ui-tree.c12
4 files changed, 15 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index a3a04d9..9535abc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -47,25 +47,25 @@ static void cgit_print_repo_page(struct cacheitem *item)
setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1);
char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc);
int show_search = 0;
if (cgit_query_page && !strcmp(cgit_query_page, "log"))
show_search = 1;
cgit_print_docstart(title, item);
cgit_print_pageheader(title, show_search);
if (!cgit_query_page) {
cgit_print_summary();
} else if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search);
} else if (!strcmp(cgit_query_page, "tree")) {
- cgit_print_tree(cgit_query_sha1);
+ cgit_print_tree(cgit_query_sha1, cgit_query_path);
} else if (!strcmp(cgit_query_page, "commit")) {
cgit_print_commit(cgit_query_sha1);
} else if (!strcmp(cgit_query_page, "view")) {
cgit_print_view(cgit_query_sha1);
} else if (!strcmp(cgit_query_page, "diff")) {
cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
}
cgit_print_docend();
}
static void cgit_fill_cache(struct cacheitem *item)
{
diff --git a/cgit.h b/cgit.h
index 3601e49..5e19b11 100644
--- a/cgit.h
+++ b/cgit.h
@@ -50,24 +50,25 @@ extern char *cgit_repo_desc;
extern char *cgit_repo_owner;
extern int cgit_query_has_symref;
extern int cgit_query_has_sha1;
extern char *cgit_querystring;
extern char *cgit_query_repo;
extern char *cgit_query_page;
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 int cgit_query_ofs;
extern int htmlfd;
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 hextoint(char c);
extern void *cgit_free_commitinfo(struct commitinfo *info);
@@ -99,17 +100,17 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(unsigned long secs);
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_repolist(struct cacheitem *item);
extern void cgit_print_summary();
extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
extern void cgit_print_view(const char *hex);
-extern void cgit_print_tree(const char *hex);
+extern void cgit_print_tree(const char *hex, char *path);
extern void cgit_print_commit(const char *hex);
extern void cgit_print_diff(const char *old_hex, const char *new_hex);
#endif /* CGIT_H */
diff --git a/shared.c b/shared.c
index e4595fa..dd711a8 100644
--- a/shared.c
+++ b/shared.c
@@ -30,24 +30,25 @@ char *cgit_repo_desc = NULL;
char *cgit_repo_owner = NULL;
int cgit_query_has_symref = 0;
int cgit_query_has_sha1 = 0;
char *cgit_querystring = NULL;
char *cgit_query_repo = NULL;
char *cgit_query_page = NULL;
char *cgit_query_head = NULL;
char *cgit_query_search = NULL;
char *cgit_query_sha1 = NULL;
char *cgit_query_sha2 = NULL;
+char *cgit_query_path = NULL;
int cgit_query_ofs = 0;
int htmlfd = 0;
void cgit_global_config_cb(const char *name, const char *value)
{
if (!strcmp(name, "root"))
cgit_root = xstrdup(value);
else if (!strcmp(name, "root-title"))
cgit_root_title = xstrdup(value);
else if (!strcmp(name, "css"))
cgit_css = xstrdup(value);
@@ -91,24 +92,26 @@ void cgit_querystring_cb(const char *name, const char *value)
cgit_query_search = xstrdup(value);
} else if (!strcmp(name, "h")) {
cgit_query_head = xstrdup(value);
cgit_query_has_symref = 1;
} else if (!strcmp(name, "id")) {
cgit_query_sha1 = xstrdup(value);
cgit_query_has_sha1 = 1;
} else if (!strcmp(name, "id2")) {
cgit_query_sha2 = xstrdup(value);
cgit_query_has_sha1 = 1;
} else if (!strcmp(name, "ofs")) {
cgit_query_ofs = atoi(value);
+ } else if (!strcmp(name, "path")) {
+ cgit_query_path = xstrdup(value);
}
}
void *cgit_free_commitinfo(struct commitinfo *info)
{
free(info->author);
free(info->author_email);
free(info->committer);
free(info->committer_email);
free(info->subject);
free(info);
return NULL;
diff --git a/ui-tree.c b/ui-tree.c
index 54dcdbe..ed9f05e 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -20,54 +20,60 @@ static int print_entry(const unsigned char *sha1, const char *base,
if (sha1_object_info(sha1, type, &size)) {
cgit_print_error(fmt("Bad object name: %s",
sha1_to_hex(sha1)));
return 0;
}
name = xstrdup(pathname);
html("<tr><td class='filemode'>");
html_filemode(mode);
html("</td><td>");
if (S_ISDIR(mode)) {
html("<div class='ls-dir'><a href='");
html_attr(cgit_pageurl(cgit_query_repo, "tree",
- fmt("id=%s", sha1_to_hex(sha1))));
+ fmt("id=%s&path=%s%s/",
+ sha1_to_hex(sha1),
+ cgit_query_path ? cgit_query_path : "",
+ pathname)));
} else {
html("<div class='ls-blob'><a href='");
html_attr(cgit_pageurl(cgit_query_repo, "view",
- fmt("id=%s", sha1_to_hex(sha1))));
+ fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
+ cgit_query_path ? cgit_query_path : "",
+ pathname)));
}
html("'>");
html_txt(name);
if (S_ISDIR(mode))
html("/");
html("</a></div></td>");
htmlf("<td class='filesize'>%li</td>", size);
html("</tr>\n");
free(name);
return 0;
}
-void cgit_print_tree(const char *hex)
+void cgit_print_tree(const char *hex, char *path)
{
struct tree *tree;
unsigned char sha1[20];
if (get_sha1_hex(hex, sha1)) {
cgit_print_error(fmt("Invalid object id: %s", hex));
return;
}
tree = parse_tree_indirect(sha1);
if (!tree) {
cgit_print_error(fmt("Not a tree object: %s", hex));
return;
}
html("<h2>Tree content</h2>\n");
+ html_txt(path);
html("<table class='list'>\n");
html("<tr>");
html("<th class='left'>Mode</th>");
html("<th class='left'>Name</th>");
html("<th class='right'>Size</th>");
html("</tr>\n");
read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
html("</table>\n");
}