private List<CommittedChangeList> loadSvnChangeListsForPatch(TreeConflictDescription description)
      throws VcsException {
    long max = description.getSourceRightVersion().getPegRevision();
    long min = description.getSourceLeftVersion().getPegRevision();

    final ChangeBrowserSettings settings = new ChangeBrowserSettings();
    settings.USE_CHANGE_BEFORE_FILTER = settings.USE_CHANGE_AFTER_FILTER = true;
    settings.CHANGE_BEFORE = "" + max;
    settings.CHANGE_AFTER = "" + min;
    final List<SvnChangeList> committedChanges =
        myVcs
            .getCachingCommittedChangesProvider()
            .getCommittedChanges(
                settings,
                new SvnRepositoryLocation(
                    description.getSourceRightVersion().getRepositoryRoot().toString()),
                0);
    final List<CommittedChangeList> lst =
        new ArrayList<CommittedChangeList>(committedChanges.size() - 1);
    for (SvnChangeList change : committedChanges) {
      if (change.getNumber() == min) {
        continue;
      }
      lst.add(change);
    }
    return lst;
  }
 private List<Change> convertPaths(List<Change> changesForPatch) throws VcsException {
   initAddOption();
   final List<Change> changes = new ArrayList<Change>();
   for (Change change : changesForPatch) {
     if (!isUnderOldDir(change, myOldFilePath)) continue;
     ContentRevision before = null;
     ContentRevision after = null;
     if (change.getBeforeRevision() != null) {
       before =
           new SimpleContentRevision(
               change.getBeforeRevision().getContent(),
               rebasePath(myOldFilePath, myNewFilePath, change.getBeforeRevision().getFile()),
               change.getBeforeRevision().getRevisionNumber().asString());
     }
     if (change.getAfterRevision() != null) {
       // if addition or move - do not move to the new path
       if (myAdd
           && (change.getBeforeRevision() == null || change.isMoved() || change.isRenamed())) {
         after = change.getAfterRevision();
       } else {
         after =
             new SimpleContentRevision(
                 change.getAfterRevision().getContent(),
                 rebasePath(myOldFilePath, myNewFilePath, change.getAfterRevision().getFile()),
                 change.getAfterRevision().getRevisionNumber().asString());
       }
     }
     changes.add(new Change(before, after));
   }
   return changes;
 }
 @Override
 public void run(ContinuationContext context) {
   final List<Change> changesForPatch;
   try {
     final List<CommittedChangeList> lst = loadSvnChangeListsForPatch(myDescription);
     changesForPatch = CommittedChangesTreeBrowser.collectChanges(lst, true);
     for (Change change : changesForPatch) {
       if (change.getBeforeRevision() != null) {
         preloadRevisionContents(change.getBeforeRevision());
       }
       if (change.getAfterRevision() != null) {
         preloadRevisionContents(change.getAfterRevision());
       }
     }
   } catch (VcsException e) {
     context.handleException(e, true);
     return;
   }
   final List<Change> binaryChanges = filterOutBinary(changesForPatch);
   if (binaryChanges != null && !binaryChanges.isEmpty()) {
     myTheirsBinaryChanges.addAll(binaryChanges);
   }
   if (!changesForPatch.isEmpty()) {
     myTheirsChanges.addAll(changesForPatch);
   }
 }
    public Pair<List<RepositoryLocationGroup>, List<RepositoryLocation>> groupLocations(
        final List<RepositoryLocation> in) {
      final List<RepositoryLocationGroup> groups = new ArrayList<RepositoryLocationGroup>();
      final List<RepositoryLocation> singles = new ArrayList<RepositoryLocation>();

      final MultiMap<SVNURL, RepositoryLocation> map = new MultiMap<SVNURL, RepositoryLocation>();

      for (RepositoryLocation location : in) {
        final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
        final String url = svnLocation.getURL();

        final SVNURL root = SvnUtil.getRepositoryRoot(myVcs, url);
        if (root == null) {
          // should not occur
          LOG.info("repository root not found for location:" + location.toPresentableString());
          singles.add(location);
        } else {
          map.putValue(root, svnLocation);
        }
      }

      final Set<SVNURL> keys = map.keySet();
      for (SVNURL key : keys) {
        final Collection<RepositoryLocation> repositoryLocations = map.get(key);
        if (repositoryLocations.size() == 1) {
          singles.add(repositoryLocations.iterator().next());
        } else {
          final SvnRepositoryLocationGroup group =
              new SvnRepositoryLocationGroup(key, repositoryLocations);
          groups.add(group);
        }
      }
      return new Pair<List<RepositoryLocationGroup>, List<RepositoryLocation>>(groups, singles);
    }
 private List<Change> filterOutBinary(List<Change> paths) {
   List<Change> result = null;
   for (Iterator<Change> iterator = paths.iterator(); iterator.hasNext(); ) {
     final Change change = iterator.next();
     if (ChangesUtil.isBinaryChange(change)) {
       result = (result == null ? new SmartList<Change>() : result);
       result.add(change);
       iterator.remove();
     }
   }
   return result;
 }
 @Override
 public void run(ContinuationContext context) {
   if (myTheirsBinaryChanges.isEmpty()) return;
   final List<Change> converted;
   try {
     converted = convertPaths(myTheirsBinaryChanges);
   } catch (VcsException e) {
     context.handleException(e, true);
     return;
   }
   if (converted.isEmpty()) return;
   final Map<FilePath, Change> map = new HashMap<FilePath, Change>();
   for (Change change : converted) {
     map.put(ChangesUtil.getFilePath(change), change);
   }
   final Collection<FilePath> selected = chooseBinaryFiles(converted, map.keySet());
   myTheirsBinaryChanges.clear();
   for (FilePath filePath : selected) {
     myTheirsBinaryChanges.add(map.get(filePath));
   }
 }
  public void execute() {
    int ok =
        Messages.showOkCancelDialog(
            myVcs.getProject(),
            (myChange.isMoved()
                ? SvnBundle.message(
                    "confirmation.resolve.tree.conflict.merge.moved",
                    myOldPresentation,
                    myNewPresentation)
                : SvnBundle.message(
                    "confirmation.resolve.tree.conflict.merge.renamed",
                    myOldPresentation,
                    myNewPresentation)),
            TreeConflictRefreshablePanel.TITLE,
            Messages.getQuestionIcon());
    if (Messages.OK != ok) return;

    FileDocumentManager.getInstance().saveAllDocuments();
    // final String name = "Merge changes from theirs for: " + myOldPresentation;

    final Continuation fragmented = Continuation.createFragmented(myVcs.getProject(), false);
    fragmented.addExceptionHandler(
        VcsException.class,
        new Consumer<VcsException>() {
          @Override
          public void consume(VcsException e) {
            myWarnings.add(e);
            if (e.isWarning()) {
              return;
            }
            AbstractVcsHelper.getInstance(myVcs.getProject())
                .showErrors(myWarnings, TreeConflictRefreshablePanel.TITLE);
          }
        });

    final List<TaskDescriptor> tasks = new SmartList<TaskDescriptor>();
    tasks.add(
        myDescription.isDirectory()
            ? new PreloadChangesContentsForDir()
            : new PreloadChangesContentsForFile());
    tasks.add(new ConvertTextPaths());
    tasks.add(new PatchCreator());
    tasks.add(new SelectPatchesInApplyPatchDialog());
    tasks.add(new SelectBinaryFiles());

    fragmented.run(tasks);
  }
  private Collection<FilePath> chooseBinaryFiles(List<Change> converted, Set<FilePath> paths) {
    String singleMessage = "";
    if (paths.size() == 1) {
      final Change change = converted.get(0);
      final FileStatus status = change.getFileStatus();
      final FilePath path = ChangesUtil.getFilePath(change);
      final String stringPath = TreeConflictRefreshablePanel.filePath(path);
      if (FileStatus.DELETED.equals(status)) {
        singleMessage = "Delete binary file " + stringPath + " (according to theirs changes)?";
      } else if (FileStatus.ADDED.equals(status)) {
        singleMessage = "Create binary file " + stringPath + " (according to theirs changes)?";
      } else {
        singleMessage =
            "Apply changes to binary file " + stringPath + " (according to theirs changes)?";
      }
    }
    return AbstractVcsHelper.getInstance(myVcs.getProject())
        .selectFilePathsToProcess(
            new ArrayList<FilePath>(paths),
            TreeConflictRefreshablePanel.TITLE,
            "Select binary files to patch",
            TreeConflictRefreshablePanel.TITLE,
            singleMessage,
            new VcsShowConfirmationOption() {

              @Override
              public Value getValue() {
                return null;
              }

              @Override
              public void setValue(Value value) {}

              @Override
              public boolean isPersistent() {
                return false;
              }
            });
  }