summaryrefslogtreecommitdiff
path: root/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java')
-rw-r--r--plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java119
1 files changed, 18 insertions, 101 deletions
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java
index 61d08bc94e8c..1d556a8b19cb 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgDiffFromHistoryHandler.java
@@ -15,22 +15,13 @@
*/
package org.zmlx.hg4idea.provider;
-import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogBuilder;
-import com.intellij.openapi.util.Couple;
import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.Change;
-import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
-import com.intellij.openapi.vcs.history.CurrentRevision;
-import com.intellij.openapi.vcs.history.DiffFromHistoryHandler;
-import com.intellij.openapi.vcs.history.VcsFileRevision;
-import com.intellij.openapi.vcs.history.VcsHistoryUtil;
+import com.intellij.openapi.vcs.history.BaseDiffFromHistoryHandler;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,111 +35,37 @@ import java.util.List;
*
* @author Nadya Zabrodina
*/
-public class HgDiffFromHistoryHandler implements DiffFromHistoryHandler {
+public class HgDiffFromHistoryHandler extends BaseDiffFromHistoryHandler<HgFileRevision> {
private static final Logger LOG = Logger.getInstance(HgDiffFromHistoryHandler.class);
- @NotNull private final Project myProject;
-
public HgDiffFromHistoryHandler(@NotNull Project project) {
- myProject = project;
+ super(project);
}
+ @NotNull
@Override
- public void showDiffForOne(@NotNull AnActionEvent e, @NotNull FilePath filePath,
- @NotNull VcsFileRevision previousRevision, @NotNull VcsFileRevision revision) {
- doShowDiff(filePath, previousRevision, revision, false);
+ protected List<Change> getChangesBetweenRevisions(@NotNull FilePath path, @NotNull HgFileRevision rev1, @Nullable HgFileRevision rev2) {
+ return executeDiff(path, rev1, rev2);
}
-
+ @NotNull
@Override
- public void showDiffForTwo(@NotNull FilePath filePath, @NotNull VcsFileRevision revision1, @NotNull VcsFileRevision revision2) {
- doShowDiff(filePath, revision1, revision2, true);
+ protected List<Change> getAffectedChanges(@NotNull FilePath path, @NotNull HgFileRevision rev) throws VcsException {
+ return executeDiff(path, null, rev);
}
- private void doShowDiff(@NotNull FilePath filePath, @NotNull VcsFileRevision revision1, @NotNull VcsFileRevision revision2,
- boolean autoSort) {
- if (!filePath.isDirectory()) {
- VcsHistoryUtil.showDifferencesInBackground(myProject, filePath, revision1, revision2, autoSort);
- }
- else if (revision2 instanceof CurrentRevision) {
- HgFileRevision left = (HgFileRevision)revision1;
- showDiffForDirectory(filePath, left, null);
- }
- else if (revision1.equals(VcsFileRevision.NULL)) {
- HgFileRevision right = (HgFileRevision)revision2;
- showDiffForDirectory(filePath, null, right);
- }
- else {
- HgFileRevision left = (HgFileRevision)revision1;
- HgFileRevision right = (HgFileRevision)revision2;
- if (autoSort) {
- Couple<VcsFileRevision> pair = VcsHistoryUtil.sortRevisions(revision1, revision2);
- left = (HgFileRevision)pair.first;
- right = (HgFileRevision)pair.second;
- }
- showDiffForDirectory(filePath, left, right);
- }
+ @NotNull
+ @Override
+ protected String getPresentableName(@NotNull HgFileRevision revision) {
+ return revision.getRevisionNumber().getChangeset();
}
- private void showDiffForDirectory(@NotNull final FilePath path,
- @Nullable final HgFileRevision rev1,
- @Nullable final HgFileRevision rev2) {
+ @NotNull
+ private List<Change> executeDiff(@NotNull FilePath path, @Nullable HgFileRevision rev1, @Nullable HgFileRevision rev2) {
VirtualFile root = VcsUtil.getVcsRootFor(myProject, path);
LOG.assertTrue(root != null, "Repository is null for " + path);
- calculateDiffInBackground(root, path, rev1, rev2, new Consumer<List<Change>>() {
- @Override
- public void consume(List<Change> changes) {
- showDirDiffDialog(path, rev1 != null ? rev1.getRevisionNumber().getChangeset() : null,
- rev2 != null ? rev2.getRevisionNumber().getChangeset() : null, changes);
- }
- });
- }
-
- // rev1 == null => rev2 is the initial commit
- // rev2 == null => comparing rev1 with local
- private void calculateDiffInBackground(@NotNull final VirtualFile root, @NotNull final FilePath path,
- @Nullable final HgFileRevision rev1, @Nullable final HgFileRevision rev2,
- final Consumer<List<Change>> successHandler) {
- new Task.Backgroundable(myProject, "Comparing revisions...") {
- private List<Change> myChanges;
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- if (myProject != null) {
- myChanges = HgUtil.getDiff(HgDiffFromHistoryHandler.this.myProject, root, path, rev1, rev2);
- }
- }
-
- @Override
- public void onSuccess() {
- successHandler.consume(myChanges);
- }
- }.queue();
- }
-
- private void showDirDiffDialog(@NotNull FilePath path, @Nullable String hash1, @Nullable String hash2, @NotNull List<Change> diff) {
- DialogBuilder dialogBuilder = new DialogBuilder(myProject);
- String title;
- if (hash2 != null) {
- if (hash1 != null) {
- title = String.format("Difference between %s and %s in %s", hash1, hash2, path.getName());
- }
- else {
- title = String.format("Initial commit %s in %s", hash2, path.getName());
- }
- }
- else {
- LOG.assertTrue(hash1 != null, "hash1 and hash2 can't both be null. Path: " + path);
- title = String.format("Difference between %s and local version in %s", hash1, path.getName());
- }
- dialogBuilder.setTitle(title);
- dialogBuilder.setActionDescriptors(new DialogBuilder.ActionDescriptor[]{new DialogBuilder.CloseDialogAction()});
- final ChangesBrowser changesBrowser = new ChangesBrowser(myProject, null, diff, null, false, true,
- null, ChangesBrowser.MyUseCase.COMMITTED_CHANGES, null);
- changesBrowser.setChangesToDisplay(diff);
- dialogBuilder.setCenterPanel(changesBrowser);
- dialogBuilder.showNotModal();
+ return HgUtil.getDiff(myProject, root, path, rev1, rev2);
}
-}
-
+} \ No newline at end of file