#include "cache.h"
#include "commit.h"
#include "color.h"
#include "graph.h"
#include "diff.h"
#include "revision.h"
/* Internal API */
/*
* 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
* next, it will simply output a line of vertical padding, extending the
* branch lines downwards, but leaving them otherwise unchanged.
*/
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb);
/*
* Print a strbuf to stdout. If the graph is non-NULL, all lines but the
* first will be prefixed with the graph output.
*
* If the strbuf ends with a newline, the output will end after this
* newline. A new graph line will not be printed after the final newline.
* If the strbuf is empty, no output will be printed.
*
* Since the first line will not include the graph output, the caller is
* responsible for printing this line's graph (perhaps via
* graph_show_commit() or graph_show_oneline()) before calling
* graph_show_strbuf().
*/
static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb);
/*
* TODO:
* - Limit the number of columns, similar to the way gitk does.
* If we reach more than a specified number of columns, omit
* sections of some columns.
*/
struct column {
/*
* The parent commit of this column.
*/
struct commit *commit;
/*
* The color to (optionally) print this column in. This is an
* index into column_colors.
*/
unsigned short color;
};
enum graph_state {
GRAPH_PADDING,
GRAPH_SKIP,
GRAPH_PRE_COMMIT,
GRAPH_COMMIT,
GRAPH_POST_MERGE,
GRAPH_COLLAPSING
};
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[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->color));
strbuf_addch(sb, col_char);
if (c->color < column_colors_max)
strbuf_addstr(sb, column_get_color_code(column_colors_max));
}
struct git_graph {
/*
* The commit currently being processed
*/
struct commit *commit;
/* The rev-info used for the current traversal */
struct rev_info *revs;
/*
* The number of interesting parents that this commit has.
*
* Note that this is not the same as the actual number of parents.
* This count excludes parents that won't be printed in the graph
* output, as determined by graph_is_interesting().
*/
int num_parents;
/*
* The width of the graph output for this commit.
* All rows for this commit are padded to this width, so that
* messages printed after the graph output are aligned.
*/
int width;
/*
* The next expansion row to print
* when state is GRAPH_PRE_COMMIT
*/
int expansion_row;
/*
* The current output state.
* This tells us what kind of line graph_next_line() should output.
*/
enum graph_state state;
/*
* The output state for the previous line of output.
* This is primarily used to determine how the first merge line
* should appear, based on the last line of the previous commit.
*/
enum graph_state prev_state;
/*
* The index of the column that refers to this commit.
*
* If none of the incoming columns refer to this commit,
* this will be equal to num_columns.
*/
int commit_index;
/*
* The commit_index for the previously displayed commit.
*
* This is used to determine how the first line of a merge
* graph output shoul
|