vcs: changes cache: Ensure each "Update Info" panel shows only change lists changed during update it reflects - make each panel use separate Consumer for getting necessary change lists (instead of subscribing to Topic in project message bus)

This commit is contained in:
Konstantin Kolosovsky
2014-08-17 00:38:16 +04:00
parent f9b99d92c1
commit 2479143fac
2 changed files with 28 additions and 18 deletions
@@ -44,6 +44,7 @@ import com.intellij.util.Consumer;
import com.intellij.util.MessageBusUtil;
import com.intellij.util.NotNullFunction;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
@@ -772,6 +773,11 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
}
public void processUpdatedFiles(final UpdatedFiles updatedFiles) {
processUpdatedFiles(updatedFiles, null);
}
public void processUpdatedFiles(final UpdatedFiles updatedFiles,
@Nullable final Consumer<List<CommittedChangeList>> incomingChangesConsumer) {
final Runnable task = new Runnable() {
@Override
public void run() {
@@ -781,7 +787,7 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
for(final ChangesCacheFile cache: caches) {
try {
if (cache.isEmpty()) {
pendingUpdateProcessed();
pendingUpdateProcessed(incomingChangesConsumer);
continue;
}
debug("Processing updated files in " + cache.getLocation());
@@ -789,12 +795,12 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
if (needRefresh) {
debug("Found unaccounted files, requesting refresh");
// todo do we need double-queueing here???
processUpdatedFilesAfterRefresh(cache, updatedFiles);
processUpdatedFilesAfterRefresh(cache, updatedFiles, incomingChangesConsumer);
}
else {
debug("Clearing cached incoming changelists");
myCachedIncomingChangeLists = null;
pendingUpdateProcessed();
pendingUpdateProcessed(incomingChangesConsumer);
}
}
catch (IOException e) {
@@ -806,15 +812,20 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
myTaskQueue.run(task);
}
private void pendingUpdateProcessed() {
private void pendingUpdateProcessed(@Nullable Consumer<List<CommittedChangeList>> incomingChangesConsumer) {
myPendingUpdateCount--;
if (myPendingUpdateCount == 0) {
notifyIncomingChangesUpdated(myNewIncomingChanges);
if (incomingChangesConsumer != null) {
incomingChangesConsumer.consume(ContainerUtil.newArrayList(myNewIncomingChanges));
}
myNewIncomingChanges.clear();
}
}
private void processUpdatedFilesAfterRefresh(final ChangesCacheFile cache, final UpdatedFiles updatedFiles) {
private void processUpdatedFilesAfterRefresh(final ChangesCacheFile cache,
final UpdatedFiles updatedFiles,
@Nullable final Consumer<List<CommittedChangeList>> incomingChangesConsumer) {
refreshCacheAsync(cache, false, new RefreshResultConsumer() {
@Override
public void receivedChanges(final List<CommittedChangeList> committedChangeLists) {
@@ -833,7 +844,7 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
debug("Clearing cached incoming changelists");
myCachedIncomingChangeLists = null;
}
pendingUpdateProcessed();
pendingUpdateProcessed(incomingChangesConsumer);
}
catch (IOException e) {
LOG.error(e);
@@ -38,7 +38,6 @@ import com.intellij.openapi.vcs.changes.RemoteRevisionsCache;
import com.intellij.openapi.vcs.changes.VcsAnnotationRefresher;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManagerImpl;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesAdapter;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache;
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
@@ -46,6 +45,7 @@ import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.Consumer;
import com.intellij.util.WaitForProgressToShow;
import com.intellij.util.ui.OptionsDialog;
import com.intellij.vcsUtil.VcsUtil;
@@ -550,10 +550,14 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction {
}
}
else if (! myUpdatedFiles.isEmpty()) {
showUpdateTree(continueChainFinal && updateSuccess && noMerged, someSessionWasCancelled);
final UpdateInfoTree tree = showUpdateTree(continueChainFinal && updateSuccess && noMerged, someSessionWasCancelled);
final CommittedChangesCache cache = CommittedChangesCache.getInstance(myProject);
cache.processUpdatedFiles(myUpdatedFiles);
cache.processUpdatedFiles(myUpdatedFiles, new Consumer<List<CommittedChangeList>>() {
@Override
public void consume(List<CommittedChangeList> incomingChangeLists) {
tree.setChangeLists(incomingChangeLists);
}
});
if (someSessionWasCancelled) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "VCS Update Incomplete" + prepareNotificationWithUpdateInfo(), MessageType.WARNING);
@@ -592,7 +596,8 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction {
}
}
private void showUpdateTree(final boolean willBeContinued, final boolean wasCanceled) {
@NotNull
private UpdateInfoTree showUpdateTree(final boolean willBeContinued, final boolean wasCanceled) {
RestoreUpdateTree restoreUpdateTree = RestoreUpdateTree.getInstance(myProject);
restoreUpdateTree.registerUpdateInformation(myUpdatedFiles, myActionInfo);
final String text = getTemplatePresentation().getText() + ((willBeContinued || (myUpdateNumber > 1)) ? ("#" + myUpdateNumber) : "");
@@ -602,13 +607,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction {
updateInfoTree.setAfter(myAfter);
updateInfoTree.setCanGroupByChangeList(canGroupByChangelist(myVcsToVirtualFiles.keySet()));
myProject.getMessageBus().connect(updateInfoTree).subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesAdapter() {
public void incomingChangesUpdated(final List<CommittedChangeList> receivedChanges) {
if (receivedChanges != null) {
updateInfoTree.setChangeLists(receivedChanges);
}
}
});
return updateInfoTree;
}
public void onCancel() {