]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/panel'
authorLars Hjemli <hjemli@gmail.com>
Mon, 23 May 2011 21:29:24 +0000 (23:29 +0200)
committerLars Hjemli <hjemli@gmail.com>
Mon, 23 May 2011 21:29:24 +0000 (23:29 +0200)
21 files changed:
cgit.c
cgit.h
cgitrc.5.txt
cmd.c
cmd.h
filters/commit-links.sh
filters/syntax-highlighting.sh
html.c
parsing.c
scan-tree.c
shared.c
tests/setup.sh
tests/t0101-index.sh
tests/t0103-log.sh
ui-commit.c
ui-diff.c
ui-log.c
ui-repolist.c
ui-snapshot.c
ui-summary.c
ui-tree.c

diff --git a/cgit.c b/cgit.c
index f4dd6ef93c4b1b73d1583df8cab06627e34ae491..6be3754d47d1c75300189ebab68e0a1c6488a139 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -26,18 +26,33 @@ void add_mimetype(const char *name, const char *value)
        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);
-       f->argv = xmalloc((2 + extra_args) * sizeof(char *));
+       args_size = (2 + extra_args) * sizeof(char *);
+       f->argv = xmalloc(args_size);
+       memset(f->argv, 0, args_size);
        f->argv[0] = f->cmd;
-       f->argv[1] = NULL;
        return f;
 }
 
@@ -81,11 +96,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
                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);
        }
 }
 
@@ -145,6 +160,8 @@ void config_cb(const char *name, const char *value)
                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"))
@@ -176,9 +193,9 @@ void config_cb(const char *name, const char *value)
        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"))
@@ -208,7 +225,7 @@ void config_cb(const char *name, const char *value)
        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"))
@@ -310,6 +327,7 @@ static void prepare_context(struct cgit_context *ctx)
        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;
@@ -437,7 +455,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
                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);
@@ -456,6 +474,8 @@ static void process_request(void *cbdata)
        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);
@@ -464,6 +484,11 @@ static void process_request(void *cbdata)
                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).
@@ -755,8 +780,11 @@ int main(int argc, const char **argv)
         * that virtual-root equals SCRIPT_NAME, minus any possibly
         * trailing slashes.
         */
