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

Straighten multiple segments, including when there are commits #11059

Merged
merged 1 commit into from Aug 13, 2023

Conversation

mstv
Copy link
Member

@mstv mstv commented Jun 18, 2023

Fixes #5782
Improves on #9050
The essence of #10778 by @o-kloster including the very useful test utility

Proposed changes

  • As of now, segments in the revision graph are straightened only of they contain no intermediate commits (i.e. it's just one segment). This change allows straightening also when there are intermediate commits and/or merges.

Screenshots

Before

image

After

image

Test methodology

  • Manual with GE repo
  • Unit tests verify the graph layout

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned mstv Jun 18, 2023
Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are 🔥
Few nits

GitUI/UserControls/RevisionGrid/Graph/RevisionGraphRow.cs Outdated Show resolved Hide resolved
@@ -508,9 +508,11 @@ static void StraightenLanes(int startIndex, int lastStraightenIndex, int lastLoo

int straightenedCurrentLane = currentLane + 1;
int lookaheadLane = currentLane;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int lookaheadLane = currentLane;
int lookAheadLane = currentLane;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- int lookaheadLane = currentLane;
+ int lookAheadLane = currentLane;

Then we would need to change the capitalization of the existing lookaheadIndex, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

for (int lookaheadIndex = currentIndex + 1; lookaheadLane == currentLane && lookaheadIndex <= Math.Min(currentIndex + _straightenLanesLookAhead, lastLookaheadIndex); ++lookaheadIndex)
{
lookaheadLane = localOrderedRowCache[lookaheadIndex].GetLaneForSegment(revisionGraphSegment).Index;
RevisionGraphRow lookaheadRow = localOrderedRowCache[lookaheadIndex];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RevisionGraphRow lookaheadRow = localOrderedRowCache[lookaheadIndex];
RevisionGraphRow lookAheadRow = localOrderedRowCache[lookaheadIndex];

Comment on lines 446 to 458
private static void AssertGraphLayout(RevisionGraph revisionGraph, string expectedLayout)
{
string expectedGraph = expectedLayout.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Join("\n");
string actualGraph = AsciiGraphFor(revisionGraph).Join("\n");
try
{
Assert.AreEqual(expectedGraph, actualGraph);
}
catch
{
Console.WriteLine(actualGraph);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using snapshot testing instead (i.e., Verify)? This way the diff would be visual

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The display (of Console.WriteLine output) in the test explorer is not perfect, but was good enough for me when using o-kloster's test utility.
Though it is very useful to have the graph definition and the expected result in one place:

                RevisionGraph revisionGraph = CreateGraph("R 4:R 3:R 2:R,3 1:2 0:1,4");

                AssertGraphLayout(revisionGraph, @"
                    0
                    |\
                    1 |
                    |  \
                    2   |
                    |\  |
                    | 3 |
                    | | |
                    | | 4
                    |/-´
                    R
                ");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The display (of Console.WriteLine output) in the test explorer is not perfect, but was good enough for me when using o-kloster's test utility. Though it is very useful to have the graph definition and the expected result in one place:

                RevisionGraph revisionGraph = CreateGraph("R 4:R 3:R 2:R,3 1:2 0:1,4");

                AssertGraphLayout(revisionGraph, @"
                    0
                    |\
                    1 |
                    |  \
                    2   |
                    |\  |
                    | 3 |
                    | | |
                    | | 4
                    |/-´
                    R
                ");

I am still convinced that this is better tp be kept in one place than fiddling around with lots of .verified.txt files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

than fiddling around with lots of .verified.txt files.

That's the key point - there's no fiddling required, the verified files are updated automatically. First, if the test result is different from the expectation, you'll see it in a diff tool. Then, if the change is expected, then the new version is applied in the diff tool.

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Jun 19, 2023
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Jun 19, 2023
@mstv mstv force-pushed the feature/straighten_segments branch from 042821e to ab8b642 Compare June 30, 2023 21:53
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well, but the scenario below is not handled, also in 4.1 though.
Not sure I have understood the details in the implementation, but it seems reasonable.

image

image

@mstv
Copy link
Member Author

mstv commented Jul 5, 2023

but the scenario below is not handled, also in 4.1 though.

I do net see a difference in the screenshots (which seem to have been taken with this PR). What would you expect?

@gerhardol
Copy link
Member

I do net see a difference in the screenshots (which seem to have been taken with this PR). What would you expect?

Bad screenshot, updated.

I expected the gap to be filled, there is nothing at all in that column.
But it is the same in 4.1.

@mstv
Copy link
Member Author

mstv commented Jul 6, 2023

Straightened lanes are bought by inserting gaps.
This PR straightens also the lane with commits in it. So the gap is moved one to the left in this case.
That's exactly how this PR is intended to work.

@mstv mstv requested a review from RussKie August 8, 2023 13:45
Co-authored-by: Igor Velikorossov <russkie@gmail.com>
@mstv mstv force-pushed the feature/straighten_segments branch from 2214231 to 80fde7e Compare August 13, 2023 07:40
@mstv mstv merged commit ae93fbc into gitextensions:master Aug 13, 2023
3 of 4 checks passed
@mstv mstv deleted the feature/straighten_segments branch August 13, 2023 07:41
@ghost ghost added this to the vNext milestone Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Readability revision graph
3 participants