summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.h2
-rw-r--r--cgitrc.5.txt10
-rw-r--r--scan-tree.c2
-rw-r--r--shared.c9
-rw-r--r--ui-commit.c12
-rw-r--r--ui-plain.c68
7 files changed, 95 insertions, 12 deletions
diff --git a/cgit.c b/cgit.c
index bf64c9e..38bc136 100644
--- a/cgit.c
+++ b/cgit.c
@@ -64,2 +64,4 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
64 repo->enable_remote_branches = atoi(value); 64 repo->enable_remote_branches = atoi(value);
65 else if (!strcmp(name, "enable-subject-links"))
66 repo->enable_subject_links = atoi(value);
65 else if (!strcmp(name, "max-stats")) 67 else if (!strcmp(name, "max-stats"))
@@ -143,2 +145,4 @@ void config_cb(const char *name, const char *value)
143 ctx.cfg.enable_remote_branches = atoi(value); 145 ctx.cfg.enable_remote_branches = atoi(value);
146 else if (!strcmp(name, "enable-subject-links"))
147 ctx.cfg.enable_subject_links = atoi(value);
144 else if (!strcmp(name, "enable-tree-linenumbers")) 148 else if (!strcmp(name, "enable-tree-linenumbers"))
diff --git a/cgit.h b/cgit.h
index 7fafb58..8884f9e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -75,2 +75,3 @@ struct cgit_repo {
75 int enable_remote_branches; 75 int enable_remote_branches;
76 int enable_subject_links;
76 int max_stats; 77 int max_stats;
@@ -184,2 +185,3 @@ struct cgit_config {
184 int enable_remote_branches; 185 int enable_remote_branches;
186 int enable_subject_links;
185 int enable_tree_linenumbers; 187 int enable_tree_linenumbers;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 6cdfd03..5c24381 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -117,2 +117,8 @@ enable-remote-branches::
117 117
118enable-subject-links::
119 Flag which, when set to "1", will make cgit use the subject of the
120 parent commit as link text when generating links to parent commits
121 in commit view. Default value: "0". See also:
122 "repo.enable-subject-links".
123
118enable-tree-linenumbers:: 124enable-tree-linenumbers::
@@ -327,2 +333,6 @@ repo.enable-remote-branches::
327 333
334repo.enable-subject-links::
335 A flag which can be used to override the global setting
336 `enable-subject-links'. Default value: none.
337
328repo.max-stats:: 338repo.max-stats::
diff --git a/scan-tree.c b/scan-tree.c
index dbca797..1e18f3c 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -58,2 +58,4 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
58 } 58 }
59 if (!stat(fmt("%s/noweb", path), &st))
60 return;
59 if ((pwd = getpwuid(st.st_uid)) == NULL) { 61 if ((pwd = getpwuid(st.st_uid)) == NULL) {
diff --git a/shared.c b/shared.c
index 5f46793..8b3a045 100644
--- a/shared.c
+++ b/shared.c
@@ -62,2 +62,3 @@ struct cgit_repo *cgit_add_repo(const char *url)
62 ret->enable_remote_branches = ctx.cfg.enable_remote_branches; 62 ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
63 ret->enable_subject_links = ctx.cfg.enable_subject_links;
63 ret->max_stats = ctx.cfg.max_stats; 64 ret->max_stats = ctx.cfg.max_stats;
@@ -281,2 +282,6 @@ int cgit_diff_files(const unsigned char *old_sha1,
281 *binary = 1; 282 *binary = 1;
283 if (file1.size)
284 free(file1.ptr);
285 if (file2.size)
286 free(file2.ptr);
282 return 0; 287 return 0;
@@ -293,2 +298,6 @@ int cgit_diff_files(const unsigned char *old_sha1,
293 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); 298 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
299 if (file1.size)
300 free(file1.ptr);
301 if (file2.size)
302 free(file2.ptr);
294 return 0; 303 return 0;
diff --git a/ui-commit.c b/ui-commit.c
index b5e3c01..41313b9 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -17,6 +17,6 @@ void cgit_print_commit(char *hex)
17 struct commit *commit, *parent; 17 struct commit *commit, *parent;
18 struct commitinfo *info; 18 struct commitinfo *info, *parent_info;
19 struct commit_list *p; 19 struct commit_list *p;
20 unsigned char sha1[20]; 20 unsigned char sha1[20];
21 char *tmp; 21 char *tmp, *tmp2;
22 int parents = 0; 22 int parents = 0;
@@ -84,4 +84,8 @@ void cgit_print_commit(char *hex)
84 "<td colspan='2' class='sha1'>"); 84 "<td colspan='2' class='sha1'>");
85 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, 85 tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
86 ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0); 86 if (ctx.repo->enable_subject_links) {
87 parent_info = cgit_parse_commit(parent);
88 tmp2 = parent_info->subject;
89 }
90 cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, 0);
87 html(" ("); 91 html(" (");
diff --git a/ui-plain.c b/ui-plain.c
index 66cb19c..da76406 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -12,4 +12,3 @@
12 12
13char *curr_rev; 13int match_baselen;
14char *match_path;
15int match; 14int match;
@@ -55,2 +54,34 @@ static void print_object(const unsigned char *sha1, const char *path)
55 54
55static void print_dir(const unsigned char *sha1, const char *path,
56 const char *base)
57{
58 char *fullpath;
59 if (path[0] || base[0])
60 fullpath = fmt("/%s%s/", base, path);
61 else
62 fullpath = "/";
63 ctx.page.etag = sha1_to_hex(sha1);
64 cgit_print_http_headers(&ctx);
65 htmlf("<html><head><title>%s</title></head>\n<body>\n"
66 " <h2>%s</h2>\n <ul>\n", fullpath, fullpath);
67 if (path[0] || base[0])
68 html(" <li><a href=\"../\">../</a></li>\n");
69 match = 2;
70}
71
72static void print_dir_entry(const unsigned char *sha1, const char *path,
73 unsigned mode)
74{
75 const char *sep = "";
76 if (S_ISDIR(mode))
77 sep = "/";
78 htmlf(" <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep);
79 match = 2;
80}
81
82static void print_dir_tail(void)
83{
84 html(" </ul>\n</body></html>\n");
85}
86
56static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 87static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
@@ -59,9 +90,23 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
59{ 90{
60 if (S_ISDIR(mode)) 91 if (baselen == match_baselen) {
92 if (S_ISREG(mode))
93 print_object(sha1, pathname);
94 else if (S_ISDIR(mode)) {
95 print_dir(sha1, pathname, base);
96 return READ_TREE_RECURSIVE;
97 }
98 }
99 else if (baselen > match_baselen)
100 print_dir_entry(sha1, pathname, mode);
101 else if (S_ISDIR(mode))
61 return READ_TREE_RECURSIVE; 102 return READ_TREE_RECURSIVE;
62 103
63 if (S_ISREG(mode) && !strncmp(base, match_path, baselen) && 104 return 0;
64 !strcmp(pathname, match_path + baselen)) 105}
65 print_object(sha1, pathname);
66 106
107static int basedir_len(const char *path)
108{
109 char *p = strrchr(path, '/');
110 if (p)
111 return p - path + 1;
67 return 0; 112 return 0;
@@ -79,3 +124,2 @@ void cgit_print_plain(struct cgit_context *ctx)
79 124
80 curr_rev = xstrdup(rev);
81 if (get_sha1(rev, sha1)) { 125 if (get_sha1(rev, sha1)) {
@@ -89,3 +133,9 @@ void cgit_print_plain(struct cgit_context *ctx)
89 } 133 }
90 match_path = ctx->qry.path; 134 if (!paths[0]) {
135 paths[0] = "";
136 match_baselen = -1;
137 print_dir(commit->tree->object.sha1, "", "");
138 }
139 else
140 match_baselen = basedir_len(paths[0]);
91 read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); 141 read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
@@ -93,2 +143,4 @@ void cgit_print_plain(struct cgit_context *ctx)
93 html_status(404, "Not found", 0); 143 html_status(404, "Not found", 0);
144 else if (match == 2)
145 print_dir_tail();
94} 146}