-       if (!ctx.cfg.virtual_root)
+       if (!ctx.cfg.virtual_root && ctx.cfg.script_name) {
                ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
+               if (!ctx.cfg.virtual_root)
+                       ctx.cfg.virtual_root = "";
+        }
 
        /* If no url parameter is specified on the querystring, lets
         * use PATH_INFO as url. This allows cgit to work with virtual
diff --git a/cgit.h b/cgit.h
index b5f00fc9c1c1d6d6e7f7a8cdc2695cab334752ab..caa9d8e91853ae626f96ff939896f0dfb83a2e31 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -51,6 +51,10 @@ typedef void (*configfn)(const char *name, const char *value);
 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;
@@ -191,6 +195,7 @@ struct cgit_config {
        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;
@@ -314,7 +319,7 @@ extern const char *cgit_repobasename(const char *reponame);
 
 extern int cgit_parse_snapshots_mask(const char *str);
 
-extern int cgit_open_filter(struct cgit_filter *filter);
+extern int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo);
 extern int cgit_close_filter(struct cgit_filter *filter);
 
 extern int readfile(const char *path, char **buf, size_t *size);
index c3698a643dc65a7d7cee43d3da780bbe9e844c2c..5903a938c8c4cbe9c5b1e110ae8fbbb787f656f9 100644 (file)
@@ -31,7 +31,7 @@ about-filter::
        about pages (both top-level and for each repository). The command will
        get the content of the about-file on its STDIN, and the STDOUT from the
        command will be included verbatim on the about page. Default value:
-       none.
+       none. See also: "FILTER API".
 
 agefile::
        Specifies a path, relative to each repository path, which can be used
@@ -81,6 +81,7 @@ commit-filter::
        The command will get the message on its STDIN, and the STDOUT from the
        command will be included verbatim as the commit message, i.e. this can
        be used to implement bugtracker integration. Default value: none.
+       See also: "FILTER API".
 
 css::
        Url which specifies the css document to include in all cgit pages.
@@ -105,6 +106,11 @@ enable-gitweb-owner::
        for the git config value "gitweb.owner" to determine the owner.
        Default value: "1". See also: scan-path.
 
+enable-http-clone::
+       If set to "1", cgit will act as an dumb HTTP endpoint for git clones.
+       If you use an alternate way of serving git repositories, you may wish
+       to disable this. Default value: "1".
+
 enable-index-links::
        Flag which, when set to "1", will make cgit generate extra links for
        each repo in the repository index (specifically, to the "summary",
@@ -287,8 +293,9 @@ scan-path::
        the result will be cached as a cgitrc include-file in the cache
        directory. If project-list has been defined prior to scan-path,
        scan-path loads only the directories listed in the file pointed to by
-       project-list. Default value: none. See also: cache-scanrc-ttl,
-       project-list.
+       project-list. Be advised that only the global settings taken
+       before the scan-path directive will be applied to each repository.
+       Default value: none. See also: cache-scanrc-ttl, project-list.
 
 section::
        The name of the current repository section - all repositories defined
@@ -308,7 +315,8 @@ side-by-side-diffs::
 snapshots::
        Text which specifies the default set of snapshot formats generated by
        cgit. The value is a space-separated list of zero or more of the
-       values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none.
+       values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". Default value:
+       none.
 
 source-filter::
        Specifies a command which will be invoked to format plaintext blobs
@@ -316,7 +324,7 @@ source-filter::
        and the name of the blob as its only command line argument. The STDOUT
        from the command will be included verbatim as the blob contents, i.e.
        this can be used to implement e.g. syntax highlighting. Default value:
-       none.
+       none. See also: "FILTER API".
 
 summary-branches::
        Specifies the number of branches to display in the repository "summary"
@@ -349,7 +357,7 @@ REPOSITORY SETTINGS
 -------------------
 repo.about-filter::
        Override the default about-filter. Default value: none. See also:
-       "enable-filter-overrides".
+       "enable-filter-overrides". See also: "FILTER API".
 
 repo.clone-url::
        A list of space-separated urls which can be used to clone this repo.
@@ -357,7 +365,7 @@ repo.clone-url::
 
 repo.commit-filter::
        Override the default commit-filter. Default value: none. See also:
-       "enable-filter-overrides".
+       "enable-filter-overrides". See also: "FILTER API".
 
 repo.defbranch::
        The name of the default branch for this repository. If no such branch
@@ -428,7 +436,7 @@ repo.section::
 
 repo.source-filter::
        Override the default source-filter. Default value: none. See also:
-       "enable-filter-overrides".
+       "enable-filter-overrides". See also: "FILTER API".
 
 repo.url::
        The relative url used to access the repository. This must be the first
@@ -448,6 +456,42 @@ Note: the "repo." prefix is dropped from the option names in repo-specific
 config files, e.g. "repo.desc" becomes "desc".
 
 
+FILTER API
+----------
+- about filter::
+  This filter is given no arguments.
+  The about text that is to be filtered is available on standard input and the
+  filtered text is expected on standard output.
+- commit filter::
+  This filter is given no arguments.
+  The commit message text that is to be filtered is available on standard input
+  and the filtered text is expected on standard output.
+- source filter::
+  This filter is given a single parameter: the filename of the source file to
+  filter. The filter can use the filename to determine (for example) the syntax
+  highlighting mode.
+  The contents of the source file that is to be filtered is available on
+  standard input and the filtered contents is expected on standard output.
+
+Also, all filters are handed the following environment variables:
+- CGIT_REPO_URL        ( = repo.url       setting )
+- CGIT_REPO_NAME       ( = repo.name      setting )
+- CGIT_REPO_PATH       ( = repo.path      setting )
+- CGIT_REPO_OWNER      ( = repo.owner     setting )
+- CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )
+- CGIT_REPO_SECTION    ( = section        setting )
+- CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )
+
+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.
+
+Note that under normal circumstance all these environment variables are
+defined. If however the total size of the defined settings exceed the
+allocated buffer within cgit then only the environment variables that fit
+in the allocated buffer are handed to the filter.
+
+
 EXAMPLE CGITRC FILE
 -------------------
 
diff --git a/cmd.c b/cmd.c
index 05d5aaf44e70dd987eb151bffa238b33b946aeda..5a3d1574556e5a09510b891482ef38b22b0ca8a6 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -130,31 +130,31 @@ static void tree_fn(struct cgit_context *ctx)
        cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
 }
 
-#define def_cmd(name, want_repo, want_layout, want_vpath) \
-       {#name, name##_fn, want_repo, want_layout, want_vpath}
+#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \
+       {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone}
 
 struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
 {
        static struct cgit_cmd cmds[] = {
-               def_cmd(HEAD, 1, 0, 0),
-               def_cmd(atom, 1, 0, 0),
-               def_cmd(about, 0, 1, 0),
-               def_cmd(blob, 1, 0, 0),
-               def_cmd(commit, 1, 1, 1),
-               def_cmd(diff, 1, 1, 1),
-               def_cmd(info, 1, 0, 0),
-               def_cmd(log, 1, 1, 1),
-               def_cmd(ls_cache, 0, 0, 0),
-               def_cmd(objects, 1, 0, 0),
-               def_cmd(patch, 1, 0, 1),
-               def_cmd(plain, 1, 0, 0),
-               def_cmd(refs, 1, 1, 0),
-               def_cmd(repolist, 0, 0, 0),
-               def_cmd(snapshot, 1, 0, 0),
-               def_cmd(stats, 1, 1, 1),
-               def_cmd(summary, 1, 1, 0),
-               def_cmd(tag, 1, 1, 0),
-               def_cmd(tree, 1, 1, 1),
+               def_cmd(HEAD, 1, 0, 0, 1),
+               def_cmd(atom, 1, 0, 0, 0),
+               def_cmd(about, 0, 1, 0, 0),
+               def_cmd(blob, 1, 0, 0, 0),
+               def_cmd(commit, 1, 1, 1, 0),
+               def_cmd(diff, 1, 1, 1, 0),
+               def_cmd(info, 1, 0, 0, 1),
+               def_cmd(log, 1, 1, 1, 0),
+               def_cmd(ls_cache, 0, 0, 0, 0),
+               def_cmd(objects, 1, 0, 0, 1),
+               def_cmd(patch, 1, 0, 1, 0),
+               def_cmd(plain, 1, 0, 0, 0),
+               def_cmd(refs, 1, 1, 0, 0),
+               def_cmd(repolist, 0, 0, 0, 0),
+               def_cmd(snapshot, 1, 0, 0, 0),
+               def_cmd(stats, 1, 1, 1, 0),
+               def_cmd(summary, 1, 1, 0, 0),
+               def_cmd(tag, 1, 1, 0, 0),
+               def_cmd(tree, 1, 1, 1, 0),
        };
        int i;
 
diff --git a/cmd.h b/cmd.h
index 8dc01bd32b6c22d3426310a916ff5dabd2f0aa88..eb5bc87feda8a62672b31a268e109d89417557e5 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -8,7 +8,8 @@ struct cgit_cmd {
        cgit_cmd_fn fn;
        unsigned int want_repo:1,
                want_layout:1,
-               want_vpath:1;
+               want_vpath:1,
+               is_clone:1;
 };
 
 extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx);
index 110c6091f37aeaa48a2fc0f1fbd119b989ca5564..d2cd2b33f3ff698ee80ccb1656272340d2d36ff3 100755 (executable)
@@ -3,6 +3,17 @@
 #
 # To use this script, refer to this file with either the commit-filter or the
 # repo.commit-filter options in cgitrc.
+#
+# The following environment variables can be used to retrieve the configuration
+# of the repository for which this script is called:
+# CGIT_REPO_URL        ( = repo.url       setting )
+# CGIT_REPO_NAME       ( = repo.name      setting )
+# CGIT_REPO_PATH       ( = repo.path      setting )
+# CGIT_REPO_OWNER      ( = repo.owner     setting )
+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )
+# CGIT_REPO_SECTION    ( = section        setting )
+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )
+#
 
 # This expression generates links to commits referenced by their SHA1.
 regex=$regex'
index 6b1c576404f886b9368b6147cf1e83cae819f274..6283ce92efc62e9cf63d2bd20486af43bec7b489 100755 (executable)
 # table.blob .kwb  { color:#830000; }
 # table.blob .kwc  { color:#000000; font-weight:bold; }
 # table.blob .kwd  { color:#010181; }
+#
+# The following environment variables can be used to retrieve the configuration
+# of the repository for which this script is called:
+# CGIT_REPO_URL        ( = repo.url       setting )
+# CGIT_REPO_NAME       ( = repo.name      setting )
+# CGIT_REPO_PATH       ( = repo.path      setting )
+# CGIT_REPO_OWNER      ( = repo.owner     setting )
+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )
+# CGIT_REPO_SECTION    ( = section        setting )
+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )
+#
 
 # store filename and extension in local vars
 BASENAME="$1"
diff --git a/html.c b/html.c
index ae1cef983265979144a6e1c6da835fd4746ae630..4a18a574e23cf8820997e0abc4111ac66e5d98e5 100644 (file)
--- a/html.c
+++ b/html.c
@@ -18,7 +18,7 @@ static const char* url_escape_table[256] = {
        "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
        "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
        "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
-       "%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
+       "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
        "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
        "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
@@ -162,9 +162,9 @@ void html_url_path(const char *txt)
        while(t && *t){
                int c = *t;
                const char *e = url_escape_table[c];
-               if (e && c!='+' && c!='&' && c!='+') {
+               if (e && c!='+' && c!='&') {
                        html_raw(txt, t - txt);
-                       html_raw(e, 3);
+                       html(e);
                        txt = t+1;
                }
                t++;
@@ -179,9 +179,11 @@ void html_url_arg(const char *txt)
        while(t && *t){
                int c = *t;
                const char *e = url_escape_table[c];
+               if (c == ' ')
+                       e = "+";
                if (e) {
                        html_raw(txt, t - txt);
-                       html_raw(e, strlen(e));
+                       html(e);
                        txt = t+1;
                }
                t++;
@@ -296,12 +298,12 @@ char *convert_query_hexchar(char *txt)
 
 int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
 {
-       char *t, *txt, *value = NULL, c;
+       char *o, *t, *txt, *value = NULL, c;
 
        if (!txt_)
                return 0;
 
-       t = txt = strdup(txt_);
+       o = t = txt = strdup(txt_);
        if (t == NULL) {
                printf("Out of memory\n");
                exit(1);
@@ -324,5 +326,6 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
        }
        if (t!=txt)
                (*fn)(txt, value);
+       free(o);
        return 0;
 }
index f37c49d261765636cfef652faec3be8baf6d2894..151c0fe468c64174ae260ba9b5ddd2d8de52e81e 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -103,10 +103,17 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
 {
        char *tmp;
 
-       if (!txt || !*txt || !src_enc || !dst_enc)
+       if (!txt)
+               return NULL;
+
+       if (!*txt || !src_enc || !dst_enc)
+               return *txt;
+
+       /* no encoding needed if src_enc equals dst_enc */
+       if(!strcasecmp(src_enc, dst_enc))
                return *txt;
 
