summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-05-11 10:12:48 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-11 10:12:48 (UTC)
commitded9393b173853d2e960f9b176aeb0bc4ed35be2 (patch) (side-by-side diff)
tree5c062b21e85ef0fe243ad900e9f4ffaf2ded0f62
parentcc1dbd1b5d610bd5e626f54d310f11cf47684ea1 (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css2
-rw-r--r--cgit.h2
-rw-r--r--cgitrc7
-rw-r--r--html.c3
-rw-r--r--shared.c6
-rw-r--r--ui-tree.c19
6 files changed, 27 insertions, 12 deletions
diff --git a/cgit.css b/cgit.css
index 640bbc9..ef4bc62 100644
--- a/cgit.css
+++ b/cgit.css
@@ -138,13 +138,13 @@ 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;
}
diff --git a/cgit.h b/cgit.h
index 292e488..b7f8827 100644
--- a/cgit.h
+++ b/cgit.h
@@ -30,12 +30,13 @@ 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;
@@ -67,12 +68,13 @@ 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;
diff --git a/cgitrc b/cgitrc
index 3bae642..f217b39 100644
--- a/cgitrc
+++ b/cgitrc
@@ -44,12 +44,16 @@
## 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
@@ -78,7 +82,8 @@
## 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
diff --git a/html.c b/html.c
index c0b2ed4..175b4b6 100644
--- a/html.c
+++ b/html.c
@@ -155,13 +155,14 @@ 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);
}
-
diff --git a/shared.c b/shared.c
index 531d8c0..19d2df0 100644
--- a/shared.c
+++ b/shared.c
@@ -12,12 +12,13 @@ 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;
@@ -82,12 +83,13 @@ struct repoinfo *add_repo(const char *url)
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"))
@@ -95,12 +97,14 @@ void cgit_global_config_cb(const char *name, const char *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);
@@ -125,12 +129,14 @@ void cgit_global_config_cb(const char *name, const char *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);
diff --git a/ui-tree.c b/ui-tree.c
index 60f7560..dee8309 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -12,44 +12,45 @@
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;
}