[PATCH] log --graph: draw '>' and '<' with --left-right

Subsystems: documentation, the rest

DORMANTno replies

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] log --graph: draw '>' and '<' with --left-right

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:44:38

Signed-off-by: Johannes Schindelin <redacted>
---
 Documentation/technical/api-history-graph.txt |    2 +-
 graph.c                                       |   16 ++++++++++++++--
 graph.h                                       |    2 +-
 revision.c                                    |    2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/Documentation/technical/api-history-graph.txt b/Documentation/technical/api-history-graph.txt
index ce1c08e..e955979 100644
--- a/Documentation/technical/api-history-graph.txt
+++ b/Documentation/technical/api-history-graph.txt
@@ -115,7 +115,7 @@ Sample usage
 
 ------------
 struct commit *commit;
-struct git_graph *graph = graph_init();
+struct git_graph *graph = graph_init(opts);
 
 while ((commit = get_revision(opts)) != NULL) {
 	graph_update(graph, commit);
diff --git a/graph.c b/graph.c
index 9d6ed30..85a9ba0 100644
--- a/graph.c
+++ b/graph.c
@@ -55,6 +55,10 @@ struct git_graph {
 	 */
 	struct commit *commit;
 	/*
+	 * For the --left-right option.
+	 */
+	struct rev_info *revs;
+	/*
 	 * The number of parents this commit has.
 	 * (Stored so we don't have to walk over them each time we need
 	 * this number)
@@ -125,10 +129,11 @@ struct git_graph {
 	int *new_mapping;
 };
 
-struct git_graph *graph_init(void)
+struct git_graph *graph_init(struct rev_info *opt)
 {
 	struct git_graph *graph = xmalloc(sizeof(struct git_graph));
 	graph->commit = NULL;
+	graph->revs = opt;
 	graph->num_parents = 0;
 	graph->expansion_row = 0;
 	graph->state = GRAPH_PADDING;
@@ -540,7 +545,14 @@ void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
 
 		if (col_commit == graph->commit) {
 			seen_this = 1;
-			if (graph->num_parents > 1)
+			if (graph->revs && graph->revs->left_right) {
+				if (graph->commit->object.flags
+						& SYMMETRIC_LEFT)
+					strbuf_addch(sb, '<');
+				else
+					strbuf_addch(sb, '>');
+			}
+			else if (graph->num_parents > 1)
 				strbuf_addch(sb, 'M');
 			else
 				strbuf_addch(sb, '*');
diff --git a/graph.h b/graph.h
index a7748a5..eab4e3d 100644
--- a/graph.h
+++ b/graph.h
@@ -8,7 +8,7 @@ struct git_graph;
  * Create a new struct git_graph.
  * The graph should be freed with graph_release() when no longer needed.
  */
-struct git_graph *graph_init();
+struct git_graph *graph_init(struct rev_info *opt);
 
 /*
  * Destroy a struct git_graph and free associated memory.
diff --git a/revision.c b/revision.c
index 39ceef0..ce0f1ac 100644
--- a/revision.c
+++ b/revision.c
@@ -1206,7 +1206,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 			if (!prefixcmp(arg, "--graph")) {
 				revs->topo_order = 1;
 				revs->rewrite_parents = 1;
-				revs->graph = graph_init();
+				revs->graph = graph_init(revs);
 				continue;
 			}
 			if (!strcmp(arg, "--root")) {
-- 
1.5.5.1.498.gaaa3c0

Re: [PATCH] log --graph: draw '>' and '<' with --left-right

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:44:38

Hi,

On Thu, 22 May 2008, Johannes Schindelin wrote:
Signed-off-by: Johannes Schindelin <redacted>
Sverre just notified me that the commit message is not brilliant.  How 
about this:

-- snip --
When calling "git log --left-right <branch1>...<branch2>", a single "<" or 
">" is shown in front of the commit line, to indicate which branch1 this 
commit comes from, branch1 or branch2.

However, it is easy to miss in the output of "git log --graph ...", since 
the graph still has "*" for regular commits and "M" for merge commits.  So 
imitate gitk, and show the "<" and ">" characters in the graph, too, 
instead of "*" (or "M").
-- snap --

Thanks,
Dscho

Re: [PATCH] log --graph: draw '>' and '<' with --left-right

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:44:38

On Thu, May 22, 2008 at 2:47 PM, Johannes Schindelin
[off-list ref] wrote:
Sverre just notified me that the commit message is not brilliant.  How
about this:

-- snip --
When calling "git log --left-right <branch1>...<branch2>", a single "<" or
">" is shown in front of the commit line, to indicate which branch1 this
commit comes from, branch1 or branch2.

However, it is easy to miss in the output of "git log --graph ...", since
the graph still has "*" for regular commits and "M" for merge commits.  So
imitate gitk, and show the "<" and ">" characters in the graph, too,
instead of "*" (or "M").
-- snap --
I admit that I didn't know how gitk does things, but yeah, this is a
lot more explanatory and makes sense :).

-- 
Cheers,

Sverre Rabbelier
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help