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>
This commit is contained in:
Lars Hjemli 2007-05-11 12:12:48 +02:00
parent cc1dbd1b5d
commit ded9393b17
6 changed files with 27 additions and 12 deletions

View File

@ -141,7 +141,7 @@ div.error {
margin: 1em 2em; margin: 1em 2em;
} }
div.ls-blob, div.ls-dir { td.ls-blob, td.ls-dir, td.ls-mod {
font-family: monospace; font-family: monospace;
} }

2
cgit.h
View File

@ -33,6 +33,7 @@ struct repoinfo {
char *path; char *path;
char *desc; char *desc;
char *owner; char *owner;
char *module_link;
int snapshots; int snapshots;
}; };
@ -70,6 +71,7 @@ extern char *cgit_root_title;
extern char *cgit_css; extern char *cgit_css;
extern char *cgit_logo; extern char *cgit_logo;
extern char *cgit_logo_link; extern char *cgit_logo_link;
extern char *cgit_module_link;
extern char *cgit_virtual_root; extern char *cgit_virtual_root;
extern char *cgit_cache_root; extern char *cgit_cache_root;

7
cgitrc
View File

@ -47,6 +47,10 @@
#logo-link=http://www.kernel.org/pub/software/scm/git/docs/ #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) ## Number of chars shown of commit subject message (in log view)
#max-message-length=60 #max-message-length=60
@ -81,4 +85,5 @@
#repo.desc=the caching cgi for git #repo.desc=the caching cgi for git
#repo.path=/pub/git/cgit #repo.path=/pub/git/cgit
#repo.owner=Lars Hjemli #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

3
html.c
View File

@ -158,10 +158,11 @@ void html_filemode(unsigned short mode)
html("d"); html("d");
else if (S_ISLNK(mode)) else if (S_ISLNK(mode))
html("l"); html("l");
else if (S_ISDIRLNK(mode))
html("m");
else else
html("-"); html("-");
html_fileperm(mode >> 6); html_fileperm(mode >> 6);
html_fileperm(mode >> 3); html_fileperm(mode >> 3);
html_fileperm(mode); html_fileperm(mode);
} }

View File

@ -15,6 +15,7 @@ char *cgit_root_title = "Git repository browser";
char *cgit_css = "/cgit.css"; char *cgit_css = "/cgit.css";
char *cgit_logo = "/git-logo.png"; char *cgit_logo = "/git-logo.png";
char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 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_virtual_root = NULL;
char *cgit_cache_root = "/var/cache/cgit"; char *cgit_cache_root = "/var/cache/cgit";
@ -85,6 +86,7 @@ struct repoinfo *add_repo(const char *url)
ret->desc = NULL; ret->desc = NULL;
ret->owner = NULL; ret->owner = NULL;
ret->snapshots = cgit_snapshots; ret->snapshots = cgit_snapshots;
ret->module_link = cgit_module_link;
return ret; return ret;
} }
@ -98,6 +100,8 @@ void cgit_global_config_cb(const char *name, const char *value)
cgit_logo = xstrdup(value); cgit_logo = xstrdup(value);
else if (!strcmp(name, "logo-link")) else if (!strcmp(name, "logo-link"))
cgit_logo_link = xstrdup(value); cgit_logo_link = xstrdup(value);
else if (!strcmp(name, "module-link"))
cgit_module_link = xstrdup(value);
else if (!strcmp(name, "virtual-root")) else if (!strcmp(name, "virtual-root"))
cgit_virtual_root = xstrdup(value); cgit_virtual_root = xstrdup(value);
else if (!strcmp(name, "nocache")) else if (!strcmp(name, "nocache"))
@ -128,6 +132,8 @@ void cgit_global_config_cb(const char *name, const char *value)
cgit_repo->owner = xstrdup(value); cgit_repo->owner = xstrdup(value);
else if (cgit_repo && !strcmp(name, "repo.snapshots")) else if (cgit_repo && !strcmp(name, "repo.snapshots"))
cgit_repo->snapshots = atoi(value); 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) void cgit_repo_config_cb(const char *name, const char *value)

View File

@ -15,11 +15,11 @@ static int print_entry(const unsigned char *sha1, const char *base,
{ {
char *name; char *name;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size = 0;
name = xstrdup(pathname); name = xstrdup(pathname);
type = sha1_object_info(sha1, &size); 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>", htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
name, name,
sha1_to_hex(sha1)); sha1_to_hex(sha1));
@ -27,26 +27,27 @@ static int print_entry(const unsigned char *sha1, const char *base,
} }
html("<tr><td class='filemode'>"); html("<tr><td class='filemode'>");
html_filemode(mode); html_filemode(mode);
html("</td><td>"); html("</td><td ");
if (S_ISDIRLNK(mode)) { 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)) { } 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", html_attr(cgit_pageurl(cgit_query_repo, "tree",
fmt("id=%s&path=%s%s/", fmt("id=%s&path=%s%s/",
sha1_to_hex(sha1), sha1_to_hex(sha1),
cgit_query_path ? cgit_query_path : "", cgit_query_path ? cgit_query_path : "",
pathname))); pathname)));
htmlf("'>%s</a></div>", name);
} else { } else {
html("<div class='ls-blob'><a href='"); html("class='ls-blob'><a href='");
html_attr(cgit_pageurl(cgit_query_repo, "view", html_attr(cgit_pageurl(cgit_query_repo, "view",
fmt("id=%s&path=%s%s", sha1_to_hex(sha1), fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
cgit_query_path ? cgit_query_path : "", cgit_query_path ? cgit_query_path : "",
pathname))); pathname)));
htmlf("'>%s</a></div>", name);
} }
html("</div></td>"); htmlf("'>%s</a></div></td>", name);
htmlf("<td class='filesize'>%li</td>", size); htmlf("<td class='filesize'>%li</td>", size);
html("</tr>\n"); html("</tr>\n");
free(name); free(name);