vcs: cleanup
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 17 Aug 2015 16:29:33 +0000 (19:29 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 19 Aug 2015 17:36:01 +0000 (20:36 +0300)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/AbstractFilePatchInProgress.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/BinaryFilePatchInProgress.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/TextFilePatchInProgress.java

index c809196397add1ab5edcf72a83cb5a68565824d6..9356b922023d22608f59f8284c074d3174380601 100644 (file)
 package com.intellij.openapi.vcs.changes.patch;
 
 import com.intellij.openapi.diff.impl.patch.FilePatch;
+import com.intellij.openapi.diff.impl.patch.PatchReader;
 import com.intellij.openapi.diff.impl.patch.formove.PathMerger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Couple;
-import com.intellij.openapi.util.Getter;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.FileStatus;
-import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.Change;
 import com.intellij.openapi.vcs.changes.ContentRevision;
 import com.intellij.openapi.vcs.changes.CurrentContentRevision;
-import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
 import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
-import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.PathUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -163,7 +159,7 @@ public abstract class AbstractFilePatchInProgress<T extends FilePatch> implement
            : (myCurrentBase != null) ? VcsUtil.getFilePath(myCurrentBase) : VcsUtil.getFilePath(myIoCurrentBase, false);
   }
 
-  private boolean isConflictingChange() {
+  protected boolean isConflictingChange() {
     if (myConflicts == null) {
       if ((myCurrentBase != null) && (myNewContentRevision instanceof LazyPatchContentRevision)) {
         ((LazyPatchContentRevision)myNewContentRevision).getContent();
@@ -199,36 +195,9 @@ public abstract class AbstractFilePatchInProgress<T extends FilePatch> implement
     public AbstractFilePatchInProgress getPatchInProgress() {
       return myPatchInProgress;
     }
-
-    @Nullable
-    public DiffRequestPresentable createDiffRequestPresentable(final Project project, final Getter<CharSequence> baseContents) {
-      return new DiffRequestPresentableProxy() {
-        @NotNull
-        @Override
-        public DiffRequestPresentable init() throws VcsException {
-          if (myPatchInProgress.isConflictingChange()) {
-            return myPatchInProgress.diffRequestForConflictingChanges(project, PatchChange.this, baseContents);
-          }
-          else {
-            return new ChangeDiffRequestPresentable(project, PatchChange.this);
-          }
-        }
-
-        @Override
-        public String getPathPresentation() {
-          final File ioCurrentBase = myPatchInProgress.getIoCurrentBase();
-          return ioCurrentBase == null ? myPatchInProgress.getCurrentPath() : ioCurrentBase.getPath();
-        }
-      };
-    }
   }
 
-  @NotNull
-  protected DiffRequestPresentable diffRequestForConflictingChanges(@NotNull Project project,
-                                                                    @NotNull PatchChange change,
-                                                                    @NotNull Getter<CharSequence> baseContents) {
-    return new ChangeDiffRequestPresentable(project, change);
-  }
+  public abstract DiffRequestPresentable getDiffRequestPresentable(Project project, PatchReader baseContents);
 
   public List<VirtualFile> getAutoBasesCopy() {
     final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>(myAutoBases.size() + 1);
index 1f5cd8e383d36b04a8e4860ef2a115b47b525543..47903d7cfb4eb2c810a483df49b8ba61dc2db890 100644 (file)
@@ -37,13 +37,13 @@ import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.ObjectsConvertor;
 import com.intellij.openapi.vcs.VcsBundle;
-import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.Change;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
-import com.intellij.openapi.vcs.changes.actions.*;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.ShowDiffAction;
+import com.intellij.openapi.vcs.changes.actions.ShowDiffUIContext;
 import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
-import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFile;
 import com.intellij.openapi.vcs.changes.ui.*;
 import com.intellij.openapi.vfs.*;
 import com.intellij.ui.DocumentAdapter;
@@ -999,35 +999,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
         for (AbstractFilePatchInProgress.PatchChange change : changes) {
           final AbstractFilePatchInProgress patchInProgress = change.getPatchInProgress();
           if (!patchInProgress.baseExistsOrAdded()) continue;
-          DiffRequestPresentable diffRequestPresentable;
-          if (patchInProgress instanceof BinaryFilePatchInProgress) {
-            final ShelvedBinaryFile file = ((BinaryFilePatchInProgress)patchInProgress).getPatch().getShelvedBinaryFile();
-            diffRequestPresentable = new DiffRequestPresentableProxy() {
-              @NotNull
-              @Override
-              public DiffRequestPresentable init() throws VcsException {
-                return new ChangeDiffRequestPresentable(myProject, file.createChange(myProject));
-              }
-
-              @Override
-              public String getPathPresentation() {
-                final File file1 = new File(VfsUtilCore.virtualToIoFile(patchInProgress.getBase()),
-                                            file.AFTER_PATH == null ? file.BEFORE_PATH : file.AFTER_PATH);
-                return FileUtil.toSystemDependentName(file1.getPath());
-              }
-            };
-          }
-          else {
-            final FilePatch patch = patchInProgress.getPatch();
-            final String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
-            diffRequestPresentable =
-              change.createDiffRequestPresentable(myProject, new Getter<CharSequence>() {
-                @Override
-                public CharSequence get() {
-                  return myReader.getBaseRevision(myProject, path);
-                }
-              });
-          }
+          DiffRequestPresentable diffRequestPresentable = patchInProgress.getDiffRequestPresentable(myProject, myReader);
           if (diffRequestPresentable != null) {
             diffRequestPresentableList.add(diffRequestPresentable);
           }
index 148a6135a475fe53db67b41ca28864eabb9b407e..855ad27e2b331bac2433316b321b0d96363ba339 100644 (file)
  */
 package com.intellij.openapi.vcs.changes.patch;
 
+import com.intellij.openapi.diff.impl.patch.PatchReader;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.ContentRevision;
+import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
 import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager.ShelvedBinaryFilePatch;
 import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryContentRevision;
+import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFile;
+import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.vcsUtil.VcsUtil;
+import org.jetbrains.annotations.NotNull;
 
+import java.io.File;
 import java.util.Collection;
 
 public class BinaryFilePatchInProgress extends AbstractFilePatchInProgress<ShelvedBinaryFilePatch> {
@@ -46,4 +57,23 @@ public class BinaryFilePatchInProgress extends AbstractFilePatchInProgress<Shelv
     }
     return myNewContentRevision;
   }
+
+  @Override
+  public DiffRequestPresentable getDiffRequestPresentable(final Project project, final PatchReader baseContents) {
+    final ShelvedBinaryFile file = getPatch().getShelvedBinaryFile();
+    return new DiffRequestPresentableProxy() {
+      @NotNull
+      @Override
+      public DiffRequestPresentable init() throws VcsException {
+        return new ChangeDiffRequestPresentable(project, file.createChange(project));
+      }
+
+      @Override
+      public String getPathPresentation() {
+        final File file1 = new File(VfsUtilCore.virtualToIoFile(getBase()),
+                                    file.AFTER_PATH == null ? file.BEFORE_PATH : file.AFTER_PATH);
+        return FileUtil.toSystemDependentName(file1.getPath());
+      }
+    };
+  }
 }
index c8068b33afdf3dd9609b1beb247b7204b76bb659..1e48da7bedfb53e18f7bba66947aa021237df385 100644 (file)
 package com.intellij.openapi.vcs.changes.patch;
 
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.diff.impl.patch.FilePatch;
+import com.intellij.openapi.diff.impl.patch.PatchReader;
 import com.intellij.openapi.diff.impl.patch.TextFilePatch;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Getter;
 import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.ContentRevision;
 import com.intellij.openapi.vcs.changes.SimpleContentRevision;
+import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
 import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
+import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.vcsUtil.VcsUtil;
 import org.jetbrains.annotations.NotNull;
 
+import java.io.File;
 import java.util.Collection;
 
 public class TextFilePatchInProgress extends AbstractFilePatchInProgress<TextFilePatch> {
@@ -62,21 +68,44 @@ public class TextFilePatchInProgress extends AbstractFilePatchInProgress<TextFil
     return myNewContentRevision;
   }
 
-  @NotNull
   @Override
-  protected DiffRequestPresentable diffRequestForConflictingChanges(@NotNull final Project project,
-                                                                    @NotNull PatchChange change,
-                                                                    @NotNull final Getter<CharSequence> baseContents) {
-    final Getter<ApplyPatchForBaseRevisionTexts> revisionTextsGetter = new Getter<ApplyPatchForBaseRevisionTexts>() {
+  public DiffRequestPresentable getDiffRequestPresentable(final Project project, final PatchReader patchReader) {
+    final PatchChange change = getChange();
+    final FilePatch patch = getPatch();
+    final String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
+    final Getter<CharSequence> baseContents = new Getter<CharSequence>() {
       @Override
-      public ApplyPatchForBaseRevisionTexts get() {
-        final VirtualFile currentBase = getCurrentBase();
-        return ApplyPatchForBaseRevisionTexts.create(project, currentBase,
-                                                     VcsUtil.getFilePath(currentBase),
-                                                     getPatch(), baseContents);
+      public CharSequence get() {
+        return patchReader.getBaseRevision(project, path);
+      }
+    };
+    return new DiffRequestPresentableProxy() {
+      @NotNull
+      @Override
+      public DiffRequestPresentable init() throws VcsException {
+        if (isConflictingChange()) {
+          final Getter<ApplyPatchForBaseRevisionTexts> revisionTextsGetter = new Getter<ApplyPatchForBaseRevisionTexts>() {
+            @Override
+            public ApplyPatchForBaseRevisionTexts get() {
+              final VirtualFile currentBase = getCurrentBase();
+              return ApplyPatchForBaseRevisionTexts.create(project, currentBase,
+                                                           VcsUtil.getFilePath(currentBase),
+                                                           getPatch(), baseContents);
+            }
+          };
+          return new MergedDiffRequestPresentable(project, revisionTextsGetter,
+                                                  getCurrentBase(), getPatch().getAfterVersionId());
+        }
+        else {
+          return new ChangeDiffRequestPresentable(project, change);
+        }
+      }
+
+      @Override
+      public String getPathPresentation() {
+        final File ioCurrentBase = getIoCurrentBase();
+        return ioCurrentBase == null ? getCurrentPath() : ioCurrentBase.getPath();
       }
     };
-    return new MergedDiffRequestPresentable(project, revisionTextsGetter,
-                                            getCurrentBase(), getPatch().getAfterVersionId());
   }
 }
\ No newline at end of file