diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsHistorySession.java b/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsHistorySession.java index 7be4ac039ff4..824c41573802 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsHistorySession.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsHistorySession.java @@ -22,14 +22,29 @@ import java.util.List; public abstract class VcsHistorySession { private final List myRevisions; - private volatile VcsRevisionNumber myCachedRevisionNumber; + private final Object myLock; + private VcsRevisionNumber myCachedRevisionNumber; + + protected VcsRevisionNumber getCachedRevision() { + synchronized (myLock) { + return myCachedRevisionNumber; + } + } + + protected void setCachedRevision(final VcsRevisionNumber number) { + synchronized (myLock) { + myCachedRevisionNumber = number; + } + } public VcsHistorySession(List revisions) { + myLock = new Object(); myRevisions = revisions; myCachedRevisionNumber = calcCurrentRevisionNumber(); } protected VcsHistorySession(List revisions, VcsRevisionNumber currentRevisionNumber) { + myLock = new Object(); myRevisions = revisions; myCachedRevisionNumber = currentRevisionNumber; } @@ -47,7 +62,7 @@ public abstract class VcsHistorySession { protected abstract VcsRevisionNumber calcCurrentRevisionNumber(); public final VcsRevisionNumber getCurrentRevisionNumber() { - return myCachedRevisionNumber; + return getCachedRevision(); } public boolean isCurrentRevision(VcsRevisionNumber rev) { @@ -56,9 +71,10 @@ public abstract class VcsHistorySession { } public synchronized boolean refresh() { - final VcsRevisionNumber oldValue = myCachedRevisionNumber; - myCachedRevisionNumber = calcCurrentRevisionNumber(); - return !Comparing.equal(oldValue, myCachedRevisionNumber); + final VcsRevisionNumber oldValue = getCachedRevision(); + final VcsRevisionNumber newNumber = calcCurrentRevisionNumber(); + setCachedRevision(newNumber); + return !Comparing.equal(oldValue, newNumber); } public boolean allowAsyncRefresh() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index 7d1c76049cd5..947ecd3be8cf 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -3,8 +3,8 @@ package com.intellij.openapi.vcs.history; import com.intellij.history.LocalHistory; import com.intellij.history.LocalHistoryAction; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.*; @@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.PanelWithActionsAndCloseButton; import com.intellij.openapi.ui.Splitter; -import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; @@ -295,7 +295,7 @@ public class FileHistoryPanelImpl() { public void consume(final VcsHistorySession session) { if (session != null) { - if (myHistorySession.allowAsyncRefresh()) { + if (session.allowAsyncRefresh()) { SwingUtilities.invokeLater(new Runnable() { public void run() { refresh(session); @@ -476,9 +476,14 @@ public class FileHistoryPanelImpl sessionGetter = new Getter() { + public VcsHistorySession get() { + return myHistorySession; + } + }; + myDualView.setTreeCellRenderer(new MyTreeCellRenderer(defaultCellRenderer, sessionGetter)); - myDualView.setCellWrapper(new MyCellWrapper(myHistorySession)); + myDualView.setCellWrapper(new MyCellWrapper(sessionGetter)); TableViewModel sortableModel = myDualView.getFlatView().getTableViewModel(); sortableModel.setSortable(true); @@ -1425,9 +1430,9 @@ public class FileHistoryPanelImpl myHistorySession; - public MyTreeCellRenderer(final TreeCellRenderer defaultCellRenderer, final VcsHistorySession historySession) { + public MyTreeCellRenderer(final TreeCellRenderer defaultCellRenderer, final Getter historySession) { myDefaultCellRenderer = defaultCellRenderer; myHistorySession = historySession; } @@ -1447,10 +1452,10 @@ public class FileHistoryPanelImpl myHistorySession; - public MyCellWrapper(final VcsHistorySession historySession) { + public MyCellWrapper(final Getter historySession) { myHistorySession = historySession; } @@ -1483,7 +1488,7 @@ public class FileHistoryPanelImpl