Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two bugs in graph.c #517

Closed

Commits on Jan 7, 2020

  1. graph: fix case that hit assert()

    A failure was reported in "git log --graph --all" with the new
    graph-rendering logic. The code fails an assert() statement when
    collapsing multiple edges from a merge.
    
    The assert was introduced by eaf158f (graph API: Use horizontal
    lines for more compact graphs, 2009-04-21), which is quite old.
    This assert is trying to say that when we complete a horizontal
    line with a single slash, it is because we have reached our target.
    
    This assertion is hit when we have two collapsing lines from the
    same merge commit, as follows:
    
        | | | | *
        | |_|_|/|
        |/| | |/
        | | |/|
        | |/| |
        | * | |
        * | | |
    
    It is actually the _second_ collapsing line that hits this assert.
    The reason we are in this code path is because we are collapsing
    the first line, and in that case we are hitting our target now
    that the horizontal line is complete. However, the second line
    cannot be a horizontal line, so it will collapse without horizontal
    lines. In this case, it is inappropriate to assert that we have
    reached our target, as we need to continue for another column
    before reaching the target. Dropping the assert is safe here.
    
    The new behavior in 0f0f389 (graph: tidy up display of
    left-skewed merges, 2019-10-15) caused the behavior change that
    made this assertion failure possible. In addition to making the
    assert possible, it also changed how multiple edges collapse.
    
    In a larger example, the current code will output a collapse
    as follows:
    
    	| | | | | | *
    	| |_|_|_|_|/|\
    	|/| | | | |/ /
    	| | | | |/| /
    	| | | |/| |/
    	| | |/| |/|
    	| |/| |/| |
    	| | |/| | |
    	| | * | | |
    
    However, the intended collapse should allow multiple horizontal lines
    as follows:
    
    	| | | | | | *
    	| |_|_|_|_|/|\
    	|/| | | | |/ /
    	| | |_|_|/| /
    	| |/| | | |/
    	| | | |_|/|
    	| | |/| | |
    	| | * | | |
    
    This behavior is not corrected by this change, but is noted for a later
    update.
    
    Helped-by: Jeff King <peff@peff.net>
    Reported-by: Bradley Smith <brad@brad-smith.co.uk>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Jan 7, 2020
    Configuration menu
    Copy the full SHA
    c05fe2c View commit details
    Browse the repository at this point in the history
  2. graph: fix lack of color in horizontal lines

    In some cases, horizontal lines in rendered graphs can lose their
    coloring. This is due to a use of graph_line_addch() instead of
    graph_line_write_column(). Using a ternary operator to pick the
    character is nice for compact code, but we actually need a column to
    provide the color.
    
    Add a test to t4215-log-skewed-merges.sh to prevent regression.
    
    Reported-by: Jeff King <peff@peff.net>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Jan 7, 2020
    Configuration menu
    Copy the full SHA
    11887bd View commit details
    Browse the repository at this point in the history