author | Lars Hjemli <hjemli@gmail.com> | 2007-05-11 10:12:48 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-11 10:12:48 (UTC) |
commit | ded9393b173853d2e960f9b176aeb0bc4ed35be2 (patch) (side-by-side diff) | |
tree | 5c062b21e85ef0fe243ad900e9f4ffaf2ded0f62 | |
parent | cc1dbd1b5d610bd5e626f54d310f11cf47684ea1 (diff) | |
download | cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.zip cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.tar.gz cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.tar.bz2 |
Add submodule links in tree listing
When a submodule occurs in a tree, generate a link to show the
module/commit. The link is specified as a sprintf string in /etc/cgitrc,
using parameters 'module-link' and 'repo.module-link'. This should probably
be extended with repo.module-link.$path.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.css | 2 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc | 7 | ||||
-rw-r--r-- | html.c | 3 | ||||
-rw-r--r-- | shared.c | 6 | ||||
-rw-r--r-- | ui-tree.c | 19 |
6 files changed, 27 insertions, 12 deletions
@@ -136,17 +136,17 @@ div#blob { } div.error { color: red; font-weight: bold; margin: 1em 2em; } -div.ls-blob, div.ls-dir { +td.ls-blob, td.ls-dir, td.ls-mod { font-family: monospace; } div.ls-dir a { font-weight: bold; } th.filesize, td.filesize { @@ -28,16 +28,17 @@ struct cacheitem { }; struct repoinfo { char *url; char *name; char *path; char *desc; char *owner; + char *module_link; int snapshots; }; struct repolist { int length; int count; struct repoinfo *repos; }; @@ -65,16 +66,17 @@ extern const char cgit_version[]; extern struct repolist cgit_repolist; extern struct repoinfo *cgit_repo; extern char *cgit_root_title; extern char *cgit_css; extern char *cgit_logo; extern char *cgit_logo_link; +extern char *cgit_module_link; extern char *cgit_virtual_root; extern char *cgit_cache_root; extern int cgit_nocache; extern int cgit_snapshots; extern int cgit_max_lock_attempts; extern int cgit_cache_root_ttl; extern int cgit_cache_repo_ttl; @@ -42,16 +42,20 @@ ## Link to logo file #logo=/cgit/git-logo.png ## Url loaded when clicking the logo #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ +## Url loaded when clicking a submodule link +#module-link=./?repo=%s&page=commit&id=%s + + ## Number of chars shown of commit subject message (in log view) #max-message-length=60 ## Root of cached output #cache-root=/var/cache/cgit @@ -76,9 +80,10 @@ ## Example repository entry. Required values are repo.url and repo.path (each ## repository section must start with repo.url). #repo.url=cgit #repo.name=cgit #repo.desc=the caching cgi for git #repo.path=/pub/git/cgit #repo.owner=Lars Hjemli -#repo.snapshots=1 # override a sitewide snapshot-setting +#repo.snapshots=1 # override a sitewide snapshot-setting +#repo.module-link=/git/%s/commit/?id=%s # override the standard module-link @@ -153,15 +153,16 @@ void html_fileperm(unsigned short mode) } void html_filemode(unsigned short mode) { if (S_ISDIR(mode)) html("d"); else if (S_ISLNK(mode)) html("l"); + else if (S_ISDIRLNK(mode)) + html("m"); else html("-"); html_fileperm(mode >> 6); html_fileperm(mode >> 3); html_fileperm(mode); } - @@ -10,16 +10,17 @@ struct repolist cgit_repolist; struct repoinfo *cgit_repo; char *cgit_root_title = "Git repository browser"; char *cgit_css = "/cgit.css"; char *cgit_logo = "/git-logo.png"; char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; +char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; char *cgit_virtual_root = NULL; char *cgit_cache_root = "/var/cache/cgit"; int cgit_nocache = 0; int cgit_snapshots = 0; int cgit_max_lock_attempts = 5; int cgit_cache_root_ttl = 5; @@ -80,29 +81,32 @@ struct repoinfo *add_repo(const char *url) ret = &cgit_repolist.repos[cgit_repolist.count-1]; ret->url = xstrdup(url); ret->name = ret->url; ret->path = NULL; ret->desc = NULL; ret->owner = NULL; ret->snapshots = cgit_snapshots; + ret->module_link = cgit_module_link; return ret; } void cgit_global_config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) cgit_root_title = xstrdup(value); else if (!strcmp(name, "css")) cgit_css = xstrdup(value); else if (!strcmp(name, "logo")) cgit_logo = xstrdup(value); else if (!strcmp(name, "logo-link")) cgit_logo_link = xstrdup(value); + else if (!strcmp(name, "module-link")) + cgit_module_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) cgit_virtual_root = xstrdup(value); else if (!strcmp(name, "nocache")) cgit_nocache = atoi(value); else if (!strcmp(name, "snapshots")) cgit_snapshots = atoi(value); else if (!strcmp(name, "cache-root")) cgit_cache_root = xstrdup(value); @@ -123,16 +127,18 @@ void cgit_global_config_cb(const char *name, const char *value) else if (cgit_repo && !strcmp(name, "repo.path")) cgit_repo->path = xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.desc")) cgit_repo->desc = xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.owner")) cgit_repo->owner = xstrdup(value); else if (cgit_repo && !strcmp(name, "repo.snapshots")) cgit_repo->snapshots = atoi(value); + else if (cgit_repo && !strcmp(name, "repo.module-link")) + cgit_repo->module_link= xstrdup(value); } void cgit_repo_config_cb(const char *name, const char *value) { if (!strcmp(name, "name")) cgit_repo_name = xstrdup(value); else if (!strcmp(name, "desc")) cgit_repo_desc = xstrdup(value); @@ -10,48 +10,49 @@ static int print_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned int mode, int stage) { char *name; enum object_type type; - unsigned long size; + unsigned long size = 0; name = xstrdup(pathname); type = sha1_object_info(sha1, &size); - if (type == OBJ_BAD) { + 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='filemode'>"); html_filemode(mode); - html("</td><td>"); + html("</td><td "); if (S_ISDIRLNK(mode)) { - htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); + htmlf("class='ls-mod'><a href='"); + html_attr(fmt(cgit_repo->module_link, + name, + sha1_to_hex(sha1))); } else if (S_ISDIR(mode)) { - html("<div class='ls-dir'><a href='"); + html("class='ls-dir'><a href='"); html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("id=%s&path=%s%s/", sha1_to_hex(sha1), cgit_query_path ? cgit_query_path : "", pathname))); - htmlf("'>%s</a></div>", name); } else { - html("<div class='ls-blob'><a href='"); + html("class='ls-blob'><a href='"); html_attr(cgit_pageurl(cgit_query_repo, "view", fmt("id=%s&path=%s%s", sha1_to_hex(sha1), cgit_query_path ? cgit_query_path : "", pathname))); - htmlf("'>%s</a></div>", name); } - html("</div></td>"); + htmlf("'>%s</a></div></td>", name); htmlf("<td class='filesize'>%li</td>", size); html("</tr>\n"); free(name); return 0; } void cgit_print_tree(const char *hex, char *path) { |