-       tmp = reencode_string(*txt, src_enc, dst_enc);
+       tmp = reencode_string(*txt, dst_enc, src_enc);
        if (tmp) {
                free(*txt);
                *txt = tmp;
@@ -160,6 +167,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
                }
        }
 
+       /* if no special encoding is found, assume UTF-8 */
+       if(!ret->msg_encoding)
+               ret->msg_encoding = xstrdup("UTF-8");
+
        // skip unknown header fields
        while (p && *p && (*p != '\n')) {
                p = strchr(p, '\n');
@@ -189,14 +200,12 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        } else
                ret->subject = xstrdup(p);
 
-       if (ret->msg_encoding) {
-               reencode(&ret->author, PAGE_ENCODING, ret->msg_encoding);
-               reencode(&ret->author_email, PAGE_ENCODING, ret->msg_encoding);
-               reencode(&ret->committer, PAGE_ENCODING, ret->msg_encoding);
-               reencode(&ret->committer_email, PAGE_ENCODING, ret->msg_encoding);
-               reencode(&ret->subject, PAGE_ENCODING, ret->msg_encoding);
-               reencode(&ret->msg, PAGE_ENCODING, ret->msg_encoding);
-       }
+       reencode(&ret->author, ret->msg_encoding, PAGE_ENCODING);
+       reencode(&ret->author_email, ret->msg_encoding, PAGE_ENCODING);
+       reencode(&ret->committer, ret->msg_encoding, PAGE_ENCODING);
+       reencode(&ret->committer_email, ret->msg_encoding, PAGE_ENCODING);
+       reencode(&ret->subject, ret->msg_encoding, PAGE_ENCODING);
+       reencode(&ret->msg, ret->msg_encoding, PAGE_ENCODING);
 
        return ret;
 }
