aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2011-06-15 17:04:13 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2011-06-15 17:40:13 (JST)
commit6857bec50a52340fa6b85d626f49d45dd331ed0e (patch)
treef746931d5173cab78d32ead3196186c97c5fd9b7
parent8729d251a900b2e6e22cc4c93a2193fd8a2b9acf (diff)
downloadcgit-6857bec50a52340fa6b85d626f49d45dd331ed0e.zip
cgit-6857bec50a52340fa6b85d626f49d45dd331ed0e.tar.gz
ui-tree.c: add support for path-selected submodule links
The current 'repo.module-link' option is sufficient when all gitlinks in a repository can be converted to commit links in a uniform way, but not when different submodules/paths needs different settings. This patch adds support for 'repo.module-link.<path>', which will be used for linking to submodules at paths matching one such entry. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r--cgit.c8
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt6
-rw-r--r--shared.c1
-rw-r--r--ui-shared.c56
-rw-r--r--ui-shared.h3
-rw-r--r--ui-tree.c13
7 files changed, 78 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c
index 51ca78a..2118675 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);
@@ -465,6 +470,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
465 cgit_print_docend(); 470 cgit_print_docend();
466 return 1; 471 return 1;
467 } 472 }
473 sort_string_list(&ctx->repo->submodules);
468 cgit_prepare_repo_env(ctx->repo); 474 cgit_prepare_repo_env(ctx->repo);
469 return 0; 475 return 0;
470} 476}
diff --git a/cgit.h b/cgit.h
index bad66f0..9d0b3d0 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 4721c1e..1162bd5 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -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 699c362..0add2e5 100644
--- a/shared.c
+++ b/shared.c
@@ -71,6 +71,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
71 ret->commit_filter = ctx.cfg.commit_filter; 71 ret->commit_filter = ctx.cfg.commit_filter;
72 ret->source_filter = ctx.cfg.source_filter; 72 ret->source_filter = ctx.cfg.source_filter;
73 ret->clone_url = ctx.cfg.clone_url; 73 ret->clone_url = ctx.cfg.clone_url;
74 ret->submodules.strdup_strings = 1;
74 return ret; 75 return ret;
75} 76}
76 77
diff --git a/ui-shared.c b/ui-shared.c
index 5aa9119..b736fca 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -503,6 +503,62 @@ void cgit_object_link(struct object *obj)
503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
504} 504}
505 505
506struct string_list_item *lookup_path(struct string_list *list,
507 const char *path)
508{
509 struct string_list_item *item;
510
511 while (path && path[0]) {
512 if ((item = string_list_lookup(list, path)))
513 return item;
514 if (!(path = strchr(path, '/')))
515 break;
516 path++;
517 }
518 return NULL;
519}
520
521void cgit_submodule_link(const char *class, char *path, const char *rev)
522{
523 struct string_list *list;
524 struct string_list_item *item;
525 char tail, *dir;
526 size_t len;
527
528 tail = 0;
529 list = &ctx.repo->submodules;
530 item = lookup_path(list, path);
531 if (!item) {
532 len = strlen(path);
533 tail = path[len - 1];
534 if (tail == '/') {
535 path[len - 1] = 0;
536 item = lookup_path(list, path);
537 }
538 }
539 html("<a ");
540 if (class)
541 htmlf("class='%s' ", class);
542 html("href='");
543 if (item) {
544 html_attr(fmt(item->util, rev));
545 } else if (ctx.repo->module_link) {
546 dir = strrchr(path, '/');
547 if (dir)
548 dir++;
549 else
550 dir = path;
551 html_attr(fmt(ctx.repo->module_link, dir, rev));
552 } else {
553 html("#");
554 }
555 html("'>");
556 html_txt(path);
557 html("</a>");
558 if (item && tail)
559 path[len - 1] = tail;
560}
561
506void cgit_print_date(time_t secs, const char *format, int local_time) 562void cgit_print_date(time_t secs, const char *format, int local_time)
507{ 563{
508 char buf[64]; 564 char buf[64];
diff --git a/ui-shared.h b/ui-shared.h
index 3cc1258..e80b975 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;