From 141e9f549d119c0d86996de9bef1f2c35babbb58 Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Sun, 8 Aug 2021 16:55:53 +0200 Subject: [PATCH] Artificial commits: Invalidate rowcache when inserting --- .../RevisionGrid/Graph/RevisionGraph.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/GitUI/UserControls/RevisionGrid/Graph/RevisionGraph.cs b/GitUI/UserControls/RevisionGrid/Graph/RevisionGraph.cs index a7126562bab..980d972a040 100644 --- a/GitUI/UserControls/RevisionGrid/Graph/RevisionGraph.cs +++ b/GitUI/UserControls/RevisionGrid/Graph/RevisionGraph.cs @@ -185,32 +185,36 @@ public void HighlightBranch(ObjectId id) /// Insert the (artificial) revision first in the graph. 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; } } @@ -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) { @@ -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); + } } ///