Search in sources :

Example 61 with VcsException

use of com.intellij.openapi.vcs.VcsException 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 62 with VcsException

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

the class ActionWithTempFile method execute.

public void execute() throws VcsException {
    try {
        try {
            init();
            executeInternal();
        } finally {
            rollbackChanges();
        }
    } catch (IOException e) {
        throw new VcsException(e);
    }
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException) IOException(java.io.IOException)

Example 63 with VcsException

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

the class SelectFilesToAddTextsToPatchPanel method getBig.

public static Set<Change> getBig(List<Change> changes) {
    final Set<Change> exclude = new HashSet<>();
    for (Change change : changes) {
        // try to estimate size via VF: we assume that base content hasn't been changed much
        VirtualFile virtualFile = getVfFromChange(change);
        if (virtualFile != null) {
            if (isBig(virtualFile)) {
                exclude.add(change);
            }
            continue;
        }
        // otherwise, to avoid regression we have to process context length
        ContentRevision beforeRevision = change.getBeforeRevision();
        if (beforeRevision != null) {
            try {
                String content = beforeRevision.getContent();
                if (content == null) {
                    final FilePath file = beforeRevision.getFile();
                    LOG.info("null content for " + (file.getPath()) + ", is dir: " + (file.isDirectory()));
                    continue;
                }
                if (content.length() > VcsConfiguration.ourMaximumFileForBaseRevisionSize) {
                    exclude.add(change);
                }
            } catch (VcsException e) {
                LOG.info(e);
            }
        }
    }
    return exclude;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) VcsException(com.intellij.openapi.vcs.VcsException) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) HashSet(java.util.HashSet)

Example 64 with VcsException

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

the class ImportIntoShelfAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true);
    FileChooser.chooseFiles(descriptor, project, null, new Consumer<List<VirtualFile>>() {

        @Override
        public void consume(final List<VirtualFile> files) {
            //gatherPatchFiles
            final ProgressManager pm = ProgressManager.getInstance();
            final ShelveChangesManager shelveChangesManager = ShelveChangesManager.getInstance(project);
            final List<VirtualFile> patchTypeFiles = new ArrayList<>();
            final boolean filesFound = pm.runProcessWithProgressSynchronously(new Runnable() {

                @Override
                public void run() {
                    patchTypeFiles.addAll(shelveChangesManager.gatherPatchFiles(files));
                }
            }, "Looking for patch files...", true, project);
            if (!filesFound || patchTypeFiles.isEmpty())
                return;
            if (!patchTypeFiles.equals(files)) {
                final String message = "Found " + (patchTypeFiles.size() == 1 ? "one patch file (" + patchTypeFiles.get(0).getPath() + ")." : (patchTypeFiles.size() + " patch files.")) + "\nContinue with import?";
                final int toImport = Messages.showYesNoDialog(project, message, "Import Patches", Messages.getQuestionIcon());
                if (Messages.NO == toImport)
                    return;
            }
            pm.runProcessWithProgressSynchronously(new Runnable() {

                @Override
                public void run() {
                    final List<VcsException> exceptions = new ArrayList<>();
                    final List<ShelvedChangeList> lists = shelveChangesManager.importChangeLists(patchTypeFiles, new Consumer<VcsException>() {

                        @Override
                        public void consume(VcsException e) {
                            exceptions.add(e);
                        }
                    });
                    if (!lists.isEmpty()) {
                        ShelvedChangesViewManager.getInstance(project).activateView(lists.get(lists.size() - 1));
                    }
                    if (!exceptions.isEmpty()) {
                        AbstractVcsHelper.getInstance(project).showErrors(exceptions, "Import patches into shelf");
                    }
                    if (lists.isEmpty() && exceptions.isEmpty()) {
                        VcsBalloonProblemNotifier.showOverChangesView(project, "No patches found", MessageType.WARNING);
                    }
                }
            }, "Import patches into shelf", true, project);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 65 with VcsException

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

the class VcsHistoryUtil method loadRevisionContent.

@NotNull
public static byte[] loadRevisionContent(@NotNull VcsFileRevision revision) throws VcsException, IOException {
    byte[] content = revision.getContent();
    if (content == null) {
        revision.loadContent();
        content = revision.getContent();
    }
    if (content == null)
        throw new VcsException("Failed to load content for revision " + revision.getRevisionNumber().asString());
    return content;
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VcsException (com.intellij.openapi.vcs.VcsException)200 VirtualFile (com.intellij.openapi.vfs.VirtualFile)89 File (java.io.File)48 NotNull (org.jetbrains.annotations.NotNull)42 FilePath (com.intellij.openapi.vcs.FilePath)35 Change (com.intellij.openapi.vcs.changes.Change)33 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 ArrayList (java.util.ArrayList)24 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 SVNException (org.tmatesoft.svn.core.SVNException)19 Project (com.intellij.openapi.project.Project)17 Ref (com.intellij.openapi.util.Ref)16 Test (org.junit.Test)14 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)13 GitRepository (git4idea.repo.GitRepository)12 Task (com.intellij.openapi.progress.Task)11 List (java.util.List)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)10 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)10