about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cgit.c9
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt8
-rw-r--r--shared.c1
-rw-r--r--ui-plain.c9
-rw-r--r--ui-shared.c56
-rw-r--r--ui-shared.h3
-rw-r--r--ui-tree.c13
8 files changed, 85 insertions, 15 deletions
diff --git a/cgit.c b/cgit.c index 1d50129..7e3d349 100644 --- a/cgit.c +++ b/cgit.c
@@ -60,6 +60,8 @@ static void process_cached_repolist(const char *path);
60 60
61void repo_config(struct cgit_repo *repo, const char *name, const char *value) 61void repo_config(struct cgit_repo *repo, const char *name, const char *value)
62{ 62{
63 struct string_list_item *item;
64
63 if (!strcmp(name, "name")) 65 if (!strcmp(name, "name"))
64 repo->name = xstrdup(value); 66 repo->name = xstrdup(value);
65 else if (!strcmp(name, "clone-url")) 67 else if (!strcmp(name, "clone-url"))
@@ -86,7 +88,10 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
86 repo->max_stats = cgit_find_stats_period(value, NULL); 88 repo->max_stats = cgit_find_stats_period(value, NULL);
87 else if (!strcmp(name, "module-link")) 89 else if (!strcmp(name, "module-link"))
88 repo->module_link= xstrdup(value); 90 repo->module_link= xstrdup(value);
89 else if (!strcmp(name, "section")) 91 else if (!prefixcmp(name, "module-link.")) {
92 item = string_list_append(&repo->submodules, name + 12);
93 item->util = xstrdup(value);
94 } else if (!strcmp(name, "section"))
90 repo->section = xstrdup(value); 95 repo->section = xstrdup(value);
91 else if (!strcmp(name, "readme") && value != NULL) 96 else if (!strcmp(name, "readme") && value != NULL)
92 repo->readme = xstrdup(value); 97 repo->readme = xstrdup(value);
@@ -339,7 +344,6 @@ static void prepare_context(struct cgit_context *ctx)
339 ctx->cfg.max_repodesc_len = 80; 344 ctx->cfg.max_repodesc_len = 80;
340 ctx->cfg.max_blob_size = 0; 345 ctx->cfg.max_blob_size = 0;
341 ctx->cfg.max_stats = 0; 346 ctx->cfg.max_stats = 0;
342 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
343 ctx->cfg.project_list = NULL; 347 ctx->cfg.project_list = NULL;
344 ctx->cfg.renamelimit = -1; 348 ctx->cfg.renamelimit = -1;
345 ctx->cfg.remove_suffix = 0; 349 ctx->cfg.remove_suffix = 0;
@@ -470,6 +474,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
470 cgit_print_docend(); 474 cgit_print_docend();
471 return 1; 475 return 1;
472 } 476 }
477 sort_string_list(&ctx->repo->submodules);
473 cgit_prepare_repo_env(ctx->repo); 478 cgit_prepare_repo_env(ctx->repo);
474 return 0; 479 return 0;
475} 480}
diff --git a/cgit.h b/cgit.h index c7ab5c6..b7c7ac9 100644 --- a/cgit.h +++ b/cgit.h
@@ -88,6 +88,7 @@ struct cgit_repo {
88 struct cgit_filter *about_filter; 88 struct cgit_filter *about_filter;
89 struct cgit_filter *commit_filter; 89 struct cgit_filter *commit_filter;
90 struct cgit_filter *source_filter; 90 struct cgit_filter *source_filter;
91 struct string_list submodules;
91}; 92};
92 93
93typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, 94typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a22423b..b4ad2ac 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt
@@ -230,7 +230,7 @@ module-link::
230 Text which will be used as the formatstring for a hyperlink when a 230 Text which will be used as the formatstring for a hyperlink when a
231 submodule is printed in a directory listing. The arguments for the 231 submodule is printed in a directory listing. The arguments for the
232 formatstring are the path and SHA1 of the submodule commit. Default 232 formatstring are the path and SHA1 of the submodule commit. Default
233 value: "./?repo=%s&page=commit&id=%s" 233 value: none.
234 234
235nocache:: 235nocache::
236 If set to the value "1" caching will be disabled. This settings is 236 If set to the value "1" caching will be disabled. This settings is
@@ -417,6 +417,12 @@ repo.module-link::
417 formatstring are the path and SHA1 of the submodule commit. Default 417 formatstring are the path and SHA1 of the submodule commit. Default
418 value: <module-link> 418 value: <module-link>
419 419
420repo.module-link.<path>::
421 Text which will be used as the formatstring for a hyperlink when a
422 submodule with the specified subdirectory path is printed in a
423 directory listing. The only argument for the formatstring is the SHA1
424 of the submodule commit. Default value: none.
425
420repo.max-stats:: 426repo.max-stats::
421 Override the default maximum statistics period. Valid values are equal 427 Override the default maximum statistics period. Valid values are equal
422 to the values specified for the global "max-stats" setting. Default 428 to the values specified for the global "max-stats" setting. Default
diff --git a/shared.c b/shared.c index 0c8ce3e..cb52380 100644 --- a/shared.c +++ b/shared.c
@@ -70,6 +70,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
70 ret->commit_filter = ctx.cfg.commit_filter; 70 ret->commit_filter = ctx.cfg.commit_filter;
71 ret->source_filter = ctx.cfg.source_filter; 71 ret->source_filter = ctx.cfg.source_filter;
72 ret->clone_url = ctx.cfg.clone_url; 72 ret->clone_url = ctx.cfg.clone_url;
73 ret->submodules.strdup_strings = 1;
73 return ret; 74 return ret;
74} 75}
75 76
diff --git a/ui-plain.c b/ui-plain.c index 733db4d..2abd210 100644 --- a/ui-plain.c +++ b/ui-plain.c
@@ -97,11 +97,14 @@ static void print_dir_entry(const unsigned char *sha1, const char *base,
97 char *fullpath; 97 char *fullpath;
98 98
99 fullpath = buildpath(base, baselen, path); 99 fullpath = buildpath(base, baselen, path);
100 if (!S_ISDIR(mode)) 100 if (!S_ISDIR(mode) && !S_ISGITLINK(mode))
101 fullpath[strlen(fullpath) - 1] = 0; 101 fullpath[strlen(fullpath) - 1] = 0;
102 html(" <li>"); 102 html(" <li>");
103 cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, 103 if (S_ISGITLINK(mode)) {
104 fullpath); 104 cgit_submodule_link(NULL, fullpath, sha1_to_hex(sha1));
105 } else
106 cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
107 fullpath);
105 html("</li>\n"); 108 html("</li>\n");
106 match = 2; 109 match = 2;
107} 110}
diff --git a/ui-shared.c b/ui-shared.c index d7d75bf..43166af 100644 --- a/ui-shared.c +++ b/ui-shared.c
@@ -509,6 +509,62 @@ void cgit_object_link(struct object *obj)
509 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 509 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
510} 510}
511 511
512struct string_list_item *lookup_path(struct string_list *list,
513 const char *path)
514{
515 struct string_list_item *item;
516
517 while (path && path[0]) {
518 if ((item = string_list_lookup(list, path)))
519 return item;
520 if (!(path = strchr(path, '/')))
521 break;
522 path++;
523 }
524 return NULL;
525}
526
527void cgit_submodule_link(const char *class, char *path, const char *rev)
528{
529 struct string_list *list;
530 struct string_list_item *item;
531 char tail, *dir;
532 size_t len;
533
534 tail = 0;
535 list = &ctx.repo->submodules;
536 item = lookup_path(list, path);
537 if (!item) {
538 len = strlen(path);
539 tail = path[len - 1];
540 if (tail == '/') {
541 path[len - 1] = 0;
542 item = lookup_path(list, path);
543 }
544 }
545 html("<a ");
546 if (class)
547 htmlf("class='%s' ", class);
548 html("href='");
549 if (item) {
550 html_attr(fmt(item->util, rev));
551 } else if (ctx.repo->module_link) {
552 dir = strrchr(path, '/');
553 if (dir)
554 dir++;
555 else
556 dir = path;
557 html_attr(fmt(ctx.repo->module_link, dir, rev));
558 } else {
559 html("#");
560 }
561 html("'>");
562 html_txt(path);
563 html("</a>");
564 if (item && tail)
565 path[len - 1] = tail;
566}
567
512void cgit_print_date(time_t secs, const char *format, int local_time) 568void cgit_print_date(time_t secs, const char *format, int local_time)
513{ 569{
514 char buf[64]; 570 char buf[64];
diff --git a/ui-shared.h b/ui-shared.h index 865bd45..87a7dac 100644 --- a/ui-shared.h +++ b/ui-shared.h
@@ -51,6 +51,9 @@ extern void cgit_self_link(char *name, const char *title,
51 const char *class, struct cgit_context *ctx); 51 const char *class, struct cgit_context *ctx);
52extern void cgit_object_link(struct object *obj); 52extern void cgit_object_link(struct object *obj);
53 53
54extern void cgit_submodule_link(const char *class, char *path,
55 const char *rev);
56
54extern void cgit_print_error(const char *msg); 57extern void cgit_print_error(const char *msg);
55extern void cgit_print_date(time_t secs, const char *format, int local_time); 58extern void cgit_print_date(time_t secs, const char *format, int local_time);
56extern void cgit_print_age(time_t t, time_t max_relative, const char *format); 59extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
diff --git a/ui-tree.c b/ui-tree.c index 442b6be..b1adcc7 100644 --- a/ui-tree.c +++ b/ui-tree.c
@@ -150,13 +150,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
150 cgit_print_filemode(mode); 150 cgit_print_filemode(mode);
151 html("</td><td>"); 151 html("</td><td>");
152 if (S_ISGITLINK(mode)) { 152 if (S_ISGITLINK(mode)) {
153 htmlf("<a class='ls-mod' href='"); 153 cgit_submodule_link("ls-mod", fullpath, sha1_to_hex(sha1));
154 html_attr(fmt(ctx.repo->module_link,
155 name,
156 sha1_to_hex(sha1)));
157 html("'>");
158 html_txt(name);
159 html("</a>");
160 } else if (S_ISDIR(mode)) { 154 } else if (S_ISDIR(mode)) {
161 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, 155 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
162 curr_rev, fullpath); 156 curr_rev, fullpath);
@@ -177,8 +171,9 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
177 if (ctx.repo->max_stats) 171 if (ctx.repo->max_stats)
178 cgit_stats_link("stats", NULL, "button", ctx.qry.head, 172 cgit_stats_link("stats", NULL, "button", ctx.qry.head,
179 fullpath); 173 fullpath);
180 cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev, 174 if (!S_ISGITLINK(mode))
181 fullpath); 175 cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev,
176 fullpath);
182 html("</td></tr>\n"); 177 html("</td></tr>\n");
183 free(name); 178 free(name);
184 return 0; 179 return 0;