index 627af1b23240dbb8401d61d8e897afaf0eb05ca4..e5a4baf556e0525f8493c6b2857ef913972c85c2 100644 (file)
@@ -219,6 +219,7 @@ void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn
        if (!projects) {
                fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n",
                        projectsfile, strerror(errno), errno);
+               return;
        }
        while (fgets(line, sizeof(line), projects) != NULL) {
                for (z = &lastc(line);
index 7ec2e19296e2bfbc7226849163b8bdb05bb56e94..be2ae59e0a3fb764b8f3d6977189ff492d831a8c 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -7,6 +7,8 @@
  */
 
 #include "cgit.h"
+#include <stdio.h>
+#include <linux/limits.h>
 
 struct cgit_repolist cgit_repolist;
 struct cgit_context ctx;
@@ -100,23 +102,15 @@ void *cgit_free_commitinfo(struct commitinfo *info)
 char *trim_end(const char *str, char c)
 {
        int len;
-       char *s, *t;
 
        if (str == NULL)
                return NULL;
-       t = (char *)str;
-       len = strlen(t);
-       while(len > 0 && t[len - 1] == c)
+       len = strlen(str);
+       while(len > 0 && str[len - 1] == c)
                len--;
-
        if (len == 0)
                return NULL;
-
-       c = t[len];
-       t[len] = '\0';
-       s = xstrdup(t);
-       t[len] = c;
-       return s;
+       return xstrndup(str, len);
 }
 
 char *strlpart(char *txt, int maxlen)
@@ -311,7 +305,6 @@ void cgit_diff_tree(const unsigned char *old_sha1,
                    filepair_fn fn, const char *prefix, int ignorews)
 {
        struct diff_options opt;
-       int ret;
        int prefixlen;
 
        diff_setup(&opt);
@@ -332,9 +325,9 @@ void cgit_diff_tree(const unsigned char *old_sha1,
        diff_setup_done(&opt);
 
        if (old_sha1 && !is_null_sha1(old_sha1))
-               ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
+               diff_tree_sha1(old_sha1, new_sha1, "", &opt);
        else
-               ret = diff_root_tree_sha1(new_sha1, "", &opt);
+               diff_root_tree_sha1(new_sha1, "", &opt);
        diffcore_std(&opt);
        diff_flush(&opt);
 }
@@ -376,7 +369,33 @@ int cgit_parse_snapshots_mask(const char *str)
        return rv;
 }
 
-int cgit_open_filter(struct cgit_filter *filter)
+typedef struct {
+       char * name;
+       char * value;
+} cgit_env_var;
+
+static void prepare_env(struct cgit_repo * repo) {
+       cgit_env_var env_vars[] = {
+               { .name = "CGIT_REPO_URL", .value = repo->url },
+               { .name = "CGIT_REPO_NAME", .value = repo->name },
+               { .name = "CGIT_REPO_PATH", .value = repo->path },
+               { .name = "CGIT_REPO_OWNER", .value = repo->owner },
+               { .name = "CGIT_REPO_DEFBRANCH", .value = repo->defbranch },
+               { .name = "CGIT_REPO_SECTION", .value = repo->section },
+               { .name = "CGIT_REPO_CLONE_URL", .value = repo->clone_url }
+       };
+       int env_var_count = ARRAY_SIZE(env_vars);
+       cgit_env_var *p, *q;
+       static char *warn = "cgit warning: failed to set env: %s=%s\n";
+
+       p = env_vars;
+       q = p + env_var_count;
+       for (; p < q; p++)
+               if (setenv(p->name, p->value, 1))
+                       fprintf(stderr, warn, p->name, p->value);
+}
+
+int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)
 {
 
        filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
@@ -387,6 +406,8 @@ int cgit_open_filter(struct cgit_filter *filter)
                close(filter->pipe_fh[1]);
                chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
                        "Unable to use pipe as STDIN");
+               if (repo)
+                       prepare_env(repo);
                execvp(filter->cmd, filter->argv);
                die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
                        strerror(errno), errno);
