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

diff --combined cgit.c
index fde0757416798d90808809e5b434384d5261f6ed,945288445472aca4850b95318db957a320ce15a1..c2638727b629438d89cb0f3d7efa851ae1779a36
--- 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);
+       } else if (!strcmp(name, "ignorews")) {
+               ctx.qry.ignorews = atoi(value);
        }
  }
  
@@@ -302,7 -296,6 +304,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"));
@@@ -705,7 -698,7 +707,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 2bf6ab023fb44340b16e564c6cfee7a2b4442fa6,1bdfbc666aeed1d4bd995e2524979a03669de471..e9e27188056157507452e13abe20e4fc056c2a6c
--- 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,8 -145,8 +146,9 @@@ struct cgit_query 
        char *sort;
        int showmsg;
        int ssdiff;
 +      int show_all;
        int context;
+       int ignorews;
        char *vpath;
  };
  
@@@ -185,10 -184,8 +186,10 @@@ 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,11 -276,12 +280,12 @@@ 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, int context, linediff_fn fn);
+                          int *binary, int context, int ignorews,
+                          linediff_fn fn);
  
  extern void cgit_diff_tree(const unsigned char *old_sha1,
                           const unsigned char *new_sha1,
-                          filepair_fn fn, const char *prefix);
+                          filepair_fn fn, const char *prefix, int ignorews);
  
  extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
  
@@@ -302,6 -300,4 +304,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 9f7d6a5cc0a7a83c689a4b345486ecf14ee985c8,d0973ab8dfa50fd77fadf59d6111c7df5f62c97e..b42c2a2fdd829c635439b568076c4462222aad7a
+++ b/shared.c
@@@ -59,7 -59,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;
@@@ -264,7 -263,7 +264,7 @@@ 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, int context,
-                   linediff_fn fn)
+                   int ignorews, 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;
+       if (ignorews)
+               diff_params.flags |= XDF_IGNORE_WHITESPACE;
        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;
  }
  
  void cgit_diff_tree(const unsigned char *old_sha1,
                    const unsigned char *new_sha1,
-                   filepair_fn fn, const char *prefix)
+                   filepair_fn fn, const char *prefix, int ignorews)
  {
        struct diff_options opt;
        int ret;
        opt.detect_rename = 1;
        opt.rename_limit = ctx.cfg.renamelimit;
        DIFF_OPT_SET(&opt, RECURSIVE);
+       if (ignorews)
+               DIFF_XDL_SET(&opt, IGNORE_WHITESPACE);
        opt.format_callback = cgit_diff_tree_cb;
        opt.format_callback_data = fn;
        if (prefix) {
@@@ -340,7 -335,8 +344,8 @@@ void cgit_diff_commit(struct commit *co
  
        if (commit->parents)
                old_sha1 = commit->parents->item->object.sha1;
-       cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
+       cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL,
+                      ctx.qry.ignorews);
  }
  
  int cgit_parse_snapshots_mask(const char *str)
@@@ -432,74 -428,3 +437,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;
 +}
diff --combined ui-log.c
index 33ec8a95f5712d09a1151f69b91cee9a6a91cb75,354ee080e0b9f7b73853e0f311b262e82bd7a2d4..ee93653384695d7337b3947c9c59505800ec853a
+++ b/ui-log.c
@@@ -33,7 -33,8 +33,8 @@@ void inspect_files(struct diff_filepai
        files++;
        if (ctx.repo->enable_log_linecount)
                cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
-                               &new_size, &binary, 0, count_lines);
+                               &new_size, &binary, 0, ctx.qry.ignorews,
+                               count_lines);
  }
  
  void show_commit_decorations(struct commit *commit)
@@@ -149,13 -150,10 +150,13 @@@ void cgit_print_log(const char *tip, in
  
        argv[1] = disambiguate_ref(tip);
  
 -      if (grep && pattern && (!strcmp(grep, "grep") ||
 -                              !strcmp(grep, "author") ||
 -                              !strcmp(grep, "committer")))
 -              argv[argc++] = fmt("--%s=%s", grep, pattern);
 +      if (grep && pattern) {
 +              if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
 +                  !strcmp(grep, "committer"))
 +                      argv[argc++] = fmt("--%s=%s", grep, pattern);
 +              if (!strcmp(grep, "range"))
 +                      argv[1] = pattern;
 +      }
  
        if (path) {
                argv[argc++] = "--";
diff --combined ui-shared.c
index c398d7aaf85a4ce5dfedbccc97bc844713dd44bf,f46c935cdeeb784ddaed4fcaf7c2e57dee49a9d9..ae29615a32d04ac8c3e933815e61b64543fdecee
@@@ -349,6 -349,11 +349,11 @@@ void cgit_commit_link(char *name, cons
                htmlf("%d", ctx.qry.context);
                delim = "&amp;";
        }
+       if (ctx.qry.ignorews) {
+               html(delim);
+               html("ignorews=1");
+               delim = "&amp;";
+       }
        html("'>");
        html_txt(name);
        html("</a>");
@@@ -397,6 -402,11 +402,11 @@@ void cgit_diff_link(const char *name, c
                htmlf("%d", ctx.qry.context);
                delim = "&amp;";
        }
+       if (ctx.qry.ignorews) {
+               html(delim);
+               html("ignorews=1");
+               delim = "&amp;";
+       }
        html("'>");
        html_txt(name);
        html("</a>");
@@@ -830,7 -840,6 +840,7 @@@ void cgit_print_pageheader(struct cgit_
                html_option("grep", "log msg", ctx->qry.grep);
                html_option("author", "author", ctx->qry.grep);
                html_option("committer", "committer", ctx->qry.grep);
 +              html_option("range", "range", ctx->qry.grep);
                html("</select>\n");
                html("<input class='txt' type='text' size='10' name='q' value='");
                html_attr(ctx->qry.search);