From 3fdee6712b47cf15e6c863d3284f0c2ed69321b1 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Sun, 16 Jun 2019 17:59:44 +0300 Subject: [PATCH] vcs: Make actions in partial diff tool to not change "exclude from commit" state for blocks from other change lists "Include/Exclude All" checkbox, "Include Only These Lines into Commit" action GitOrigin-RevId: 187e30410a15c40f15239d08379e449ba438034e --- .../lst/SimpleLocalChangeListDiffViewer.java | 4 ++-- .../vcs/ex/PartialLocalLineStatusTracker.kt | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/lst/SimpleLocalChangeListDiffViewer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/lst/SimpleLocalChangeListDiffViewer.java index 66aa4abe340a..5866494bfb46 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/lst/SimpleLocalChangeListDiffViewer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/lst/SimpleLocalChangeListDiffViewer.java @@ -407,7 +407,7 @@ public class SimpleLocalChangeListDiffViewer extends SimpleDiffViewer { @NotNull List selectedChanges) { BitSet selectedLines = getLocalSelectedLines(selectedChanges); - tracker.setExcludedFromCommit(true); + tracker.setExcludedFromCommit(myChangelistId, true); tracker.setExcludedFromCommit(selectedLines, false); rediff(); @@ -542,7 +542,7 @@ public class SimpleLocalChangeListDiffViewer extends SimpleDiffViewer { PartialLocalLineStatusTracker tracker = getPartialTracker(); if (tracker != null && tracker.isValid()) { ExclusionState exclusionState = tracker.getExcludedFromCommitState(myChangelistId); - getPartialTracker().setExcludedFromCommit(exclusionState == ExclusionState.ALL_INCLUDED); + getPartialTracker().setExcludedFromCommit(myChangelistId, exclusionState == ExclusionState.ALL_INCLUDED); refresh(); rediff(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt index 8bd213e98e89..1305de495153 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.ex import com.intellij.diff.util.Side @@ -56,6 +56,7 @@ interface PartialLocalLineStatusTracker : LineStatusTracker { fun getExcludedFromCommitState(changelistId: String): ExclusionState fun setExcludedFromCommit(isExcluded: Boolean) + fun setExcludedFromCommit(changelistId: String, isExcluded: Boolean) fun setExcludedFromCommit(range: Range, isExcluded: Boolean) fun setExcludedFromCommit(lines: BitSet, isExcluded: Boolean) @@ -114,7 +115,7 @@ class ChangelistsLocalLineStatusTracker(project: Project, private var hasUndoInCommand: Boolean = false - private var shouldInitializeWithExcludedFromCommit: Boolean = false + private val initialExcludeState = mutableMapOf() private val undoableActions: WeakList = WeakList() @@ -455,11 +456,9 @@ class ChangelistsLocalLineStatusTracker(project: Project, override fun onUnfreeze() { super.onUnfreeze() - if (shouldInitializeWithExcludedFromCommit) { - shouldInitializeWithExcludedFromCommit = false - for (block in blocks) { - block.excludedFromCommit = true - } + if (initialExcludeState.isNotEmpty()) { + blocks.forEach { block -> initialExcludeState[block.marker]?.let { block.excludedFromCommit = it } } + initialExcludeState.clear() } if (isValid()) eventDispatcher.multicaster.onBecomingValid(this@ChangelistsLocalLineStatusTracker) @@ -678,9 +677,14 @@ class ChangelistsLocalLineStatusTracker(project: Project, @CalledInAwt override fun setExcludedFromCommit(isExcluded: Boolean) { - setExcludedFromCommit({ true }, isExcluded) + affectedChangeLists.forEach { setExcludedFromCommit(it, isExcluded) } + } - if (!isOperational() || !isExcluded) shouldInitializeWithExcludedFromCommit = isExcluded + override fun setExcludedFromCommit(changelistId: String, isExcluded: Boolean) { + val marker = ChangeListMarker(changelistId) + setExcludedFromCommit({ it.marker == marker }, isExcluded) + + if (!isOperational()) initialExcludeState[marker] = isExcluded } override fun setExcludedFromCommit(range: Range, isExcluded: Boolean) {