mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: merge two related functions
This commit is contained in:
@@ -46,6 +46,7 @@ import com.intellij.openapi.roots.impl.DirectoryIndex;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.changes.committed.AbstractCalledLater;
|
||||
@@ -293,25 +294,19 @@ public class LineStatusTrackerManager implements ProjectComponent, LineStatusTra
|
||||
return;
|
||||
}
|
||||
|
||||
final VcsRevisionNumber baseRevision = myStatusProvider.getBaseRevision(myVirtualFile);
|
||||
final Pair<VcsRevisionNumber, String> baseRevision = myStatusProvider.getBaseRevision(myVirtualFile);
|
||||
if (baseRevision == null) {
|
||||
log("installTracker() for file " + myVirtualFile.getPath() + " failed: null returned for base revision number");
|
||||
reportTrackerBaseLoadFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
// loads are sequential (in single threaded QueueProcessor);
|
||||
// so myLoadCounter can't take less value for greater base revision -> the only thing we want from it
|
||||
final LineStatusTracker.RevisionPack revisionPack = new LineStatusTracker.RevisionPack(myLoadCounter, baseRevision);
|
||||
final LineStatusTracker.RevisionPack revisionPack = new LineStatusTracker.RevisionPack(myLoadCounter, baseRevision.first);
|
||||
++myLoadCounter;
|
||||
|
||||
final String lastUpToDateContent = myStatusProvider.getBaseVersionContent(myVirtualFile);
|
||||
if (lastUpToDateContent == null) {
|
||||
log("installTracker() for file " + myVirtualFile.getPath() + " failed: no up to date content");
|
||||
reportTrackerBaseLoadFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
final String converted = StringUtil.convertLineSeparators(lastUpToDateContent);
|
||||
final String converted = StringUtil.convertLineSeparators(baseRevision.second);
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
synchronized (myLock) {
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.impl;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -25,8 +27,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Time: 1:12 PM
|
||||
*/
|
||||
public interface VcsBaseContentProvider {
|
||||
/*
|
||||
* return pair of base revision number and content
|
||||
*
|
||||
* null is returned if an error occurred
|
||||
*/
|
||||
@Nullable
|
||||
String getBaseVersionContent(VirtualFile file);
|
||||
@Nullable
|
||||
VcsRevisionNumber getBaseRevision(VirtualFile file);
|
||||
Pair<VcsRevisionNumber, String> getBaseRevision(@NotNull VirtualFile file);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
@@ -150,45 +151,38 @@ public class VcsFileStatusProvider implements FileStatusProvider, VcsBaseContent
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getBaseVersionContent(final VirtualFile file) {
|
||||
public Pair<VcsRevisionNumber, String> getBaseRevision(@NotNull final VirtualFile file) {
|
||||
final Change change = ChangeListManager.getInstance(myProject).getChange(file);
|
||||
if (change != null) {
|
||||
final ContentRevision beforeRevision = change.getBeforeRevision();
|
||||
if (beforeRevision instanceof BinaryContentRevision) {
|
||||
return null;
|
||||
}
|
||||
if (beforeRevision instanceof BinaryContentRevision) return null;
|
||||
if (beforeRevision != null) {
|
||||
String content;
|
||||
try {
|
||||
content = beforeRevision.getContent();
|
||||
}
|
||||
catch(VcsException ex) {
|
||||
catch (VcsException ex) {
|
||||
content = null;
|
||||
}
|
||||
if (content == null) myHaveEmptyContentRevisions = true;
|
||||
return content;
|
||||
if (content == null) {
|
||||
myHaveEmptyContentRevisions = true;
|
||||
return null;
|
||||
}
|
||||
return Pair.create(beforeRevision.getRevisionNumber(), content);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isDocumentModified(file)) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
|
||||
String content = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
|
||||
@Override
|
||||
public String compute() {
|
||||
return LoadTextUtil.loadText(file).toString();
|
||||
}
|
||||
});
|
||||
return Pair.create(VcsRevisionNumber.NULL, content);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VcsRevisionNumber getBaseRevision(VirtualFile file) {
|
||||
final Change change = ChangeListManager.getInstance(myProject).getChange(file);
|
||||
if (change != null && change.getBeforeRevision() != null && (! FileStatus.ADDED.equals(change.getFileStatus()))) {
|
||||
return change.getBeforeRevision().getRevisionNumber();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user