index 30f90d5c39663166ad51e3c41995e255041420ee..b2f1169c789846abc912c7429dee19dfb3c1487c 100755 (executable)
@@ -20,10 +20,10 @@ mkrepo() {
        name=$1
        count=$2
        dir=$PWD
-       test -d $name && return
+       test -d "$name" && return
        printf "Creating testrepo %s\n" $name
-       mkdir -p $name
-       cd $name
+       mkdir -p "$name"
+       cd "$name"
        git init
        n=1
        while test $n -le $count
@@ -50,6 +50,7 @@ setup_repos()
        mkrepo trash/repos/foo 5 >/dev/null
        mkrepo trash/repos/bar 50 >/dev/null
        mkrepo trash/repos/foo+bar 10 testplus >/dev/null
+       mkrepo "trash/repos/with space" 2 >/dev/null
        cat >trash/cgitrc <<EOF
 virtual-root=/
 cache-root=$PWD/trash/cache
@@ -75,6 +76,10 @@ repo.desc=the bar repo
 repo.url=foo+bar
 repo.path=$PWD/trash/repos/foo+bar/.git
 repo.desc=the foo+bar repo
+
+repo.url=with space
+repo.path=$PWD/trash/repos/with space/.git
+repo.desc=spaced repo
 EOF
 }
 
