From: Lars Hjemli Date: Sun, 18 Jul 2010 13:03:08 +0000 (+0200) Subject: Merge branch 'lh/macros' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/5c5d189635287a3bfaa1a4aef133dc0c582a27c2?hp=-c Merge branch 'lh/macros' --- 5c5d189635287a3bfaa1a4aef133dc0c582a27c2 diff --combined cgit.c index ab25b6a,37154e3..fde0757 --- a/cgit.c +++ b/cgit.c @@@ -62,8 -62,6 +62,8 @@@ void repo_config(struct cgit_repo *repo repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); else if (!strcmp(name, "enable-remote-branches")) repo->enable_remote_branches = atoi(value); + else if (!strcmp(name, "enable-subject-links")) + repo->enable_subject_links = atoi(value); else if (!strcmp(name, "max-stats")) repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) @@@ -143,8 -141,6 +143,8 @@@ void config_cb(const char *name, const ctx.cfg.enable_log_linecount = atoi(value); else if (!strcmp(name, "enable-remote-branches")) ctx.cfg.enable_remote_branches = atoi(value); + else if (!strcmp(name, "enable-subject-links")) + ctx.cfg.enable_subject_links = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); else if (!strcmp(name, "max-stats")) @@@ -152,7 -148,7 +152,7 @@@ else if (!strcmp(name, "cache-size")) ctx.cfg.cache_size = atoi(value); else if (!strcmp(name, "cache-root")) - ctx.cfg.cache_root = xstrdup(value); + ctx.cfg.cache_root = xstrdup(expand_macros(value)); else if (!strcmp(name, "cache-root-ttl")) ctx.cfg.cache_root_ttl = atoi(value); else if (!strcmp(name, "cache-repo-ttl")) @@@ -169,8 -165,6 +169,8 @@@ ctx.cfg.commit_filter = new_filter(value, 0); else if (!strcmp(name, "embedded")) ctx.cfg.embedded = atoi(value); + else if (!strcmp(name, "max-atom-items")) + ctx.cfg.max_atom_items = atoi(value); else if (!strcmp(name, "max-message-length")) ctx.cfg.max_msg_len = atoi(value); else if (!strcmp(name, "max-repodesc-length")) @@@ -183,9 -177,9 +183,9 @@@ ctx.cfg.max_commit_count = atoi(value); else if (!strcmp(name, "scan-path")) if (!ctx.cfg.nocache && ctx.cfg.cache_size) - process_cached_repolist(value); + process_cached_repolist(expand_macros(value)); else - scan_tree(value, repo_config); + scan_tree(expand_macros(value), repo_config); else if (!strcmp(name, "source-filter")) ctx.cfg.source_filter = new_filter(value, 1); else if (!strcmp(name, "summary-log")) @@@ -209,7 -203,7 +209,7 @@@ else if (!prefixcmp(name, "mimetype.")) add_mimetype(name + 9, value); else if (!strcmp(name, "include")) - parse_configfile(value, config_cb); + parse_configfile(expand_macros(value), config_cb); } static void querystring_cb(const char *name, const char *value) @@@ -256,10 -250,6 +256,10 @@@ ctx.qry.period = xstrdup(value); } else if (!strcmp(name, "ss")) { ctx.qry.ssdiff = atoi(value); + } else if (!strcmp(name, "all")) { + ctx.qry.show_all = atoi(value); + } else if (!strcmp(name, "context")) { + ctx.qry.context = atoi(value); } } @@@ -302,7 -292,6 +302,7 @@@ static void prepare_context(struct cgit ctx->cfg.summary_branches = 10; ctx->cfg.summary_log = 10; ctx->cfg.summary_tags = 10; + ctx->cfg.max_atom_items = 10; ctx->cfg.ssdiff = 0; ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); @@@ -435,12 -424,6 +435,12 @@@ static void process_request(void *cbdat return; } + /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" + * in-project path limit to be made available at ctx->qry.vpath. + * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). + */ + ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; + if (cmd->want_repo && !ctx->repo) { cgit_print_http_headers(ctx); cgit_print_docstart(ctx); @@@ -705,7 -688,7 +705,7 @@@ int main(int argc, const char **argv cgit_repolist.repos = NULL; cgit_parse_args(argc, argv); - parse_configfile(ctx.env.cgit_config, config_cb); + parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); ctx.repo = NULL; http_parse_querystring(ctx.qry.raw, querystring_cb); diff --combined cgit.h index 2b28d63,568e0c0..2bf6ab0 --- a/cgit.h +++ b/cgit.h @@@ -73,7 -73,6 +73,7 @@@ struct cgit_repo int enable_log_filecount; int enable_log_linecount; int enable_remote_branches; + int enable_subject_links; int max_stats; time_t mtime; struct cgit_filter *about_filter; @@@ -146,9 -145,6 +146,9 @@@ struct cgit_query char *sort; int showmsg; int ssdiff; + int show_all; + int context; + char *vpath; }; struct cgit_config { @@@ -185,10 -181,8 +185,10 @@@ int enable_log_filecount; int enable_log_linecount; int enable_remote_branches; + int enable_subject_links; int enable_tree_linenumbers; int local_time; + int max_atom_items; int max_repo_count; int max_commit_count; int max_lock_attempts; @@@ -279,7 -273,7 +279,7 @@@ extern void *cgit_free_commitinfo(struc extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, unsigned long *old_size, unsigned long *new_size, - int *binary, linediff_fn fn); + int *binary, int context, linediff_fn fn); extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, @@@ -302,4 -296,6 +302,6 @@@ extern int cgit_close_filter(struct cgi extern int readfile(const char *path, char **buf, size_t *size); + extern char *expand_macros(const char *txt); + #endif /* CGIT_H */ diff --combined shared.c index 06f70bb,76d26dd..9f7d6a5 --- a/shared.c +++ b/shared.c @@@ -10,6 -10,7 +10,6 @@@ struct cgit_repolist cgit_repolist; struct cgit_context ctx; -int cgit_cmd; int chk_zero(int result, char *msg) { @@@ -59,7 -60,6 +59,7 @@@ struct cgit_repo *cgit_add_repo(const c ret->enable_log_filecount = ctx.cfg.enable_log_filecount; ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->enable_remote_branches = ctx.cfg.enable_remote_branches; + ret->enable_subject_links = ctx.cfg.enable_subject_links; ret->max_stats = ctx.cfg.max_stats; ret->module_link = ctx.cfg.module_link; ret->readme = NULL; @@@ -263,8 -263,7 +263,8 @@@ int filediff_cb(void *priv, mmbuffer_t int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, unsigned long *old_size, - unsigned long *new_size, int *binary, linediff_fn fn) + unsigned long *new_size, int *binary, int context, + linediff_fn fn) { mmfile_t file1, file2; xpparam_t diff_params; @@@ -280,10 -279,6 +280,10 @@@ if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { *binary = 1; + if (file1.size) + free(file1.ptr); + if (file2.size) + free(file2.ptr); return 0; } @@@ -291,15 -286,11 +291,15 @@@ memset(&emit_params, 0, sizeof(emit_params)); memset(&emit_cb, 0, sizeof(emit_cb)); diff_params.flags = XDF_NEED_MINIMAL; - emit_params.ctxlen = 3; + emit_params.ctxlen = context > 0 ? context : 3; emit_params.flags = XDL_EMIT_FUNCNAMES; emit_cb.outf = filediff_cb; emit_cb.priv = fn; xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); + if (file1.size) + free(file1.ptr); + if (file2.size) + free(file2.ptr); return 0; } @@@ -432,3 -423,74 +432,74 @@@ int readfile(const char *path, char **b close(fd); return (*size == st.st_size ? 0 : e); } + + int is_token_char(char c) + { + return isalnum(c) || c == '_'; + } + + /* Replace name with getenv(name), return pointer to zero-terminating char + */ + char *expand_macro(char *name, int maxlength) + { + char *value; + int len; + + len = 0; + value = getenv(name); + if (value) { + len = strlen(value); + if (len > maxlength) + len = maxlength; + strncpy(name, value, len); + } + return name + len; + } + + #define EXPBUFSIZE (1024 * 8) + + /* Replace all tokens prefixed by '$' in the specified text with the + * value of the named environment variable. + * NB: the return value is a static buffer, i.e. it must be strdup'd + * by the caller. + */ + char *expand_macros(const char *txt) + { + static char result[EXPBUFSIZE]; + char *p, *start; + int len; + + p = result; + start = NULL; + while (p < result + EXPBUFSIZE - 1 && txt && *txt) { + *p = *txt; + if (start) { + if (!is_token_char(*txt)) { + if (p - start > 0) { + *p = '\0'; + len = result + EXPBUFSIZE - start - 1; + p = expand_macro(start, len) - 1; + } + start = NULL; + txt--; + } + p++; + txt++; + continue; + } + if (*txt == '$') { + start = p; + txt++; + continue; + } + p++; + txt++; + } + *p = '\0'; + if (start && p - start > 0) { + len = result + EXPBUFSIZE - start - 1; + p = expand_macro(start, len); + *p = '\0'; + } + return result; + }