]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/plugins'
authorLars Hjemli <hjemli@gmail.com>
Sun, 9 Aug 2009 11:46:01 +0000 (13:46 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sun, 9 Aug 2009 11:46:01 +0000 (13:46 +0200)
Conflicts:
cgit.c
cgit.h

1  2 
cgit.c
cgit.h
cgitrc.5.txt
ui-commit.c
ui-tree.c

diff --combined cgit.c
index aa1107ae2100f0c13b47f18085f38542bfb3c570,b3a98c1599ff8971d9af03a0ca8ea1a1b6d8abb0..dbec1962763145d3c88f89b3ba947dd9ca11bbd5
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
  
  const char *cgit_version = CGIT_VERSION;
  
 +void add_mimetype(const char *name, const char *value)
 +{
 +      struct string_list_item *item;
 +
 +      item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
 +      item->util = xstrdup(value);
 +}
 +
+ struct cgit_filter *new_filter(const char *cmd, int extra_args)
+ {
+       struct cgit_filter *f;
+       if (!cmd || !cmd[0])
+               return NULL;
+       f = xmalloc(sizeof(struct cgit_filter));
+       f->cmd = xstrdup(cmd);
+       f->argv = xmalloc((2 + extra_args) * sizeof(char *));
+       f->argv[0] = f->cmd;
+       f->argv[1] = NULL;
+       return f;
+ }
  void config_cb(const char *name, const char *value)
  {
        if (!strcmp(name, "root-title"))
@@@ -59,8 -66,6 +74,8 @@@
                        ctx.cfg.virtual_root = "";
        } else if (!strcmp(name, "nocache"))
                ctx.cfg.nocache = atoi(value);
 +      else if (!strcmp(name, "noplainemail"))
 +              ctx.cfg.noplainemail = atoi(value);
        else if (!strcmp(name, "noheader"))
                ctx.cfg.noheader = atoi(value);
        else if (!strcmp(name, "snapshots"))
                ctx.cfg.cache_static_ttl = atoi(value);
        else if (!strcmp(name, "cache-dynamic-ttl"))
                ctx.cfg.cache_dynamic_ttl = atoi(value);
+       else if (!strcmp(name, "commit-filter"))
+               ctx.cfg.commit_filter = new_filter(value, 0);
        else if (!strcmp(name, "embedded"))
                ctx.cfg.embedded = atoi(value);
        else if (!strcmp(name, "max-message-length"))
                ctx.cfg.max_repo_count = atoi(value);
        else if (!strcmp(name, "max-commit-count"))
                ctx.cfg.max_commit_count = atoi(value);
+       else if (!strcmp(name, "source-filter"))
+               ctx.cfg.source_filter = new_filter(value, 1);
        else if (!strcmp(name, "summary-log"))
                ctx.cfg.summary_log = atoi(value);
        else if (!strcmp(name, "summary-branches"))
                ctx.cfg.clone_prefix = xstrdup(value);
        else if (!strcmp(name, "local-time"))
                ctx.cfg.local_time = atoi(value);
 +      else if (!prefixcmp(name, "mimetype."))
 +              add_mimetype(name + 9, value);
        else if (!strcmp(name, "repo.group"))
                ctx.cfg.repo_group = xstrdup(value);
        else if (!strcmp(name, "repo.url"))
                ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
        else if (ctx.repo && !strcmp(name, "repo.module-link"))
                ctx.repo->module_link= xstrdup(value);
+       else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
+               ctx.repo->commit_filter = new_filter(value, 0);
+       else if (ctx.repo && !strcmp(name, "repo.source-filter"))
+               ctx.repo->source_filter = new_filter(value, 1);
        else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
                if (*value == '/')
                        ctx.repo->readme = xstrdup(value);
@@@ -225,7 -236,6 +248,7 @@@ static void prepare_context(struct cgit
        ctx->page.modified = time(NULL);
        ctx->page.expires = ctx->page.modified;
        ctx->page.etag = NULL;
 +      memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
  }
  
  struct refmatch {
diff --combined cgit.h
index 1194eb0209880289729ac3a196d6037ea7427561,f10ba054bc1a7b0d0e728e10983490347a9d9713..b8557ace3912b4b62c59eb709fc37dea2f1f506c
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
@@@ -15,7 -15,6 +15,7 @@@
  #include <revision.h>
  #include <log-tree.h>
  #include <archive.h>
 +#include <string-list.h>
  #include <xdiff-interface.h>
  #include <xdiff/xdiff.h>
  #include <utf8.h>
@@@ -49,6 -48,15 +49,15 @@@ typedef void (*configfn)(const char *na
  typedef void (*filepair_fn)(struct diff_filepair *pair);
  typedef void (*linediff_fn)(char *line, int len);
  
+ struct cgit_filter {
+       char *cmd;
+       char **argv;
+       int old_stdout;
+       int pipe_fh[2];
+       int pid;
+       int exitstatus;
+ };
  struct cgit_repo {
        char *url;
        char *name;
@@@ -65,6 -73,8 +74,8 @@@
        int enable_log_linecount;
        int max_stats;
        time_t mtime;
+       struct cgit_filter *commit_filter;
+       struct cgit_filter *source_filter;
  };
  
  struct cgit_repolist {
@@@ -169,14 -179,14 +180,16 @@@ struct cgit_config 
        int max_repodesc_len;
        int max_stats;
        int nocache;
 +      int noplainemail;
        int noheader;
        int renamelimit;
        int snapshots;
        int summary_branches;
        int summary_log;
        int summary_tags;
 +      struct string_list mimetypes;
+       struct cgit_filter *commit_filter;
+       struct cgit_filter *source_filter;
  };
  
  struct cgit_page {
@@@ -251,5 -261,8 +264,8 @@@ extern const char *cgit_repobasename(co
  
  extern int cgit_parse_snapshots_mask(const char *str);
  
+ extern int cgit_open_filter(struct cgit_filter *filter);
+ extern int cgit_close_filter(struct cgit_filter *filter);
  
  #endif /* CGIT_H */
diff --combined cgitrc.5.txt
index 0412f64acb507b3a2fa652108890e367017c0732,ffb3e0f4bf6d2abc5fefe5192c07cb7bf31688e3..dc63637b4bb7b17f9a5aeb7088e94db343189d72
@@@ -55,6 -55,12 +55,12 @@@ clone-prefix:
        setting is only used if `repo.clone-url` is unspecified. Default value:
        none.
  
+ commit-filter::
+       Specifies a command which will be invoked to format commit messages.
+       The command will get the message on its STDIN, and the STDOUT from the
+       command will be included verbatim as the commit message, i.e. this can
+       be used to implement bugtracker integration. Default value: none.
  css::
        Url which specifies the css document to include in all cgit pages.
        Default value: "/cgit.css".
@@@ -147,10 -153,6 +153,10 @@@ max-stats:
        "month", "quarter" and "year". If unspecified, statistics are
        disabled. Default value: none. See also: "repo.max-stats".
  
 +mimetype.<ext>::
 +      Set the mimetype for the specified filename extension. This is used
 +      by the `plain` command when returning blob content.
 +
  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
@@@ -162,10 -164,6 +168,10 @@@ nocache:
        deprecated, and will not be honored starting with cgit-1.0. Default
        value: "0".
  
 +noplainemail::
 +      If set to "1" showing full author email adresses will be disabled.
 +      Default value: "0".
 +
  noheader::
        Flag which, when set to "1", will make cgit omit the standard header
        on all pages. Default value: none. See also: "embedded".
@@@ -206,6 -204,14 +212,14 @@@ snapshots:
                "zip"           zip-file
        Default value: none.
  
+ source-filter::
+       Specifies a command which will be invoked to format plaintext blobs
+       in the tree view. The command will get the blob content on its STDIN
+       and the name of the blob as its only command line argument. The STDOUT
+       from the command will be included verbatim as the blob contents, i.e.
+       this can be used to implement e.g. syntax highlighting. Default value:
+       none.
  summary-branches::
        Specifies the number of branches to display in the repository "summary"
        view. Default value: "10".
@@@ -232,6 -238,9 +246,9 @@@ repo.clone-url:
        A list of space-separated urls which can be used to clone this repo.
        Default value: none.
  
+ repo.commit-filter::
+       Override the default commit-filter. Default value: <commit-filter>.
  repo.defbranch::
        The name of the default branch for this repository. If no such branch
        exists in the repository, the first branch name (when sorted) is used
@@@ -272,6 -281,9 +289,9 @@@ repo.snapshots:
        A mask of allowed snapshot-formats for this repo, restricted by the
        "snapshots" global setting. Default value: <snapshots>.
  
+ repo.source-filter::
+       Override the default source-filter. Default value: <source-filter>.
  repo.url::
        The relative url used to access the repository. This must be the first
        setting specified for each repo. Default value: none.
@@@ -332,19 -344,6 +352,19 @@@ root-readme=/var/www/htdocs/about.htm
  snapshots=tar.gz tar.bz2 zip
  
  
 +##
 +## List of common mimetypes
 +##
 +
 +mimetype.git=image/git
 +mimetype.html=text/html
 +mimetype.jpg=image/jpeg
 +mimetype.jpeg=image/jpeg
 +mimetype.pdf=application/pdf
 +mimetype.png=image/png
 +mimetype.svg=image/svg+xml
 +
 +
  ##
  ## List of repositories.
  ## PS: Any repositories listed when repo.group is unset will not be
diff --combined ui-commit.c
index 9fdb8eed4d2118c968571db50839bac55f0f7c3f,5815b585509d4459bbd4a2b516ac1250a6d609a1..d6b73eed90aaf5ee232e89f5a1655c94db392577
@@@ -40,19 -40,15 +40,19 @@@ void cgit_print_commit(char *hex
        html("<table summary='commit info' class='commit-info'>\n");
        html("<tr><th>author</th><td>");
        html_txt(info->author);
 -      html(" ");
 -      html_txt(info->author_email);
 +      if (!ctx.cfg.noplainemail) {
 +              html(" ");
 +              html_txt(info->author_email);
 +      }
        html("</td><td class='right'>");
        cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
        html("</td></tr>\n");
        html("<tr><th>committer</th><td>");
        html_txt(info->committer);
 -      html(" ");
 -      html_txt(info->committer_email);
 +      if (!ctx.cfg.noplainemail) {
 +              html(" ");
 +              html_txt(info->committer_email);
 +      }
        html("</td><td class='right'>");
        cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
        html("</td></tr>\n");
        }
        html("</table>\n");
        html("<div class='commit-subject'>");
+       if (ctx.repo->commit_filter)
+               cgit_open_filter(ctx.repo->commit_filter);
        html_txt(info->subject);
+       if (ctx.repo->commit_filter)
+               cgit_close_filter(ctx.repo->commit_filter);
        show_commit_decorations(commit);
        html("</div>");
        html("<div class='commit-msg'>");
+       if (ctx.repo->commit_filter)
+               cgit_open_filter(ctx.repo->commit_filter);
        html_txt(info->msg);
+       if (ctx.repo->commit_filter)
+               cgit_close_filter(ctx.repo->commit_filter);
        html("</div>");
        if (parents < 3) {
                if (parents)
diff --combined ui-tree.c
index 61fcf5a0776433a3a129a8fa805f7ab2ce11ff6f,caf6a9e979bea7d9994e8137f25e0563358abea9..c608754f3e8e930169fda2ad08b7aba00a07cdb1
+++ b/ui-tree.c
@@@ -15,13 -15,23 +15,23 @@@ char *curr_rev
  char *match_path;
  int header = 0;
  
- static void print_text_buffer(char *buf, unsigned long size)
+ static void print_text_buffer(const char *name, char *buf, unsigned long size)
  {
        unsigned long lineno, idx;
        const char *numberfmt =
                "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
  
        html("<table summary='blob content' class='blob'>\n");
+       if (ctx.repo->source_filter) {
+               html("<tr><td class='lines'><pre><code>");
+               ctx.repo->source_filter->argv[1] = xstrdup(name);
+               cgit_open_filter(ctx.repo->source_filter);
+               write(STDOUT_FILENO, buf, size);
+               cgit_close_filter(ctx.repo->source_filter);
+               html("</code></pre></td></tr></table>\n");
+               return;
+       }
        html("<tr><td class='linenumbers'><pre>");
        idx = 0;
        lineno = 0;
@@@ -65,7 -75,7 +75,7 @@@ static void print_binary_buffer(char *b
        html("</table>\n");
  }
  
- static void print_object(const unsigned char *sha1, char *path)
+ static void print_object(const unsigned char *sha1, char *path, const char *basename)
  {
        enum object_type type;
        char *buf;
        if (buffer_is_binary(buf, size))
                print_binary_buffer(buf, size);
        else
-               print_text_buffer(buf, size);
+               print_text_buffer(basename, buf, size);
  }
  
  
@@@ -103,7 -113,6 +113,7 @@@ static int ls_item(const unsigned char 
  {
        char *name;
        char *fullpath;
 +      char *class;
        enum object_type type;
        unsigned long size = 0;
  
                cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
                               curr_rev, fullpath);
        } else {
 -              cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
 +              class = strrchr(name, '.');
 +              if (class != NULL) {
 +                      class = fmt("ls-blob %s", class + 1);
 +              } else
 +                      class = "ls-blob";
 +              cgit_tree_link(name, NULL, class, ctx.qry.head,
                               curr_rev, fullpath);
        }
        htmlf("</td><td class='ls-size'>%li</td>", size);
@@@ -219,7 -223,7 +229,7 @@@ static int walk_tree(const unsigned cha
                        ls_head();
                        return READ_TREE_RECURSIVE;
                } else {
-                       print_object(sha1, buffer);
+                       print_object(sha1, buffer, pathname);
                        return 0;
                }
        }