@@ -101,6 +106,12 @@ tests_done()
 
 run_test()
 {
+       bug=0
+       if test "$1" = "BUG"
+       then
+               bug=1
+               shift
+       fi
        desc=$1
        script=$2
        test_count=$(expr $test_count + 1)
@@ -109,9 +120,15 @@ run_test()
        eval "$2" >>test-output.log 2>>test-output.log
        res=$?
        printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
-       if test $res = 0
+       if test $res = 0 -a $bug = 0
        then
                printf " %2d) %-60s [ok]\n" $test_count "$desc"
+       elif test $res = 0 -a $bug = 1
+       then
+               printf " %2d) %-60s [BUG FIXED]\n" $test_count "$desc"
+       elif test $bug = 1
+       then
+               printf " %2d) %-60s [KNOWN BUG]\n" $test_count "$desc"
        else
                test_failed=$(expr $test_failed + 1)
                printf " %2d) %-60s [failed]\n" $test_count "$desc"
index 07e39f9139de1324013677e58b34ac01ecdc4bba..573a351b8078193563f26f22888b6f1a90f7ab78 100755 (executable)
@@ -11,6 +11,7 @@ run_test 'find bar repo' 'grep -e "bar" trash/tmp'
 run_test 'find bar description' 'grep -e "the bar repo" trash/tmp'
 run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp'
 run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp'
+run_test 'verify "with%20space" link' 'grep -e "/with%20space/" trash/tmp'
 run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp'
 run_test 'no log-link' '! grep -e "foo/log" trash/tmp'
 
index b08cd299f37f298887b586cac10384ae793e7d9d..def5c1812ac82017193a8d2a1be4aa22b8e39ca5 100755 (executable)
@@ -12,4 +12,14 @@ run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp'
 run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
 run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
 
+run_test 'generate "with%20space/log?qt=grep&q=commit+1"' '
+       cgit_url "with+space/log&qt=grep&q=commit+1" >trash/tmp
+'
+run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
+run_test 'find link with %20 in path' 'grep -e "/with%20space/log/?qt=grep" trash/tmp'
+run_test 'find link with + in arg' 'grep -e "/log/?qt=grep&q=commit+1" trash/tmp'
+run_test BUG 'no links with space in path' '! grep -e "href=./with space/" trash/tmp'
+run_test 'no links with space in arg' '! grep -e "q=commit 1" trash/tmp'
+run_test 'commit 2 is not visible' '! grep -e "commit 2" trash/tmp'
+
 tests_done
index 536a8e82d5486be05e98f59079ba1c7bfe536d75..a69dec649f05cb8035f415dc395ed6d1f312f921 100644 (file)
@@ -106,7 +106,7 @@ void cgit_print_commit(char *hex, const char *prefix)
        html("</table>\n");
        html("<div class='commit-subject'>");
        if (ctx.repo->commit_filter)
-               cgit_open_filter(ctx.repo->commit_filter);
+               cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
        html_txt(info->subject);
        if (ctx.repo->commit_filter)
                cgit_close_filter(ctx.repo->commit_filter);
@@ -114,7 +114,7 @@ void cgit_print_commit(char *hex, const char *prefix)
        html("</div>");
        html("<div class='commit-msg'>");
        if (ctx.repo->commit_filter)
-               cgit_open_filter(ctx.repo->commit_filter);
+               cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
        html_txt(info->msg);
        if (ctx.repo->commit_filter)
                cgit_close_filter(ctx.repo->commit_filter);
@@ -123,7 +123,7 @@ void cgit_print_commit(char *hex, const char *prefix)
                html("<div class='notes-header'>Notes</div>");
                html("<div class='notes'>");
                if (ctx.repo->commit_filter)
-                       cgit_open_filter(ctx.repo->commit_filter);
+                       cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
                html_txt(notes.buf);
                if (ctx.repo->commit_filter)
                        cgit_close_filter(ctx.repo->commit_filter);
index b7767b3c07a23ea06e3aa3aab103fe3bf765cfe4..868ceec23b813f8dbd39b9eda8249131caa308e3 100644 (file)
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -368,8 +368,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
                return;
        }
        commit = lookup_commit_reference(new_rev_sha1);
