]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/noweb'
authorLars Hjemli <hjemli@gmail.com>
Sat, 19 Jun 2010 09:41:32 +0000 (11:41 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sat, 19 Jun 2010 09:41:32 +0000 (11:41 +0200)
cgit.c
cgit.h
cgitrc.5.txt
shared.c
ui-commit.c
ui-plain.c
ui-tree.c

diff --git a/cgit.c b/cgit.c
index 9305d0a873a191e730d622d14067a2eee56003a6..6ccf4aaf43bf9ca1b250991a0e5a3cdeb1d95fb4 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -62,6 +62,8 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
                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"))
@@ -141,6 +143,8 @@ void config_cb(const char *name, const char *value)
                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"))
diff --git a/cgit.h b/cgit.h
index cd4af7247b7c00dd9562917d2df94472d2e1317e..9b1e3f8ca7862857a0fa800dc6fda5becbe614c9 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -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;
@@ -181,6 +182,7 @@ 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_repo_count;
index d74d9e7eec85582be2548319aa415d5ff97ea7a9..fcd4308d603a89c6823618531da4e76eedb5a7c3 100644 (file)
@@ -115,6 +115,12 @@ enable-remote-branches::
        in the summary and refs views. Default value: "0". See also:
        "repo.enable-remote-branches".
 
+enable-subject-links::
+       Flag which, when set to "1", will make cgit use the subject of the
+       parent commit as link text when generating links to parent commits
+       in commit view. Default value: "0". See also:
+       "repo.enable-subject-links".
+
 enable-tree-linenumbers::
        Flag which, when set to "1", will make cgit generate linenumber links
        for plaintext blobs printed in the tree view. Default value: "1".
@@ -321,6 +327,10 @@ repo.enable-remote-branches::
        Flag which, when set to "1", will make cgit display remote branches
        in the summary and refs views. Default value: <enable-remote-branches>.
 
+repo.enable-subject-links::
+       A flag which can be used to override the global setting
+       `enable-subject-links'. 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
index 5f4679335e0f063cadc57b79953f2c078cff11a3..8b3a0457748a3f3ef30b48c8d1aecffa4a2c6b66 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -60,6 +60,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
        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;
@@ -279,6 +280,10 @@ int cgit_diff_files(const unsigned char *old_sha1,
        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;
        }
 
@@ -291,6 +296,10 @@ int cgit_diff_files(const unsigned char *old_sha1,
        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;
 }
 
index b5e3c0159ba78ec080ee3f5cde8d2253c6cd8cbf..41313b9d7d08fb6b5fa17f4d3bfa73db04ba50e2 100644 (file)
 void cgit_print_commit(char *hex)
 {
        struct commit *commit, *parent;
-       struct commitinfo *info;
+       struct commitinfo *info, *parent_info;
        struct commit_list *p;
        unsigned char sha1[20];
-       char *tmp;
+       char *tmp, *tmp2;
        int parents = 0;
 
        if (!hex)
@@ -82,8 +82,12 @@ void cgit_print_commit(char *hex)
                }
                html("<tr><th>parent</th>"
                     "<td colspan='2' class='sha1'>");
-               cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
-                                ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0);
+               tmp = tmp2 = sha1_to_hex(p->item->object.sha1);
+               if (ctx.repo->enable_subject_links) {
+                       parent_info = cgit_parse_commit(parent);
+                       tmp2 = parent_info->subject;
+               }
+               cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, 0);
                html(" (");
                cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
                               sha1_to_hex(p->item->object.sha1), NULL, 0);
index 66cb19cdbd1058e37e60157c40a18d1a782bb3ff..da76406a9142c820625dd02bd53b0033ee6d1d83 100644 (file)
@@ -10,8 +10,7 @@
 #include "html.h"
 #include "ui-shared.h"
 
-char *curr_rev;
-char *match_path;
+int match_baselen;
 int match;
 
 static void print_object(const unsigned char *sha1, const char *path)
@@ -53,17 +52,63 @@ static void print_object(const unsigned char *sha1, const char *path)
        match = 1;
 }
 
+static void print_dir(const unsigned char *sha1, const char *path,
+                     const char *base)
+{
+       char *fullpath;
+       if (path[0] || base[0])
+               fullpath = fmt("/%s%s/", base, path);
+       else
+               fullpath = "/";
+       ctx.page.etag = sha1_to_hex(sha1);
+       cgit_print_http_headers(&ctx);
+       htmlf("<html><head><title>%s</title></head>\n<body>\n"
+             " <h2>%s</h2>\n <ul>\n", fullpath, fullpath);
+       if (path[0] || base[0])
+             html("  <li><a href=\"../\">../</a></li>\n");
+       match = 2;
+}
+
+static void print_dir_entry(const unsigned char *sha1, const char *path,
+                           unsigned mode)
+{
+       const char *sep = "";
+       if (S_ISDIR(mode))
+               sep = "/";
+       htmlf("  <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep);
+       match = 2;
+}
+
+static void print_dir_tail(void)
+{
+       html(" </ul>\n</body></html>\n");
+}
+
 static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
                     const char *pathname, unsigned mode, int stage,
                     void *cbdata)
 {
-       if (S_ISDIR(mode))
+       if (baselen == match_baselen) {
+               if (S_ISREG(mode))
+                       print_object(sha1, pathname);
+               else if (S_ISDIR(mode)) {
+                       print_dir(sha1, pathname, base);
+                       return READ_TREE_RECURSIVE;
+               }
+       }
+       else if (baselen > match_baselen)
+               print_dir_entry(sha1, pathname, mode);
+       else if (S_ISDIR(mode))
                return READ_TREE_RECURSIVE;
 
-       if (S_ISREG(mode) && !strncmp(base, match_path, baselen) &&
-           !strcmp(pathname, match_path + baselen))
-               print_object(sha1, pathname);
+       return 0;
+}
 
+static int basedir_len(const char *path)
+{
+       char *p = strrchr(path, '/');
+       if (p)
+               return p - path + 1;
        return 0;
 }
 
@@ -77,7 +122,6 @@ void cgit_print_plain(struct cgit_context *ctx)
        if (!rev)
                rev = ctx->qry.head;
 
-       curr_rev = xstrdup(rev);
        if (get_sha1(rev, sha1)) {
                html_status(404, "Not found", 0);
                return;
@@ -87,8 +131,16 @@ void cgit_print_plain(struct cgit_context *ctx)
                html_status(404, "Not found", 0);
                return;
        }
-       match_path = ctx->qry.path;
+       if (!paths[0]) {
+               paths[0] = "";
+               match_baselen = -1;
+               print_dir(commit->tree->object.sha1, "", "");
+       }
+       else
+               match_baselen = basedir_len(paths[0]);
        read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
        if (!match)
                html_status(404, "Not found", 0);
+       else if (match == 2)
+               print_dir_tail();
 }
index 94aff8f5d176df3aa544bb63e4146c19f66a0447..0ee38f289a5a21e5385cd1289aa234c33bab30d6 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -175,6 +175,8 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
        if (ctx.repo->max_stats)
                cgit_stats_link("stats", NULL, "button", ctx.qry.head,
                                fullpath);
+       cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev,
+                       fullpath);
        html("</td></tr>\n");
        free(name);
        return 0;