The graph API is used to draw a text-based representation of the commit history. The API generates the graph in a line-by-line fashion.

Functions

Core functions:

The following utility functions are wrappers around graph_next_line() and graph_is_commit_finished(). They always print the output to stdout. They can all be called with a NULL graph argument, in which case no graph output will be printed.

Data structure

struct git_graph is an opaque data type used to store the current graph state.

Calling sequence

Limitations

Sample usage

struct commit *commit;
struct git_graph *graph = graph_init(opts);

while ((commit = get_revision(opts)) != NULL) {
        graph_update(graph, commit);
        while (!graph_is_commit_finished(graph))
        {
                struct strbuf sb;
                int is_commit_line;

                strbuf_init(&sb, 0);
                is_commit_line = graph_next_line(graph, &sb);
                fputs(sb.buf, stdout);

                if (is_commit_line)
                        log_tree_commit(opts, commit);
                else
                        putchar(opts->diffopt.line_termination);
        }
}

Sample output

The following is an example of the output from the graph API. This output does not include any commit summary information—callers are responsible for outputting that information, if desired.

*
*
*
|\
* |
| | *
| \ \
|  \ \
*-. \ \
|\ \ \ \
| | * | |
| | | | | *
| | | | | *
| | | | | *
| | | | | |\
| | | | | | *
| * | | | | |
| | | | | *  \
| | | | | |\  |
| | | | * | | |
| | | | * | | |
* | | | | | | |
| |/ / / / / /
|/| / / / / /
* | | | | | |
|/ / / / / /
* | | | | |
| | | | | *
| | | | |/
| | | | *