Search in sources :

Example 1 with VcsRevisionNumber

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Trinity(com.intellij.openapi.util.Trinity) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) ExceptionWorker(com.intellij.execution.filters.ExceptionWorker) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber)

Example 2 with VcsRevisionNumber

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;
        }
    };
}
Also used : HashMap(com.intellij.util.containers.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with VcsRevisionNumber

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;
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) FileGroup(com.intellij.openapi.vcs.update.FileGroup) Pair(com.intellij.openapi.util.Pair)

Example 4 with VcsRevisionNumber

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;
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber)

Example 5 with VcsRevisionNumber

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);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRoot(com.intellij.openapi.vcs.VcsRoot) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Aggregations

VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)48 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)11 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Project (com.intellij.openapi.project.Project)5 VcsException (com.intellij.openapi.vcs.VcsException)4 File (java.io.File)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Pair (com.intellij.openapi.util.Pair)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 VcsRoot (com.intellij.openapi.vcs.VcsRoot)3 Change (com.intellij.openapi.vcs.changes.Change)3 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)3 HashMap (com.intellij.util.containers.HashMap)3 DiffContent (com.intellij.diff.contents.DiffContent)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2