]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/macros'
authorLars Hjemli <hjemli@gmail.com>
Sun, 18 Jul 2010 13:03:08 +0000 (15:03 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sun, 18 Jul 2010 13:03:08 +0000 (15:03 +0200)
1  2 
cgit.c
cgit.h
shared.c

diff --combined cgit.c
index ab25b6a00efe4889863b7625c22e9ea180d0fe61,37154e3c2afe9e409bd04f79a6691102cd9d529c..fde0757416798d90808809e5b434384d5261f6ed
--- 1/cgit.c
--- 2/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"))
        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"))
                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"))
                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"))
        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)
                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 2b28d636e20ba1f79c398a83f9383d43cba9e2e0,568e0c088e543846739af1e51c4fcc06fbc82fcc..2bf6ab023fb44340b16e564c6cfee7a2b4442fa6
--- 1/cgit.h
--- 2/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 {
        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 06f70bb141587c25565664ef42cbdd9b1addec09,76d26dd99e902c0e651c33c9f40dd64428c5f6b7..9f7d6a5cc0a7a83c689a4b345486ecf14ee985c8
+++ 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;
        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;
        }
  
        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;
+ }