Search in sources :

Example 21 with VcsFileRevision

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

the class AnnotateRevisionFromHistoryAction method performAction.

@Override
protected void performAction(@NotNull Project project, @NotNull FileHistoryUi ui, @NotNull VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
    VcsKey vcsKey = e.getRequiredData(VcsDataKeys.VCS);
    VcsFileRevision revision = ui.createRevision(detail);
    VirtualFile vcsVirtualFile = ui.createVcsVirtualFile(detail);
    if (!VcsHistoryUtil.isEmpty(revision) && vcsVirtualFile != null) {
        AnnotateRevisionActionBase.annotate(vcsVirtualFile, revision, notNull(VcsUtil.findVcsByKey(project, vcsKey)), null, 0);
    }
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision)

Example 22 with VcsFileRevision

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

the class AnnotateRevisionFromHistoryAction method isEnabled.

@Override
protected boolean isEnabled(@NotNull FileHistoryUi ui, @Nullable VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
    VcsKey key = e.getData(VcsDataKeys.VCS);
    if (key == null)
        return false;
    AbstractVcs vcs = VcsUtil.findVcsByKey(notNull(e.getProject()), key);
    if (vcs == null)
        return false;
    AnnotationProvider provider = vcs.getAnnotationProvider();
    if (provider == null)
        return false;
    if (detail != null) {
        VcsFileRevision fileRevision = ui.createRevision(detail);
        return AnnotateRevisionActionBase.isEnabled(vcs, ui.createVcsVirtualFile(fileRevision), fileRevision);
    }
    return true;
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 23 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision 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)

Example 24 with VcsFileRevision

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

the class CvsAnnotationProvider method annotate.

public FileAnnotation annotate(VirtualFile cvsVirtualFile, String revision, CvsEnvironment environment) throws VcsException {
    // the VirtualFile has a full path if annotate is called from history (when we have a real file on disk),
    // and has the path equal to a CVS module name if annotate is called from the CVS repository browser
    // (when there's no real path)
    boolean hasLocalFile = false;
    File cvsFile = new File(cvsVirtualFile.getPath());
    if (cvsFile.isAbsolute()) {
        hasLocalFile = true;
        cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile));
    }
    final boolean binary = annotateBinary(cvsVirtualFile, environment);
    final AnnotateOperation annotateOperation = executeOperation(cvsFile, revision, environment, binary, true);
    final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations();
    final List<VcsFileRevision> revisions;
    if (hasLocalFile) {
        final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile);
        revisions = myCvsHistoryProvider.createRevisions(filePath);
        // in annotation cvs returns only 8 symbols of username
        // try to find usernames in history and use them
        adjustAnnotation(revisions, lineAnnotations);
    } else {
        // imitation
        revisions = new ArrayList<>();
        final Set<String> usedRevisions = new HashSet<>();
        for (Annotation annotation : lineAnnotations) {
            if (!usedRevisions.contains(annotation.getRevision())) {
                revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate()));
                usedRevisions.add(annotation.getRevision());
            }
        }
    }
    return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile, revision, myProject);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) AnnotateOperation(com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Annotation(com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 25 with VcsFileRevision

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

the class CvsAnnotationProvider method adjustAnnotation.

private static void adjustAnnotation(@Nullable List<VcsFileRevision> revisions, @NotNull Annotation[] lineAnnotations) {
    if (revisions != null) {
        final Map<String, VcsFileRevision> revisionMap = new HashMap<>();
        for (VcsFileRevision vcsFileRevision : revisions) {
            revisionMap.put(vcsFileRevision.getRevisionNumber().asString(), vcsFileRevision);
        }
        for (Annotation lineAnnotation : lineAnnotations) {
            final String revisionNumber = lineAnnotation.getRevision();
            final VcsFileRevision revision = revisionMap.get(revisionNumber);
            if (revision != null) {
                lineAnnotation.setUser(revision.getAuthor());
                lineAnnotation.setDate(revision.getRevisionDate());
            }
        }
    }
}
Also used : VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Annotation(com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation)

Aggregations

VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 Nullable (org.jetbrains.annotations.Nullable)13 FilePath (com.intellij.openapi.vcs.FilePath)12 Project (com.intellij.openapi.project.Project)10 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)8 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)7 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)7 VcsKey (com.intellij.openapi.vcs.VcsKey)5 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)5 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)5 Semaphore (com.intellij.util.concurrency.Semaphore)5 GitFileRevision (git4idea.GitFileRevision)5 Test (org.junit.Test)5 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)4 Annotation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)3 HashMap (com.intellij.util.containers.HashMap)3