use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.
the class VcsContentAnnotationExceptionFilter method applyHeavyFilter.
@Override
public void applyHeavyFilter(@NotNull final Document copiedFragment, int startOffset, int startLineNumber, @NotNull Consumer<AdditionalHighlight> consumer) {
VcsContentAnnotation vcsContentAnnotation = VcsContentAnnotationImpl.getInstance(myProject);
final LocalChangesCorrector localChangesCorrector = new LocalChangesCorrector(myProject);
Trinity<PsiClass, PsiFile, String> previousLineResult = null;
for (int i = 0; i < copiedFragment.getLineCount(); i++) {
final int lineStartOffset = copiedFragment.getLineStartOffset(i);
final int lineEndOffset = copiedFragment.getLineEndOffset(i);
final ExceptionWorker worker = new ExceptionWorker(myCache);
final String lineText = copiedFragment.getText(new TextRange(lineStartOffset, lineEndOffset));
if (ReadAction.compute(() -> worker.execute(lineText, lineEndOffset)) != null) {
VirtualFile vf = worker.getFile().getVirtualFile();
if (vf.getFileSystem().isReadOnly())
continue;
VcsRevisionNumber recentChangeRevision = myRevNumbersCache.get(vf);
if (recentChangeRevision == null) {
recentChangeRevision = vcsContentAnnotation.fileRecentlyChanged(vf);
if (recentChangeRevision == null) {
myRevNumbersCache.put(vf, VcsRevisionNumber.NULL);
} else {
myRevNumbersCache.put(vf, recentChangeRevision);
}
}
if (VcsRevisionNumber.NULL.equals(recentChangeRevision)) {
recentChangeRevision = null;
}
if (localChangesCorrector.isFileAlreadyIdentifiedAsChanged(vf) || ChangeListManager.isFileChanged(myProject, vf) || recentChangeRevision != null) {
final Document document = getDocumentForFile(worker);
if (document == null)
return;
int startFileOffset = worker.getInfo().getThird().getStartOffset();
int idx = lineText.indexOf(':', startFileOffset);
int endIdx = idx == -1 ? worker.getInfo().getThird().getEndOffset() : idx;
consumer.consume(new MyAdditionalHighlight(startOffset + lineStartOffset + startFileOffset + 1, startOffset + lineStartOffset + endIdx));
if (worker.getPsiClass() != null) {
// also check method
final List<TextRange> ranges = findMethodRange(worker, document, previousLineResult);
if (ranges != null) {
boolean methodChanged = false;
for (TextRange range : ranges) {
if (localChangesCorrector.isRangeChangedLocally(vf, document, range)) {
methodChanged = true;
break;
}
final TextRange correctedRange = localChangesCorrector.getCorrectedRange(vf, document, range);
if (vcsContentAnnotation.intervalRecentlyChanged(vf, correctedRange, recentChangeRevision)) {
methodChanged = true;
break;
}
}
if (methodChanged) {
consumer.consume(new MyAdditionalHighlight(startOffset + lineStartOffset + worker.getInfo().getSecond().getStartOffset(), startOffset + lineStartOffset + worker.getInfo().getSecond().getEndOffset()));
}
}
}
}
}
previousLineResult = worker.getResult() == null ? null : new Trinity<>(worker.getPsiClass(), worker.getFile(), worker.getMethod());
}
}
use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.
the class FileAnnotation method createDefaultPreviousFileRevisionProvider.
@Nullable
private static PreviousFileRevisionProvider createDefaultPreviousFileRevisionProvider(@NotNull FileAnnotation annotation) {
List<VcsFileRevision> revisions = annotation.getRevisions();
if (revisions == null)
return null;
Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
for (int i = 0; i < revisions.size(); i++) {
VcsFileRevision revision = revisions.get(i);
VcsFileRevision previousRevision = i + 1 < revisions.size() ? revisions.get(i + 1) : null;
map.put(revision.getRevisionNumber(), previousRevision);
}
List<VcsFileRevision> lineToRevision = new ArrayList<>(annotation.getLineCount());
for (int i = 0; i < annotation.getLineCount(); i++) {
lineToRevision.add(map.get(annotation.getLineRevisionNumber(i)));
}
VcsFileRevision lastRevision = ContainerUtil.getFirstItem(revisions);
return new PreviousFileRevisionProvider() {
@Nullable
@Override
public VcsFileRevision getPreviousRevision(int lineNumber) {
LOG.assertTrue(lineNumber >= 0 && lineNumber < lineToRevision.size());
return lineToRevision.get(lineNumber);
}
@Nullable
@Override
public VcsFileRevision getLastRevision() {
return lastRevision;
}
};
}
use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.
the class ChangesCacheFile method processGroup.
private boolean processGroup(final FileGroup group, final List<IncomingChangeListData> incomingData, final ReceivedChangeListTracker tracker) {
boolean haveUnaccountedUpdatedFiles = false;
final List<Pair<String, VcsRevisionNumber>> list = group.getFilesAndRevisions(myVcsManager);
for (Pair<String, VcsRevisionNumber> pair : list) {
final String file = pair.first;
FilePath path = VcsUtil.getFilePath(file, false);
if (!path.isUnder(myRootPath, false) || pair.second == null) {
continue;
}
if (group.getId().equals(FileGroup.REMOVED_FROM_REPOSITORY_ID)) {
haveUnaccountedUpdatedFiles |= processDeletedFile(path, incomingData, tracker);
} else {
haveUnaccountedUpdatedFiles |= processFile(path, pair.second, incomingData, tracker);
}
}
for (FileGroup childGroup : group.getChildren()) {
haveUnaccountedUpdatedFiles |= processGroup(childGroup, incomingData, tracker);
}
return haveUnaccountedUpdatedFiles;
}
use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.
the class ChangeListWorker method sameBeforeRevision.
private static boolean sameBeforeRevision(final Change change1, final Change change2) {
final ContentRevision b1 = change1.getBeforeRevision();
final ContentRevision b2 = change2.getBeforeRevision();
if (b1 != null && b2 != null) {
final VcsRevisionNumber rn1 = b1.getRevisionNumber();
final VcsRevisionNumber rn2 = b2.getRevisionNumber();
final boolean isBinary1 = (b1 instanceof BinaryContentRevision);
final boolean isBinary2 = (b2 instanceof BinaryContentRevision);
return rn1 != VcsRevisionNumber.NULL && rn2 != VcsRevisionNumber.NULL && rn1.compareTo(rn2) == 0 && isBinary1 == isBinary2;
}
return b1 == null && b2 == null;
}
use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.
the class RemoteRevisionsNumbersCache method directoryMappingChanged.
public void directoryMappingChanged() {
// copy myData under lock
HashSet<String> keys;
synchronized (myLock) {
keys = new HashSet<>(myData.keySet());
}
// collect new vcs for scheduled files
final Map<String, Pair<VirtualFile, AbstractVcs>> vFiles = new HashMap<>();
for (String key : keys) {
final VirtualFile vf = myLfs.refreshAndFindFileByIoFile(new File(key));
final AbstractVcs newVcs = (vf == null) ? null : myVcsManager.getVcsFor(vf);
vFiles.put(key, vf == null ? Pair.create((VirtualFile) null, (AbstractVcs) null) : Pair.create(vf, newVcs));
}
synchronized (myLock) {
keys = new HashSet<>(myData.keySet());
for (String key : keys) {
final Pair<VcsRoot, VcsRevisionNumber> value = myData.get(key);
final VcsRoot storedVcsRoot = value.getFirst();
final Pair<VirtualFile, AbstractVcs> pair = vFiles.get(key);
if (pair == null) {
// already added with new mappings
continue;
}
final VirtualFile vf = pair.getFirst();
final AbstractVcs newVcs = pair.getSecond();
if (newVcs == null) {
myData.remove(key);
getQueue(storedVcsRoot).forceRemove(key);
} else {
final VirtualFile newRoot = myVcsManager.getVcsRootFor(vf);
final VcsRoot newVcsRoot = new VcsRoot(newVcs, newRoot);
if (!storedVcsRoot.equals(newVcsRoot)) {
switchVcs(storedVcsRoot, newVcsRoot, key);
}
}
}
}
}
Aggregations