From: Junio C Hamano Date: Mon, 18 May 2009 15:59:30 +0000 (-0700) Subject: Merge branch 'ac/graph-horizontal-line' X-Git-Tag: v1.6.4-rc0~161 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7f1eaec7f477fb3e81b9c5489d9ecf9bbefe0b8c?hp=-c Merge branch 'ac/graph-horizontal-line' * ac/graph-horizontal-line: graph API: Use horizontal lines for more compact graphs --- 7f1eaec7f477fb3e81b9c5489d9ecf9bbefe0b8c diff --combined graph.c index 06fbeb6c24,47bce05c98..f8d7a5c0f6 --- a/graph.c +++ b/graph.c @@@ -35,7 -35,7 +35,7 @@@ static void graph_padding_line(struct g * newline. A new graph line will not be printed after the final newline. * If the strbuf is empty, no output will be printed. * - * Since the first line will not include the graph ouput, the caller is + * Since the first line will not include the graph output, the caller is * responsible for printing this line's graph (perhaps via * graph_show_commit() or graph_show_oneline()) before calling * graph_show_strbuf(). @@@ -47,20 -47,6 +47,6 @@@ static void graph_show_strbuf(struct gi * - Limit the number of columns, similar to the way gitk does. * If we reach more than a specified number of columns, omit * sections of some columns. - * - * - The output during the GRAPH_PRE_COMMIT and GRAPH_COLLAPSING states - * could be made more compact by printing horizontal lines, instead of - * long diagonal lines. For example, during collapsing, something like - * this: instead of this: - * | | | | | | | | | | - * | |_|_|/ | | | |/ - * |/| | | | | |/| - * | | | | | |/| | - * |/| | | - * | | | | - * - * If there are several parallel diagonal lines, they will need to be - * replaced with horizontal lines on subsequent rows. */ struct column { @@@ -727,8 -713,8 +713,8 @@@ static void graph_output_pre_commit_lin if (col->commit == graph->commit) { seen_this = 1; strbuf_write_column(sb, col, '|'); - strbuf_addf(sb, " %*s", graph->expansion_row, ""); - chars_written += 2 + graph->expansion_row; + strbuf_addf(sb, "%*s", graph->expansion_row, ""); + chars_written += 1 + graph->expansion_row; } else if (seen_this && (graph->expansion_row == 0)) { /* * This is the first line of the pre-commit output. @@@ -852,7 -838,7 +838,7 @@@ static void graph_output_commit_line(st graph_output_commit_char(graph, sb); chars_written++; - if (graph->num_parents > 3) + if (graph->num_parents > 2) chars_written += graph_draw_octopus_merge(graph, sb); } else if (seen_this && (graph->num_parents > 2)) { @@@ -982,6 -968,9 +968,9 @@@ static void graph_output_collapsing_lin { int i; int *tmp_mapping; + short used_horizontal = 0; + int horizontal_edge = -1; + int horizontal_edge_target = -1; /* * Clear out the new_mapping array @@@ -1019,6 -1008,23 +1008,23 @@@ * Move to the left by one */ graph->new_mapping[i - 1] = target; + /* + * If there isn't already an edge moving horizontally + * select this one. + */ + if (horizontal_edge == -1) { + int j; + horizontal_edge = i; + horizontal_edge_target = target; + /* + * The variable target is the index of the graph + * column, and therefore target*2+3 is the + * actual screen column of the first horizontal + * line. + */ + for (j = (target * 2)+3; j < (i - 2); j += 2) + graph->new_mapping[j] = target; + } } else if (graph->new_mapping[i - 1] == target) { /* * There is a branch line to our left @@@ -1039,10 -1045,21 +1045,21 @@@ * * The space just to the left of this * branch should always be empty. + * + * 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; + /* + * Mark this branch as the horizontal edge to + * prevent any other edges from moving + * horizontally. + */ + if (horizontal_edge == -1) + horizontal_edge = i; } } @@@ -1061,8 -1078,23 +1078,23 @@@ strbuf_addch(sb, ' '); else if (target * 2 == i) strbuf_write_column(sb, &graph->new_columns[target], '|'); - else + else if (target == horizontal_edge_target && + i != horizontal_edge - 1) { + /* + * Set the mappings for all but the + * first segment to -1 so that they + * won't continue into the next line. + */ + if (i != (target * 2)+3) + graph->new_mapping[i] = -1; + used_horizontal = 1; + strbuf_write_column(sb, &graph->new_columns[target], '_'); + } else { + if (used_horizontal && i < horizontal_edge) + graph->new_mapping[i] = -1; strbuf_write_column(sb, &graph->new_columns[target], '/'); + + } } graph_pad_horizontally(graph, sb, graph->mapping_size); diff --combined t/t4202-log.sh index 64502e2be7,a3b0cb88d1..aad3894ad4 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@@ -284,36 -284,10 +284,36 @@@ test_expect_success 'set up more tangle git merge master~3 && git merge side~1 && git checkout master && - git merge tangle + git merge tangle && + git checkout -b reach && + test_commit reach && + git checkout master && + git checkout -b octopus-a && + test_commit octopus-a && + git checkout master && + git checkout -b octopus-b && + test_commit octopus-b && + git checkout master && + test_commit seventh && + git merge octopus-a octopus-b + git merge reach ' cat > expect <<\EOF +* Merge branch 'reach' +|\ +| \ +| \ +*-. \ Merge branches 'octopus-a' and 'octopus-b' +|\ \ \ +* | | | seventh +| | * | octopus-b +| |/ / +|/| | +| * | octopus-a +|/ / +| * reach +|/ * Merge branch 'tangle' |\ | * Merge branch 'side' (early part) into tangle @@@ -324,14 -298,12 +324,12 @@@ * | | | Merge branch 'side' |\ \ \ \ | * | | | side-2 - | | | |/ - | | |/| + | | |_|/ | |/| | | * | | side-1 * | | | Second * | | | sixth - | | |/ - | |/| + | |_|/ |/| | * | | fifth * | | fourth