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

Artificial commits: Invalidate rowcache when inserting #9459

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 deletions GitUI/UserControls/RevisionGrid/Graph/RevisionGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,32 +185,36 @@ public void HighlightBranch(ObjectId id)
/// <param name="insertAsFirst">Insert the (artificial) revision first in the graph.</param>
public void Add(GitRevision revision, RevisionNodeFlags types, bool insertAsFirst = false)
{
// The commits are sorted by the score (not contiuous numbering there may be gaps)
// This commit will be ordered after existing, _maxScore is a preliminary score
_maxScore++;

bool updateParents = true;
if (!_nodeByObjectId.TryGetValue(revision.ObjectId, out RevisionGraphRevision revisionGraphRevision))
{
int score = insertAsFirst

// Insert first artificial (WorkTree) before first existing
// _maxScore does not need to be updated
? -1

// This revision is added from the log, but not seen before. This is probably a root node (new branch)
// OR the revisions are not in topo order. If this the case, we deal with it later.
: ++_maxScore;
: _maxScore;
revisionGraphRevision = new RevisionGraphRevision(revision.ObjectId, score);
_nodeByObjectId.TryAdd(revision.ObjectId, revisionGraphRevision);
}
else
{
// This revision was added earlier, but is now found in the log.
// Increase the score to the current maxScore to keep the order in tact.
if (!insertAsFirst)
{
revisionGraphRevision.EnsureScoreIsAbove(++_maxScore);
// Increase the score to the current maxScore to keep the order intact.
revisionGraphRevision.EnsureScoreIsAbove(_maxScore);
}
else
{
// Second artificial (Index), score already set
// Second artificial (Index), score already set, no parent (HEAD not in grid)
// No parent segment to be added
updateParents = false;
}
}
Expand All @@ -221,13 +225,7 @@ public void Add(GitRevision revision, RevisionNodeFlags types, bool insertAsFirs

// Build the revisions parent/child structure. The parents need to added here. The child structure is kept in synch in
// the RevisionGraphRevision class.
if (!updateParents)
{
// score set already for the commit, force reorder
// Parent (HEAD) not in the graph, no segment added
_reorder = true;
}
else if (revision.ParentIds is not null)
if (revision.ParentIds is not null && updateParents)
{
foreach (ObjectId parentObjectId in revision.ParentIds)
{
Expand Down Expand Up @@ -264,6 +262,13 @@ public void Add(GitRevision revision, RevisionNodeFlags types, bool insertAsFirs

// Ensure all parents are loaded before adding it to the _nodes list. This is important for ordering.
ImmutableInterlocked.Update(ref _nodes, (list, revision) => list.Add(revision), revisionGraphRevision);

if (!updateParents)
{
// The rows may already be cached, invalidate
_reorder = true;
CacheTo(0, 0);
}
}

/// <summary>
Expand Down