Blame graph.h

Packit Service fe3200
#ifndef GRAPH_H
Packit Service fe3200
#define GRAPH_H
Packit Service fe3200
#include "diff.h"
Packit Service fe3200
Packit Service fe3200
/**
Packit Service fe3200
 * The graph API is used to draw a text-based representation of the commit
Packit Service fe3200
 * history. The API generates the graph in a line-by-line fashion.
Packit Service fe3200
 *
Packit Service fe3200
 * Calling sequence
Packit Service fe3200
 * ----------------
Packit Service fe3200
 *
Packit Service fe3200
 * - Create a `struct git_graph` by calling `graph_init()`.  When using the
Packit Service fe3200
 *   revision walking API, this is done automatically by `setup_revisions()` if
Packit Service fe3200
 *   the '--graph' option is supplied.
Packit Service fe3200
 *
Packit Service fe3200
 * - Use the revision walking API to walk through a group of contiguous commits.
Packit Service fe3200
 *   The `get_revision()` function automatically calls `graph_update()` each time
Packit Service fe3200
 *   it is invoked.
Packit Service fe3200
 *
Packit Service fe3200
 * - For each commit, call `graph_next_line()` repeatedly, until
Packit Service fe3200
 *   `graph_is_commit_finished()` returns non-zero.  Each call to
Packit Service fe3200
 *   `graph_next_line()` will output a single line of the graph.  The resulting
Packit Service fe3200
 *   lines will not contain any newlines.  `graph_next_line()` returns 1 if the
Packit Service fe3200
 *   resulting line contains the current commit, or 0 if this is merely a line
Packit Service fe3200
 *   needed to adjust the graph before or after the current commit.  This return
Packit Service fe3200
 *   value can be used to determine where to print the commit summary information
Packit Service fe3200
 *   alongside the graph output.
Packit Service fe3200
 *
Packit Service fe3200
 * Limitations
Packit Service fe3200
 * -----------
Packit Service fe3200
 * - Check the graph_update() function for its limitations.
Packit Service fe3200
 *
Packit Service fe3200
 * - The graph API does not currently support reverse commit ordering.  In
Packit Service fe3200
 *   order to implement reverse ordering, the graphing API needs an
Packit Service fe3200
 *   (efficient) mechanism to find the children of a commit.
Packit Service fe3200
 *
Packit Service fe3200
 * Sample usage
Packit Service fe3200
 * ------------
Packit Service fe3200
 *
Packit Service fe3200
 * ------------
Packit Service fe3200
 * struct commit *commit;
Packit Service fe3200
 * struct git_graph *graph = graph_init(opts);
Packit Service fe3200
 *
Packit Service fe3200
 * while ((commit = get_revision(opts)) != NULL) {
Packit Service fe3200
 * 	while (!graph_is_commit_finished(graph))
Packit Service fe3200
 * 	{
Packit Service fe3200
 * 		struct strbuf sb;
Packit Service fe3200
 * 		int is_commit_line;
Packit Service fe3200
 *
Packit Service fe3200
 * 		strbuf_init(&sb, 0);
Packit Service fe3200
 * 		is_commit_line = graph_next_line(graph, &sb);
Packit Service fe3200
 * 		fputs(sb.buf, stdout);
Packit Service fe3200
 *
Packit Service fe3200
 * 		if (is_commit_line)
Packit Service fe3200
 * 			log_tree_commit(opts, commit);
Packit Service fe3200
 * 		else
Packit Service fe3200
 * 			putchar(opts->diffopt.line_termination);
Packit Service fe3200
 * 	}
Packit Service fe3200
 * }
Packit Service fe3200
 * ------------
Packit Service fe3200
 * Sample output
Packit Service fe3200
 * -------------
Packit Service fe3200
 *
Packit Service fe3200
 * The following is an example of the output from the graph API.  This output does
Packit Service fe3200
 * not include any commit summary information--callers are responsible for
Packit Service fe3200
 * outputting that information, if desired.
Packit Service fe3200
 * ------------
Packit Service fe3200
 * *
Packit Service fe3200
 * *
Packit Service fe3200
 * *
Packit Service fe3200
 * |\
Packit Service fe3200
 * * |
Packit Service fe3200
 * | | *
Packit Service fe3200
 * | \ \
Packit Service fe3200
 * |  \ \
Packit Service fe3200
 * *-. \ \
Packit Service fe3200
 * |\ \ \ \
Packit Service fe3200
 * | | * | |
Packit Service fe3200
 * | | | | | *
Packit Service fe3200
 * | | | | | *
Packit Service fe3200
 * | | | | | *
Packit Service fe3200
 * | | | | | |\
Packit Service fe3200
 * | | | | | | *
Packit Service fe3200
 * | * | | | | |
Packit Service fe3200
 * | | | | | *  \
Packit Service fe3200
 * | | | | | |\  |
Packit Service fe3200
 * | | | | * | | |
Packit Service fe3200
 * | | | | * | | |
Packit Service fe3200
 * * | | | | | | |
Packit Service fe3200
 * | |/ / / / / /
Packit Service fe3200
 * |/| / / / / /
Packit Service fe3200
 * * | | | | | |
Packit Service fe3200
 * |/ / / / / /
Packit Service fe3200
 * * | | | | |
Packit Service fe3200
 * | | | | | *
Packit Service fe3200
 * | | | | |/
Packit Service fe3200
 * | | | | *
Packit Service fe3200
 * ------------
Packit Service fe3200
 *
Packit Service fe3200
 */
