]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'jp/defbranch'
authorLars Hjemli <hjemli@gmail.com>
Sun, 18 Mar 2012 21:00:18 +0000 (21:00 +0000)
committerLars Hjemli <hjemli@gmail.com>
Sun, 18 Mar 2012 21:00:18 +0000 (21:00 +0000)
1  2 
cgit.c
cgitrc.5.txt
shared.c
ui-repolist.c

diff --combined cgit.c
index 7e3d349aa78a813e4547885aae46492220982c82,624cb2c1282369be19a283ade86dd8e9fc5837cc..6a75f2706ff0c711e8c3f38ae20d3be867b858bd
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
@@@ -60,8 -60,6 +60,8 @@@ static void process_cached_repolist(con
  
  void repo_config(struct cgit_repo *repo, const char *name, const char *value)
  {
 +      struct string_list_item *item;
 +
        if (!strcmp(name, "name"))
                repo->name = xstrdup(value);
        else if (!strcmp(name, "clone-url"))
                repo->max_stats = cgit_find_stats_period(value, NULL);
        else if (!strcmp(name, "module-link"))
                repo->module_link= xstrdup(value);
 -      else if (!strcmp(name, "section"))
 +      else if (!prefixcmp(name, "module-link.")) {
 +              item = string_list_append(&repo->submodules, name + 12);
 +              item->util = xstrdup(value);
 +      } else if (!strcmp(name, "section"))
                repo->section = xstrdup(value);
        else if (!strcmp(name, "readme") && value != NULL)
                repo->readme = xstrdup(value);
@@@ -303,7 -298,6 +303,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")) {
@@@ -344,6 -338,7 +344,6 @@@ static void prepare_context(struct cgit
        ctx->cfg.max_repodesc_len = 80;
        ctx->cfg.max_blob_size = 0;
        ctx->cfg.max_stats = 0;
 -      ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
        ctx->cfg.project_list = NULL;
        ctx->cfg.renamelimit = -1;
        ctx->cfg.remove_suffix = 0;
@@@ -421,6 -416,17 +421,17 @@@ char *find_default_branch(struct cgit_r
        return ref;
  }
  
+ static char *guess_defbranch(const char *repo_path)
+ {
+       const char *ref;
+       unsigned char sha1[20];
+       ref = resolve_ref("HEAD", sha1, 0, NULL);
+       if (!ref || prefixcmp(ref, "refs/heads/"))
+               return "master";
+       return xstrdup(ref + 11);
+ }
  static int prepare_repo_cmd(struct cgit_context *ctx)
  {
        char *tmp;
        }
        ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
  
+       if (!ctx->repo->defbranch)
+               ctx->repo->defbranch = guess_defbranch(ctx->repo->path);
        if (!ctx->qry.head) {
                ctx->qry.nohead = 1;
                ctx->qry.head = find_default_branch(ctx->repo);
-               ctx->repo->defbranch = ctx->qry.head;
        }
  
        if (!ctx->qry.head) {
                cgit_print_docend();
                return 1;
        }
 +      sort_string_list(&ctx->repo->submodules);
        cgit_prepare_repo_env(ctx->repo);
        return 0;
  }
diff --combined cgitrc.5.txt
index b4ad2acb5481e99fc592d400ea70c062f4bd4e75,c2c56800e097fd599a69788c872f72c205b36619..fab0e0a60e5f27d9e15e0b00680906b7fec6e6f8
@@@ -230,7 -230,7 +230,7 @@@ 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
        formatstring are the path and SHA1 of the submodule commit. Default
 -      value: "./?repo=%s&page=commit&id=%s"
 +      value: none.
  
  nocache::
        If set to the value "1" caching will be disabled. This settings is
@@@ -377,7 -377,8 +377,8 @@@ repo.commit-filter:
  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
-       as default instead. Default value: "master".
+       as default instead. Default value: branch pointed to by HEAD, or
+       "master" if there is no suitable HEAD.
  
  repo.desc::
        The value to show as repository description. Default value: none.
@@@ -417,12 -418,6 +418,12 @@@ repo.module-link:
        formatstring are the path and SHA1 of the submodule commit. Default
        value: <module-link>
  
 +repo.module-link.<path>::
 +      Text which will be used as the formatstring for a hyperlink when a
 +      submodule with the specified subdirectory path is printed in a
 +      directory listing. The only argument for the formatstring is the SHA1
 +      of the submodule commit. Default value: none.
 +
  repo.max-stats::
        Override the default maximum statistics period. Valid values are equal
        to the values specified for the global "max-stats" setting. Default
@@@ -506,7 -501,7 +507,7 @@@ Also, all filters are handed the follow
  
  If a setting is not defined for a repository and the corresponding global
  setting is also not defined (if applicable), then the corresponding
 -environment variable will be an empty string.
 +environment variable will be unset.
  
  
  MACRO EXPANSION
diff --combined shared.c
index cb52380916447eecb62b66957a1655dd6a6a0fd6,9c839a94d0aee9ee9a9462c1646af52afef7d92d..0a0e22e7255b0db8b9446c496fa85b58d46e24aa
+++ b/shared.c
@@@ -8,6 -8,7 +8,6 @@@
  
  #include "cgit.h"
  #include <stdio.h>
 -#include <linux/limits.h>
  
  struct cgit_repolist cgit_repolist;
  struct cgit_context ctx;
@@@ -55,7 -56,6 +55,6 @@@ struct cgit_repo *cgit_add_repo(const c
        ret->desc = "[no description]";
        ret->owner = NULL;
        ret->section = ctx.cfg.section;
-       ret->defbranch = "master";
        ret->snapshots = ctx.cfg.snapshots;
        ret->enable_commit_graph = ctx.cfg.enable_commit_graph;
        ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
@@@ -70,7 -70,6 +69,7 @@@
        ret->commit_filter = ctx.cfg.commit_filter;
        ret->source_filter = ctx.cfg.source_filter;
        ret->clone_url = ctx.cfg.clone_url;
 +      ret->submodules.strdup_strings = 1;
        return ret;
  }
  
@@@ -393,7 -392,7 +392,7 @@@ void cgit_prepare_repo_env(struct cgit_
        p = env_vars;
        q = p + env_var_count;
        for (; p < q; p++)
 -              if (setenv(p->name, p->value, 1))
 +              if (p->value && setenv(p->name, p->value, 1))
                        fprintf(stderr, warn, p->name, p->value);
  }
  
diff --combined ui-repolist.c
index a09a6894442ca546b08b55f51f5ec2f3403b4d51,f21d28d5bc5b5f41207530bd5111553377735cc0..d946f32cd5354021c45637a0af24e1a7653dff92
@@@ -45,7 -45,8 +45,8 @@@ static int get_repo_modtime(const struc
                return 1;
        }
  
-       path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
+       path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch ?
+                  repo->defbranch : "master");
        if (stat(path, &s) == 0) {
                *mtime = s.st_mtime;
                r->mtime = *mtime;
@@@ -118,13 -119,13 +119,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 -292,7 +292,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();
  }