]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/module-links'
authorLars Hjemli <hjemli@gmail.com>
Sun, 18 Mar 2012 20:59:36 +0000 (20:59 +0000)
committerLars Hjemli <hjemli@gmail.com>
Sun, 18 Mar 2012 20:59:36 +0000 (20:59 +0000)
1  2 
cgit.c
cgit.h
cgitrc.5.txt
shared.c
ui-shared.c
ui-shared.h

diff --combined cgit.c
index 1d50129498ae63a458a69cbc5d3ee4a0365c0ae9,9eb2535f65080a4389398b0edae50ac643d22a65..7e3d349aa78a813e4547885aae46492220982c82
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
@@@ -60,6 -60,8 +60,8 @@@ static void process_cached_repolist(con
  
  void repo_config(struct cgit_repo *repo, const char *name, const char *value)
  {
+       struct string_list_item *item;
        if (!strcmp(name, "name"))
                repo->name = xstrdup(value);
        else if (!strcmp(name, "clone-url"))
                repo->max_stats = cgit_find_stats_period(value, NULL);
        else if (!strcmp(name, "module-link"))
                repo->module_link= xstrdup(value);
-       else if (!strcmp(name, "section"))
+       else if (!prefixcmp(name, "module-link.")) {
+               item = string_list_append(&repo->submodules, name + 12);
+               item->util = xstrdup(value);
+       } else if (!strcmp(name, "section"))
                repo->section = xstrdup(value);
        else if (!strcmp(name, "readme") && value != NULL)
                repo->readme = xstrdup(value);
@@@ -298,7 -303,6 +303,7 @@@ static void querystring_cb(const char *
                ctx.qry.period = xstrdup(value);
        } else if (!strcmp(name, "ss")) {
                ctx.qry.ssdiff = atoi(value);
 +              ctx.qry.has_ssdiff = 1;
        } else if (!strcmp(name, "all")) {
                ctx.qry.show_all = atoi(value);
        } else if (!strcmp(name, "context")) {
@@@ -339,7 -343,6 +344,6 @@@ static void prepare_context(struct cgit
        ctx->cfg.max_repodesc_len = 80;
        ctx->cfg.max_blob_size = 0;
        ctx->cfg.max_stats = 0;
-       ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
        ctx->cfg.project_list = NULL;
        ctx->cfg.renamelimit = -1;
        ctx->cfg.remove_suffix = 0;
@@@ -422,17 -425,13 +426,17 @@@ static int prepare_repo_cmd(struct cgit
        char *tmp;
        unsigned char sha1[20];
        int nongit = 0;
 +      int rc;
  
        setenv("GIT_DIR", ctx->repo->path, 1);
        setup_git_directory_gently(&nongit);
        if (nongit) {
 +              rc = errno;
                ctx->page.title = fmt("%s - %s", ctx->cfg.root_title,
                                      "config error");
 -              tmp = fmt("Not a git repository: '%s'", ctx->repo->path);
 +              tmp = fmt("Failed to open %s: %s",
 +                        ctx->repo->name,
 +                        rc ? strerror(rc) : "Not a valid git repository");
                ctx->repo = NULL;
                cgit_print_http_headers(ctx);
                cgit_print_docstart(ctx);
                cgit_print_docend();
                return 1;
        }
+       sort_string_list(&ctx->repo->submodules);
        cgit_prepare_repo_env(ctx->repo);
        return 0;
  }
diff --combined cgit.h
index c7ab5c63928ccc4efa4672182bc035fbae9d7135,9d0b3d012a33c14d207a740858208e7ffbc3320a..b7c7ac949cbee102faf96de540129a273a4177c8
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
@@@ -88,6 -88,7 +88,7 @@@ struct cgit_repo 
        struct cgit_filter *about_filter;
        struct cgit_filter *commit_filter;
        struct cgit_filter *source_filter;
+       struct string_list submodules;
  };
  
  typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
@@@ -137,7 -138,6 +138,7 @@@ struct reflist 
  struct cgit_query {
        int has_symref;
        int has_sha1;
 +      int has_ssdiff;
        char *raw;
        char *repo;
        char *page;
diff --combined cgitrc.5.txt
index a22423bcaeb9ebce08f73e1c219707511635dea7,c8198c124744bae66e5ee65730c6e1ef32bd983c..b4ad2acb5481e99fc592d400ea70c062f4bd4e75
@@@ -230,7 -230,7 +230,7 @@@ module-link:
        Text which will be used as the formatstring for a hyperlink when a
        submodule is printed in a directory listing. The arguments for the
        formatstring are the path and SHA1 of the submodule commit. Default
-       value: "./?repo=%s&page=commit&id=%s"
+       value: none.
  
  nocache::
        If set to the value "1" caching will be disabled. This settings is
@@@ -417,6 -417,12 +417,12 @@@ repo.module-link:
        formatstring are the path and SHA1 of the submodule commit. Default
        value: <module-link>
  
+ repo.module-link.<path>::
+       Text which will be used as the formatstring for a hyperlink when a
+       submodule with the specified subdirectory path is printed in a
+       directory listing. The only argument for the formatstring is the SHA1
+       of the submodule commit. Default value: none.
  repo.max-stats::
        Override the default maximum statistics period. Valid values are equal
        to the values specified for the global "max-stats" setting. Default
@@@ -500,7 -506,7 +506,7 @@@ Also, all filters are handed the follow
  
  If a setting is not defined for a repository and the corresponding global
  setting is also not defined (if applicable), then the corresponding
 -environment variable will be an empty string.
 +environment variable will be unset.
  
  
  MACRO EXPANSION
diff --combined shared.c
index 0c8ce3e2ce79140192585b81d66a589dbaacbdbb,0add2e5df2e369e7ae1113bcdcd70985bcaf512b..cb52380916447eecb62b66957a1655dd6a6a0fd6
+++ b/shared.c
@@@ -8,6 -8,7 +8,6 @@@
  
  #include "cgit.h"
  #include <stdio.h>
 -#include <linux/limits.h>
  
  struct cgit_repolist cgit_repolist;
  struct cgit_context ctx;
@@@ -70,6 -71,7 +70,7 @@@ struct cgit_repo *cgit_add_repo(const c
        ret->commit_filter = ctx.cfg.commit_filter;
        ret->source_filter = ctx.cfg.source_filter;
        ret->clone_url = ctx.cfg.clone_url;
+       ret->submodules.strdup_strings = 1;
        return ret;
  }
  
@@@ -392,7 -394,7 +393,7 @@@ void cgit_prepare_repo_env(struct cgit_
        p = env_vars;
        q = p + env_var_count;
        for (; p < q; p++)
 -              if (setenv(p->name, p->value, 1))
 +              if (p->value && setenv(p->name, p->value, 1))
                        fprintf(stderr, warn, p->name, p->value);
  }
  
diff --combined ui-shared.c
index d7d75bf0cf56b8581fb382b7ee2f996e38a32758,b736fca2d02f79ed2edeca5e3d2e99c342e78f09..43166af4d568125306ff3f88d2f6f97c54d2405e
@@@ -133,7 -133,7 +133,7 @@@ char *cgit_currurl(
                return fmt("%s/", ctx.cfg.virtual_root);
  }
  
 -static void site_url(const char *page, const char *search, int ofs)
 +static void site_url(const char *page, const char *search, const char *sort, int ofs)
  {
        char *delim = "?";
  
                html_attr(search);
                delim = "&";
        }
 +      if (sort) {
 +              html(delim);
 +              html("s=");
 +              html_attr(sort);
 +              delim = "&";
 +      }
        if (ofs) {
                html(delim);
                htmlf("ofs=%d", ofs);
  }
  
  static void site_link(const char *page, const char *name, const char *title,
 -                    const char *class, const char *search, int ofs)
 +                    const char *class, const char *search, const char *sort, int ofs)
  {
        html("<a");
        if (title) {
                html("'");
        }
        html(" href='");
 -      site_url(page, search, ofs);
 +      site_url(page, search, sort, ofs);
        html("'>");
        html_txt(name);
        html("</a>");
  }
  
  void cgit_index_link(const char *name, const char *title, const char *class,
 -                   const char *pattern, int ofs)
 +                   const char *pattern, const char *sort, int ofs)
  {
 -      site_link(NULL, name, title, class, pattern, ofs);
 +      site_link(NULL, name, title, class, pattern, sort, ofs);
  }
  
  static char *repolink(const char *title, const char *class, const char *page,
@@@ -294,7 -288,7 +294,7 @@@ void cgit_log_link(const char *name, co
        char *delim;
  
        delim = repolink(title, class, "log", head, path);
 -      if (rev && strcmp(rev, ctx.qry.head)) {
 +      if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
                html(delim);
                html("id=");
                html_url_arg(rev);
@@@ -338,7 -332,7 +338,7 @@@ void cgit_commit_link(char *name, cons
        char *delim;
  
        delim = repolink(title, class, "commit", head, path);
 -      if (rev && strcmp(rev, ctx.qry.head)) {
 +      if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
                html(delim);
                html("id=");
                html_url_arg(rev);
@@@ -434,7 -428,7 +434,7 @@@ void cgit_self_link(char *name, const c
                    struct cgit_context *ctx)
  {
        if (!strcmp(ctx->qry.page, "repolist"))
 -              return cgit_index_link(name, title, class, ctx->qry.search,
 +              return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort,
                                       ctx->qry.ofs);
        else if (!strcmp(ctx->qry.page, "summary"))
                return cgit_summary_link(name, title, class, ctx->qry.head);
@@@ -509,6 -503,62 +509,62 @@@ void cgit_object_link(struct object *ob
        reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
  }
  
+ struct string_list_item *lookup_path(struct string_list *list,
+                                    const char *path)
+ {
+       struct string_list_item *item;
+       while (path && path[0]) {
+               if ((item = string_list_lookup(list, path)))
+                       return item;
+               if (!(path = strchr(path, '/')))
+                       break;
+               path++;
+       }
+       return NULL;
+ }
+ void cgit_submodule_link(const char *class, char *path, const char *rev)
+ {
+       struct string_list *list;
+       struct string_list_item *item;
+       char tail, *dir;
+       size_t len;
+       tail = 0;
+       list = &ctx.repo->submodules;
+       item = lookup_path(list, path);
+       if (!item) {
+               len = strlen(path);
+               tail = path[len - 1];
+               if (tail == '/') {
+                       path[len - 1] = 0;
+                       item = lookup_path(list, path);
+               }
+       }
+       html("<a ");
+       if (class)
+               htmlf("class='%s' ", class);
+       html("href='");
+       if (item) {
+               html_attr(fmt(item->util, rev));
+       } else if (ctx.repo->module_link) {
+               dir = strrchr(path, '/');
+               if (dir)
+                       dir++;
+               else
+                       dir = path;
+               html_attr(fmt(ctx.repo->module_link, dir, rev));
+       } else {
+               html("#");
+       }
+       html("'>");
+       html_txt(path);
+       html("</a>");
+       if (item && tail)
+               path[len - 1] = tail;
+ }
  void cgit_print_date(time_t secs, const char *format, int local_time)
  {
        char buf[64];
@@@ -619,7 -669,7 +675,7 @@@ void cgit_print_docstart(struct cgit_co
                html_attr(ctx->cfg.favicon);
                html("'/>\n");
        }
 -      if (host && ctx->repo) {
 +      if (host && ctx->repo && ctx->qry.head) {
                html("<link rel='alternate' title='Atom feed' href='");
                html(cgit_httpscheme());
                html_attr(cgit_hosturl());
@@@ -788,7 -838,7 +844,7 @@@ static void print_header(struct cgit_co
  
        html("<td class='main'>");
        if (ctx->repo) {
 -              cgit_index_link("index", NULL, NULL, NULL, 0);
 +              cgit_index_link("index", NULL, NULL, NULL, NULL, 0);
                html(" : ");
                cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
                html("</td><td class='form'>");
@@@ -864,10 -914,10 +920,10 @@@ void cgit_print_pageheader(struct cgit_
                html("<input type='submit' value='search'/>\n");
                html("</form>\n");
        } else {
 -              site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0);
 +              site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, NULL, 0);
                if (ctx->cfg.root_readme)
                        site_link("about", "about", NULL, hc(ctx, "about"),
 -                                NULL, 0);
 +                                NULL, NULL, 0);
                html("</td><td class='form'>");
                html("<form method='get' action='");
                html_attr(cgit_rooturl());
diff --combined ui-shared.h
index 865bd45b50e8b77eb809ae976ddaeb39fba8e39a,e80b975ef8b0478c9f8bc7d6d49264deeb8b41f5..87a7dac82f85d5d8f9dc391f5fe9a1ffe940c222
@@@ -11,7 -11,7 +11,7 @@@ extern char *cgit_pageurl(const char *r
                          const char *query);
  
  extern void cgit_index_link(const char *name, const char *title,
 -                          const char *class, const char *pattern, int ofs);
 +                          const char *class, const char *pattern, const char *sort, int ofs);
  extern void cgit_summary_link(const char *name, const char *title,
                              const char *class, const char *head);
  extern void cgit_tag_link(const char *name, const char *title,
@@@ -51,6 -51,9 +51,9 @@@ extern void cgit_self_link(char *name, 
                           const char *class, struct cgit_context *ctx);
  extern void cgit_object_link(struct object *obj);
  
+ extern void cgit_submodule_link(const char *class, char *path,
+                               const char *rev);
  extern void cgit_print_error(const char *msg);
  extern void cgit_print_date(time_t secs, const char *format, int local_time);
  extern void cgit_print_age(time_t t, time_t max_relative, const char *format);