svn: Refactored "SvnCommittedChangesProvider" - code simplified, warnings fixed

This commit is contained in:
Konstantin Kolosovsky
2016-11-09 23:53:59 +03:00
parent dd569e6b37
commit 705ac9a1e5
3 changed files with 80 additions and 126 deletions
@@ -723,7 +723,7 @@ public class SvnVcs extends AbstractVcs<CommittedChangeList> {
@NotNull
public CommittedChangesProvider<SvnChangeList, ChangeBrowserSettings> getCommittedChangesProvider() {
if (myCommittedChangesProvider == null) {
myCommittedChangesProvider = new SvnCommittedChangesProvider(myProject);
myCommittedChangesProvider = new SvnCommittedChangesProvider(this);
}
return myCommittedChangesProvider;
}
@@ -795,13 +795,10 @@ public class SvnChangeList implements CommittedChangeList, VcsRevisionNumberAwar
}
}
public void forceReloadCachedInfo(final boolean reloadRoot) {
public void forceReloadCachedInfo() {
myCachedInfoLoaded = false;
myBranchUrl = null;
if (reloadRoot) {
myWcRoot = null;
}
myWcRoot = null;
}
@NotNull
@@ -16,13 +16,10 @@
package org.jetbrains.idea.svn.history;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry;
@@ -39,8 +36,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.AsynchConsumer;
import com.intellij.util.Consumer;
import com.intellij.util.PairConsumer;
import com.intellij.util.ThrowableConsumer;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
@@ -63,16 +58,20 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import static com.intellij.openapi.application.ApplicationManager.getApplication;
import static com.intellij.util.containers.ContainerUtil.newArrayList;
import static com.intellij.util.containers.ContainerUtil.newHashSet;
import static java.util.Collections.singletonList;
/**
* @author yole
*/
public class SvnCommittedChangesProvider implements CachingCommittedChangesProvider<SvnChangeList, ChangeBrowserSettings> {
private final static Logger LOG = Logger.getInstance(SvnCommittedChangesProvider.class);
@NotNull private final Project myProject;
@NotNull private final SvnVcs myVcs;
@NotNull private final MessageBusConnection myConnection;
private MergeInfoUpdatesListener myMergeInfoUpdatesListener;
@@ -81,30 +80,17 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
public final static int VERSION_WITH_COPY_PATHS_ADDED = 2;
public final static int VERSION_WITH_REPLACED_PATHS = 3;
public SvnCommittedChangesProvider(@NotNull Project project) {
myProject = project;
myVcs = SvnVcs.getInstance(myProject);
public SvnCommittedChangesProvider(@NotNull SvnVcs vcs) {
myVcs = vcs;
myZipper = new SvnCommittedListsZipper(myVcs);
myConnection = myProject.getMessageBus().connect();
myConnection.subscribe(VcsConfigurationChangeListener.BRANCHES_CHANGED_RESPONSE, new VcsConfigurationChangeListener.DetailedNotification() {
public void execute(final Project project, final VirtualFile vcsRoot, final List<CommittedChangeList> cachedList) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (project.isDisposed()) {
return;
}
for (CommittedChangeList committedChangeList : cachedList) {
if ((committedChangeList instanceof SvnChangeList) &&
((vcsRoot == null) || (vcsRoot.equals(((SvnChangeList)committedChangeList).getVcsRoot())))) {
((SvnChangeList) committedChangeList).forceReloadCachedInfo(true);
}
}
}
});
}
});
myConnection = myVcs.getProject().getMessageBus().connect();
myConnection.subscribe(VcsConfigurationChangeListener.BRANCHES_CHANGED_RESPONSE,
(project, vcsRoot, cachedList) -> getApplication().invokeLater(() -> {
cachedList.stream().filter(SvnChangeList.class::isInstance).map(SvnChangeList.class::cast)
.filter(list -> vcsRoot == null || vcsRoot.equals(list.getVcsRoot()))
.forEach(SvnChangeList::forceReloadCachedInfo);
}, project.getDisposed()));
}
@NotNull
@@ -113,13 +99,13 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
}
@NotNull
public ChangesBrowserSettingsEditor<ChangeBrowserSettings> createFilterUI(final boolean showDateFilter) {
public ChangesBrowserSettingsEditor<ChangeBrowserSettings> createFilterUI(boolean showDateFilter) {
return new SvnVersionFilterComponent(showDateFilter);
}
@Nullable
public RepositoryLocation getLocationFor(@NotNull FilePath root) {
final String url = SvnUtil.getExactLocation(myVcs, root.getIOFile());
String url = SvnUtil.getExactLocation(myVcs, root.getIOFile());
return url == null ? null : new SvnRepositoryLocation(url, root);
}
@@ -137,20 +123,20 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
public void loadCommittedChanges(@NotNull ChangeBrowserSettings settings,
@NotNull RepositoryLocation location,
int maxCount,
@NotNull final AsynchConsumer<CommittedChangeList> consumer) throws VcsException {
@NotNull AsynchConsumer<CommittedChangeList> consumer) throws VcsException {
try {
final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
final String repositoryRoot = getRepositoryRoot(svnLocation);
final ChangeBrowserSettings.Filter filter = settings.createFilter();
getCommittedChangesImpl(settings, svnLocation, maxCount, new Consumer<LogEntry>() {
public void consume(final LogEntry svnLogEntry) {
final SvnChangeList cl = new SvnChangeList(myVcs, svnLocation, svnLogEntry, repositoryRoot);
if (filter.accepts(cl)) {
consumer.consume(cl);
}
SvnRepositoryLocation svnLocation = (SvnRepositoryLocation)location;
String repositoryRoot = getRepositoryRoot(svnLocation);
ChangeBrowserSettings.Filter filter = settings.createFilter();
Consumer<LogEntry> resultConsumer = logEntry -> {
SvnChangeList list = new SvnChangeList(myVcs, svnLocation, logEntry, repositoryRoot);
if (filter.accepts(list)) {
consumer.consume(list);
}
}, false, true);
};
SvnTarget target = SvnTarget.fromURL(svnLocation.toSvnUrl(), createBeforeRevision(settings));
getCommittedChangesImpl(settings, target, maxCount, resultConsumer, false, true);
}
finally {
consumer.finished();
@@ -161,15 +147,13 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
public List<SvnChangeList> getCommittedChanges(@NotNull ChangeBrowserSettings settings,
@NotNull RepositoryLocation location,
int maxCount) throws VcsException {
final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
final ArrayList<SvnChangeList> result = new ArrayList<>();
final String repositoryRoot = getRepositoryRoot(svnLocation);
SvnRepositoryLocation svnLocation = (SvnRepositoryLocation)location;
List<SvnChangeList> result = newArrayList();
String repositoryRoot = getRepositoryRoot(svnLocation);
Consumer<LogEntry> resultConsumer = logEntry -> result.add(new SvnChangeList(myVcs, svnLocation, logEntry, repositoryRoot));
SvnTarget target = SvnTarget.fromURL(svnLocation.toSvnUrl(), createBeforeRevision(settings));
getCommittedChangesImpl(settings, svnLocation, maxCount, new Consumer<LogEntry>() {
public void consume(final LogEntry svnLogEntry) {
result.add(new SvnChangeList(myVcs, svnLocation, svnLogEntry, repositoryRoot));
}
}, false, true);
getCommittedChangesImpl(settings, target, maxCount, resultConsumer, false, true);
settings.filterChanges(result);
return result;
}
@@ -177,31 +161,20 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
public void getCommittedChangesWithMergedRevisons(@NotNull ChangeBrowserSettings settings,
@NotNull RepositoryLocation location,
int maxCount,
@NotNull final PairConsumer<SvnChangeList, LogHierarchyNode> finalConsumer)
@NotNull PairConsumer<SvnChangeList, LogHierarchyNode> finalConsumer)
throws VcsException {
final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
final String repositoryRoot = getRepositoryRoot(svnLocation);
SvnRepositoryLocation svnLocation = (SvnRepositoryLocation)location;
String repositoryRoot = getRepositoryRoot(svnLocation);
MergeSourceHierarchyBuilder builder = new MergeSourceHierarchyBuilder(
node -> finalConsumer.consume(new SvnChangeList(myVcs, svnLocation, node.getMe(), repositoryRoot), node));
SvnMergeSourceTracker mergeSourceTracker = new SvnMergeSourceTracker(builder);
final MergeSourceHierarchyBuilder builder = new MergeSourceHierarchyBuilder(new Consumer<LogHierarchyNode>() {
public void consume(LogHierarchyNode node) {
finalConsumer.consume(new SvnChangeList(myVcs, svnLocation, node.getMe(), repositoryRoot), node);
getCommittedChangesImpl(settings, SvnTarget.fromURL(svnLocation.toSvnUrl()), maxCount, logEntry -> {
try {
mergeSourceTracker.consume(logEntry);
}
});
final SvnMergeSourceTracker mergeSourceTracker = new SvnMergeSourceTracker(new ThrowableConsumer<Pair<LogEntry, Integer>, SVNException>() {
public void consume(Pair<LogEntry, Integer> svnLogEntryIntegerPair) throws SVNException {
builder.consume(svnLogEntryIntegerPair);
}
});
getCommittedChangesImpl(settings, SvnTarget.fromURL(svnLocation.toSvnUrl()), maxCount, new Consumer<LogEntry>() {
public void consume(final LogEntry svnLogEntry) {
try {
mergeSourceTracker.consume(svnLogEntry);
}
catch (SVNException e) {
throw new RuntimeException(e);
// will not occur actually but anyway never eat them
}
catch (SVNException e) {
throw new RuntimeException(e);
}
}, true, false);
@@ -222,17 +195,6 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
return rootUrl.toDecodedString();
}
private void getCommittedChangesImpl(@NotNull ChangeBrowserSettings settings,
@NotNull SvnRepositoryLocation location,
int maxCount,
@NotNull Consumer<LogEntry> resultConsumer,
boolean includeMergedRevisions,
boolean filterOutByDate) throws VcsException {
SvnTarget target = SvnTarget.fromURL(location.toSvnUrl(), createBeforeRevision(settings));
getCommittedChangesImpl(settings, target, maxCount, resultConsumer, includeMergedRevisions, filterOutByDate);
}
private void getCommittedChangesImpl(@NotNull ChangeBrowserSettings settings,
@NotNull SvnTarget target,
int maxCount,
@@ -262,7 +224,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
@NotNull
private static SVNRevision createRevision(@Nullable Date date, @Nullable Long change, @NotNull SVNRevision defaultValue) {
final SVNRevision result;
SVNRevision result;
if (date != null) {
result = SVNRevision.create(date);
@@ -278,22 +240,17 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
}
@NotNull
private LogEntryConsumer createLogHandler(@NotNull final Consumer<LogEntry> resultConsumer,
final boolean filterOutByDate,
@Nullable final String author) {
return new LogEntryConsumer() {
@Override
public void consume(LogEntry logEntry) {
if (myProject.isDisposed()) throw new ProcessCanceledException();
private LogEntryConsumer createLogHandler(@NotNull Consumer<LogEntry> resultConsumer, boolean filterOutByDate, @Nullable String author) {
return logEntry -> {
if (myVcs.getProject().isDisposed()) throw new ProcessCanceledException();
ProgressManager.progress2(SvnBundle.message("progress.text2.processing.revision", logEntry.getRevision()));
if (filterOutByDate && logEntry.getDate() == null) {
// do not add lists without info - this situation is possible for lists where there are paths that user has no rights to observe
return;
}
if (author == null || author.equalsIgnoreCase(logEntry.getAuthor())) {
resultConsumer.consume(logEntry);
}
ProgressManager.progress2(SvnBundle.message("progress.text2.processing.revision", logEntry.getRevision()));
if (filterOutByDate && logEntry.getDate() == null) {
// do not add lists without info - this situation is possible for lists where there are paths that user has no rights to observe
return;
}
if (author == null || author.equalsIgnoreCase(logEntry.getAuthor())) {
resultConsumer.consume(logEntry);
}
};
}
@@ -305,7 +262,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
@NotNull
public ChangeListColumn[] getColumns() {
return new ChangeListColumn[] {
return new ChangeListColumn[]{
new ChangeListColumn.ChangeListNumberColumn(SvnBundle.message("revision.title")),
ChangeListColumn.NAME, ChangeListColumn.DATE, ChangeListColumn.DESCRIPTION
};
@@ -313,31 +270,29 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
private void refreshMergeInfo(@NotNull RootsAndBranches action) {
if (myMergeInfoUpdatesListener == null) {
myMergeInfoUpdatesListener = new MergeInfoUpdatesListener(myProject, myConnection);
myMergeInfoUpdatesListener = new MergeInfoUpdatesListener(myVcs.getProject(), myConnection);
}
myMergeInfoUpdatesListener.addPanel(action);
}
@NotNull
public VcsCommittedViewAuxiliary createActions(@NotNull DecoratorManager manager, @Nullable RepositoryLocation location) {
final RootsAndBranches rootsAndBranches = new RootsAndBranches(myVcs, manager, location);
RootsAndBranches rootsAndBranches = new RootsAndBranches(myVcs, manager, location);
refreshMergeInfo(rootsAndBranches);
final DefaultActionGroup popup = new DefaultActionGroup(myVcs.getDisplayName(), true);
DefaultActionGroup popup = new DefaultActionGroup(myVcs.getDisplayName(), true);
popup.add(rootsAndBranches.getIntegrateAction());
popup.add(rootsAndBranches.getUndoIntegrateAction());
popup.add(new ConfigureBranchesAction());
final ShowHideMergePanelAction action = new ShowHideMergePanelAction(manager, rootsAndBranches.getStrategy());
ShowHideMergePanelAction action = new ShowHideMergePanelAction(manager, rootsAndBranches.getStrategy());
return new VcsCommittedViewAuxiliary(Collections.<AnAction>singletonList(popup), new Runnable() {
public void run() {
if (myMergeInfoUpdatesListener != null) {
myMergeInfoUpdatesListener.removePanel(rootsAndBranches);
rootsAndBranches.dispose();
}
return new VcsCommittedViewAuxiliary(singletonList(popup), () -> {
if (myMergeInfoUpdatesListener != null) {
myMergeInfoUpdatesListener.removePanel(rootsAndBranches);
rootsAndBranches.dispose();
}
}, Collections.<AnAction>singletonList(action));
}, singletonList(action));
}
public int getUnlimitedCountValue() {
@@ -371,7 +326,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
@NotNull
public SvnChangeList readChangeList(@NotNull RepositoryLocation location, @NotNull DataInput stream) throws IOException {
final int version = getFormatVersion();
int version = getFormatVersion();
return new SvnChangeList(myVcs, (SvnRepositoryLocation)location, stream, VERSION_WITH_COPY_PATHS_ADDED <= version,
VERSION_WITH_REPLACED_PATHS <= version);
}
@@ -402,7 +357,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
// TODO: could only be used with url targets - so we could not use "svn diff" here now for all cases (we could not use url with
// TODO: concrete revision as there could be mixed revision working copy).
final Set<FilePath> result = ContainerUtil.newHashSet();
Set<FilePath> result = newHashSet();
File rootFile = root.getIOFile();
myVcs.getFactory(rootFile).createStatusClient()
@@ -415,7 +370,7 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
isNotNone(status.getRemotePropertiesStatus());
if (file != null && changedOnServer) {
result.add(VcsUtil.getFilePath(file, file.isDirectory()));
result.add(VcsUtil.getFilePath(file));
}
}
}, null);
@@ -435,8 +390,10 @@ public class SvnCommittedChangesProvider implements CachingCommittedChangesProvi
return SvnBundle.message("changes.browser.revision.term");
}
public boolean isChangeLocallyAvailable(FilePath filePath, @Nullable VcsRevisionNumber localRevision, VcsRevisionNumber changeRevision,
final SvnChangeList changeList) {
public boolean isChangeLocallyAvailable(FilePath filePath,
@Nullable VcsRevisionNumber localRevision,
VcsRevisionNumber changeRevision,
SvnChangeList changeList) {
return localRevision != null && localRevision.compareTo(changeRevision) >= 0;
}