Search in sources :

Example 91 with FilePath

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

the class TabbedShowHistoryAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull VcsContext context) {
    Project project = assertNotNull(context.getProject());
    Pair<FilePath, VirtualFile> pair = getPathAndParentFile(context);
    FilePath path = assertNotNull(pair.first);
    VirtualFile fileOrParent = assertNotNull(pair.second);
    AbstractVcs vcs = assertNotNull(ChangesUtil.getVcsForFile(fileOrParent, project));
    if (canShowNewFileHistory(project, path)) {
        showNewFileHistory(project, path);
    } else {
        showOldFileHistory(project, vcs, path);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 92 with FilePath

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

the class ChangeDiffRequestProducer method createContent.

@NotNull
public static DiffContent createContent(@Nullable Project project, @Nullable ContentRevision revision, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    try {
        indicator.checkCanceled();
        if (revision == null)
            return DiffContentFactory.getInstance().createEmpty();
        FilePath filePath = revision.getFile();
        DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
        if (revision instanceof CurrentContentRevision) {
            VirtualFile vFile = ((CurrentContentRevision) revision).getVirtualFile();
            if (vFile == null)
                throw new DiffRequestProducerException("Can't get current revision content");
            return contentFactory.create(project, vFile);
        }
        if (revision instanceof BinaryContentRevision) {
            byte[] content = ((BinaryContentRevision) revision).getBinaryContent();
            if (content == null) {
                throw new DiffRequestProducerException("Can't get binary revision content");
            }
            return contentFactory.createFromBytes(project, content, filePath);
        }
        if (revision instanceof ByteBackedContentRevision) {
            byte[] revisionContent = ((ByteBackedContentRevision) revision).getContentAsBytes();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.createFromBytes(project, revisionContent, filePath);
        } else {
            String revisionContent = revision.getContent();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.create(project, revisionContent, filePath);
        }
    } catch (IOException | VcsException e) {
        LOG.info(e);
        throw new DiffRequestProducerException(e);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) VcsException(com.intellij.openapi.vcs.VcsException) DiffContentFactoryEx(com.intellij.diff.DiffContentFactoryEx) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with FilePath

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

the class ChangeDiffRequestProducer method getRequestTitle.

@NotNull
public static String getRequestTitle(@NotNull Change change) {
    ContentRevision bRev = change.getBeforeRevision();
    ContentRevision aRev = change.getAfterRevision();
    assert bRev != null || aRev != null;
    if (bRev != null && aRev != null) {
        FilePath bPath = bRev.getFile();
        FilePath aPath = aRev.getFile();
        if (bPath.equals(aPath)) {
            return DiffRequestFactoryImpl.getContentTitle(bPath);
        } else {
            return DiffRequestFactoryImpl.getTitle(bPath, aPath, " -> ");
        }
    } else if (bRev != null) {
        return DiffRequestFactoryImpl.getContentTitle(bRev.getFile());
    } else {
        return DiffRequestFactoryImpl.getContentTitle(aRev.getFile());
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with FilePath

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

the class AbstractMissingFilesAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final List<FilePath> files = e.getData(ChangesListView.MISSING_FILES_DATA_KEY);
    if (files == null)
        return;
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Runnable action = new Runnable() {

        public void run() {
            final List<VcsException> allExceptions = new ArrayList<>();
            ChangesUtil.processFilePathsByVcs(project, files, (vcs, items) -> {
                final List<VcsException> exceptions = processFiles(vcs, files);
                if (exceptions != null) {
                    allExceptions.addAll(exceptions);
                }
            });
            for (FilePath file : files) {
                VcsDirtyScopeManager.getInstance(project).fileDirty(file);
            }
            ChangesViewManager.getInstance(project).scheduleRefresh();
            if (allExceptions.size() > 0) {
                AbstractVcsHelper.getInstance(project).showErrors(allExceptions, "VCS Errors");
            }
        }
    };
    if (synchronously()) {
        action.run();
    } else {
        progressManager.runProcessWithProgressSynchronously(action, getName(), true, project);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList)

Example 95 with FilePath

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

the class ChangeListsIndexes method getDelta.

/**
   * this method is called after each local changes refresh and collects all:
   * - paths that are new in local changes
   * - paths that are no more changed locally
   * - paths that were and are changed, but base revision has changed (ex. external update)
   * (for RemoteRevisionsCache and annotation listener)
   */
public void getDelta(final ChangeListsIndexes newIndexes, Set<BaseRevision> toRemove, Set<BaseRevision> toAdd, Set<BeforeAfter<BaseRevision>> toModify) {
    TreeMap<FilePath, Data> oldMap = myMap;
    TreeMap<FilePath, Data> newMap = newIndexes.myMap;
    Set<FilePath> oldFiles = oldMap.keySet();
    Set<FilePath> newFiles = newMap.keySet();
    final Set<FilePath> toRemoveSet = newHashSet(oldFiles);
    toRemoveSet.removeAll(newFiles);
    final Set<FilePath> toAddSet = newHashSet(newFiles);
    toAddSet.removeAll(oldFiles);
    final Set<FilePath> toModifySet = newHashSet(oldFiles);
    toModifySet.removeAll(toRemoveSet);
    for (FilePath s : toRemoveSet) {
        final Data data = oldMap.get(s);
        toRemove.add(createBaseRevision(s, data));
    }
    for (FilePath s : toAddSet) {
        final Data data = newMap.get(s);
        toAdd.add(createBaseRevision(s, data));
    }
    for (FilePath s : toModifySet) {
        final Data oldData = oldMap.get(s);
        final Data newData = newMap.get(s);
        assert oldData != null && newData != null;
        if (!oldData.sameRevisions(newData)) {
            toModify.add(new BeforeAfter<>(createBaseRevision(s, oldData), createBaseRevision(s, newData)));
        }
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)167 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 NotNull (org.jetbrains.annotations.NotNull)43 VcsException (com.intellij.openapi.vcs.VcsException)34 File (java.io.File)30 Change (com.intellij.openapi.vcs.changes.Change)26 Nullable (org.jetbrains.annotations.Nullable)22 Project (com.intellij.openapi.project.Project)20 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)15 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)13 FileStatus (com.intellij.openapi.vcs.FileStatus)10 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)8 GitRepository (git4idea.repo.GitRepository)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Test (org.junit.Test)6 StringUtil (com.intellij.openapi.util.text.StringUtil)5 Logger (com.intellij.openapi.diagnostic.Logger)4