From: Lars Hjemli Date: Sun, 9 Aug 2009 11:46:01 +0000 (+0200) Subject: Merge branch 'lh/plugins' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/db6303b58883c4417f5bcc0c1ee34fed6553dca3?hp=-c Merge branch 'lh/plugins' Conflicts: cgit.c cgit.h --- db6303b58883c4417f5bcc0c1ee34fed6553dca3 diff --combined cgit.c index aa1107a,b3a98c1..dbec196 --- a/cgit.c +++ b/cgit.c @@@ -17,14 -17,21 +17,29 @@@ 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")) @@@ -85,6 -90,8 +100,8 @@@ 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")) @@@ -95,6 -102,8 +112,8 @@@ 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")) @@@ -111,8 -120,6 +130,8 @@@ 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")) @@@ -139,6 -146,10 +158,10 @@@ 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 1194eb0,f10ba05..b8557ac --- a/cgit.h +++ b/cgit.h @@@ -15,7 -15,6 +15,7 @@@ #include #include #include +#include #include #include #include @@@ -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 0412f64,ffb3e0f..dc63637 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@@ -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.:: + 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: . + 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: . + repo.source-filter:: + Override the default source-filter. Default value: . + 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 9fdb8ee,5815b58..d6b73ee --- a/ui-commit.c +++ b/ui-commit.c @@@ -40,19 -40,15 +40,19 @@@ void cgit_print_commit(char *hex html("\n"); html("\n"); html("\n"); @@@ -93,11 -89,19 +93,19 @@@ } html("
author"); html_txt(info->author); - html(" "); - html_txt(info->author_email); + if (!ctx.cfg.noplainemail) { + html(" "); + html_txt(info->author_email); + } html(""); cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); html("
committer"); html_txt(info->committer); - html(" "); - html_txt(info->committer_email); + if (!ctx.cfg.noplainemail) { + html(" "); + html_txt(info->committer_email); + } html(""); cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); html("
\n"); html("
"); + 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("
"); html("
"); + 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("
"); if (parents < 3) { if (parents) diff --combined ui-tree.c index 61fcf5a,caf6a9e..c608754 --- a/ui-tree.c +++ 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 = "%1$d\n"; html("\n"); + if (ctx.repo->source_filter) { + html("
");
+ 		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("
\n"); + return; + } + html("
");
  	idx = 0;
  	lineno = 0;
@@@ -65,7 -75,7 +75,7 @@@ static void print_binary_buffer(char *b
  	html("\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;
@@@ -93,7 -103,7 +103,7 @@@
  	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;
  
@@@ -136,12 -145,7 +146,12 @@@
  		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("%li", 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;
  		}
  	}