* [PATCH 1/2] Make graph_next_line() available in the graph.h API
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
@ 2010-07-13 21:23 ` Johan Herland
2010-07-13 21:23 ` [PATCH 2/2] Enable custom schemes for column colors in the graph API Johan Herland
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, johan, Lars Hjemli, nanako3, adam
In order to successfully use the graph API from a context other than the
stdout/command-line scenario (where the graph_show_* functions are
suitable), we need direct access to graph_next_line(), to drive the
graph drawing process.
Signed-off-by: Johan Herland <johan@herland.net>
---
graph.c | 13 +------------
graph.h | 11 +++++++++++
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/graph.c b/graph.c
index ac7c605..47397da 100644
--- a/graph.c
+++ b/graph.c
@@ -8,17 +8,6 @@
/* Internal API */
/*
- * Output the next line for a graph.
- * This formats the next graph line into the specified strbuf. It is not
- * terminated with a newline.
- *
- * Returns 1 if the line includes the current commit, and 0 otherwise.
- * graph_next_line() will return 1 exactly once for each time
- * graph_update() is called.
- */
-static int graph_next_line(struct git_graph *graph, struct strbuf *sb);
-
-/*
* Output a padding line in the graph.
* This is similar to graph_next_line(). However, it is guaranteed to
* never print the current commit line. Instead, if the commit line is
@@ -1143,7 +1132,7 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
graph_update_state(graph, GRAPH_PADDING);
}
-static int graph_next_line(struct git_graph *graph, struct strbuf *sb)
+int graph_next_line(struct git_graph *graph, struct strbuf *sb)
{
switch (graph->state) {
case GRAPH_PADDING:
diff --git a/graph.h b/graph.h
index b82ae87..f188168 100644
--- a/graph.h
+++ b/graph.h
@@ -32,6 +32,17 @@ void graph_update(struct git_graph *graph, struct commit *commit);
*/
int graph_is_commit_finished(struct git_graph const *graph);
+/*
+ * Output the next line for a graph.
+ * This formats the next graph line into the specified strbuf. It is not
+ * terminated with a newline.
+ *
+ * Returns 1 if the line includes the current commit, and 0 otherwise.
+ * graph_next_line() will return 1 exactly once for each time
+ * graph_update() is called.
+ */
+int graph_next_line(struct git_graph *graph, struct strbuf *sb);
+
/*
* graph_show_*: helper functions for printing to stdout
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/2] Enable custom schemes for column colors in the graph API
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
2010-07-13 21:23 ` [PATCH 1/2] Make graph_next_line() available in the graph.h API Johan Herland
@ 2010-07-13 21:23 ` Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view Johan Herland
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, johan, Lars Hjemli, nanako3, adam
Currently, the graph code is hardcoded to use ANSI color escapes for
coloring the column characters in the generated graphs. This patch
allows a custom scheme of colors to be set at runtime, allowing
different types of color escapes to be used.
A new function - graph_set_column_colors() - is added to the graph.h API,
which allows a custom column_colors array (and column_colors_max value)
to replace the builtin ANSI array (and _max value). The new function -
if used - must be called before graph_init() is called.
Signed-off-by: Johan Herland <johan@herland.net>
---
graph.c | 37 ++++++++++++++++++++++++++-----------
graph.h | 17 +++++++++++++++++
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/graph.c b/graph.c
index 47397da..e2a5860 100644
--- a/graph.c
+++ b/graph.c
@@ -62,7 +62,7 @@ enum graph_state {
/*
* The list of available column colors.
*/
-static char column_colors[][COLOR_MAXLEN] = {
+static const char *column_colors_ansi[] = {
GIT_COLOR_RED,
GIT_COLOR_GREEN,
GIT_COLOR_YELLOW,
@@ -75,23 +75,33 @@ static char column_colors[][COLOR_MAXLEN] = {
GIT_COLOR_BOLD_BLUE,
GIT_COLOR_BOLD_MAGENTA,
GIT_COLOR_BOLD_CYAN,
+ GIT_COLOR_RESET,
};
-#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))
+#define COLUMN_COLORS_ANSI_MAX (ARRAY_SIZE(column_colors_ansi) - 1)
-static const char *column_get_color_code(const struct column *c)
+static const char **column_colors;
+static unsigned short column_colors_max;
+
+void graph_set_column_colors(const char **colors, unsigned short colors_max)
+{
+ column_colors = colors;
+ column_colors_max = colors_max;
+}
+
+static const char *column_get_color_code(unsigned short color)
{
- return column_colors[c->color];
+ return column_colors[color];
}
static void strbuf_write_column(struct strbuf *sb, const struct column *c,
char col_char)
{
- if (c->color < COLUMN_COLORS_MAX)
- strbuf_addstr(sb, column_get_color_code(c));
+ if (c->color < column_colors_max)
+ strbuf_addstr(sb, column_get_color_code(c->color));
strbuf_addch(sb, col_char);
- if (c->color < COLUMN_COLORS_MAX)
- strbuf_addstr(sb, GIT_COLOR_RESET);
+ if (c->color < column_colors_max)
+ strbuf_addstr(sb, column_get_color_code(column_colors_max));
}
struct git_graph {
@@ -215,6 +225,11 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
struct git_graph *graph_init(struct rev_info *opt)
{
struct git_graph *graph = xmalloc(sizeof(struct git_graph));
+
+ if (!column_colors)
+ graph_set_column_colors(column_colors_ansi,
+ COLUMN_COLORS_ANSI_MAX);
+
graph->commit = NULL;
graph->revs = opt;
graph->num_parents = 0;
@@ -231,7 +246,7 @@ struct git_graph *graph_init(struct rev_info *opt)
* always increment it for the first commit we output.
* This way we start at 0 for the first commit.
*/
- graph->default_column_color = COLUMN_COLORS_MAX - 1;
+ graph->default_column_color = column_colors_max - 1;
/*
* Allocate a reasonably large default number of columns
@@ -354,7 +369,7 @@ static struct commit_list *first_interesting_parent(struct git_graph *graph)
static unsigned short graph_get_current_column_color(const struct git_graph *graph)
{
if (!DIFF_OPT_TST(&graph->revs->diffopt, COLOR_DIFF))
- return COLUMN_COLORS_MAX;
+ return column_colors_max;
return graph->default_column_color;
}
@@ -364,7 +379,7 @@ static unsigned short graph_get_current_column_color(const struct git_graph *gra
static void graph_increment_column_color(struct git_graph *graph)
{
graph->default_column_color = (graph->default_column_color + 1) %
- COLUMN_COLORS_MAX;
+ column_colors_max;
}
static unsigned short graph_find_commit_color(const struct git_graph *graph,
diff --git a/graph.h b/graph.h
index f188168..aff960c 100644
--- a/graph.h
+++ b/graph.h
@@ -5,6 +5,23 @@
struct git_graph;
/*
+ * Set up a custom scheme for column colors.
+ *
+ * The default column color scheme inserts ANSI color escapes to colorize
+ * the graph. The various color escapes are stored in an array of strings
+ * where each entry corresponds to a color, except for the last entry,
+ * which denotes the escape for resetting the color back to the default.
+ * When generating the graph, strings from this array are inserted before
+ * and after the various column characters.
+ *
+ * This function allows you to enable a custom array of color escapes.
+ * The 'colors_max' argument is the index of the last "reset" entry.
+ *
+ * This functions must be called BEFORE graph_init() is called.
+ */
+void graph_set_column_colors(const char **colors, unsigned short colors_max);
+
+/*
* Create a new struct git_graph.
*/
struct git_graph *graph_init(struct rev_info *opt);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
2010-07-13 21:23 ` [PATCH 1/2] Make graph_next_line() available in the graph.h API Johan Herland
2010-07-13 21:23 ` [PATCH 2/2] Enable custom schemes for column colors in the graph API Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
2010-07-13 22:57 ` Lars Hjemli
2010-07-13 21:40 ` [CGit RFC/PATCH 1/5] ui-stats: Remove unnecessary #include Johan Herland
` (4 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
Hi,
Here are some patches to implement an ASCII-art commit graph on CGit's
'log' page. The patches reuse the graph-drawing code from Git's own
'git log --graph'. As such, these patches depend on the two patches
I just submitted to the Git list for extending the graph.h API.
More detailed: Patch #4 in this series (ui-log: Implement support for
commit graphs) depend on patch #1 in the other series (Make
graph_next_line() available in the graph.h API), while patch #5 in
this series (ui-log: Colorize commit graph) depends on patch #2 in the
other series (Enable custom schemes for column colors in the graph
API).
Otherwise, the first patch in this series is a minor cleanup patch,
while patches #2 and #3 prepare for the introduction of commit graphs
in patch #4.
Have fun!
...Johan
Johan Herland (5):
ui-stats: Remove unnecessary #include
ui-log: Move 'Age' column to the right of 'Author', like in gitk
ui-log: Refactor display of commit messages
ui-log: Implement support for commit graphs
ui-log: Colorize commit graph
cgit.c | 6 +++
cgit.css | 31 ++++++++++++-
cgit.h | 3 +
cgitrc.5.txt | 15 ++++++-
shared.c | 1 +
ui-log.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++-----------
ui-stats.c | 2 -
7 files changed, 168 insertions(+), 30 deletions(-)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view
2010-07-13 21:40 ` [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view Johan Herland
@ 2010-07-13 22:57 ` Lars Hjemli
2010-07-14 5:59 ` Johan Herland
0 siblings, 1 reply; 12+ messages in thread
From: Lars Hjemli @ 2010-07-13 22:57 UTC (permalink / raw)
To: Johan Herland; +Cc: git
On Tue, Jul 13, 2010 at 23:40, Johan Herland <johan@herland.net> wrote:
> Here are some patches to implement an ASCII-art commit graph on CGit's
> 'log' page. The patches reuse the graph-drawing code from Git's own
> 'git log --graph'. As such, these patches depend on the two patches
> I just submitted to the Git list for extending the graph.h API.
Thanks. I've applied the git patches to the jh/graph branch in
git://hjemli.net/pub/git/git (based on v1.7.1-rc2) and updated the
submodule in cgit to point at the tip of this branch. The cgit patches
are then applied on top of this and merged into the wip branch in
git://hjemli.net/pub/git/cgit.
The end result can be seen in action at http://hjemli.net/git/cgit/log
[1] - it works, but I'll have to think about possible compromises
between correctness and performance (i.e. the dependency on
--topo-order).
--
larsh
[1] If the graph looks strange, you might have a cached cgit.css.
Please force a reload in your browser.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view
2010-07-13 22:57 ` Lars Hjemli
@ 2010-07-14 5:59 ` Johan Herland
2010-07-18 13:26 ` Lars Hjemli
0 siblings, 1 reply; 12+ messages in thread
From: Johan Herland @ 2010-07-14 5:59 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git
On Wednesday 14 July 2010, Lars Hjemli wrote:
> On Tue, Jul 13, 2010 at 23:40, Johan Herland <johan@herland.net> wrote:
> > Here are some patches to implement an ASCII-art commit graph on CGit's
> > 'log' page. The patches reuse the graph-drawing code from Git's own
> > 'git log --graph'. As such, these patches depend on the two patches
> > I just submitted to the Git list for extending the graph.h API.
>
> Thanks. I've applied the git patches to the jh/graph branch in
> git://hjemli.net/pub/git/git (based on v1.7.1-rc2) and updated the
> submodule in cgit to point at the tip of this branch. The cgit patches
> are then applied on top of this and merged into the wip branch in
> git://hjemli.net/pub/git/cgit.
Thanks.
> The end result can be seen in action at http://hjemli.net/git/cgit/log
> [1] - it works, but I'll have to think about possible compromises
> between correctness and performance (i.e. the dependency on
> --topo-order).
Yes, this feature definitely introduces a performance tradeoff. IMHO it's up
to the server admin to choose whether to enable this in the config or not.
If you're serving large repos from a small server, you might simply want to
turn it off.
We might also want to consider adding a query (and cookie?) flag enabling
visitors to turn off graphs for faster browsing as well.
BTW, have you had time to look at my previous patch series for ignoring
whitespace in diffs?
Have fun! :)
...Johan
--
Johan Herland, <johan@herland.net>
www.herland.net
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view
2010-07-14 5:59 ` Johan Herland
@ 2010-07-18 13:26 ` Lars Hjemli
0 siblings, 0 replies; 12+ messages in thread
From: Lars Hjemli @ 2010-07-18 13:26 UTC (permalink / raw)
To: Johan Herland; +Cc: git
[Sorry for the late reply]
On Wed, Jul 14, 2010 at 07:59, Johan Herland <johan@herland.net> wrote:
> BTW, have you had time to look at my previous patch series for ignoring
> whitespace in diffs?
It took a while, but I've now merged all your patches (except the
graph series) into my master branch. Thanks.
--
larsh
^ permalink raw reply [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 1/5] ui-stats: Remove unnecessary #include
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
` (2 preceding siblings ...)
2010-07-13 21:40 ` [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 2/5] ui-log: Move 'Age' column to the right of 'Author', like in gitk Johan Herland
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
<string-list.h> is already #included from cgit.h
Signed-off-by: Johan Herland <johan@herland.net>
---
ui-stats.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/ui-stats.c b/ui-stats.c
index bdaf9cc..e8ea57a 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -1,5 +1,3 @@
-#include <string-list.h>
-
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 2/5] ui-log: Move 'Age' column to the right of 'Author', like in gitk
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
` (3 preceding siblings ...)
2010-07-13 21:40 ` [CGit RFC/PATCH 1/5] ui-stats: Remove unnecessary #include Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 3/5] ui-log: Refactor display of commit messages Johan Herland
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
This is in preparation for putting the commit graph to the left of the
commit message. IMHO, it looks better when the commit message is right
next to the graph, than if the age is wedged in between.
Signed-off-by: Johan Herland <johan@herland.net>
---
ui-log.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/ui-log.c b/ui-log.c
index 33ec8a9..390c38b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -79,23 +79,22 @@ void print_commit(struct commit *commit)
{
struct commitinfo *info;
char *tmp;
- int cols = 2;
+ int cols = 3;
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'" : "");
+ htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : "");
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
show_commit_decorations(commit);
html("</td><td>");
html_txt(info->author);
+ 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) {
files = 0;
add_lines = 0;
@@ -115,7 +114,7 @@ void print_commit(struct commit *commit)
if (ctx.repo->enable_log_linecount)
cols++;
}
- htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
+ htmlf("<tr class='nohover'><td colspan='%d' class='logmsg'>",
cols);
html_txt(info->msg);
html("</td></tr>\n");
@@ -176,8 +175,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (pager)
html("<table class='list nowrap'>");
- html("<tr class='nohover'><th class='left'>Age</th>"
- "<th class='left'>Commit message");
+ html("<tr class='nohover'><th class='left'>Commit message");
if (pager) {
html(" (");
cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
@@ -186,7 +184,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
html(")");
}
- html("</th><th class='left'>Author</th>");
+ html("</th><th class='left'>Author</th><th class='left'>Age</th>");
if (ctx.repo->enable_log_filecount) {
html("<th class='left'>Files</th>");
columns++;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 3/5] ui-log: Refactor display of commit messages
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
` (4 preceding siblings ...)
2010-07-13 21:40 ` [CGit RFC/PATCH 2/5] ui-log: Move 'Age' column to the right of 'Author', like in gitk Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 4/5] ui-log: Implement support for commit graphs Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 5/5] ui-log: Colorize commit graph Johan Herland
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
Split new function print_commit_line() out of print_commit(). The new
function only prints the initial table cells containing commit metadata,
i.e. the commit subject, author and date (and file/line-count if enabled).
The printing of the rest of the commit message (when showmsg is enabled)
is still performed in print_commit(), but is slightly changed to use
additional newlines to achieve the vertical margins that were previously
implemented with CSS. This is in preparation for the commit graph which
will be printed to the left of the commit message as part of the same
table row, and therefore needs to minimize margins that would otherwise
cause ugly gaps in the graph.
Signed-off-by: Johan Herland <johan@herland.net>
---
cgit.css | 2 +-
ui-log.c | 38 +++++++++++++++++++++++++-------------
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/cgit.css b/cgit.css
index 6e47eb3..78f654e 100644
--- a/cgit.css
+++ b/cgit.css
@@ -161,7 +161,7 @@ table.list td.logsubject {
table.list td.logmsg {
font-family: monospace;
white-space: pre;
- padding: 1em 0.5em 2em 0.5em;
+ padding: 0 0.5em;
}
table.list td a {
diff --git a/ui-log.c b/ui-log.c
index 390c38b..2cd0f19 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -75,14 +75,10 @@ void show_commit_decorations(struct commit *commit)
}
}
-void print_commit(struct commit *commit)
+static void print_commit_line(struct commit *commit, struct commitinfo *info)
{
- struct commitinfo *info;
char *tmp;
- int cols = 3;
- info = cgit_parse_commit(commit);
- htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : "");
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
@@ -107,18 +103,34 @@ void print_commit(struct commit *commit)
htmlf("-%d/+%d", rem_lines, add_lines);
}
}
- html("</td></tr>\n");
- if (ctx.qry.showmsg) {
- if (ctx.repo->enable_log_filecount) {
+ html("</td>");
+}
+
+void print_commit(struct commit *commit)
+{
+ struct commitinfo *info = cgit_parse_commit(commit);
+ int cols = 3;
+
+ if (ctx.repo->enable_log_filecount) {
+ cols++;
+ if (ctx.repo->enable_log_linecount)
cols++;
- if (ctx.repo->enable_log_linecount)
- cols++;
+ }
+
+ htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
+ print_commit_line(commit, info);
+ html("</tr>\n");
+
+ if (ctx.qry.showmsg) {
+ html("<tr class='nohover'>");
+ htmlf("<td colspan='%d' class='logmsg'>\n", cols);
+ if (*(info->msg)) {
+ html_txt(info->msg);
+ html("\n\n");
}
- htmlf("<tr class='nohover'><td colspan='%d' class='logmsg'>",
- cols);
- html_txt(info->msg);
html("</td></tr>\n");
}
+
cgit_free_commitinfo(info);
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 4/5] ui-log: Implement support for commit graphs
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
` (5 preceding siblings ...)
2010-07-13 21:40 ` [CGit RFC/PATCH 3/5] ui-log: Refactor display of commit messages Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 5/5] ui-log: Colorize commit graph Johan Herland
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
Teach CGit to print an ASCII art commit graph to the left of the commit
message, similar to 'git log --graph'. The graph adds extra lines (table
rows) to the log when needed to add/remove/shuffle edges in the graph.
When 'showmsg' is enabled, the graph auto-adjusts to the lines added by
the commit message.
This feature is controlled by a new config variable: "enable-commit-graph"
(disabled by default), and individual repos can disable it by settign
"repo.enable-commit-graph" to "0".
Signed-off-by: Johan Herland <johan@herland.net>
---
cgit.c | 6 +++++
cgit.css | 5 ++++
cgit.h | 3 ++
cgitrc.5.txt | 15 +++++++++++-
shared.c | 1 +
ui-log.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
6 files changed, 94 insertions(+), 7 deletions(-)
diff --git a/cgit.c b/cgit.c
index ab25b6a..29fb57f 100644
--- a/cgit.c
+++ b/cgit.c
@@ -56,6 +56,8 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
repo->defbranch = xstrdup(value);
else if (!strcmp(name, "snapshots"))
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"))
repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
else if (!strcmp(name, "enable-log-linecount"))
@@ -137,6 +139,8 @@ void config_cb(const char *name, const char *value)
ctx.cfg.enable_filter_overrides = atoi(value);
else if (!strcmp(name, "enable-index-links"))
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"))
ctx.cfg.enable_log_filecount = atoi(value);
else if (!strcmp(name, "enable-log-linecount"))
@@ -522,6 +526,8 @@ void print_repo(FILE *f, struct cgit_repo *repo)
fprintf(f, "repo.section=%s\n", repo->section);
if (repo->clone_url)
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",
repo->enable_log_filecount);
fprintf(f, "repo.enable-log-linecount=%d\n",
diff --git a/cgit.css b/cgit.css
index 78f654e..65da960 100644
--- a/cgit.css
+++ b/cgit.css
@@ -153,6 +153,11 @@ table.list td {
padding: 0.1em 0.5em 0.1em 0.5em;
}
+table.list td.commitgraph {
+ font-family: monospace;
+ white-space: pre;
+}
+
table.list td.logsubject {
font-family: monospace;
font-weight: bold;
diff --git a/cgit.h b/cgit.h
index 2b28d63..402610b 100644
--- a/cgit.h
+++ b/cgit.h
@@ -19,6 +19,7 @@
#include <xdiff-interface.h>
#include <xdiff/xdiff.h>
#include <utf8.h>
+#include <graph.h>
/*
@@ -70,6 +71,7 @@ struct cgit_repo {
char *section;
char *clone_url;
int snapshots;
+ int enable_commit_graph;
int enable_log_filecount;
int enable_log_linecount;
int enable_remote_branches;
@@ -182,6 +184,7 @@ struct cgit_config {
int embedded;
int enable_filter_overrides;
int enable_index_links;
+ int enable_commit_graph;
int enable_log_filecount;
int enable_log_linecount;
int enable_remote_branches;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index a853522..72fd2e1 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -90,7 +90,12 @@ embedded::
Flag which, when set to "1", will make cgit generate a html fragment
suitable for embedding in other html pages. Default value: none. See
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::
Flag which, when set to "1", allows all filter settings to be
overridden in repository-specific cgitrc files. Default value: none.
@@ -319,6 +324,10 @@ repo.defbranch::
repo.desc::
The value to show as repository description. Default value: none.
+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::
A flag which can be used to disable the global setting
`enable-log-filecount'. Default value: none.
@@ -404,6 +413,10 @@ css=/css/cgit.css
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
enable-log-filecount=1
diff --git a/shared.c b/shared.c
index 06f70bb..9c00a7d 100644
--- a/shared.c
+++ b/shared.c
@@ -56,6 +56,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
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;
ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
diff --git a/ui-log.c b/ui-log.c
index 2cd0f19..3cfe3f9 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -106,7 +106,7 @@ static void print_commit_line(struct commit *commit, struct commitinfo *info)
html("</td>");
}
-void print_commit(struct commit *commit)
+void print_commit(struct commit *commit, struct rev_info *revs)
{
struct commitinfo *info = cgit_parse_commit(commit);
int cols = 3;
@@ -117,11 +117,65 @@ void print_commit(struct commit *commit)
cols++;
}
- htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
+ if (revs->graph) {
+ struct strbuf msgbuf = STRBUF_INIT;
+
+ while (!graph_next_line(revs->graph, &msgbuf)) {
+ /* Create graph line + empty table row */
+ html("<tr class='nohover'><td class='commitgraph'>");
+ html_txt(msgbuf.buf);
+ htmlf("</td><td colspan='%d' /></tr>\n", cols);
+ strbuf_setlen(&msgbuf, 0);
+ }
+ /* Create graph line + commit info table row */
+ htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
+ html("<td class='commitgraph'>");
+ html_txt(msgbuf.buf);
+ html("</td>");
+ strbuf_release(&msgbuf);
+ }
+ else
+ htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
+
print_commit_line(commit, info);
html("</tr>\n");
- if (ctx.qry.showmsg) {
+ if (revs->graph) {
+ struct strbuf msgbuf = STRBUF_INIT;
+ int lines = 0;
+
+ if (ctx.qry.showmsg) {
+ /* Count #lines in commit message */
+ lines = 1;
+ if (*(info->msg)) {
+ const char *p = info->msg;
+ lines += 3;
+ while ((p = strchr(p, '\n') + 1) > info->msg)
+ lines++;
+ }
+ }
+
+ /* Print graph padding */
+ html("<tr class='nohover'><td class='commitgraph'>");
+ while (lines > 0 || !graph_is_commit_finished(revs->graph)) {
+ if (msgbuf.len)
+ html("\n");
+ strbuf_setlen(&msgbuf, 0);
+ graph_next_line(revs->graph, &msgbuf);
+ html_txt(msgbuf.buf);
+ lines--;
+ }
+
+ /* Print remainder of table row */
+ htmlf("</td><td colspan='%d'%s>\n", cols,
+ ctx.qry.showmsg ? " class='logmsg'" : "");
+ if (ctx.qry.showmsg && *(info->msg)) {
+ html_txt(info->msg);
+ html("\n\n");
+ }
+ html("</td></tr>\n");
+ }
+ else if (ctx.qry.showmsg) {
html("<tr class='nohover'>");
htmlf("<td colspan='%d' class='logmsg'>\n", cols);
if (*(info->msg)) {
@@ -151,7 +205,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
{
struct rev_info rev;
struct commit *commit;
- const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
+ const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL};
int argc = 2;
int i, columns = 3;
@@ -167,6 +221,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (!strcmp(grep, "range"))
argv[1] = pattern;
}
+ if (ctx.repo->enable_commit_graph)
+ argv[argc++] = "--graph";
if (path) {
argv[argc++] = "--";
@@ -187,7 +243,10 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (pager)
html("<table class='list nowrap'>");
- html("<tr class='nohover'><th class='left'>Commit message");
+ html("<tr class='nohover'>");
+ if (ctx.repo->enable_commit_graph)
+ html("<th></th>");
+ html("<th class='left'>Commit message");
if (pager) {
html(" (");
cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
@@ -218,7 +277,7 @@ 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);
commit->buffer = NULL;
free_commit_list(commit->parents);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [CGit RFC/PATCH 5/5] ui-log: Colorize commit graph
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
` (6 preceding siblings ...)
2010-07-13 21:40 ` [CGit RFC/PATCH 4/5] ui-log: Implement support for commit graphs Johan Herland
@ 2010-07-13 21:40 ` Johan Herland
7 siblings, 0 replies; 12+ messages in thread
From: Johan Herland @ 2010-07-13 21:40 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, johan
Use the existing coloring logic in Git's graph code to color the lines
between commits in the commit graph.
Whereas Git normally uses ANSI color escapes to produce colors, we here
use graph_set_column_colors() to replace those with "HTML color escapes"
which embed the graph lines in <span> tags that apply the desired color
using CSS.
Signed-off-by: Johan Herland <johan@herland.net>
---
cgit.css | 24 ++++++++++++++++++++++++
ui-log.c | 29 ++++++++++++++++++++++++-----
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/cgit.css b/cgit.css
index 65da960..e8be2b1 100644
--- a/cgit.css
+++ b/cgit.css
@@ -158,6 +158,30 @@ table.list td.commitgraph {
white-space: pre;
}
+table.list td.commitgraph .column1 {
+ color: #a00;
+}
+
+table.list td.commitgraph .column2 {
+ color: #0a0;
+}
+
+table.list td.commitgraph .column3 {
+ color: #aa0;
+}
+
+table.list td.commitgraph .column4 {
+ color: #00a;
+}
+
+table.list td.commitgraph .column5 {
+ color: #a0a;
+}
+
+table.list td.commitgraph .column6 {
+ color: #0aa;
+}
+
table.list td.logsubject {
font-family: monospace;
font-weight: bold;
diff --git a/ui-log.c b/ui-log.c
index 3cfe3f9..2fc8c7b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -12,6 +12,21 @@
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)
{
if (size <= 0)
@@ -123,14 +138,14 @@ void print_commit(struct commit *commit, struct rev_info *revs)
while (!graph_next_line(revs->graph, &msgbuf)) {
/* Create graph line + empty table row */
html("<tr class='nohover'><td class='commitgraph'>");
- html_txt(msgbuf.buf);
+ html(msgbuf.buf);
htmlf("</td><td colspan='%d' /></tr>\n", cols);
strbuf_setlen(&msgbuf, 0);
}
/* Create graph line + commit info table row */
htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
html("<td class='commitgraph'>");
- html_txt(msgbuf.buf);
+ html(msgbuf.buf);
html("</td>");
strbuf_release(&msgbuf);
}
@@ -162,7 +177,7 @@ void print_commit(struct commit *commit, struct rev_info *revs)
html("\n");
strbuf_setlen(&msgbuf, 0);
graph_next_line(revs->graph, &msgbuf);
- html_txt(msgbuf.buf);
+ html(msgbuf.buf);
lines--;
}
@@ -205,7 +220,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
{
struct rev_info rev;
struct commit *commit;
- const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL};
+ const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
int argc = 2;
int i, columns = 3;
@@ -221,8 +236,12 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (!strcmp(grep, "range"))
argv[1] = pattern;
}
- if (ctx.repo->enable_commit_graph)
+ if (ctx.repo->enable_commit_graph) {
argv[argc++] = "--graph";
+ argv[argc++] = "--color";
+ graph_set_column_colors(column_colors_html,
+ COLUMN_COLORS_HTML_MAX);
+ }
if (path) {
argv[argc++] = "--";
--
1.7.0.4
^ permalink raw reply related [flat|nested] 12+ messages in thread