Skip to content

Conversation

gerhardol
Copy link
Member

@gerhardol gerhardol commented Oct 12, 2023

Proposed changes

If HEAD is not included in git-log, the artificial commits are
inserted after all commits are loaded.

This is a refactoring to separate the normal add and the insert to
simplify the handling.

--

This is primary a refactoring, minor changed functionality.
The node cache was not always invalidated if a previous node was added as a parent and the node was already cached.
Draft as it is based on #11266, could be separated if a nullcheck is added.
There are not really any tests related to this. I have another PR for cleaning up some datastructures that I would like to handle first.

--

One partial alternative to this is to only insert first in the grid if HEAD is found.
Some special handling is still needed.
The behavior when filtering will be worse (the artificial is inserted at next commit in current branch now).

Test methodology

Manual

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.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

This refactoring improves the clarity a lot.

@gerhardol gerhardol force-pushed the feature/simplify-articicial-insert branch from fe57f2c to c679b58 Compare October 15, 2023 22:17
@gerhardol
Copy link
Member Author

Cleaned up the insert some more, it is now completely separated from Add.

I found an issue where the nodeCache was not invalidated when a previous added node had an updated score (not likely to occur)
Also, the parent scores could be updated twice.

@gerhardol gerhardol marked this pull request as ready for review October 15, 2023 22:25
@RussKie
Copy link
Member

RussKie commented Oct 17, 2023

MC

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Oct 17, 2023
@gerhardol gerhardol force-pushed the feature/simplify-articicial-insert branch from c679b58 to b70050a Compare October 17, 2023 19:19
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Oct 17, 2023
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

👍 but

Comment on lines 312 to 313
_nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision);
_nodeByObjectId.TryAdd(indexRev.ObjectId, indexGraphRevision);
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
_nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision);
_nodeByObjectId.TryAdd(indexRev.ObjectId, indexGraphRevision);
_nodeByObjectId.Add(workTreeRev.ObjectId, workTreeGraphRevision);
_nodeByObjectId.Add(indexRev.ObjectId, indexGraphRevision);

If this can really be attempted twice, then skip the entire block "// Add graph revisions including segment." using
if (!_nodeByObjectId.TryAdd(workTreeRev.ObjectId))
or

            if (_nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision))
            {
                RevisionGraphRevision indexGraphRevision = new(indexRev.ObjectId, ++insertScore)
                .
                .
                .
                ImmutableInterlocked.Update(ref _nodes, (list, revision) => list.Add(revision), indexGraphRevision);
            }

Copy link
Member Author

Choose a reason for hiding this comment

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

If added twice, the revision will be replaced but a segment added earlier may fail - but that would be very strange.
No checks here, to not delay loading

Update of _nodes should be done last, that is used to add to nodescache to update grid.
In #11268 _nodes is removed so the code is slightly changed

Do you want to remove the comment?

Copy link
Member

Choose a reason for hiding this comment

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

The PR implementation creates an inconsistent state:

  • old RevisionGraphRevision is kept in _nodeByObjectId
  • new RevisionGraphRevision in _nodes

The following avoids the inconsistency and does not add extra cost (except an if on the return value):

            // Add graph revisions including segment.
            RevisionGraphRevision workTreeGraphRevision = new(workTreeRev.ObjectId, insertScore)
            {
                GitRevision = workTreeRev
            };

            if (_nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision)
            {
                RevisionGraphRevision indexGraphRevision = new(indexRev.ObjectId, ++insertScore)
                {
                    GitRevision = indexRev
                };

                workTreeGraphRevision.AddParent(indexGraphRevision, workTreeGraphRevision.Score + 1);
                _nodeByObjectId.Add(indexRev.ObjectId, indexGraphRevision);
                ImmutableInterlocked.Update(ref _nodes, (list, revision) => list.Add(revision), workTreeGraphRevision);
                ImmutableInterlocked.Update(ref _nodes, (list, revision) => list.Add(revision), indexGraphRevision);
            }

Copy link
Member Author

Choose a reason for hiding this comment

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

But worktree and index is not added previously - the code should return if that is checked.
Add segment should b done before.

_nodeByObjectId.Add() will be the latest lines in next PR anyway.

Copy link
Member

@mstv mstv Oct 19, 2023

Choose a reason for hiding this comment

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

_nodeByObjectId.Add() will be the latest lines in next PR anyway.

But actually, it still is a blind _nodeByObjectId.TryAdd() ignoring the result, which is a code smell.
Either "But worktree and index is not added previously" is true, then .Add(), or we should not call the entire method, should we?
At least it should be

Suggested change
_nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision);
_nodeByObjectId.TryAdd(indexRev.ObjectId, indexGraphRevision);
_ = _nodeByObjectId.TryAdd(workTreeRev.ObjectId, workTreeGraphRevision)
&& _nodeByObjectId.TryAdd(indexRev.ObjectId, indexGraphRevision);

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted to the suggestion

There is no Add() for CuncurrentDirectory.
There is AddOrUpdate() with an update method though.

_nodeByObjectId is not checked for normal insertion either (before or now)
A Debug.Assert(!Contains()) could be used here

But I rather save this suggestion to next PR where structures are changed.

@gerhardol gerhardol force-pushed the feature/simplify-articicial-insert branch from 1fa1fe6 to b70050a Compare October 18, 2023 19:54
If HEAD is not included in git-log, the artificial commits are
inserted after all commits are loaded.

This is a refactoring to separate the normal add and the insert to
simplify the handling.

Set the score where to invalidate the node cache from
and check the parent scores only once.
@gerhardol gerhardol force-pushed the feature/simplify-articicial-insert branch from b70050a to 7d280af Compare October 19, 2023 21:55
@gerhardol
Copy link
Member Author

One more change, to hide the scores to check (added in this PR to avoid running the check twice), which was confusing in the tests.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

👍

@gerhardol gerhardol merged commit 7cee1b8 into gitextensions:master Oct 24, 2023
@gerhardol gerhardol deleted the feature/simplify-articicial-insert branch October 24, 2023 21:12
@ghost ghost added this to the vNext milestone Oct 24, 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.

3 participants