]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'stable'
authorLars Hjemli <hjemli@gmail.com>
Tue, 3 Jan 2012 16:06:58 +0000 (16:06 +0000)
committerLars Hjemli <hjemli@gmail.com>
Tue, 3 Jan 2012 16:06:58 +0000 (16:06 +0000)
1  2 
cgit.c
cgit.h
ui-diff.c
ui-log.c
ui-repolist.c

diff --combined cgit.c
index b7807ad81a71d34d1a647a282dd5eb71dc72ef0c,435ce5a538d95ebec0c5a1397c5b9bdba00d86b8..1d50129498ae63a458a69cbc5d3ee4a0365c0ae9
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
@@@ -26,27 -26,14 +26,27 @@@ void add_mimetype(const char *name, con
        item->util = xstrdup(value);
  }
  
 -struct cgit_filter *new_filter(const char *cmd, int extra_args)
 +struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
  {
        struct cgit_filter *f;
        int args_size = 0;
 +      int extra_args;
  
        if (!cmd || !cmd[0])
                return NULL;
  
 +      switch (filtertype) {
 +              case SOURCE:
 +                      extra_args = 1;
 +                      break;
 +
 +              case ABOUT:
 +              case COMMIT:
 +              default:
 +                      extra_args = 0;
 +                      break;
 +      }
 +
        f = xmalloc(sizeof(struct cgit_filter));
        f->cmd = xstrdup(cmd);
        args_size = (2 + extra_args) * sizeof(char *);
@@@ -96,11 -83,11 +96,11 @@@ void repo_config(struct cgit_repo *repo
                repo->logo_link = xstrdup(value);
        else if (ctx.cfg.enable_filter_overrides) {
                if (!strcmp(name, "about-filter"))
 -                      repo->about_filter = new_filter(value, 0);
 +                      repo->about_filter = new_filter(value, ABOUT);
                else if (!strcmp(name, "commit-filter"))
 -                      repo->commit_filter = new_filter(value, 0);
 +                      repo->commit_filter = new_filter(value, COMMIT);
                else if (!strcmp(name, "source-filter"))
 -                      repo->source_filter = new_filter(value, 1);
 +                      repo->source_filter = new_filter(value, SOURCE);
        }
  }
  
@@@ -160,8 -147,6 +160,8 @@@ void config_cb(const char *name, const 
                ctx.cfg.enable_filter_overrides = atoi(value);
        else if (!strcmp(name, "enable-gitweb-owner"))
                ctx.cfg.enable_gitweb_owner = atoi(value);
 +      else if (!strcmp(name, "enable-http-clone"))
 +              ctx.cfg.enable_http_clone = atoi(value);
        else if (!strcmp(name, "enable-index-links"))
                ctx.cfg.enable_index_links = atoi(value);
        else if (!strcmp(name, "enable-commit-graph"))
        else if (!strcmp(name, "cache-dynamic-ttl"))
                ctx.cfg.cache_dynamic_ttl = atoi(value);
        else if (!strcmp(name, "about-filter"))
 -              ctx.cfg.about_filter = new_filter(value, 0);
 +              ctx.cfg.about_filter = new_filter(value, ABOUT);
        else if (!strcmp(name, "commit-filter"))
 -              ctx.cfg.commit_filter = new_filter(value, 0);
 +              ctx.cfg.commit_filter = new_filter(value, COMMIT);
        else if (!strcmp(name, "embedded"))
                ctx.cfg.embedded = atoi(value);
        else if (!strcmp(name, "max-atom-items"))
        else if (!strcmp(name, "section-from-path"))
                ctx.cfg.section_from_path = atoi(value);
        else if (!strcmp(name, "source-filter"))
 -              ctx.cfg.source_filter = new_filter(value, 1);
 +              ctx.cfg.source_filter = new_filter(value, SOURCE);
        else if (!strcmp(name, "summary-log"))
                ctx.cfg.summary_log = atoi(value);
        else if (!strcmp(name, "summary-branches"))
                ctx.cfg.robots = xstrdup(value);
        else if (!strcmp(name, "clone-prefix"))
                ctx.cfg.clone_prefix = xstrdup(value);
 +      else if (!strcmp(name, "clone-url"))
 +              ctx.cfg.clone_url = xstrdup(value);
        else if (!strcmp(name, "local-time"))
                ctx.cfg.local_time = atoi(value);
        else if (!prefixcmp(name, "mimetype."))
@@@ -298,6 -281,7 +298,7 @@@ static void querystring_cb(const char *
                ctx.qry.period = xstrdup(value);
        } else if (!strcmp(name, "ss")) {
                ctx.qry.ssdiff = atoi(value);
+               ctx.qry.has_ssdiff = 1;
        } else if (!strcmp(name, "all")) {
                ctx.qry.show_all = atoi(value);
        } else if (!strcmp(name, "context")) {
@@@ -329,7 -313,6 +330,7 @@@ static void prepare_context(struct cgit
        ctx->cfg.logo = "/cgit.png";
        ctx->cfg.local_time = 0;
        ctx->cfg.enable_gitweb_owner = 1;
 +      ctx->cfg.enable_http_clone = 1;
        ctx->cfg.enable_tree_linenumbers = 1;
        ctx->cfg.max_repo_count = 50;
        ctx->cfg.max_commit_count = 50;
@@@ -461,7 -444,7 +462,7 @@@ static int prepare_repo_cmd(struct cgit
                tmp = xstrdup(ctx->qry.head);
                ctx->qry.head = ctx->repo->defbranch;
                ctx->page.status = 404;
 -              ctx->page.statusmsg = "not found";
 +              ctx->page.statusmsg = "Not found";
                cgit_print_http_headers(ctx);
                cgit_print_docstart(ctx);
                cgit_print_pageheader(ctx);
                cgit_print_docend();
                return 1;
        }
 +      cgit_prepare_repo_env(ctx->repo);
        return 0;
  }
  
@@@ -481,8 -463,6 +482,8 @@@ static void process_request(void *cbdat
        cmd = cgit_get_cmd(ctx);
        if (!cmd) {
                ctx->page.title = "cgit error";
 +              ctx->page.status = 404;
 +              ctx->page.statusmsg = "Not found";
                cgit_print_http_headers(ctx);
                cgit_print_docstart(ctx);
                cgit_print_pageheader(ctx);
                return;
        }
  
 +      if (!ctx->cfg.enable_http_clone && cmd->is_clone) {
 +              html_status(404, "Not found", 0);
 +              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).
diff --combined cgit.h
index bad66f0e24849d97d2630ac779792b1388c20494,63847ff49a64caa7ba9367e58526bcbebe9cfa9b..c7ab5c63928ccc4efa4672182bc035fbae9d7135
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
@@@ -51,10 -51,6 +51,10 @@@ typedef void (*configfn)(const char *na
  typedef void (*filepair_fn)(struct diff_filepair *pair);
  typedef void (*linediff_fn)(char *line, int len);
  
 +typedef enum {
 +      ABOUT, COMMIT, SOURCE
 +} filter_type;
 +
  struct cgit_filter {
        char *cmd;
        char **argv;
@@@ -137,6 -133,7 +137,7 @@@ struct reflist 
  struct cgit_query {
        int has_symref;
        int has_sha1;
+       int has_ssdiff;
        char *raw;
        char *repo;
        char *page;
@@@ -165,7 -162,6 +166,7 @@@ struct cgit_config 
        char *agefile;
        char *cache_root;
        char *clone_prefix;
 +      char *clone_url;
        char *css;
        char *favicon;
        char *footer;
        int embedded;
        int enable_filter_overrides;
        int enable_gitweb_owner;
 +      int enable_http_clone;
        int enable_index_links;
        int enable_commit_graph;
        int enable_log_filecount;
@@@ -323,8 -318,6 +324,8 @@@ extern int cgit_parse_snapshots_mask(co
  extern int cgit_open_filter(struct cgit_filter *filter);
  extern int cgit_close_filter(struct cgit_filter *filter);
  
 +extern void cgit_prepare_repo_env(struct cgit_repo * repo);
 +
  extern int readfile(const char *path, char **buf, size_t *size);
  
  extern char *expand_macros(const char *txt);
diff --combined ui-diff.c
index d97a8012cfffc4d10986c27d3f3a6f7bfa4019fd,f8782df260c03a5231ecb740658caff4e3f8a583..af24a6c4ccffa1520f383748f574dd87d0945b52
+++ b/ui-diff.c
@@@ -169,7 -169,7 +169,7 @@@ static void inspect_filepair(struct dif
  void cgit_print_diffstat(const unsigned char *old_sha1,
                         const unsigned char *new_sha1, const char *prefix)
  {
 -      int i, save_context = ctx.qry.context;
 +      int i;
  
        html("<div class='diffstat-header'>");
        cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
                html_txt(prefix);
                html("')");
        }
 -      html(" (");
 -      ctx.qry.context = (save_context > 0 ? save_context : 3) << 1;
 -      cgit_self_link("more", NULL, NULL, &ctx);
 -      html("/");
 -      ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1;
 -      cgit_self_link("less", NULL, NULL, &ctx);
 -      ctx.qry.context = save_context;
 -      html(" context)");
 -      html(" (");
 -      ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
 -      cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx);
 -      ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2;
 -      html(" whitespace changes)");
        html("</div>");
        html("<table summary='diffstat' class='diffstat'>");
        max_changes = 0;
@@@ -267,6 -280,19 +267,6 @@@ static void header(unsigned char *sha1
        html("</div>");
  }
  
 -static void print_ssdiff_link()
 -{
 -      if (!strcmp(ctx.qry.page, "diff")) {
 -              if (use_ssdiff)
 -                      cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
 -                                     ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1);
 -              else
 -                      cgit_diff_link("Side-by-side diff", NULL, NULL,
 -                                     ctx.qry.head, ctx.qry.sha1,
 -                                     ctx.qry.sha2, ctx.qry.path, 1);
 -      }
 -}
 -
  static void filepair_cb(struct diff_filepair *pair)
  {
        unsigned long old_size = 0;
                cgit_ssdiff_footer();
  }
  
 -void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
 +void cgit_print_diff_ctrls()
 +{
 +      int i, curr;
 +
 +      html("<div class='cgit-panel'>");
 +      html("<b>diff options</b>");
 +      html("<form method='get' action='.'>");
 +      cgit_add_hidden_formfields(1, 0, ctx.qry.page);
 +      html("<table>");
 +      html("<tr><td colspan='2'/></tr>");
 +      html("<tr>");
 +      html("<td class='label'>context:</td>");
 +      html("<td class='ctrl'>");
 +      html("<select name='context' onchange='this.form.submit();'>");
 +      curr = ctx.qry.context;
 +      if (!curr)
 +              curr = 3;
 +      for (i = 1; i <= 10; i++)
 +              html_intoption(i, fmt("%d", i), curr);
 +      for (i = 15; i <= 40; i += 5)
 +              html_intoption(i, fmt("%d", i), curr);
 +      html("</select>");
 +      html("</td>");
 +      html("</tr><tr>");
 +      html("<td class='label'>space:</td>");
 +      html("<td class='ctrl'>");
 +      html("<select name='ignorews' onchange='this.form.submit();'>");
 +      html_intoption(0, "include", ctx.qry.ignorews);
 +      html_intoption(1, "ignore", ctx.qry.ignorews);
 +      html("</select>");
 +      html("</td>");
 +      html("</tr><tr>");
 +      html("<td class='label'>mode:</td>");
 +      html("<td class='ctrl'>");
 +      html("<select name='ss' onchange='this.form.submit();'>");
 +      curr = ctx.qry.ssdiff;
 +      if (!curr && ctx.cfg.ssdiff)
 +              curr = 1;
 +      html_intoption(0, "unified", curr);
 +      html_intoption(1, "ssdiff", curr);
 +      html("</select></td></tr>");
 +      html("<tr><td/><td class='ctrl'>");
 +      html("<noscript><input type='submit' value='reload'/></noscript>");
 +      html("</td></tr></table>");
 +      html("</form>");
 +      html("</div>");
 +}
 +
 +void cgit_print_diff(const char *new_rev, const char *old_rev,
 +                   const char *prefix, int show_ctrls)
  {
        enum object_type type;
        unsigned long size;
                }
        }
  
-       if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
-               use_ssdiff = 1;
+       use_ssdiff = ctx.qry.has_ssdiff ? ctx.qry.ssdiff : ctx.cfg.ssdiff;
  
 -      print_ssdiff_link();
 +      if (show_ctrls)
 +              cgit_print_diff_ctrls();
 +
        cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
  
        if (use_ssdiff) {
diff --combined ui-log.c
index 4a295bd4a484bb86ba3373a07a62f3b2ed4b1d35,b67c2ef279059130df10ea3f45cccc20964c610a..6b12ca2acb845951be734a964725962f4e67cb93
+++ b/ui-log.c
@@@ -76,6 -76,8 +76,8 @@@ void show_commit_decorations(struct com
                        cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
                }
                else if (!prefixcmp(deco->name, "refs/remotes/")) {
+                       if (!ctx.repo->enable_remote_branches)
+                               goto next;
                        strncpy(buf, deco->name + 13, sizeof(buf) - 1);
                        cgit_log_link(buf, NULL, "remote-deco", NULL,
                                      sha1_to_hex(commit->object.sha1),
@@@ -88,6 -90,7 +90,7 @@@
                                         sha1_to_hex(commit->object.sha1),
                                         ctx.qry.vpath, 0);
                }
+ next:
                deco = deco->next;
        }
  }
@@@ -99,10 -102,11 +102,10 @@@ void print_commit(struct commit *commit
        struct strbuf graphbuf = STRBUF_INIT;
        struct strbuf msgbuf = STRBUF_INIT;
  
 -      if (ctx.repo->enable_log_filecount) {
 +      if (ctx.repo->enable_log_filecount)
 +              cols++;
 +      if (ctx.repo->enable_log_linecount)
                cols++;
 -              if (ctx.repo->enable_log_linecount)
 -                      cols++;
 -      }
  
        if (revs->graph) {
                /* Advance graph until current commit */
                cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
        }
  
 -      if (ctx.repo->enable_log_filecount) {
 +      if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) {
                files = 0;
                add_lines = 0;
                rem_lines = 0;
                cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);
 -              html("</td><td>");
 -              htmlf("%d", files);
 -              if (ctx.repo->enable_log_linecount) {
 -                      html("</td><td>");
 -                      htmlf("-%d/+%d", rem_lines, add_lines);
 -              }
        }
 +
 +      if (ctx.repo->enable_log_filecount)
 +              htmlf("</td><td>%d", files);
 +      if (ctx.repo->enable_log_linecount)
 +              htmlf("</td><td>-%d/+%d", rem_lines, add_lines);
 +
        html("</td></tr>\n");
  
        if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */
@@@ -369,10 -373,10 +372,10 @@@ void cgit_print_log(const char *tip, in
        if (ctx.repo->enable_log_filecount) {
                html("<th class='left'>Files</th>");
                columns++;
 -              if (ctx.repo->enable_log_linecount) {
 -                      html("<th class='left'>Lines</th>");
 -                      columns++;
 -              }
 +      }
 +      if (ctx.repo->enable_log_linecount) {
 +              html("<th class='left'>Lines</th>");
 +              columns++;
        }
        html("</tr>\n");
  
diff --combined ui-repolist.c
index 25c36ce39b052bddd62199bf398c5c80ede05cc9,4b21e2f214f4518eee57351d4f01b6584fad9d69..a09a6894442ca546b08b55f51f5ec2f3403b4d51
@@@ -46,20 -46,11 +46,20 @@@ static int get_repo_modtime(const struc
        }
  
        path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
 -      if (stat(path, &s) == 0)
 +      if (stat(path, &s) == 0) {
                *mtime = s.st_mtime;
 -      else
 -              *mtime = 0;
 +              r->mtime = *mtime;
 +              return 1;
 +      }
 +
 +      path = fmt("%s/%s", repo->path, "packed-refs");
 +      if (stat(path, &s) == 0) {
 +              *mtime = s.st_mtime;
 +              r->mtime = *mtime;
 +              return 1;
 +      }
  
 +      *mtime = 0;
        r->mtime = *mtime;
        return (r->mtime != 0);
  }
@@@ -118,13 -109,13 +118,13 @@@ void print_header(int columns
  }
  
  
- void print_pager(int items, int pagelen, char *search)
+ void print_pager(int items, int pagelen, char *search, char *sort)
  {
        int i;
        html("<div class='pager'>");
        for(i = 0; i * pagelen < items; i++)
                cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL,
-                               search, i * pagelen);
+                               search, sort, i * pagelen);
        html("</div>");
  }
  
@@@ -291,7 -282,7 +291,7 @@@ void cgit_print_repolist(
        if (!hits)
                cgit_print_error("No repositories found");
        else if (hits > ctx.cfg.max_repo_count)
-               print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
+               print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
        cgit_print_docend();
  }