-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cgit.c | 6 | ||||
-rw-r--r-- | cgit.css | 40 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 15 | ||||
-rw-r--r-- | cmd.c | 3 | ||||
m--------- | git | 0 | ||||
-rw-r--r-- | html.c | 4 | ||||
-rw-r--r-- | shared.c | 1 | ||||
-rw-r--r-- | ui-log.c | 266 | ||||
-rw-r--r-- | ui-log.h | 3 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | vector.c | 38 | ||||
-rw-r--r-- | vector.h | 17 |
14 files changed, 338 insertions, 63 deletions
@@ -14,3 +14,3 @@ mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 1.7.3 +GIT_VER = 1.7.4 GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 @@ -117,2 +117,3 @@ OBJECTS += ui-tag.o OBJECTS += ui-tree.o +OBJECTS += vector.o @@ -59,2 +59,4 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); + else if (!strcmp(name, "enable-commit-graph")) + repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value); else if (!strcmp(name, "enable-log-filecount")) @@ -143,2 +145,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.enable_index_links = atoi(value); + else if (!strcmp(name, "enable-commit-graph")) + ctx.cfg.enable_commit_graph = atoi(value); else if (!strcmp(name, "enable-log-filecount")) @@ -545,2 +549,4 @@ void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); + fprintf(f, "repo.enable-commit-graph=%d\n", + repo->enable_commit_graph); fprintf(f, "repo.enable-log-filecount=%d\n", @@ -155,22 +155,40 @@ table.list td { -table.list td.logsubject { +table.list td.commitgraph { font-family: monospace; - font-weight: bold; + white-space: pre; } -table.list td.logmsg { - font-family: monospace; - white-space: pre; - padding: 1em 0.5em 2em 0.5em; +table.list td.commitgraph .column1 { + color: #a00; +} + +table.list td.commitgraph .column2 { + color: #0a0; +} + +table.list td.commitgraph .column3 { + color: #aa0; } -table.list td.lognotes-label { - text-align:right; - vertical-align:top; +table.list td.commitgraph .column4 { + color: #00a; } -table.list td.lognotes { +table.list td.commitgraph .column5 { + color: #a0a; +} + +table.list td.commitgraph .column6 { + color: #0aa; +} + +table.list td.logsubject { + font-family: monospace; + font-weight: bold; +} + +table.list td.logmsg { font-family: monospace; white-space: pre; - padding: 0em 0.5em 2em 0.5em; + padding: 0 0.5em; } @@ -22,2 +22,3 @@ #include <notes.h> +#include <graph.h> @@ -73,2 +74,3 @@ struct cgit_repo { int snapshots; + int enable_commit_graph; int enable_log_filecount; @@ -190,2 +192,3 @@ struct cgit_config { int enable_index_links; + int enable_commit_graph; int enable_log_filecount; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 1dc3cce..a832830 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -92,3 +92,8 @@ embedded:: also: "noheader". - + +enable-commit-graph:: + Flag which, when set to "1", will make cgit print an ASCII-art commit + history graph to the left of the commit messages in the repository + log page. Default value: "0". + enable-filter-overrides:: @@ -364,2 +369,6 @@ repo.desc:: +repo.enable-commit-graph:: + A flag which can be used to disable the global setting + `enable-commit-graph'. Default value: none. + repo.enable-log-filecount:: @@ -451,2 +460,6 @@ enable-index-links=1 +# Enable ASCII art commit history graph on the log pages +enable-commit-graph=1 + + # Show number of affected files per commit on the log pages @@ -69,3 +69,4 @@ static void log_fn(struct cgit_context *ctx) cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, - ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); + ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1, + ctx->repo->enable_commit_graph); } diff --git a/git b/git -Subproject 87b50542a08ac6caa083ddc376e674424e37940 +Subproject 7ed863a85a6ce2c4ac4476848310b8f917ab41f @@ -20,3 +20,3 @@ static const char* url_escape_table[256] = { "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", - "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, + "%1e", "%1f", "+", 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", @@ -183,3 +183,3 @@ void html_url_arg(const char *txt) html_raw(txt, t - txt); - html_raw(e, 3); + html_raw(e, strlen(e)); txt = t+1; @@ -58,2 +58,3 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->snapshots = ctx.cfg.snapshots; + ret->enable_commit_graph = ctx.cfg.enable_commit_graph; ret->enable_log_filecount = ctx.cfg.enable_log_filecount; @@ -11,2 +11,3 @@ #include "ui-shared.h" +#include "vector.h" @@ -14,2 +15,17 @@ int files, add_lines, rem_lines; +/* + * The list of available column colors in the commit graph. + */ +static const char *column_colors_html[] = { + "<span class='column1'>", + "<span class='column2'>", + "<span class='column3'>", + "<span class='column4'>", + "<span class='column5'>", + "<span class='column6'>", + "</span>", +}; + +#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) + void count_lines(char *line, int size) @@ -78,3 +94,3 @@ void show_commit_decorations(struct commit *commit) -void print_commit(struct commit *commit) +void print_commit(struct commit *commit, struct rev_info *revs) { @@ -82,14 +98,70 @@ void print_commit(struct commit *commit) char *tmp; - int cols = 2; + int cols = revs->graph ? 3 : 2; + struct strbuf graphbuf = STRBUF_INIT; + struct strbuf msgbuf = STRBUF_INIT; + + if (ctx.repo->enable_log_filecount) { + cols++; + if (ctx.repo->enable_log_linecount) + cols++; + } + + if (revs->graph) { + /* Advance graph until current commit */ + while (!graph_next_line(revs->graph, &graphbuf)) { + /* Print graph segment in otherwise empty table row */ + html("<tr class='nohover'><td class='commitgraph'>"); + html(graphbuf.buf); + htmlf("</td><td colspan='%d' /></tr>\n", cols); + strbuf_setlen(&graphbuf, 0); + } + /* Current commit's graph segment is now ready in graphbuf */ + } info = cgit_parse_commit(commit); - htmlf("<tr%s><td>", - ctx.qry.showmsg ? " class='logheader'" : ""); - tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); - tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); - html_link_open(tmp, NULL, NULL); - cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); - html_link_close(); - htmlf("</td><td%s>", - ctx.qry.showmsg ? " class='logsubject'" : ""); + htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); + + if (revs->graph) { + /* Print graph segment for current commit */ + html("<td class='commitgraph'>"); + html(graphbuf.buf); + html("</td>"); + strbuf_setlen(&graphbuf, 0); + } + else { + html("<td>"); + tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); + tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); + html_link_open(tmp, NULL, NULL); + cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); + html_link_close(); + html("</td>"); + } + + htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : ""); + if (ctx.qry.showmsg) { + /* line-wrap long commit subjects instead of truncating them */ + size_t subject_len = strlen(info->subject); + + if (subject_len > ctx.cfg.max_msg_len && + ctx.cfg.max_msg_len >= 15) { + /* symbol for signaling line-wrap (in PAGE_ENCODING) */ + const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 }; + int i = ctx.cfg.max_msg_len - strlen(wrap_symbol); + + /* Rewind i to preceding space character */ + while (i > 0 && !isspace(info->subject[i])) + --i; + if (!i) /* Oops, zero spaces. Reset i */ + i = ctx.cfg.max_msg_len - strlen(wrap_symbol); + + /* add remainder starting at i to msgbuf */ + strbuf_add(&msgbuf, info->subject + i, subject_len - i); + strbuf_trim(&msgbuf); + strbuf_add(&msgbuf, "\n\n", 2); + + /* Place wrap_symbol at position i in info->subject */ + strcpy(info->subject + i, wrap_symbol); + } + } cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, @@ -99,2 +171,12 @@ void print_commit(struct commit *commit) html_txt(info->author); + + if (revs->graph) { + html("</td><td>"); + tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); + tmp = cgit_fileurl(ctx.repo->url, "commit", ctx.qry.vpath, tmp); + html_link_open(tmp, NULL, NULL); + cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); + html_link_close(); + } + if (ctx.repo->enable_log_filecount) { @@ -112,25 +194,57 @@ void print_commit(struct commit *commit) html("</td></tr>\n"); - if (ctx.qry.showmsg) { - struct strbuf notes = STRBUF_INIT; - format_note(NULL, commit->object.sha1, ¬es, PAGE_ENCODING, 0); - if (ctx.repo->enable_log_filecount) { - cols++; - if (ctx.repo->enable_log_linecount) - cols++; + if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ + html("<tr class='nohover'>"); + + if (ctx.qry.showmsg) { + /* Concatenate commit message + notes in msgbuf */ + if (info->msg && *(info->msg)) { + strbuf_addstr(&msgbuf, info->msg); + strbuf_addch(&msgbuf, '\n'); + } + format_note(NULL, commit->object.sha1, &msgbuf, + PAGE_ENCODING, + NOTES_SHOW_HEADER | NOTES_INDENT); + strbuf_addch(&msgbuf, '\n'); + strbuf_ltrim(&msgbuf); } - htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", - cols); - html_txt(info->msg); - html("</td></tr>\n"); - if (notes.len != 0) { - html("<tr class='nohover'>"); - html("<td class='lognotes-label'>Notes:</td>"); - htmlf("<td colspan='%d' class='lognotes'>", - cols); - html_txt(notes.buf); - html("</td></tr>\n"); + + if (revs->graph) { + int lines = 0; + + /* Calculate graph padding */ + if (ctx.qry.showmsg) { + /* Count #lines in commit message + notes */ + const char *p = msgbuf.buf; + lines = 1; + while ((p = strchr(p, '\n'))) { + p++; + lines++; + } + } + + /* Print graph padding */ + html("<td class='commitgraph'>"); + while (lines > 0 || !graph_is_commit_finished(revs->graph)) { + if (graphbuf.len) + html("\n"); + strbuf_setlen(&graphbuf, 0); + graph_next_line(revs->graph, &graphbuf); + html(graphbuf.buf); + lines--; + } + html("</td>\n"); } - strbuf_release(¬es); + else + html("<td/>"); /* Empty 'Age' column */ + + /* Print msgbuf into remainder of table row */ + htmlf("<td colspan='%d'%s>\n", cols, + ctx.qry.showmsg ? " class='logmsg'" : ""); + html_txt(msgbuf.buf); + html("</td></tr>\n"); } + + strbuf_release(&msgbuf); + strbuf_release(&graphbuf); cgit_free_commitinfo(info); @@ -150,4 +264,26 @@ static const char *disambiguate_ref(const char *ref) +static char *next_token(char **src) +{ + char *result; + + if (!src || !*src) + return NULL; + while (isspace(**src)) + (*src)++; + if (!**src) + return NULL; + result = *src; + while (**src) { + if (isspace(**src)) { + **src = '\0'; + (*src)++; + break; + } + (*src)++; + } + return result; +} + void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, - char *path, int pager) + char *path, int pager, int commit_graph) { @@ -155,5 +291,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern struct commit *commit; - const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; - int argc = 2; + struct vector vec = VECTOR_INIT(char *); int i, columns = 3; + char *arg; + + /* First argv is NULL */ + vector_push(&vec, NULL, 0); @@ -161,11 +300,36 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern tip = ctx.qry.head; - - argv[1] = disambiguate_ref(tip); + tip = disambiguate_ref(tip); + vector_push(&vec, &tip, 0); if (grep && pattern && *pattern) { + pattern = xstrdup(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; + !strcmp(grep, "committer")) { + arg = fmt("--%s=%s", grep, pattern); + vector_push(&vec, &arg, 0); + } + if (!strcmp(grep, "range")) { + /* Split the pattern at whitespace and add each token + * as a revision expression. Do not accept other + * rev-list options. Also, replace the previously + * pushed tip (it's no longer relevant). + */ + vec.count--; + while ((arg = next_token(&pattern))) { + if (*arg == '-') { + fprintf(stderr, "Bad range expr: %s\n", + arg); + break; + } + vector_push(&vec, &arg, 0); + } + } + } + if (commit_graph) { + static const char *graph_arg = "--graph"; + static const char *color_arg = "--color"; + vector_push(&vec, &graph_arg, 0); + vector_push(&vec, &color_arg, 0); + graph_set_column_colors(column_colors_html, + COLUMN_COLORS_HTML_MAX); } @@ -173,5 +337,11 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (path) { - argv[argc++] = "--"; - argv[argc++] = path; + arg = "--"; + vector_push(&vec, &arg, 0); + vector_push(&vec, &path, 0); } + + /* Make sure the vector is NULL-terminated */ + vector_push(&vec, NULL, 0); + vec.count--; + init_revisions(&rev, NULL); @@ -181,3 +351,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern rev.show_root_diff = 0; - setup_revisions(argc, argv, &rev, NULL); + setup_revisions(vec.count, vec.data, &rev, NULL); load_ref_decorations(DECORATE_FULL_REFS); @@ -191,4 +361,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern - html("<tr class='nohover'><th class='left'>Age</th>" - "<th class='left'>Commit message"); + html("<tr class='nohover'>"); + if (commit_graph) + html("<th></th>"); + else + html("<th class='left'>Age</th>"); + html("<th class='left'>Commit message"); if (pager) { @@ -202,2 +376,4 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern html("</th><th class='left'>Author</th>"); + if (commit_graph) + html("<th class='left'>Age</th>"); if (ctx.repo->enable_log_filecount) { @@ -223,3 +399,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { - print_commit(commit); + print_commit(commit, &rev); free(commit->buffer); @@ -4,3 +4,4 @@ extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, - char *pattern, char *path, int pager); + char *pattern, char *path, int pager, + int commit_graph); extern void show_commit_decorations(struct commit *commit); diff --git a/ui-summary.c b/ui-summary.c index b203bcc..5be2545 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -61,3 +61,3 @@ void cgit_print_summary() cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, - NULL, NULL, 0); + NULL, NULL, 0, 0); } diff --git a/vector.c b/vector.c new file mode 100644 index 0000000..0863908 --- a/dev/null +++ b/vector.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include "vector.h" + +static int grow(struct vector *vec, int gently) +{ + size_t new_alloc; + void *new_data; + + new_alloc = vec->alloc * 3 / 2; + if (!new_alloc) + new_alloc = 8; + new_data = realloc(vec->data, new_alloc * vec->size); + if (!new_data) { + if (gently) + return ENOMEM; + perror("vector.c:grow()"); + exit(1); + } + vec->data = new_data; + vec->alloc = new_alloc; + return 0; +} + +int vector_push(struct vector *vec, const void *data, int gently) +{ + int rc; + + if (vec->count == vec->alloc && (rc = grow(vec, gently))) + return rc; + if (data) + memmove(vec->data + vec->count * vec->size, data, vec->size); + else + memset(vec->data + vec->count * vec->size, 0, vec->size); + vec->count++; + return 0; +} diff --git a/vector.h b/vector.h new file mode 100644 index 0000000..c64eb1f --- a/dev/null +++ b/vector.h @@ -0,0 +1,17 @@ +#ifndef CGIT_VECTOR_H +#define CGIT_VECTOR_H + +#include <stdlib.h> + +struct vector { + size_t size; + size_t count; + size_t alloc; + void *data; +}; + +#define VECTOR_INIT(type) {sizeof(type), 0, 0, NULL} + +int vector_push(struct vector *vec, const void *data, int gently); + +#endif /* CGIT_VECTOR_H */ |