From 660e113ce11840f4bc4028bff89889e6122fe89a Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Wed, 31 Aug 2016 16:27:20 -0700 Subject: graph: add support for --line-prefix on all graph-aware output Add an extension to git-diff and git-log (and any other graph-aware displayable output) such that "--line-prefix=" will print the additional line-prefix on every line of output. To make this work, we have to fix a few bugs in the graph API that force graph_show_commit_msg to be used only when you have a valid graph. Additionally, we extend the default_diff_output_prefix handler to work even when no graph is enabled. This is somewhat of a hack on top of the graph API, but I think it should be acceptable here. This will be used by a future extension of submodule display which displays the submodule diff as the actual diff between the pre and post commit in the submodule project. Add some tests for both git-log and git-diff to ensure that the prefix is honored correctly. Signed-off-by: Jacob Keller Signed-off-by: Junio C Hamano --- graph.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'graph.h') diff --git a/graph.h b/graph.h index 3f48c19b62..af623390b6 100644 --- a/graph.h +++ b/graph.h @@ -1,9 +1,22 @@ #ifndef GRAPH_H #define GRAPH_H +#include "diff.h" /* A graph is a pointer to this opaque structure */ struct git_graph; +/* + * Called to setup global display of line_prefix diff option. + * + * Passed a diff_options structure which indicates the line_prefix and the + * file to output the prefix to. This is sort of a hack used so that the + * line_prefix will be honored by all flows which also honor "--graph" + * regardless of whether a graph has actually been setup. The normal graph + * flow will honor the exact diff_options passed, but a NULL graph will cause + * display of a line_prefix to stdout. + */ +void graph_setup_line_prefix(struct diff_options *diffopt); + /* * Set up a custom scheme for column colors. * @@ -113,7 +126,14 @@ int graph_show_remainder(struct git_graph *graph); * missing a terminating newline (including if it is empty), the output * printed by graph_show_commit_msg() will also be missing a terminating * newline. + * + * Note that unlike some other graph display functions, you must pass the file + * handle directly. It is assumed that this is the same file handle as the + * file specified by the graph diff options. This is necessary so that + * graph_show_commit_msg can be called even with a NULL graph. */ -void graph_show_commit_msg(struct git_graph *graph, struct strbuf const *sb); +void graph_show_commit_msg(struct git_graph *graph, + FILE *file, + struct strbuf const *sb); #endif /* GRAPH_H */ -- cgit v1.2.3