Пример #1
0
static void graph_output_padding_line(struct git_graph *graph,
                                      struct strbuf *sb)
{
    int i;

    /*
     * We could conceivable be called with a NULL commit
     * if our caller has a bug, and invokes graph_next_line()
     * immediately after graph_init(), without first calling
     * graph_update().  Return without outputting anything in this
     * case.
     */
    if (!graph->commit)
        return;

    /*
     * Output a padding row, that leaves all branch lines unchanged
     */
    for (i = 0; i < graph->num_new_columns; i++) {
        strbuf_write_column(sb, &graph->new_columns[i], '|');
        strbuf_addch(sb, ' ');
    }

    graph_pad_horizontally(graph, sb, graph->num_new_columns * 2);
}
Пример #2
0
Файл: graph.c Проект: 1tgr/git
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
{
	int i;

	if (graph->state != GRAPH_COMMIT) {
		graph_next_line(graph, sb);
		return;
	}

	/*
	 * Output the row containing this commit
	 * Iterate up to and including graph->num_columns,
	 * since the current commit may not be in any of the existing
	 * columns.  (This happens when the current commit doesn't have any
	 * children that we have already processed.)
	 */
	for (i = 0; i < graph->num_columns; i++) {
		struct column *col = &graph->columns[i];
		strbuf_write_column(sb, col, '|');
		if (col->commit == graph->commit && graph->num_parents > 2)
			strbuf_addchars(sb, ' ', (graph->num_parents - 2) * 2);
		else
			strbuf_addch(sb, ' ');
	}

	graph_pad_horizontally(graph, sb, graph->num_columns);

	/*
	 * Update graph->prev_state since we have output a padding line
	 */
	graph->prev_state = GRAPH_PADDING;
}
Пример #3
0
static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb)
{
    /*
     * Output an ellipsis to indicate that a portion
     * of the graph is missing.
     */
    strbuf_addstr(sb, "...");
    graph_pad_horizontally(graph, sb, 3);

    if (graph->num_parents >= 3 &&
            graph->commit_index < (graph->num_columns - 1))
        graph_update_state(graph, GRAPH_PRE_COMMIT);
    else
        graph_update_state(graph, GRAPH_COMMIT);
}
Пример #4
0
Файл: graph.c Проект: Pistos/git
void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
{
	int i, j;

	if (graph->state != GRAPH_COMMIT) {
		graph_next_line(graph, sb);
		return;
	}

	/*
	 * Output the row containing this commit
	 * Iterate up to and including graph->num_columns,
	 * since the current commit may not be in any of the existing
	 * columns.  (This happens when the current commit doesn't have any
	 * children that we have already processed.)
	 */
	for (i = 0; i < graph->num_columns; i++) {
		struct commit *col_commit = graph->columns[i].commit;
		if (col_commit == graph->commit) {
			strbuf_addch(sb, '|');

			if (graph->num_parents < 3)
				strbuf_addch(sb, ' ');
			else {
				int num_spaces = ((graph->num_parents - 2) * 2);
				for (j = 0; j < num_spaces; j++)
					strbuf_addch(sb, ' ');
			}
		} else {
			strbuf_addstr(sb, "| ");
		}
	}

	graph_pad_horizontally(graph, sb);

	/*
	 * Update graph->prev_state since we have output a padding line
	 */
	graph->prev_state = GRAPH_PADDING;
}
Пример #5
0
Файл: graph.c Проект: Pistos/git
void graph_output_post_merge_line(struct git_graph *graph, struct strbuf *sb)
{
	int seen_this = 0;
	int i, j;

	/*
	 * Output the post-merge row
	 */
	for (i = 0; i <= graph->num_columns; i++) {
		struct commit *col_commit;
		if (i == graph->num_columns) {
			if (seen_this)
				break;
			col_commit = graph->commit;
		} else {
			col_commit = graph->columns[i].commit;
		}

		if (col_commit == graph->commit) {
			seen_this = 1;
			strbuf_addch(sb, '|');
			for (j = 0; j < graph->num_parents - 1; j++)
				strbuf_addstr(sb, "\\ ");
		} else if (seen_this) {
			strbuf_addstr(sb, "\\ ");
		} else {
			strbuf_addstr(sb, "| ");
		}
	}

	graph_pad_horizontally(graph, sb);

	/*
	 * Update graph->state
	 */
	if (graph_is_mapping_correct(graph))
		graph_update_state(graph, GRAPH_PADDING);
	else
		graph_update_state(graph, GRAPH_COLLAPSING);
}
Пример #6
0
static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf *sb)
{
    int i;
    int *tmp_mapping;
    short used_horizontal = 0;
    int horizontal_edge = -1;
    int horizontal_edge_target = -1;

    /*
     * Clear out the new_mapping array
     */
    for (i = 0; i < graph->mapping_size; i++)
        graph->new_mapping[i] = -1;

    for (i = 0; i < graph->mapping_size; i++) {
        int target = graph->mapping[i];
        if (target < 0)
            continue;

        /*
         * Since update_columns() always inserts the leftmost
         * column first, each branch's target location should
         * always be either its current location or to the left of
         * its current location.
         *
         * We never have to move branches to the right.  This makes
         * the graph much more legible, since whenever branches
         * cross, only one is moving directions.
         */
        assert(target * 2 <= i);

        if (target * 2 == i) {
            /*
             * 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) {
            /*
             * Nothing is to the left.
             * 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
             * already, and it is our target.  We
             * combine with this line, since we share
             * the same parent commit.
             *
             * We don't have to add anything to the
             * output or new_mapping, since the
             * existing branch line has already taken
             * care of it.
             */
        } else {
            /*
             * There is a branch line to our left,
             * but it isn't our target.  We need to
             * cross over it.
             *
             * 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;
        }
    }

    /*
     * The new mapping may be 1 smaller than the old mapping
     */
    if (graph->new_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];
        if (target < 0)
            strbuf_addch(sb, ' ');
        else if (target * 2 == i)
            strbuf_write_column(sb, &graph->new_columns[target], '|');
        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);

    /*
     * Swap mapping and new_mapping
     */
    tmp_mapping = graph->mapping;
    graph->mapping = graph->new_mapping;
    graph->new_mapping = tmp_mapping;

    /*
     * If graph->mapping indicates that all of the branch lines
     * are already in the correct positions, we are done.
     * Otherwise, we need to collapse some branch lines together.
     */
    if (graph_is_mapping_correct(graph))
        graph_update_state(graph, GRAPH_PADDING);
}
Пример #7
0
static void graph_output_post_merge_line(struct git_graph *graph, struct strbuf *sb)
{
    int seen_this = 0;
    int i, j, chars_written;

    /*
     * Output the post-merge row
     */
    chars_written = 0;
    for (i = 0; i <= graph->num_columns; i++) {
        struct column *col = &graph->columns[i];
        struct commit *col_commit;
        if (i == graph->num_columns) {
            if (seen_this)
                break;
            col_commit = graph->commit;
        } else {
            col_commit = col->commit;
        }

        if (col_commit == graph->commit) {
            /*
             * Since the current commit is a merge find
             * the columns for the parent commits in
             * new_columns and use those to format the
             * edges.
             */
            struct commit_list *parents = NULL;
            struct column *par_column;
            seen_this = 1;
            parents = first_interesting_parent(graph);
            assert(parents);
            par_column = find_new_column_by_commit(graph, parents->item);
            assert(par_column);

            strbuf_write_column(sb, par_column, '|');
            chars_written++;
            for (j = 0; j < graph->num_parents - 1; j++) {
                parents = next_interesting_parent(graph, parents);
                assert(parents);
                par_column = find_new_column_by_commit(graph, parents->item);
                assert(par_column);
                strbuf_write_column(sb, par_column, '\\');
                strbuf_addch(sb, ' ');
            }
            chars_written += j * 2;
        } else if (seen_this) {
            strbuf_write_column(sb, col, '\\');
            strbuf_addch(sb, ' ');
            chars_written += 2;
        } else {
            strbuf_write_column(sb, col, '|');
            strbuf_addch(sb, ' ');
            chars_written += 2;
        }
    }

    graph_pad_horizontally(graph, sb, chars_written);

    /*
     * Update graph->state
     */
    if (graph_is_mapping_correct(graph))
        graph_update_state(graph, GRAPH_PADDING);
    else
        graph_update_state(graph, GRAPH_COLLAPSING);
}
Пример #8
0
static void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
{
    int seen_this = 0;
    int i, chars_written;

    /*
     * Output the row containing this commit
     * Iterate up to and including graph->num_columns,
     * since the current commit may not be in any of the existing
     * columns.  (This happens when the current commit doesn't have any
     * children that we have already processed.)
     */
    seen_this = 0;
    chars_written = 0;
    for (i = 0; i <= graph->num_columns; i++) {
        struct column *col = &graph->columns[i];
        struct commit *col_commit;
        if (i == graph->num_columns) {
            if (seen_this)
                break;
            col_commit = graph->commit;
        } else {
            col_commit = graph->columns[i].commit;
        }

        if (col_commit == graph->commit) {
            seen_this = 1;
            graph_output_commit_char(graph, sb);
            chars_written++;

            if (graph->num_parents > 2)
                chars_written += graph_draw_octopus_merge(graph,
                                 sb);
        } else if (seen_this && (graph->num_parents > 2)) {
            strbuf_write_column(sb, col, '\\');
            chars_written++;
        } else if (seen_this && (graph->num_parents == 2)) {
            /*
             * This is a 2-way merge commit.
             * There is no GRAPH_PRE_COMMIT stage for 2-way
             * merges, so this is the first line of output
             * for this commit.  Check to see what the previous
             * line of output was.
             *
             * If it was GRAPH_POST_MERGE, the branch line
             * coming into this commit may have been '\',
             * and not '|' or '/'.  If so, output the branch
             * line as '\' on this line, instead of '|'.  This
             * makes the output look nicer.
             */
            if (graph->prev_state == GRAPH_POST_MERGE &&
                    graph->prev_commit_index < i)
                strbuf_write_column(sb, col, '\\');
            else
                strbuf_write_column(sb, col, '|');
            chars_written++;
        } else {
            strbuf_write_column(sb, col, '|');
            chars_written++;
        }
        strbuf_addch(sb, ' ');
        chars_written++;
    }

    graph_pad_horizontally(graph, sb, chars_written);

    /*
     * Update graph->state
     */
    if (graph->num_parents > 1)
        graph_update_state(graph, GRAPH_POST_MERGE);
    else if (graph_is_mapping_correct(graph))
        graph_update_state(graph, GRAPH_PADDING);
    else
        graph_update_state(graph, GRAPH_COLLAPSING);
}
Пример #9
0
static void graph_output_pre_commit_line(struct git_graph *graph,
        struct strbuf *sb)
{
    int num_expansion_rows;
    int i, seen_this;
    int chars_written;

    /*
     * This function formats a row that increases the space around a commit
     * with multiple parents, to make room for it.  It should only be
     * called when there are 3 or more parents.
     *
     * We need 2 extra rows for every parent over 2.
     */
    assert(graph->num_parents >= 3);
    num_expansion_rows = (graph->num_parents - 2) * 2;

    /*
     * graph->expansion_row tracks the current expansion row we are on.
     * It should be in the range [0, num_expansion_rows - 1]
     */
    assert(0 <= graph->expansion_row &&
           graph->expansion_row < num_expansion_rows);

    /*
     * Output the row
     */
    seen_this = 0;
    chars_written = 0;
    for (i = 0; i < graph->num_columns; i++) {
        struct column *col = &graph->columns[i];
        if (col->commit == graph->commit) {
            seen_this = 1;
            strbuf_write_column(sb, col, '|');
            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.
             * If the previous commit was a merge commit and
             * ended in the GRAPH_POST_MERGE state, all branch
             * lines after graph->prev_commit_index were
             * printed as "\" on the previous line.  Continue
             * to print them as "\" on this line.  Otherwise,
             * print the branch lines as "|".
             */
            if (graph->prev_state == GRAPH_POST_MERGE &&
                    graph->prev_commit_index < i)
                strbuf_write_column(sb, col, '\\');
            else
                strbuf_write_column(sb, col, '|');
            chars_written++;
        } else if (seen_this && (graph->expansion_row > 0)) {
            strbuf_write_column(sb, col, '\\');
            chars_written++;
        } else {
            strbuf_write_column(sb, col, '|');
            chars_written++;
        }
        strbuf_addch(sb, ' ');
        chars_written++;
    }

    graph_pad_horizontally(graph, sb, chars_written);

    /*
     * Increment graph->expansion_row,
     * and move to state GRAPH_COMMIT if necessary
     */
    graph->expansion_row++;
    if (graph->expansion_row >= num_expansion_rows)
        graph_update_state(graph, GRAPH_COMMIT);
}
Пример #10
0
Файл: graph.c Проект: Pistos/git
void graph_output_collapsing_line(struct git_graph *graph, struct strbuf *sb)
{
	int i;
	int *tmp_mapping;

	/*
	 * Clear out the new_mapping array
	 */
	for (i = 0; i < graph->mapping_size; i++)
		graph->new_mapping[i] = -1;

	for (i = 0; i < graph->mapping_size; i++) {
		int target = graph->mapping[i];
		if (target < 0)
			continue;

		/*
		 * Since update_columns() always inserts the leftmost
		 * column first, each branch's target location should
		 * always be either its current location or to the left of
		 * its current location.
		 *
		 * We never have to move branches to the right.  This makes
		 * the graph much more legible, since whenever branches
		 * cross, only one is moving directions.
		 */
		assert(target * 2 <= i);

		if (target * 2 == i) {
			/*
			 * 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) {
			/*
			 * Nothing is to the left.
			 * Move to the left by one
			 */
			graph->new_mapping[i - 1] = target;
		} else if (graph->new_mapping[i - 1] == target) {
			/*
			 * There is a branch line to our left
			 * already, and it is our target.  We
			 * combine with this line, since we share
			 * the same parent commit.
			 *
			 * We don't have to add anything to the
			 * output or new_mapping, since the
			 * existing branch line has already taken
			 * care of it.
			 */
		} else {
			/*
			 * There is a branch line to our left,
			 * but it isn't our target.  We need to
			 * cross over it.
			 *
			 * The space just to the left of this
			 * branch should always be empty.
			 */
			assert(graph->new_mapping[i - 1] > target);
			assert(graph->new_mapping[i - 2] < 0);
			graph->new_mapping[i - 2] = target;
		}
	}

	/*
	 * The new mapping may be 1 smaller than the old mapping
	 */
	if (graph->new_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];
		if (target < 0)
			strbuf_addch(sb, ' ');
		else if (target * 2 == i)
			strbuf_addch(sb, '|');
		else
			strbuf_addch(sb, '/');
	}

	graph_pad_horizontally(graph, sb);

	/*
	 * Swap mapping and new_mapping
	 */
	tmp_mapping = graph->mapping;
	graph->mapping = graph->new_mapping;
	graph->new_mapping = tmp_mapping;

	/*
	 * If graph->mapping indicates that all of the branch lines
	 * are already in the correct positions, we are done.
	 * Otherwise, we need to collapse some branch lines together.
	 */
	if (graph_is_mapping_correct(graph))
		graph_update_state(graph, GRAPH_PADDING);
}