git: Fix panic when unstaged diff is recalculated before its primary diff (#49753)
For inverted diff APIs like `hunks_intersecting_base_text_range`, we need a snapshot of the main buffer to use as context to compare hunk anchors, convert anchors to points, etc. Previously, we were always using a snapshot of the main buffer at the time when the diff was calculated. This worked well for the hunks of the primary `BufferDiff`, but it's not valid when the diff also has a secondary set of hunks, because those hunks are recalculated on their own schedule--so it's possible for the hunks of the secondary diff to contain anchors that are newer than the original buffer snapshot that was taken at the time the primary diff hunks were last calculated. This caused a panic when using these anchors with the original buffer snapshot. This PR fixes the issue by using the same approach for inverted diffs as for non-inverted diffs at the multibuffer level: we take a snapshot of the main buffer at the time when we snapshot the diff state (including the diff itself), guaranteeing that that snapshot will be new enough to resolve all the anchors included in both the primary diff and the secondary diff. Closes ZED-54J Release Notes: - Fixed a panic that could occur when using the branch diff in split view mode. --------- Co-authored-by: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
1 parent
765444d100
commit
930d9321dc
6 files changed
+308
-61
No files matched your search
@@ -248,7 +248,7 @@ impl BufferDiffSnapshot {
|
||||
self.inner.buffer_version()
|
||||
}
|
||||
|
||||
pub fn original_buffer_snapshot(&self) -> &text::BufferSnapshot {
|
||||
fn original_buffer_snapshot(&self) -> &text::BufferSnapshot {
|
||||
&self.inner.buffer_snapshot
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user