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);
}
}
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;
}
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);
}
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);
}
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());
}
}
}
}
Aggregations