]> granicus.if.org Git - cgit/commitdiff
Add support for automatic and custom clone urls
authorLars Hjemli <hjemli@gmail.com>
Mon, 3 Dec 2007 00:49:38 +0000 (01:49 +0100)
committerLars Hjemli <hjemli@gmail.com>
Mon, 3 Dec 2007 00:49:38 +0000 (01:49 +0100)
This adds support for two new parameters to cgitrc: clone-prefix and
repo.clone-url.

If clone-prefix is specified, all repos will get a clone url printed in the
sidebar; the url is generated by clone-prefix + repo.url.

Additionally, each repo can specify repo.clone-url which will override any
such auto-generated url.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.h
cgitrc
shared.c
ui-shared.c

diff --git a/cgit.h b/cgit.h
index ab0efeb45b5385038fbd237767e11ac96bc94a18..f223dbc28aed7a23c8f4283280f6fbf24a438b26 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -75,6 +75,7 @@ struct repoinfo {
        char *group;
        char *module_link;
        char *readme;
+       char *clone_url;
        int snapshots;
        int enable_log_filecount;
        int enable_log_linecount;
@@ -140,6 +141,7 @@ extern char *cgit_script_name;
 extern char *cgit_cache_root;
 extern char *cgit_repo_group;
 extern char *cgit_robots;
+extern char *cgit_clone_prefix;
 
 extern int cgit_nocache;
 extern int cgit_snapshots;
diff --git a/cgitrc b/cgitrc
index 8c616e02a4f13abae8cc7952bddd694aa6bbff11..ce0c01bd689f473dc8c8f7e6da2342cec1c0b813 100644 (file)
--- a/cgitrc
+++ b/cgitrc
 #module-link=./?repo=%s&page=commit&id=%s
 
 
+## Shared prefix which, when combined with repo url, becomes the url used
+## to clone the repo
+#clone-prefix=
+
+
 ## Number of chars shown of repo description (in repolist view)
 #max-repodesc-length=60
 
 #repo.enable-log-linecount=0                   ## override the default linecount setting
 #repo.module-link=/git/%s/commit/?id=%s                ## override the standard module-link
 #repo.readme=info/web/readme                   ## specify a file to include on summary page
+#repo.clone-url=git://hjemli.net/pub/git/cgit
 
 ## Additional repositories grouped under "mirrors"
 #repo.group=mirrors
 
 #repo.url=git
 #repo.path=/pub/git/git
+#repo.clone-url=git://hjemli.net/pub/git/git
 #
 #repo.url=linux
 #repo.path=/pub/git/linux
index fd8b1e33580cff40b1564e593db9b0abdbcdbaa5..2c309f591cc34ea7f9a5fc78bbad37029c0096d0 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -27,6 +27,7 @@ char *cgit_script_name  = CGIT_SCRIPT_NAME;
 char *cgit_cache_root   = CGIT_CACHE_ROOT;
 char *cgit_repo_group   = NULL;
 char *cgit_robots       = "index, nofollow";
+char *cgit_clone_prefix = NULL;
 
 int cgit_nocache               =  0;
 int cgit_snapshots             =  0;
@@ -200,6 +201,8 @@ void cgit_global_config_cb(const char *name, const char *value)
                cgit_renamelimit = atoi(value);
        else if (!strcmp(name, "robots"))
                cgit_robots = xstrdup(value);
+       else if (!strcmp(name, "clone-prefix"))
+               cgit_clone_prefix = xstrdup(value);
        else if (!strcmp(name, "repo.group"))
                cgit_repo_group = xstrdup(value);
        else if (!strcmp(name, "repo.url"))
@@ -208,6 +211,8 @@ void cgit_global_config_cb(const char *name, const char *value)
                cgit_repo->name = xstrdup(value);
        else if (cgit_repo && !strcmp(name, "repo.path"))
                cgit_repo->path = trim_end(value, '/');
+       else if (cgit_repo && !strcmp(name, "repo.clone-url"))
+               cgit_repo->clone_url = xstrdup(value);
        else if (cgit_repo && !strcmp(name, "repo.desc"))
                cgit_repo->desc = xstrdup(value);
        else if (cgit_repo && !strcmp(name, "repo.owner"))
index 3e13c8602a6804839d302a9bd415467240c74785..ece041ce705d9b4d9ba02712f24be957433a2b25 100644 (file)
@@ -460,6 +460,7 @@ void cgit_print_pageheader(char *title, int show_search)
 {
        static const char *default_info = "This is cgit, a fast webinterface for git repositories";
        int header = 0;
+       char *url;
 
        html("<table id='layout' summary=''>\n");
        html("<tr><td id='sidebar'>\n");
@@ -492,6 +493,22 @@ void cgit_print_pageheader(char *title, int show_search)
 
                for_each_ref(print_archive_ref, &header);
 
+               if (cgit_repo->clone_url || cgit_clone_prefix) {
+                       html("<h1>clone</h1>\n");
+                       if (cgit_repo->clone_url)
+                               url = cgit_repo->clone_url;
+                       else
+                               url = fmt("%s%s", cgit_clone_prefix,
+                                         cgit_repo->url);
+                       html("<a class='menu' href='");
+                       html_attr(url);
+                       html("' title='");
+                       html_attr(url);
+                       html("'>\n");
+                       html_txt(strrpart(url, 20));
+                       html("</a>\n");
+               }
+
                html("<h1>branch</h1>\n");
                html("<form method='get' action=''>\n");
                add_hidden_formfields(0, 1, cgit_query_page);