From: "James Coglan via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, James Coglan <jcoglan@gmail.com>
Subject: [PATCH v3 10/13] graph: rename `new_mapping` to `old_mapping`
Date: Tue, 15 Oct 2019 23:47:56 +0000 [thread overview]
Message-ID: <f5c27914360e4f9139d676b777484fa55e87d78d.1571183279.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.383.v3.git.1571183279.gitgitgadget@gmail.com>
From: James Coglan <jcoglan@gmail.com>
The change I'm about to make requires being able to inspect the mapping
array that was used to render the last GRAPH_COLLAPSING line while
rendering a GRAPH_COMMIT line. The `new_mapping` array currently exists
as a pre-allocated space for computing the next `mapping` array during
`graph_output_collapsing_line()`, but we can repurpose it to let us see
the previous `mapping` state.
To support this use it will make more sense if this array is named
`old_mapping`, as it will contain the mapping data for the previous line
we rendered, at the point we're rendering a commit line.
Signed-off-by: James Coglan <jcoglan@gmail.com>
---
graph.c | 54 +++++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/graph.c b/graph.c
index 21edad8085..2315f3604d 100644
--- a/graph.c
+++ b/graph.c
@@ -259,7 +259,7 @@ struct git_graph {
/*
* The maximum number of columns that can be stored in the columns
* and new_columns arrays. This is also half the number of entries
- * that can be stored in the mapping and new_mapping arrays.
+ * that can be stored in the mapping and old_mapping arrays.
*/
int column_capacity;
/*
@@ -302,7 +302,7 @@ struct git_graph {
* of the git_graph simply so we don't have to allocate a new
* temporary array each time we have to output a collapsing line.
*/
- int *new_mapping;
+ int *old_mapping;
/*
* The current default column color being used. This is
* stored as an index into the array column_colors.
@@ -388,7 +388,7 @@ struct git_graph *graph_init(struct rev_info *opt)
ALLOC_ARRAY(graph->columns, graph->column_capacity);
ALLOC_ARRAY(graph->new_columns, graph->column_capacity);
ALLOC_ARRAY(graph->mapping, 2 * graph->column_capacity);
- ALLOC_ARRAY(graph->new_mapping, 2 * graph->column_capacity);
+ ALLOC_ARRAY(graph->old_mapping, 2 * graph->column_capacity);
/*
* The diff output prefix callback, with this we can make
@@ -418,7 +418,7 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
REALLOC_ARRAY(graph->columns, graph->column_capacity);
REALLOC_ARRAY(graph->new_columns, graph->column_capacity);
REALLOC_ARRAY(graph->mapping, graph->column_capacity * 2);
- REALLOC_ARRAY(graph->new_mapping, graph->column_capacity * 2);
+ REALLOC_ARRAY(graph->old_mapping, graph->column_capacity * 2);
}
/*
@@ -1116,13 +1116,18 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
int horizontal_edge_target = -1;
/*
- * Clear out the new_mapping array
+ * Swap the mapping and old_mapping arrays
+ */
+ SWAP(graph->mapping, graph->old_mapping);
+
+ /*
+ * Clear out the mapping array
*/
for (i = 0; i < graph->mapping_size; i++)
- graph->new_mapping[i] = -1;
+ graph->mapping[i] = -1;
for (i = 0; i < graph->mapping_size; i++) {
- int target = graph->mapping[i];
+ int target = graph->old_mapping[i];
if (target < 0)
continue;
@@ -1143,14 +1148,14 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
* This column is already in the
* correct place
*/
- assert(graph->new_mapping[i] == -1);
- graph->new_mapping[i] = target;
- } else if (graph->new_mapping[i - 1] < 0) {
+ assert(graph->mapping[i] == -1);
+ graph->mapping[i] = target;
+ } else if (graph->mapping[i - 1] < 0) {
/*
* Nothing is to the left.
* Move to the left by one
*/
- graph->new_mapping[i - 1] = target;
+ graph->mapping[i - 1] = target;
/*
* If there isn't already an edge moving horizontally
* select this one.
@@ -1166,9 +1171,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
* line.
*/
for (j = (target * 2)+3; j < (i - 2); j += 2)
- graph->new_mapping[j] = target;
+ graph->mapping[j] = target;
}
- } else if (graph->new_mapping[i - 1] == target) {
+ } else if (graph->mapping[i - 1] == target) {
/*
* There is a branch line to our left
* already, and it is our target. We
@@ -1176,7 +1181,7 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
* the same parent commit.
*
* We don't have to add anything to the
- * output or new_mapping, since the
+ * output or mapping, since the
* existing branch line has already taken
* care of it.
*/
@@ -1192,10 +1197,10 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
* The branch to the left of that space
* should be our eventual target.
*/
- assert(graph->new_mapping[i - 1] > target);
- assert(graph->new_mapping[i - 2] < 0);
- assert(graph->new_mapping[i - 3] == target);
- graph->new_mapping[i - 2] = target;
+ assert(graph->mapping[i - 1] > target);
+ assert(graph->mapping[i - 2] < 0);
+ assert(graph->mapping[i - 3] == target);
+ graph->mapping[i - 2] = target;
/*
* Mark this branch as the horizontal edge to
* prevent any other edges from moving
@@ -1209,14 +1214,14 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
/*
* The new mapping may be 1 smaller than the old mapping
*/
- if (graph->new_mapping[graph->mapping_size - 1] < 0)
+ if (graph->mapping[graph->mapping_size - 1] < 0)
graph->mapping_size--;
/*
* Output out a line based on the new mapping info
*/
for (i = 0; i < graph->mapping_size; i++) {
- int target = graph->new_mapping[i];
+ int target = graph->mapping[i];
if (target < 0)
graph_line_addch(line, ' ');
else if (target * 2 == i)
@@ -1229,22 +1234,17 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
* won't continue into the next line.
*/
if (i != (target * 2)+3)
- graph->new_mapping[i] = -1;
+ graph->mapping[i] = -1;
used_horizontal = 1;
graph_line_write_column(line, &graph->new_columns[target], '_');
} else {
if (used_horizontal && i < horizontal_edge)
- graph->new_mapping[i] = -1;
+ graph->mapping[i] = -1;
graph_line_write_column(line, &graph->new_columns[target], '/');
}
}
- /*
- * Swap mapping and new_mapping
- */
- SWAP(graph->mapping, graph->new_mapping);
-
/*
* If graph->mapping indicates that all of the branch lines
* are already in the correct positions, we are done.
--
gitgitgadget
next prev parent reply other threads:[~2019-10-15 23:48 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-10 16:13 [PATCH 00/11] Improve the readability of log --graph output James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 01/11] graph: automatically track visible width of `strbuf` James Coglan via GitGitGadget
2019-10-10 21:07 ` Johannes Schindelin
2019-10-10 23:05 ` Denton Liu
2019-10-11 0:49 ` Derrick Stolee
2019-10-11 1:42 ` Junio C Hamano
2019-10-11 5:01 ` Denton Liu
2019-10-11 16:02 ` Johannes Schindelin
2019-10-11 17:20 ` James Coglan
2019-10-12 0:27 ` Junio C Hamano
2019-10-12 16:22 ` Johannes Schindelin
2019-10-14 12:55 ` James Coglan
2019-10-14 13:01 ` James Coglan
2019-10-16 2:15 ` Junio C Hamano
2019-10-11 1:40 ` Junio C Hamano
2019-10-11 17:08 ` James Coglan
2019-10-10 16:13 ` [PATCH 02/11] graph: reuse `find_new_column_by_commit()` James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 03/11] graph: reduce duplication in `graph_insert_into_new_columns()` James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 04/11] graph: remove `mapping_idx` and `graph_update_width()` James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 05/11] graph: extract logic for moving to GRAPH_PRE_COMMIT state James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 06/11] graph: tidy up display of left-skewed merges James Coglan via GitGitGadget
2019-10-10 17:19 ` Derrick Stolee
2019-10-11 16:50 ` James Coglan
2019-10-12 1:36 ` Derrick Stolee
2019-10-14 13:11 ` James Coglan
2019-10-10 16:13 ` [PATCH 07/11] graph: commit and post-merge lines for " James Coglan via GitGitGadget
2019-10-10 17:49 ` Derrick Stolee
2019-10-11 17:04 ` James Coglan
2019-10-13 6:56 ` Jeff King
2019-10-14 15:38 ` James Coglan
2019-10-14 17:41 ` Derrick Stolee
2019-10-14 20:42 ` Johannes Schindelin
2019-10-10 16:13 ` [PATCH 08/11] graph: rename `new_mapping` to `old_mapping` James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 09/11] graph: smooth appearance of collapsing edges on commit lines James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 10/11] graph: flatten edges that join to their right neighbor James Coglan via GitGitGadget
2019-10-10 16:13 ` [PATCH 11/11] graph: fix coloring of octopus dashes James Coglan via GitGitGadget
2019-10-10 18:16 ` Denton Liu
2019-10-10 18:28 ` Denton Liu
2019-10-13 7:22 ` Jeff King
2019-10-10 17:54 ` [PATCH 00/11] Improve the readability of log --graph output Derrick Stolee
2019-10-13 7:15 ` Jeff King
2019-10-14 15:49 ` James Coglan
2019-10-15 23:40 ` [PATCH v2 00/13] " James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 01/13] graph: automatically track display width of graph lines James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 02/13] graph: handle line padding in `graph_next_line()` James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 03/13] graph: reuse `find_new_column_by_commit()` James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 04/13] graph: reduce duplication in `graph_insert_into_new_columns()` James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 05/13] graph: remove `mapping_idx` and `graph_update_width()` James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 06/13] graph: extract logic for moving to GRAPH_PRE_COMMIT state James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 07/13] graph: example of graph output that can be simplified James Coglan via GitGitGadget
2019-10-15 23:40 ` [PATCH v2 08/13] graph: tidy up display of left-skewed merges James Coglan via GitGitGadget
2019-10-15 23:41 ` [PATCH v2 09/13] graph: commit and post-merge lines for " James Coglan via GitGitGadget
2019-10-15 23:41 ` [PATCH v2 10/13] graph: rename `new_mapping` to `old_mapping` James Coglan via GitGitGadget
2019-10-15 23:41 ` [PATCH v2 11/13] graph: smooth appearance of collapsing edges on commit lines James Coglan via GitGitGadget
2019-10-15 23:41 ` [PATCH v2 12/13] graph: flatten edges that fuse with their right neighbor James Coglan via GitGitGadget
2019-10-15 23:41 ` [PATCH v2 13/13] graph: fix coloring of octopus dashes James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 00/13] Improve the readability of log --graph output James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 01/13] graph: automatically track display width of graph lines James Coglan via GitGitGadget
2019-10-16 3:35 ` Junio C Hamano
2019-10-16 5:10 ` Junio C Hamano
2019-10-15 23:47 ` [PATCH v3 02/13] graph: handle line padding in `graph_next_line()` James Coglan via GitGitGadget
2019-10-16 3:37 ` Junio C Hamano
2019-10-15 23:47 ` [PATCH v3 03/13] graph: reuse `find_new_column_by_commit()` James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 04/13] graph: reduce duplication in `graph_insert_into_new_columns()` James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 05/13] graph: remove `mapping_idx` and `graph_update_width()` James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 06/13] graph: extract logic for moving to GRAPH_PRE_COMMIT state James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 07/13] graph: example of graph output that can be simplified James Coglan via GitGitGadget
2019-10-17 12:30 ` Derrick Stolee
2019-10-18 15:21 ` SZEDER Gábor
2019-11-12 1:08 ` [PATCH] t4215: don't put git commands upstream of pipe Denton Liu
2019-11-12 6:57 ` Junio C Hamano
2019-11-12 10:54 ` SZEDER Gábor
2019-11-12 18:56 ` [PATCH v3] t4215: use helper function to check output Denton Liu
2019-11-13 2:05 ` Junio C Hamano
2019-10-15 23:47 ` [PATCH v3 08/13] graph: tidy up display of left-skewed merges James Coglan via GitGitGadget
2019-10-16 4:00 ` Junio C Hamano
2019-10-17 12:34 ` Derrick Stolee
2019-10-18 0:49 ` Junio C Hamano
2019-10-15 23:47 ` [PATCH v3 09/13] graph: commit and post-merge lines for " James Coglan via GitGitGadget
2019-10-15 23:47 ` James Coglan via GitGitGadget [this message]
2019-10-15 23:47 ` [PATCH v3 11/13] graph: smooth appearance of collapsing edges on commit lines James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 12/13] graph: flatten edges that fuse with their right neighbor James Coglan via GitGitGadget
2019-10-15 23:47 ` [PATCH v3 13/13] graph: fix coloring of octopus dashes James Coglan via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f5c27914360e4f9139d676b777484fa55e87d78d.1571183279.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jcoglan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).