-       if (!commit || parse_commit(commit))
+       if (!commit || parse_commit(commit)) {
                cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
+               return;
+       }
 
        if (old_rev)
                get_sha1(old_rev, old_rev_sha1);
@@ -385,8 +387,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
                        return;
                }
                commit2 = lookup_commit_reference(old_rev_sha1);
-               if (!commit2 || parse_commit(commit2))
+               if (!commit2 || parse_commit(commit2)) {
                        cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
+                       return;
+               }
        }
 
        if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
index 8add66aa0f41c16081a2ead29ba2c19a8f41ace5..2e6e9d66125064c3737954ef7420240c28d26eeb 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -100,11 +100,10 @@ void print_commit(struct commit *commit, struct rev_info *revs)
        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 */
@@ -179,18 +178,18 @@ void print_commit(struct commit *commit, struct rev_info *revs)
                html_link_close();
        }
 
-       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 */
@@ -379,10 +378,10 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
        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");
 
index 2c98668ad931489ad54632d3c869c06de294f1cb..6f304bb36006834da65a319da5163ffe6b1bed60 100644 (file)
@@ -20,7 +20,7 @@ time_t read_agefile(char *path)
        if (readfile(path, &buf, &size))
                return -1;
 
-       if (parse_date(buf, buf2, sizeof(buf2)))
+       if (parse_date(buf, buf2, sizeof(buf2)) > 0)
                result = strtoul(buf2, NULL, 10);
        else
                result = 0;
@@ -291,7 +291,7 @@ void cgit_print_site_readme()
        if (!ctx.cfg.root_readme)
                return;
        if (ctx.cfg.about_filter)
-               cgit_open_filter(ctx.cfg.about_filter);
+               cgit_open_filter(ctx.cfg.about_filter, NULL);
        html_include(ctx.cfg.root_readme);
        if (ctx.cfg.about_filter)
                cgit_close_filter(ctx.cfg.about_filter);
index 6e3412c9e3a6b3175475e0b7a0b4c5433850f612..067082c30c225ef445acc8c226881436e2cb736e 100644 (file)
@@ -19,7 +19,7 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f
        f.argv = malloc(2 * sizeof(char *));
        f.argv[0] = f.cmd;
        f.argv[1] = NULL;
-       cgit_open_filter(&f);
+       cgit_open_filter(&f, NULL);
        rv = write_tar_archive(args);
        cgit_close_filter(&f);
        return rv;
index 5be2545c398ca7f7ac715991e58b90b52f32e636..1e9a1b6daec6120c46148752b5afc8ec18e41691 100644 (file)
@@ -113,7 +113,7 @@ void cgit_print_repo_readme(char *path)
         */
        html("<div id='summary'>");
        if (ctx.repo->about_filter)
-               cgit_open_filter(ctx.repo->about_filter);
+               cgit_open_filter(ctx.repo->about_filter, ctx.repo);
        if (ref)
                cgit_print_file(tmp, ref);
        else
index 0b1b531494c4f24c059d4b80cf7d6faaf8612d0d..2d8d2f3b83738fb007228f6f84e78dbe881d7f39 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -45,9 +45,11 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
        if (ctx.repo->source_filter) {
                html("<td class='lines'><pre><code>");
                ctx.repo->source_filter->argv[1] = xstrdup(name);
-               cgit_open_filter(ctx.repo->source_filter);
+               cgit_open_filter(ctx.repo->source_filter, ctx.repo);
                html_raw(buf, size);
                cgit_close_filter(ctx.repo->source_filter);
+               free(ctx.repo->source_filter->argv[1]);
+               ctx.repo->source_filter->argv[1] = NULL;
                html("</code></pre></td></tr></table>\n");
                return;
        }