Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 1 | #ifndef GRAPH_H |
| 2 | #define GRAPH_H |
Jacob Keller | 660e113 | 2016-08-31 16:27:20 -0700 | [diff] [blame] | 3 | #include "diff.h" |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 4 | |
| 5 | /* A graph is a pointer to this opaque structure */ |
| 6 | struct git_graph; |
| 7 | |
John Keeping | ac751a0 | 2013-03-04 00:03:37 +0000 | [diff] [blame] | 8 | /* |
Jacob Keller | 660e113 | 2016-08-31 16:27:20 -0700 | [diff] [blame] | 9 | * Called to setup global display of line_prefix diff option. |
| 10 | * |
| 11 | * Passed a diff_options structure which indicates the line_prefix and the |
| 12 | * file to output the prefix to. This is sort of a hack used so that the |
| 13 | * line_prefix will be honored by all flows which also honor "--graph" |
| 14 | * regardless of whether a graph has actually been setup. The normal graph |
| 15 | * flow will honor the exact diff_options passed, but a NULL graph will cause |
| 16 | * display of a line_prefix to stdout. |
| 17 | */ |
| 18 | void graph_setup_line_prefix(struct diff_options *diffopt); |
| 19 | |
| 20 | /* |
John Keeping | ac751a0 | 2013-03-04 00:03:37 +0000 | [diff] [blame] | 21 | * Set up a custom scheme for column colors. |
| 22 | * |
| 23 | * The default column color scheme inserts ANSI color escapes to colorize |
| 24 | * the graph. The various color escapes are stored in an array of strings |
| 25 | * where each entry corresponds to a color, except for the last entry, |
| 26 | * which denotes the escape for resetting the color back to the default. |
| 27 | * When generating the graph, strings from this array are inserted before |
| 28 | * and after the various column characters. |
| 29 | * |
| 30 | * This function allows you to enable a custom array of color escapes. |
| 31 | * The 'colors_max' argument is the index of the last "reset" entry. |
| 32 | * |
| 33 | * This functions must be called BEFORE graph_init() is called. |
| 34 | * |
| 35 | * NOTE: This function isn't used in Git outside graph.c but it is used |
| 36 | * by CGit (http://git.zx2c4.com/cgit/) to use HTML for colors. |
| 37 | */ |
| 38 | void graph_set_column_colors(const char **colors, unsigned short colors_max); |
Johan Herland | 1e3d411 | 2010-07-13 23:23:39 +0200 | [diff] [blame] | 39 | |
| 40 | /* |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 41 | * Create a new struct git_graph. |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 42 | */ |
Adam Simpkins | 7528f27 | 2008-05-25 00:07:21 -0700 | [diff] [blame] | 43 | struct git_graph *graph_init(struct rev_info *opt); |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 46 | * Update a git_graph with a new commit. |
| 47 | * This will cause the graph to begin outputting lines for the new commit |
| 48 | * the next time graph_next_line() is called. |
| 49 | * |
| 50 | * If graph_update() is called before graph_is_commit_finished() returns 1, |
| 51 | * the next call to graph_next_line() will output an ellipsis ("...") |
| 52 | * to indicate that a portion of the graph is missing. |
| 53 | */ |
| 54 | void graph_update(struct git_graph *graph, struct commit *commit); |
| 55 | |
| 56 | /* |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 57 | * Determine if a graph has finished outputting lines for the current |
| 58 | * commit. |
| 59 | * |
| 60 | * Returns 1 if graph_next_line() needs to be called again before |
| 61 | * graph_update() should be called. Returns 0 if no more lines are needed |
| 62 | * for this commit. If 0 is returned, graph_next_line() may still be |
| 63 | * called without calling graph_update(), and it will merely output |
| 64 | * appropriate "vertical padding" in the graph. |
| 65 | */ |
| 66 | int graph_is_commit_finished(struct git_graph const *graph); |
| 67 | |
John Keeping | ac751a0 | 2013-03-04 00:03:37 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Output the next line for a graph. |
| 70 | * This formats the next graph line into the specified strbuf. It is not |
| 71 | * terminated with a newline. |
| 72 | * |
| 73 | * Returns 1 if the line includes the current commit, and 0 otherwise. |
| 74 | * graph_next_line() will return 1 exactly once for each time |
| 75 | * graph_update() is called. |
| 76 | * |
| 77 | * NOTE: This function isn't used in Git outside graph.c but it is used |
| 78 | * by CGit (http://git.zx2c4.com/cgit/) to wrap HTML around graph lines. |
| 79 | */ |
| 80 | int graph_next_line(struct git_graph *graph, struct strbuf *sb); |
| 81 | |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
Josef Kufner | 3ad87c8 | 2016-06-16 20:18:37 +0700 | [diff] [blame] | 84 | * Return current width of the graph in on-screen characters. |
| 85 | */ |
| 86 | int graph_width(struct git_graph *graph); |
| 87 | |
| 88 | /* |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 89 | * graph_show_*: helper functions for printing to stdout |
| 90 | */ |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * If the graph is non-NULL, print the history graph to stdout, |
| 95 | * up to and including the line containing this commit. |
| 96 | * Does not print a terminating newline on the last line. |
| 97 | */ |
| 98 | void graph_show_commit(struct git_graph *graph); |
| 99 | |
| 100 | /* |
| 101 | * If the graph is non-NULL, print one line of the history graph to stdout. |
| 102 | * Does not print a terminating newline on the last line. |
| 103 | */ |
| 104 | void graph_show_oneline(struct git_graph *graph); |
| 105 | |
| 106 | /* |
| 107 | * If the graph is non-NULL, print one line of vertical graph padding to |
| 108 | * stdout. Does not print a terminating newline on the last line. |
| 109 | */ |
| 110 | void graph_show_padding(struct git_graph *graph); |
| 111 | |
| 112 | /* |
| 113 | * If the graph is non-NULL, print the rest of the history graph for this |
| 114 | * commit to stdout. Does not print a terminating newline on the last line. |
| 115 | */ |
| 116 | int graph_show_remainder(struct git_graph *graph); |
| 117 | |
| 118 | /* |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 119 | * Print a commit message strbuf and the remainder of the graph to stdout. |
| 120 | * |
| 121 | * This is similar to graph_show_strbuf(), but it always prints the |
| 122 | * remainder of the graph. |
| 123 | * |
| 124 | * If the strbuf ends with a newline, the output printed by |
| 125 | * graph_show_commit_msg() will end with a newline. If the strbuf is |
| 126 | * missing a terminating newline (including if it is empty), the output |
| 127 | * printed by graph_show_commit_msg() will also be missing a terminating |
| 128 | * newline. |
Jacob Keller | 660e113 | 2016-08-31 16:27:20 -0700 | [diff] [blame] | 129 | * |
| 130 | * Note that unlike some other graph display functions, you must pass the file |
| 131 | * handle directly. It is assumed that this is the same file handle as the |
| 132 | * file specified by the graph diff options. This is necessary so that |
| 133 | * graph_show_commit_msg can be called even with a NULL graph. |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 134 | */ |
Jacob Keller | 660e113 | 2016-08-31 16:27:20 -0700 | [diff] [blame] | 135 | void graph_show_commit_msg(struct git_graph *graph, |
| 136 | FILE *file, |
| 137 | struct strbuf const *sb); |
Adam Simpkins | c12172d | 2008-05-04 03:36:53 -0700 | [diff] [blame] | 138 | |
| 139 | #endif /* GRAPH_H */ |