Packit Service fe3200
Packit Service fe3200
/* A graph is a pointer to this opaque structure */
Packit Service fe3200
struct git_graph;
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Called to setup global display of line_prefix diff option.
Packit Service fe3200
 *
Packit Service fe3200
 * Passed a diff_options structure which indicates the line_prefix and the
Packit Service fe3200
 * file to output the prefix to. This is sort of a hack used so that the
Packit Service fe3200
 * line_prefix will be honored by all flows which also honor "--graph"
Packit Service fe3200
 * regardless of whether a graph has actually been setup. The normal graph
Packit Service fe3200
 * flow will honor the exact diff_options passed, but a NULL graph will cause
Packit Service fe3200
 * display of a line_prefix to stdout.
Packit Service fe3200
 */
Packit Service fe3200
void graph_setup_line_prefix(struct diff_options *diffopt);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Set up a custom scheme for column colors.
Packit Service fe3200
 *
Packit Service fe3200
 * The default column color scheme inserts ANSI color escapes to colorize
Packit Service fe3200
 * the graph. The various color escapes are stored in an array of strings
Packit Service fe3200
 * where each entry corresponds to a color, except for the last entry,
Packit Service fe3200
 * which denotes the escape for resetting the color back to the default.
Packit Service fe3200
 * When generating the graph, strings from this array are inserted before
Packit Service fe3200
 * and after the various column characters.
Packit Service fe3200
 *
Packit Service fe3200
 * This function allows you to enable a custom array of color escapes.
Packit Service fe3200
 * The 'colors_max' argument is the index of the last "reset" entry.
Packit Service fe3200
 *
Packit Service fe3200
 * This functions must be called BEFORE graph_init() is called.
Packit Service fe3200
 *
Packit Service fe3200
 * NOTE: This function isn't used in Git outside graph.c but it is used
