Search in sources :

Example 51 with FilePath

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

the class VcsLogPathsIndex method iterateCommits.

public void iterateCommits(@NotNull Collection<FilePath> paths, @NotNull ObjIntConsumer<Couple<FilePath>> consumer) throws IOException, StorageException {
    Set<Integer> startIds = getPathIds(paths);
    Set<Integer> allIds = ContainerUtil.newHashSet(startIds);
    Set<Integer> newIds = ContainerUtil.newHashSet();
    while (!startIds.isEmpty()) {
        for (int currentPathId : startIds) {
            FilePath currentPath = VcsUtil.getFilePath(myPathsIndexer.myPathsEnumerator.valueOf(currentPathId));
            iterateCommitIdsAndValues(currentPathId, (renamedPathId, commitId) -> {
                FilePath renamedPath = null;
                if (renamedPathId != null) {
                    if (!allIds.contains(renamedPathId)) {
                        newIds.add(renamedPathId);
                    }
                    try {
                        renamedPath = VcsUtil.getFilePath(myPathsIndexer.myPathsEnumerator.valueOf(renamedPathId));
                    } catch (IOException e) {
                        LOG.error(e);
                    }
                }
                consumer.accept(Couple.of(currentPath, renamedPath), commitId);
            });
        }
        startIds = ContainerUtil.newHashSet(newIds);
        allIds.addAll(startIds);
        newIds.clear();
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) IOException(java.io.IOException)

Example 52 with FilePath

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

the class CvsCheckinHandlerFactory method createVcsHandler.

@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
    return new CheckinHandler() {

        @Nullable
        public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
            final Project project = panel.getProject();
            final CvsVcs2 cvs = CvsVcs2.getInstance(project);
            final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
            final Collection<VirtualFile> roots = panel.getRoots();
            final Collection<FilePath> files = new HashSet<>();
            for (VirtualFile root : roots) {
                final VcsRoot vcsRoot = vcsManager.getVcsRootObjectFor(root);
                if (vcsRoot == null || vcsRoot.getVcs() != cvs) {
                    continue;
                }
                files.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root));
            }
            return new AdditionalOptionsPanel(CvsConfiguration.getInstance(project), files, project);
        }
    };
}
Also used : Disposable(com.intellij.openapi.Disposable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) VcsRoot(com.intellij.openapi.vcs.VcsRoot) AdditionalOptionsPanel(com.intellij.cvsSupport2.checkinProject.AdditionalOptionsPanel) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with FilePath

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

the class ModuleVcsPathPresenter method getPresentableRelativePath.

@Override
public String getPresentableRelativePath(@NotNull final ContentRevision fromRevision, @NotNull final ContentRevision toRevision) {
    final FilePath fromPath = fromRevision.getFile();
    final FilePath toPath = toRevision.getFile();
    // need to use parent path because the old file is already not there
    final VirtualFile fromParent = getParentFile(fromPath);
    final VirtualFile toParent = getParentFile(toPath);
    if (fromParent != null && toParent != null) {
        String moduleResult = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

            @Override
            public String compute() {
                final boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files");
                ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
                Module fromModule = fileIndex.getModuleForFile(fromParent, hideExcludedFiles);
                Module toModule = fileIndex.getModuleForFile(toParent, hideExcludedFiles);
                if (fromModule == null || toModule == null || fromModule.equals(toModule))
                    return null;
                VirtualFile fromContentRoot = fileIndex.getContentRootForFile(fromParent, hideExcludedFiles);
                if (fromContentRoot == null)
                    return null;
                String relativePath = VfsUtilCore.getRelativePath(fromParent, fromContentRoot, File.separatorChar);
                assert relativePath != null;
                relativePath += File.separatorChar;
                if (!fromPath.getName().equals(toPath.getName())) {
                    relativePath += fromPath.getName();
                }
                return getPresentableRelativePathFor(fromModule, fromContentRoot, relativePath);
            }
        });
        if (moduleResult != null)
            return moduleResult;
    }
    final RelativePathCalculator calculator = new RelativePathCalculator(toPath.getPath(), fromPath.getPath());
    calculator.execute();
    final String result = calculator.getResult();
    return result != null ? result.replace("/", File.separator) : null;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) RelativePathCalculator(com.intellij.openapi.vcs.changes.patch.RelativePathCalculator) Module(com.intellij.openapi.module.Module)

Example 54 with FilePath

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

the class ShowDiffWithLocalFromHistoryAction method performAction.

@Override
protected void performAction(@NotNull Project project, @NotNull FileHistoryUi ui, @NotNull VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
    if (ChangeListManager.getInstance(project).isFreezedWithNotification(null))
        return;
    FilePath path = e.getRequiredData(VcsDataKeys.FILE_PATH);
    VcsFileRevision revision = ui.createRevision(detail);
    if (revision != null) {
        StandardDiffFromHistoryHandler handler = new StandardDiffFromHistoryHandler();
        handler.showDiffForTwo(project, path, revision, new CurrentRevision(notNull(path.getVirtualFile()), VcsRevisionNumber.NULL));
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) StandardDiffFromHistoryHandler(com.intellij.openapi.vcs.history.StandardDiffFromHistoryHandler) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) CurrentRevision(com.intellij.openapi.vcs.history.CurrentRevision)

Example 55 with FilePath

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

the class CompareRevisionsFromHistoryAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
    FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
    if (e.getInputEvent() instanceof MouseEvent && ui.getTable().isResizingColumns()) {
        // disable action during columns resize
        return;
    }
    VcsLogUtil.triggerUsage(e);
    List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
    if (commits.size() != 1 && commits.size() != 2)
        return;
    List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
    ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
        if (details.size() == 2) {
            VcsFileRevision newestRevision = ui.createRevision(details.get(0));
            VcsFileRevision olderRevision = ui.createRevision(details.get(1));
            if (olderRevision != null && newestRevision != null) {
                myDiffHandler.showDiffForTwo(project, filePath, olderRevision, newestRevision);
            }
        } else if (details.size() == 1) {
            VcsFullCommitDetails detail = ObjectUtils.notNull(ContainerUtil.getFirstItem(details));
            List<Change> changes = ui.collectRelevantChanges(detail);
            if (filePath.isDirectory()) {
                VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(), ContainerUtil.newArrayList(changes));
            } else {
                ShowDiffAction.showDiffForChange(project, changes, 0, new ShowDiffContext());
            }
        }
    }, null);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) CommitId(com.intellij.vcs.log.CommitId) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) List(java.util.List) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

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