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.startup.StartupManager;
|
||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vcs.*;
|
import com.intellij.openapi.vcs.*;
|
||||||
import com.intellij.openapi.vcs.changes.committed.AbstractCalledLater;
|
import com.intellij.openapi.vcs.changes.committed.AbstractCalledLater;
|
||||||
@@ -293,25 +294,19 @@ public class LineStatusTrackerManager implements ProjectComponent, LineStatusTra
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final VcsRevisionNumber baseRevision = myStatusProvider.getBaseRevision(myVirtualFile);
|
final Pair<VcsRevisionNumber, String> baseRevision = myStatusProvider.getBaseRevision(myVirtualFile);
|
||||||
if (baseRevision == null) {
|
if (baseRevision == null) {
|
||||||
log("installTracker() for file " + myVirtualFile.getPath() + " failed: null returned for base revision number");
|
log("installTracker() for file " + myVirtualFile.getPath() + " failed: null returned for base revision number");
|
||||||
reportTrackerBaseLoadFailed();
|
reportTrackerBaseLoadFailed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// loads are sequential (in single threaded QueueProcessor);
|
// 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
|
// 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;
|
++myLoadCounter;
|
||||||
|
|
||||||
final String lastUpToDateContent = myStatusProvider.getBaseVersionContent(myVirtualFile);
|
final String converted = StringUtil.convertLineSeparators(baseRevision.second);
|
||||||
if (lastUpToDateContent == null) {
|
|
||||||
log("installTracker() for file " + myVirtualFile.getPath() + " failed: no up to date content");
|
|
||||||
reportTrackerBaseLoadFailed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String converted = StringUtil.convertLineSeparators(lastUpToDateContent);
|
|
||||||
final Runnable runnable = new Runnable() {
|
final Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (myLock) {
|
synchronized (myLock) {
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.intellij.openapi.vcs.impl;
|
package com.intellij.openapi.vcs.impl;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,8 +27,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* Time: 1:12 PM
|
* Time: 1:12 PM
|
||||||
*/
|
*/
|
||||||
public interface VcsBaseContentProvider {
|
public interface VcsBaseContentProvider {
|
||||||
|
/*
|
||||||
|
* return pair of base revision number and content
|
||||||
|
*
|
||||||
|
* null is returned if an error occurred
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getBaseVersionContent(VirtualFile file);
|
Pair<VcsRevisionNumber, String> getBaseRevision(@NotNull VirtualFile file);
|
||||||
@Nullable
|
|
||||||
VcsRevisionNumber getBaseRevision(VirtualFile file);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
|
|||||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Computable;
|
import com.intellij.openapi.util.Computable;
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.openapi.vcs.*;
|
import com.intellij.openapi.vcs.*;
|
||||||
import com.intellij.openapi.vcs.changes.*;
|
import com.intellij.openapi.vcs.changes.*;
|
||||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||||
@@ -150,45 +151,38 @@ public class VcsFileStatusProvider implements FileStatusProvider, VcsBaseContent
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getBaseVersionContent(final VirtualFile file) {
|
public Pair<VcsRevisionNumber, String> getBaseRevision(@NotNull final VirtualFile file) {
|
||||||
final Change change = ChangeListManager.getInstance(myProject).getChange(file);
|
final Change change = ChangeListManager.getInstance(myProject).getChange(file);
|
||||||
if (change != null) {
|
if (change != null) {
|
||||||
final ContentRevision beforeRevision = change.getBeforeRevision();
|
final ContentRevision beforeRevision = change.getBeforeRevision();
|
||||||
if (beforeRevision instanceof BinaryContentRevision) {
|
if (beforeRevision instanceof BinaryContentRevision) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (beforeRevision != null) {
|
if (beforeRevision != null) {
|
||||||
String content;
|
String content;
|
||||||
try {
|
try {
|
||||||
content = beforeRevision.getContent();
|
content = beforeRevision.getContent();
|
||||||
}
|
}
|
||||||
catch(VcsException ex) {
|
catch (VcsException ex) {
|
||||||
content = null;
|
content = null;
|
||||||
}
|
}
|
||||||
if (content == null) myHaveEmptyContentRevisions = true;
|
if (content == null) {
|
||||||
return content;
|
myHaveEmptyContentRevisions = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Pair.create(beforeRevision.getRevisionNumber(), content);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDocumentModified(file)) {
|
if (isDocumentModified(file)) {
|
||||||
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
|
String content = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
|
||||||
@Override
|
@Override
|
||||||
public String compute() {
|
public String compute() {
|
||||||
return LoadTextUtil.loadText(file).toString();
|
return LoadTextUtil.loadText(file).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return Pair.create(VcsRevisionNumber.NULL, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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