Search in sources :

Example 16 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class FileAnnotation method createDefaultCurrentFileRevisionProvider.

@Nullable
private static CurrentFileRevisionProvider createDefaultCurrentFileRevisionProvider(@NotNull FileAnnotation annotation) {
    List<VcsFileRevision> revisions = annotation.getRevisions();
    if (revisions == null)
        return null;
    Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
    for (VcsFileRevision revision : revisions) {
        map.put(revision.getRevisionNumber(), revision);
    }
    List<VcsFileRevision> lineToRevision = new ArrayList<>(annotation.getLineCount());
    for (int i = 0; i < annotation.getLineCount(); i++) {
        lineToRevision.add(map.get(annotation.getLineRevisionNumber(i)));
    }
    return (lineNumber) -> {
        LOG.assertTrue(lineNumber >= 0 && lineNumber < lineToRevision.size());
        return lineToRevision.get(lineNumber);
    };
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsKey(com.intellij.openapi.vcs.VcsKey) ContainerUtil(com.intellij.util.containers.ContainerUtil) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) Nullable(org.jetbrains.annotations.Nullable) DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) UpToDateLineNumberProvider(com.intellij.openapi.localVcs.UpToDateLineNumberProvider) Consumer(com.intellij.util.Consumer) 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 17 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class VcsVirtualFile method loadContent.

private void loadContent() throws IOException {
    if (myContent != null)
        return;
    assert myFileRevision != null;
    final VcsFileSystem vcsFileSystem = ((VcsFileSystem) getFileSystem());
    try {
        myFileRevision.loadContent();
        fireBeforeContentsChange();
        myModificationStamp++;
        final VcsRevisionNumber revisionNumber = myFileRevision.getRevisionNumber();
        if (revisionNumber instanceof ShortVcsRevisionNumber) {
            setRevision(((ShortVcsRevisionNumber) revisionNumber).toShortString());
        } else {
            setRevision(revisionNumber.asString());
        }
        myContent = myFileRevision.getContent();
        myCharset = new CharsetToolkit(myContent).guessEncoding(myContent.length);
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            public void run() {
                vcsFileSystem.fireContentsChanged(this, VcsVirtualFile.this, 0);
            }
        });
    } catch (VcsException e) {
        myContentLoadFailed = true;
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            public void run() {
                vcsFileSystem.fireBeforeFileDeletion(this, VcsVirtualFile.this);
            }
        });
        myContent = ArrayUtil.EMPTY_BYTE_ARRAY;
        setRevision("0");
        Messages.showMessageDialog(VcsBundle.message("message.text.could.not.load.virtual.file.content", getPresentableUrl(), e.getLocalizedMessage()), VcsBundle.message("message.title.could.not.load.content"), Messages.getInformationIcon());
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            public void run() {
                vcsFileSystem.fireFileDeleted(this, VcsVirtualFile.this, getName(), getParent());
            }
        });
    } catch (ProcessCanceledException ex) {
        myContent = null;
    }
}
Also used : CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) ShortVcsRevisionNumber(com.intellij.openapi.vcs.history.ShortVcsRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) ShortVcsRevisionNumber(com.intellij.openapi.vcs.history.ShortVcsRevisionNumber) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 18 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class ShelvedChange method getChange.

public Change getChange(Project project) {
    // todo unify with
    if (myChange == null) {
        File baseDir = new File(project.getBaseDir().getPath());
        File file = getAbsolutePath(baseDir, myBeforePath);
        FilePath beforePath = VcsUtil.getFilePath(file, false);
        beforePath.refresh();
        ContentRevision beforeRevision = null;
        if (myFileStatus != FileStatus.ADDED) {
            beforeRevision = new CurrentContentRevision(beforePath) {

                @Override
                @NotNull
                public VcsRevisionNumber getRevisionNumber() {
                    return new TextRevisionNumber(VcsBundle.message("local.version.title"));
                }
            };
        }
        ContentRevision afterRevision = null;
        if (myFileStatus != FileStatus.DELETED) {
            FilePath afterPath = VcsUtil.getFilePath(getAbsolutePath(baseDir, myAfterPath), false);
            afterRevision = new PatchedContentRevision(project, beforePath, afterPath);
        }
        myChange = new Change(beforeRevision, afterRevision, myFileStatus);
    }
    return myChange;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class CvsChangeProvider method processFile.

private void processFile(final VirtualFile dir, @Nullable VirtualFile file, Entry entry, final ChangelistBuilder builder, final ProgressIndicator progress) throws VcsException {
    final FilePath filePath = VcsUtil.getFilePath(dir, entry.getFileName());
    final FileStatus status = CvsStatusProvider.getStatus(file, entry);
    final VcsRevisionNumber number = createRevisionNumber(entry.getRevision(), status);
    processStatus(filePath, file, status, number, builder);
    progress.checkCanceled();
    checkSwitchedFile(filePath, builder, dir, entry);
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber)

Example 20 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class GitAnnotationProvider method annotate.

@NotNull
private GitFileAnnotation annotate(@NotNull final FilePath repositoryFilePath, @Nullable final VcsRevisionNumber revision, @NotNull final VirtualFile file) throws VcsException {
    GitVcs vcs = GitVcs.getInstance(myProject);
    assert vcs != null;
    VcsRevisionNumber actualRevision = revision != null ? revision : vcs.getDiffProvider().getCurrentRevision(file);
    if (actualRevision != null) {
        Object annotatedData = myCache.get(repositoryFilePath, GitVcs.getKey(), actualRevision);
        if (annotatedData instanceof CachedData)
            return restoreFromCache(file, actualRevision, (CachedData) annotatedData);
    }
    GitFileAnnotation fileAnnotation = doAnnotate(repositoryFilePath, actualRevision, file);
    if (actualRevision != null) {
        myCache.put(repositoryFilePath, GitVcs.getKey(), actualRevision, cacheData(fileAnnotation));
    }
    return fileAnnotation;
}
Also used : GitVcs(git4idea.GitVcs) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) NotNull(org.jetbrains.annotations.NotNull)

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