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) (unidiff)
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 {
138div.error { 138div.error {
139 color: red; 139 color: red;
140 font-weight: bold; 140 font-weight: bold;
141 margin: 1em 2em; 141 margin: 1em 2em;
142} 142}
143 143
144div.ls-blob, div.ls-dir { 144td.ls-blob, td.ls-dir, td.ls-mod {
145 font-family: monospace; 145 font-family: monospace;
146} 146}
147 147
148div.ls-dir a { 148div.ls-dir a {
149 font-weight: bold; 149 font-weight: bold;
150} 150}
diff --git a/cgit.h b/cgit.h
index 292e488..b7f8827 100644
--- a/cgit.h
+++ b/cgit.h
@@ -30,12 +30,13 @@ struct cacheitem {
30struct repoinfo { 30struct repoinfo {
31 char *url; 31 char *url;
32 char *name; 32 char *name;
33 char *path; 33 char *path;
34 char *desc; 34 char *desc;
35 char *owner; 35 char *owner;
36 char *module_link;
36 int snapshots; 37 int snapshots;
37}; 38};
38 39
39struct repolist { 40struct repolist {
40 int length; 41 int length;
41 int count; 42 int count;
@@ -67,12 +68,13 @@ extern struct repolist cgit_repolist;
67extern struct repoinfo *cgit_repo; 68extern struct repoinfo *cgit_repo;
68 69
69extern char *cgit_root_title; 70extern char *cgit_root_title;
70extern char *cgit_css; 71extern char *cgit_css;
71extern char *cgit_logo; 72extern char *cgit_logo;
72extern char *cgit_logo_link; 73extern char *cgit_logo_link;
74extern char *cgit_module_link;
73extern char *cgit_virtual_root; 75extern char *cgit_virtual_root;
74extern char *cgit_cache_root; 76extern char *cgit_cache_root;
75 77
76extern int cgit_nocache; 78extern int cgit_nocache;
77extern int cgit_snapshots; 79extern int cgit_snapshots;
78extern int cgit_max_lock_attempts; 80extern int cgit_max_lock_attempts;
diff --git a/cgitrc b/cgitrc
index 3bae642..f217b39 100644
--- a/cgitrc
+++ b/cgitrc
@@ -44,12 +44,16 @@
44 44
45 45
46## Url loaded when clicking the logo 46## Url loaded when clicking the logo
47#logo-link=http://www.kernel.org/pub/software/scm/git/docs/ 47#logo-link=http://www.kernel.org/pub/software/scm/git/docs/
48 48
49 49
50## Url loaded when clicking a submodule link
51#module-link=./?repo=%s&page=commit&id=%s
52
53
50## Number of chars shown of commit subject message (in log view) 54## Number of chars shown of commit subject message (in log view)
51#max-message-length=60 55#max-message-length=60
52 56
53 57
54## Root of cached output 58## Root of cached output
55#cache-root=/var/cache/cgit 59#cache-root=/var/cache/cgit
@@ -78,7 +82,8 @@
78## repository section must start with repo.url). 82## repository section must start with repo.url).
79#repo.url=cgit 83#repo.url=cgit
80#repo.name=cgit 84#repo.name=cgit
81#repo.desc=the caching cgi for git 85#repo.desc=the caching cgi for git
82#repo.path=/pub/git/cgit 86#repo.path=/pub/git/cgit
83#repo.owner=Lars Hjemli 87#repo.owner=Lars Hjemli
84#repo.snapshots=1 # override a sitewide snapshot-setting 88 #repo.snapshots=1 # override a sitewide snapshot-setting
89 #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)
155void html_filemode(unsigned short mode) 155void html_filemode(unsigned short mode)
156{ 156{
157 if (S_ISDIR(mode)) 157 if (S_ISDIR(mode))
158 html("d"); 158 html("d");
159 else if (S_ISLNK(mode)) 159 else if (S_ISLNK(mode))
160 html("l"); 160 html("l");
161 else if (S_ISDIRLNK(mode))
162 html("m");
161 else 163 else
162 html("-"); 164 html("-");
163 html_fileperm(mode >> 6); 165 html_fileperm(mode >> 6);
164 html_fileperm(mode >> 3); 166 html_fileperm(mode >> 3);
165 html_fileperm(mode); 167 html_fileperm(mode);
166} 168}
167
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;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13 13
14char *cgit_root_title = "Git repository browser"; 14char *cgit_root_title = "Git repository browser";
15char *cgit_css = "/cgit.css"; 15char *cgit_css = "/cgit.css";
16char *cgit_logo = "/git-logo.png"; 16char *cgit_logo = "/git-logo.png";
17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
18char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
18char *cgit_virtual_root = NULL; 19char *cgit_virtual_root = NULL;
19 20
20char *cgit_cache_root = "/var/cache/cgit"; 21char *cgit_cache_root = "/var/cache/cgit";
21 22
22int cgit_nocache = 0; 23int cgit_nocache = 0;
23int cgit_snapshots = 0; 24int cgit_snapshots = 0;
@@ -82,12 +83,13 @@ struct repoinfo *add_repo(const char *url)
82 ret->url = xstrdup(url); 83 ret->url = xstrdup(url);
83 ret->name = ret->url; 84 ret->name = ret->url;
84 ret->path = NULL; 85 ret->path = NULL;
85 ret->desc = NULL; 86 ret->desc = NULL;
86 ret->owner = NULL; 87 ret->owner = NULL;
87 ret->snapshots = cgit_snapshots; 88 ret->snapshots = cgit_snapshots;
89 ret->module_link = cgit_module_link;
88 return ret; 90 return ret;
89} 91}
90 92
91void cgit_global_config_cb(const char *name, const char *value) 93void cgit_global_config_cb(const char *name, const char *value)
92{ 94{
93 if (!strcmp(name, "root-title")) 95 if (!strcmp(name, "root-title"))
@@ -95,12 +97,14 @@ void cgit_global_config_cb(const char *name, const char *value)
95 else if (!strcmp(name, "css")) 97 else if (!strcmp(name, "css"))
96 cgit_css = xstrdup(value); 98 cgit_css = xstrdup(value);
97 else if (!strcmp(name, "logo")) 99 else if (!strcmp(name, "logo"))
98 cgit_logo = xstrdup(value); 100 cgit_logo = xstrdup(value);
99 else if (!strcmp(name, "logo-link")) 101 else if (!strcmp(name, "logo-link"))
100 cgit_logo_link = xstrdup(value); 102 cgit_logo_link = xstrdup(value);
103 else if (!strcmp(name, "module-link"))
104 cgit_module_link = xstrdup(value);
101 else if (!strcmp(name, "virtual-root")) 105 else if (!strcmp(name, "virtual-root"))
102 cgit_virtual_root = xstrdup(value); 106 cgit_virtual_root = xstrdup(value);
103 else if (!strcmp(name, "nocache")) 107 else if (!strcmp(name, "nocache"))
104 cgit_nocache = atoi(value); 108 cgit_nocache = atoi(value);
105 else if (!strcmp(name, "snapshots")) 109 else if (!strcmp(name, "snapshots"))
106 cgit_snapshots = atoi(value); 110 cgit_snapshots = atoi(value);
@@ -125,12 +129,14 @@ void cgit_global_config_cb(const char *name, const char *value)
125 else if (cgit_repo && !strcmp(name, "repo.desc")) 129 else if (cgit_repo && !strcmp(name, "repo.desc"))
126 cgit_repo->desc = xstrdup(value); 130 cgit_repo->desc = xstrdup(value);
127 else if (cgit_repo && !strcmp(name, "repo.owner")) 131 else if (cgit_repo && !strcmp(name, "repo.owner"))
128 cgit_repo->owner = xstrdup(value); 132 cgit_repo->owner = xstrdup(value);
129 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 133 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
130 cgit_repo->snapshots = atoi(value); 134 cgit_repo->snapshots = atoi(value);
135 else if (cgit_repo && !strcmp(name, "repo.module-link"))
136 cgit_repo->module_link= xstrdup(value);
131} 137}
132 138
133void cgit_repo_config_cb(const char *name, const char *value) 139void cgit_repo_config_cb(const char *name, const char *value)
134{ 140{
135 if (!strcmp(name, "name")) 141 if (!strcmp(name, "name"))
136 cgit_repo_name = xstrdup(value); 142 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 @@
12static int print_entry(const unsigned char *sha1, const char *base, 12static int print_entry(const unsigned char *sha1, const char *base,
13 int baselen, const char *pathname, unsigned int mode, 13 int baselen, const char *pathname, unsigned int mode,
14 int stage) 14 int stage)
15{ 15{
16 char *name; 16 char *name;
17 enum object_type type; 17 enum object_type type;
18 unsigned long size; 18 unsigned long size = 0;
19 19
20 name = xstrdup(pathname); 20 name = xstrdup(pathname);
21 type = sha1_object_info(sha1, &size); 21 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD) { 22 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
24 name, 24 name,
25 sha1_to_hex(sha1)); 25 sha1_to_hex(sha1));
26 return 0; 26 return 0;
27 } 27 }
28 html("<tr><td class='filemode'>"); 28 html("<tr><td class='filemode'>");
29 html_filemode(mode); 29 html_filemode(mode);
30 html("</td><td>"); 30 html("</td><td ");
31 if (S_ISDIRLNK(mode)) { 31 if (S_ISDIRLNK(mode)) {
32 htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); 32 htmlf("class='ls-mod'><a href='");
33 html_attr(fmt(cgit_repo->module_link,
34 name,
35 sha1_to_hex(sha1)));
33 } else if (S_ISDIR(mode)) { 36 } else if (S_ISDIR(mode)) {
34 html("<div class='ls-dir'><a href='"); 37 html("class='ls-dir'><a href='");
35 html_attr(cgit_pageurl(cgit_query_repo, "tree", 38 html_attr(cgit_pageurl(cgit_query_repo, "tree",
36 fmt("id=%s&path=%s%s/", 39 fmt("id=%s&path=%s%s/",
37 sha1_to_hex(sha1), 40 sha1_to_hex(sha1),
38 cgit_query_path ? cgit_query_path : "", 41 cgit_query_path ? cgit_query_path : "",
39 pathname))); 42 pathname)));
40 htmlf("'>%s</a></div>", name);
41 } else { 43 } else {
42 html("<div class='ls-blob'><a href='"); 44 html("class='ls-blob'><a href='");
43 html_attr(cgit_pageurl(cgit_query_repo, "view", 45 html_attr(cgit_pageurl(cgit_query_repo, "view",
44 fmt("id=%s&path=%s%s", sha1_to_hex(sha1), 46 fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
45 cgit_query_path ? cgit_query_path : "", 47 cgit_query_path ? cgit_query_path : "",
46 pathname))); 48 pathname)));
47 htmlf("'>%s</a></div>", name);
48 } 49 }
49 html("</div></td>"); 50 htmlf("'>%s</a></div></td>", name);
50 htmlf("<td class='filesize'>%li</td>", size); 51 htmlf("<td class='filesize'>%li</td>", size);
51 html("</tr>\n"); 52 html("</tr>\n");
52 free(name); 53 free(name);
53 return 0; 54 return 0;
54} 55}
55 56