Packit Service fe3200
 * by CGit (http://git.zx2c4.com/cgit/) to use HTML for colors.
Packit Service fe3200
 */
Packit Service fe3200
void graph_set_column_colors(const char **colors, unsigned short colors_max);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Create a new struct git_graph.
Packit Service fe3200
 */
Packit Service fe3200
struct git_graph *graph_init(struct rev_info *opt);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Update a git_graph with a new commit.
Packit Service fe3200
 * This will cause the graph to begin outputting lines for the new commit
Packit Service fe3200
 * the next time graph_next_line() is called.
Packit Service fe3200
 *
Packit Service fe3200
 * If graph_update() is called before graph_is_commit_finished() returns 1,
Packit Service fe3200
 * the next call to graph_next_line() will output an ellipsis ("...")
Packit Service fe3200
 * to indicate that a portion of the graph is missing.
Packit Service fe3200
 *
Packit Service fe3200
 * Limitations:
Packit Service fe3200
 * -----------
Packit Service fe3200
 *
Packit Service fe3200
 * - `graph_update()` must be called with commits in topological order.  It should
Packit Service fe3200
 *   not be called on a commit if it has already been invoked with an ancestor of
Packit Service fe3200
 *   that commit, or the graph output will be incorrect.
Packit Service fe3200
 *
Packit Service fe3200
 * - `graph_update()` must be called on a contiguous group of commits.  If
Packit Service fe3200
 *   `graph_update()` is called on a particular commit, it should later be called
Packit Service fe3200
 *   on all parents of that commit.  Parents must not be skipped, or the graph
Packit Service fe3200
 *   output will appear incorrect.
Packit Service fe3200
 *
Packit Service fe3200
 * - `graph_update()` may be used on a pruned set of commits only if the parent list
Packit Service fe3200
 *   has been rewritten so as to include only ancestors from the pruned set.
Packit Service fe3200
 */
Packit Service fe3200
void graph_update(struct git_graph *graph, struct commit *commit);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Determine if a graph has finished outputting lines for the current
Packit Service fe3200
 * commit.
Packit Service fe3200
 *
Packit Service fe3200
 * Returns 1 if graph_next_line() needs to be called again before
Packit Service fe3200
 * graph_update() should be called.  Returns 0 if no more lines are needed
Packit Service fe3200
 * for this commit.  If 0 is returned, graph_next_line() may still be
Packit Service fe3200
 * called without calling graph_update(), and it will merely output
Packit Service fe3200
 * appropriate "vertical padding" in the graph.
Packit Service fe3200
 *
Packit Service fe3200
 * If `graph_update()` is called before all lines for the current commit have
Packit Service fe3200
 * been printed, the next call to `graph_next_line()` will output an ellipsis,
Packit Service fe3200
 * to indicate that a portion of the graph was omitted.
Packit Service fe3200
 */
Packit Service fe3200
int graph_is_commit_finished(struct git_graph const *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Output the next line for a graph.
Packit Service fe3200
 * This formats the next graph line into the specified strbuf.  It is not
Packit Service fe3200
 * terminated with a newline.
Packit Service fe3200
 *
Packit Service fe3200
 * Returns 1 if the line includes the current commit, and 0 otherwise.
Packit Service fe3200
 * graph_next_line() will return 1 exactly once for each time
Packit Service fe3200
 * graph_update() is called.
Packit Service fe3200
 *
Packit Service fe3200
 * NOTE: This function isn't used in Git outside graph.c but it is used
Packit Service fe3200
 * by CGit (http://git.zx2c4.com/cgit/) to wrap HTML around graph lines.
Packit Service fe3200
 */
Packit Service fe3200
int graph_next_line(struct git_graph *graph, struct strbuf *sb);
Packit Service fe3200
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Return current width of the graph in on-screen characters.
Packit Service fe3200
 */
Packit Service fe3200
int graph_width(struct git_graph *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * graph_show_*: helper functions for printing to stdout
Packit Service fe3200
 */
Packit Service fe3200
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * If the graph is non-NULL, print the history graph to stdout,
Packit Service fe3200
 * up to and including the line containing this commit.
Packit Service fe3200
 * Does not print a terminating newline on the last line.
Packit Service fe3200
 */
Packit Service fe3200
void graph_show_commit(struct git_graph *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * If the graph is non-NULL, print one line of the history graph to stdout.
Packit Service fe3200
 * Does not print a terminating newline on the last line.
Packit Service fe3200
 */
Packit Service fe3200
void graph_show_oneline(struct git_graph *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * If the graph is non-NULL, print one line of vertical graph padding to
Packit Service fe3200
 * stdout.  Does not print a terminating newline on the last line.
Packit Service fe3200
 */
Packit Service fe3200
void graph_show_padding(struct git_graph *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * If the graph is non-NULL, print the rest of the history graph for this
Packit Service fe3200
 * commit to stdout.  Does not print a terminating newline on the last line.
Packit Service fe3200
 * Returns 1 if output was printed, and 0 if no output was necessary.
Packit Service fe3200
 */
Packit Service fe3200
int graph_show_remainder(struct git_graph *graph);
Packit Service fe3200
Packit Service fe3200
/*
Packit Service fe3200
 * Print a commit message strbuf and the remainder of the graph to stdout.
Packit Service fe3200
 *
Packit Service fe3200
 * This is similar to graph_show_strbuf(), but it always prints the
Packit Service fe3200
 * remainder of the graph.
Packit Service fe3200
 *
Packit Service fe3200
 * It is better than directly calling `graph_show_strbuf()` followed by
Packit Service fe3200
 * `graph_show_remainder()` since it properly handles buffers that do not end in
Packit Service fe3200
 * a terminating newline.
Packit Service fe3200
 *
Packit Service fe3200
 * If the strbuf ends with a newline, the output printed by
Packit Service fe3200
 * graph_show_commit_msg() will end with a newline.  If the strbuf is
Packit Service fe3200
 * missing a terminating newline (including if it is empty), the output
Packit Service fe3200
 * printed by graph_show_commit_msg() will also be missing a terminating
Packit Service fe3200
 * newline.
Packit Service fe3200
 *
Packit Service fe3200
 * Note that unlike some other graph display functions, you must pass the file
Packit Service fe3200
 * handle directly. It is assumed that this is the same file handle as the
Packit Service fe3200
 * file specified by the graph diff options. This is necessary so that
Packit Service fe3200
 * graph_show_commit_msg can be called even with a NULL graph.
Packit Service fe3200
 */
Packit Service fe3200
void graph_show_commit_msg(struct git_graph *graph,
Packit Service fe3200
			   FILE *file,
Packit Service fe3200
			   struct strbuf const *sb);
Packit Service fe3200
Packit Service fe3200
#endif /* GRAPH_H */