use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class SvnHistoryTest method testLocallyRenamedFileHistory.
@Test
public void testLocallyRenamedFileHistory() throws Exception {
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
myCnt = 0;
final VcsHistoryProvider provider = SvnVcs.getInstance(myProject).getVcsHistoryProvider();
final SubTree tree = new SubTree(myWorkingCopyDir);
checkin();
for (int i = 0; i < 10; i++) {
VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n" + i);
checkin();
}
VcsTestUtil.renameFileInCommand(myProject, tree.myS1File, "renamed.txt");
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
ChangeListManager.getInstance(myProject).ensureUpToDate(false);
final Semaphore semaphore = new Semaphore();
semaphore.down();
provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myS1File), new VcsAppendableHistorySessionPartner() {
@Override
public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
}
@Override
public void acceptRevision(VcsFileRevision revision) {
++myCnt;
}
@Override
public void reportException(VcsException exception) {
throw new RuntimeException(exception);
}
@Override
public void finished() {
semaphore.up();
}
@Override
public void beforeRefresh() {
}
@Override
public void forceRefresh() {
}
});
semaphore.waitFor(1000);
Assert.assertEquals(11, myCnt);
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class SvnEditCommitMessageFromFileHistoryAction method update.
@Override
public void update(AnActionEvent e) {
final VcsKey vcsKey = e.getData(VcsDataKeys.VCS);
final boolean isSvn = SvnVcs.getKey().equals(vcsKey);
e.getPresentation().setVisible(isSvn);
final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
e.getPresentation().setEnabled(isSvn && revision != null);
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class SvnEditCommitMessageFromFileHistoryAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null)
return;
final VcsKey vcsKey = e.getData(VcsDataKeys.VCS);
if (vcsKey == null || !SvnVcs.getKey().equals(vcsKey))
return;
final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
final VirtualFile revisionVirtualFile = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
if (revision == null || revisionVirtualFile == null)
return;
final SvnFileRevision svnFileRevision = (SvnFileRevision) revision;
final Consumer<String> listener = VcsDataKeys.REMOTE_HISTORY_CHANGED_LISTENER.getData(e.getDataContext());
SvnEditCommitMessageAction.askAndEditRevision(svnFileRevision.getRevision().getNumber(), svnFileRevision.getCommitMessage(), (SvnRepositoryLocation) svnFileRevision.getChangedRepositoryPath(), project, newMessage -> {
svnFileRevision.setCommitMessage(newMessage);
if (listener != null) {
listener.consume(newMessage);
}
ProjectLevelVcsManager.getInstance(project).getVcsHistoryCache().editCached(VcsUtil.getFilePath(revisionVirtualFile), vcsKey, revisions -> {
for (VcsFileRevision fileRevision : revisions) {
if (!(fileRevision instanceof SvnFileRevision))
continue;
if (((SvnFileRevision) fileRevision).getRevision().getNumber() == svnFileRevision.getRevision().getNumber()) {
((SvnFileRevision) fileRevision).setCommitMessage(newMessage);
break;
}
}
});
}, true);
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class MergeSourceDetailsAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
if (!enabled(e))
return;
final Project project = e.getData(CommonDataKeys.PROJECT);
final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
final VirtualFile revisionVirtualFile = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
SvnMergeSourceDetails.showMe(project, (SvnFileRevision) revision, revisionVirtualFile);
}
use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.
the class AnnotateStackTraceAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
myIsLoading = true;
ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {
private final Object LOCK = new Object();
private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);
private MyActiveAnnotationGutter myGutter;
@Override
public void onCancel() {
myEditor.getGutter().closeAllAnnotations();
}
@Override
public void onFinished() {
myIsLoading = false;
Disposer.dispose(myUpdateQueue);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
ApplicationManager.getApplication().runReadAction(() -> {
for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
indicator.checkCanceled();
VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
if (file == null)
continue;
files2lines.putValue(file, line);
}
});
files2lines.entrySet().forEach(entry -> {
indicator.checkCanceled();
VirtualFile file = entry.getKey();
Collection<Integer> lines = entry.getValue();
LastRevision revision = getLastRevision(file);
if (revision == null)
return;
synchronized (LOCK) {
for (Integer line : lines) {
revisions.put(line, revision);
}
}
myUpdateQueue.queue(new Update("update") {
@Override
public void run() {
updateGutter(indicator, revisions);
}
});
});
// myUpdateQueue can be disposed before the last revisions are passed to the gutter
ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
}
@CalledInAwt
private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
if (indicator.isCanceled())
return;
if (myGutter == null) {
myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
}
Map<Integer, LastRevision> revisionsCopy;
synchronized (LOCK) {
revisionsCopy = ContainerUtil.newHashMap(revisions);
}
myGutter.updateData(revisionsCopy);
((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
}
@Nullable
private LastRevision getLastRevision(@NotNull VirtualFile file) {
try {
AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
if (vcs == null)
return null;
VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null)
return null;
FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
if (historyProvider instanceof VcsHistoryProviderEx) {
VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
if (revision == null)
return null;
return LastRevision.create(revision);
} else {
VcsHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
List<VcsFileRevision> list = session.getRevisionList();
if (list == null || list.isEmpty())
return null;
return LastRevision.create(list.get(0));
}
} catch (VcsException ignored) {
LOG.warn(ignored);
return null;
}
}
});
}
Aggregations