@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);
   }
 }
Example #2
0
 @NotNull
 public static List<VcsDirectoryMapping> addMapping(
     @NotNull List<VcsDirectoryMapping> existingMappings,
     @NotNull String path,
     @NotNull String vcs) {
   List<VcsDirectoryMapping> mappings = new ArrayList<VcsDirectoryMapping>(existingMappings);
   for (Iterator<VcsDirectoryMapping> iterator = mappings.iterator(); iterator.hasNext(); ) {
     VcsDirectoryMapping mapping = iterator.next();
     if (mapping.isDefaultMapping() && StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
       LOG.debug("Removing <Project> -> <None> mapping");
       iterator.remove();
     } else if (FileUtil.pathsEqual(mapping.getDirectory(), path)) {
       if (!StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
         LOG.warn(
             "Substituting existing mapping ["
                 + path
                 + "] -> ["
                 + mapping.getVcs()
                 + "] with ["
                 + vcs
                 + "]");
       } else {
         LOG.debug("Removing [" + path + "] -> <None> mapping");
       }
       iterator.remove();
     }
   }
   mappings.add(new VcsDirectoryMapping(path, vcs));
   return mappings;
 }
 @Override
 public void onFrameActivated() {
   final List<VirtualFile> folders = ((ChangeListManagerImpl) myClManager).getLockedFolders();
   if (!folders.isEmpty()) {
     myDirtyScopeManager.filesDirty(null, folders);
   }
 }
  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;
  }
  public static void showDiffForChange(
      final Iterable<Change> changes,
      final Condition<Change> selectionChecker,
      final Project project,
      @NotNull ShowDiffUIContext context) {
    int cnt = 0;
    int newIndex = -1;
    final List<Change> changeList = new ArrayList<Change>();
    for (Change change : changes) {
      if (!directoryOrBinary(change)) { // todo
        changeList.add(change);
        if ((newIndex == -1) && selectionChecker.value(change)) {
          newIndex = cnt;
        }
        ++cnt;
      }
    }
    if (changeList.isEmpty()) {
      return;
    }
    if (newIndex < 0) {
      newIndex = 0;
    }

    showDiffImpl(
        project,
        ObjectsConvertor.convert(
            changeList, new ChangeForDiffConvertor(project, true), ObjectsConvertor.NOT_NULL),
        newIndex,
        context);
  }
  private <V extends FilePatch, T extends ApplyFilePatchBase<V>> ApplyPatchStatus applyList(
      final List<Pair<VirtualFile, T>> patches,
      final ApplyPatchContext context,
      ApplyPatchStatus status,
      CommitContext commiContext)
      throws IOException {
    for (Pair<VirtualFile, T> patch : patches) {
      ApplyPatchStatus patchStatus =
          ApplyPatchAction.applyOnly(
              myProject,
              patch.getSecond(),
              context,
              patch.getFirst(),
              commiContext,
              myReverseConflict,
              myLeftConflictPanelTitle,
              myRightConflictPanelTitle);

      if (patchStatus == ApplyPatchStatus.ABORT) return patchStatus;
      status = ApplyPatchStatus.and(status, patchStatus);
      if (patchStatus == ApplyPatchStatus.FAILURE) {
        myFailedPatches.add(patch.getSecond().getPatch());
        continue;
      }
      if (patchStatus != ApplyPatchStatus.SKIP) {
        myVerifier.doMoveIfNeeded(patch.getFirst());
        myRemainingPatches.remove(patch.getSecond().getPatch());
      }
    }
    return status;
  }
 public List<ShelvedChangeList> importChangeLists(
     final Collection<VirtualFile> files, final Consumer<VcsException> exceptionConsumer) {
   final List<ShelvedChangeList> result = new ArrayList<ShelvedChangeList>(files.size());
   try {
     final FilesProgress filesProgress = new FilesProgress(files.size(), "Processing ");
     for (VirtualFile file : files) {
       filesProgress.updateIndicator(file);
       final String description = file.getNameWithoutExtension().replace('_', ' ');
       final File patchPath = getPatchPath(description);
       final ShelvedChangeList list =
           new ShelvedChangeList(
               patchPath.getPath(),
               description,
               new SmartList<ShelvedBinaryFile>(),
               file.getTimeStamp());
       try {
         final List<TextFilePatch> patchesList =
             loadPatches(myProject, file.getPath(), new CommitContext());
         if (!patchesList.isEmpty()) {
           FileUtil.copy(new File(file.getPath()), patchPath);
           // add only if ok to read patch
           myShelvedChangeLists.add(list);
           result.add(list);
         }
       } catch (IOException e) {
         exceptionConsumer.consume(new VcsException(e));
       } catch (PatchSyntaxException e) {
         exceptionConsumer.consume(new VcsException(e));
       }
     }
   } finally {
     notifyStateChanged();
   }
   return result;
 }
 public List<LocalChangeList> getListsCopy() {
   final List<LocalChangeList> result = new ArrayList<LocalChangeList>();
   for (LocalChangeList list : myMap.values()) {
     result.add(list.copy());
   }
   return result;
 }
    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> 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;
 }
 private Collection<VirtualFile> promptAboutAddition(
     SvnVcs vcs,
     List<VirtualFile> addedVFiles,
     VcsShowConfirmationOption.Value value,
     AbstractVcsHelper vcsHelper) {
   Collection<VirtualFile> filesToProcess;
   if (value == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY) {
     filesToProcess = addedVFiles;
   } else {
     final String singleFilePrompt;
     if (addedVFiles.size() == 1 && addedVFiles.get(0).isDirectory()) {
       singleFilePrompt = SvnBundle.getString("confirmation.text.add.dir");
     } else {
       singleFilePrompt = SvnBundle.getString("confirmation.text.add.file");
     }
     filesToProcess =
         vcsHelper.selectFilesToProcess(
             addedVFiles,
             SvnBundle.message("confirmation.title.add.multiple.files"),
             null,
             SvnBundle.message("confirmation.title.add.file"),
             singleFilePrompt,
             vcs.getAddConfirmation());
   }
   return filesToProcess;
 }
  private void refreshFiles(final Project project) {
    final List<VirtualFile> toRefreshFiles = new ArrayList<VirtualFile>();
    final List<VirtualFile> toRefreshDirs = new ArrayList<VirtualFile>();
    for (VirtualFile file : myFilesToRefresh) {
      if (file == null) continue;
      if (file.isDirectory()) {
        toRefreshDirs.add(file);
      } else {
        toRefreshFiles.add(file);
      }
    }
    // if refresh asynchronously, local changes would also be notified that they are dirty
    // asynchronously,
    // and commit could be executed while not all changes are visible
    filterOutInvalid(myFilesToRefresh);
    RefreshQueue.getInstance()
        .refresh(
            true,
            true,
            new Runnable() {
              public void run() {
                if (project.isDisposed()) return;
                filterOutInvalid(toRefreshFiles);
                filterOutInvalid(toRefreshDirs);

                final VcsDirtyScopeManager vcsDirtyScopeManager =
                    VcsDirtyScopeManager.getInstance(project);
                vcsDirtyScopeManager.filesDirty(toRefreshFiles, toRefreshDirs);
              }
            },
            myFilesToRefresh);
    myFilesToRefresh.clear();
  }
  public boolean move(VirtualFile file, VirtualFile toDir) throws IOException {
    File srcFile = getIOFile(file);
    File dstFile = new File(getIOFile(toDir), file.getName());

    final SvnVcs vcs = getVCS(toDir);
    final SvnVcs sourceVcs = getVCS(file);
    if (vcs == null && sourceVcs == null) return false;

    if (vcs == null) {
      return false;
    }

    FileDocumentManager.getInstance().saveAllDocuments();
    if (sourceVcs == null) {
      return createItem(toDir, file.getName(), file.isDirectory(), true);
    }

    if (isPendingAdd(vcs.getProject(), toDir)) {

      myMovedFiles.add(new MovedFileInfo(sourceVcs.getProject(), srcFile, dstFile));
      return true;
    } else {
      final VirtualFile oldParent = file.getParent();
      myFilesToRefresh.add(oldParent);
      myFilesToRefresh.add(toDir);
      return doMove(sourceVcs, srcFile, dstFile);
    }
  }
 public List<File> getAffectedPaths() {
   final SortedSet<FilePath> set = myIdx.getAffectedPaths();
   final List<File> result = new ArrayList<File>(set.size());
   for (FilePath path : set) {
     result.add(path.getIOFile());
   }
   return result;
 }
 private void addToMoveExceptions(@NotNull final Project project, @NotNull final Exception e) {
   List<VcsException> exceptionList = myMoveExceptions.get(project);
   if (exceptionList == null) {
     exceptionList = new ArrayList<VcsException>();
     myMoveExceptions.put(project, exceptionList);
   }
   exceptionList.add(handleMoveException(e));
 }
  public static void readExternal(
      final Element element,
      final List<ShelvedChangeList> changes,
      final List<ShelvedChangeList> recycled)
      throws InvalidDataException {
    changes.addAll(ShelvedChangeList.readChanges(element, false, true));

    recycled.addAll(ShelvedChangeList.readChanges(element, true, true));
  }
 @Nullable
 private static Change[] loadFakeRevisions(final Project project, final Change[] changes) {
   List<Change> matchingChanges = new ArrayList<Change>();
   for (Change change : changes) {
     matchingChanges.addAll(
         ChangeListManager.getInstance(project).getChangesIn(ChangesUtil.getFilePath(change)));
   }
   return matchingChanges.toArray(new Change[matchingChanges.size()]);
 }
 public void deleteChangeList(final ShelvedChangeList changeList) {
   deleteListImpl(changeList);
   if (!changeList.isRecycled()) {
     myShelvedChangeLists.remove(changeList);
   } else {
     myRecycledShelvedChangeLists.remove(changeList);
   }
   notifyStateChanged();
 }
  @CalledInAwt
  protected void refreshFiles(final Collection<FilePath> additionalDirectly) {
    final List<FilePath> directlyAffected = myVerifier.getDirectlyAffected();
    final List<VirtualFile> indirectlyAffected = myVerifier.getAllAffected();
    directlyAffected.addAll(additionalDirectly);

    refreshPassedFilesAndMoveToChangelist(
        myProject, directlyAffected, indirectlyAffected, myToTargetListsMover);
  }
  public ShelvedChangeList shelveChanges(
      final Collection<Change> changes, final String commitMessage, final boolean rollback)
      throws IOException, VcsException {
    final List<Change> textChanges = new ArrayList<Change>();
    final List<ShelvedBinaryFile> binaryFiles = new ArrayList<ShelvedBinaryFile>();
    for (Change change : changes) {
      if (ChangesUtil.getFilePath(change).isDirectory()) {
        continue;
      }
      if (change.getBeforeRevision() instanceof BinaryContentRevision
          || change.getAfterRevision() instanceof BinaryContentRevision) {
        binaryFiles.add(shelveBinaryFile(change));
      } else {
        textChanges.add(change);
      }
    }

    final ShelvedChangeList changeList;
    try {
      File patchPath = getPatchPath(commitMessage);
      ProgressManager.checkCanceled();
      final List<FilePatch> patches =
          IdeaTextPatchBuilder.buildPatch(
              myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false);
      ProgressManager.checkCanceled();

      CommitContext commitContext = new CommitContext();
      baseRevisionsOfDvcsIntoContext(textChanges, commitContext);
      myFileProcessor.savePathFile(
          new CompoundShelfFileProcessor.ContentProvider() {
            public void writeContentTo(final Writer writer, CommitContext commitContext)
                throws IOException {
              UnifiedDiffWriter.write(myProject, patches, writer, "\n", commitContext);
            }
          },
          patchPath,
          commitContext);

      changeList =
          new ShelvedChangeList(
              patchPath.toString(), commitMessage.replace('\n', ' '), binaryFiles);
      myShelvedChangeLists.add(changeList);
      ProgressManager.checkCanceled();

      if (rollback) {
        new RollbackWorker(myProject, false)
            .doRollback(changes, true, null, VcsBundle.message("shelve.changes.action"));
      }
    } finally {
      notifyStateChanged();
    }

    return changeList;
  }
Example #21
0
  @CalledInAwt
  public void execute() {
    FileDocumentManager.getInstance().saveAllDocuments();

    final List<TaskDescriptor> tasks = new LinkedList<TaskDescriptor>();
    tasks.add(new MyInitChecks());
    tasks.add(new SourceUrlCorrection());
    tasks.add(new CheckRepositorySupportsMergeinfo());

    myContinuation.run(tasks);
  }
 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 consume(Collection<FilePath> directlyAffected) {
      List<Change> changes = new ArrayList<>();
      for (FilePath file : directlyAffected) {
        final Change change = myChangeListManager.getChange(file);
        if (change != null) {
          changes.add(change);
        }
      }

      myChangeListManager.moveChangesTo(
          myTargetChangeList, changes.toArray(new Change[changes.size()]));
    }
Example #24
0
 private void insertMergeAll(final List<TaskDescriptor> queue) {
   queue.add(new LocalChangesPrompt(true, null, null));
   final MergeAllWithBranchCopyPoint mergeAllExecutor = new MergeAllWithBranchCopyPoint();
   queue.add(
       myVcs
           .getSvnBranchPointsCalculator()
           .getFirstCopyPointTask(
               myWcInfo.getRepositoryRoot(),
               mySourceUrl,
               myWcInfo.getRootUrl(),
               mergeAllExecutor));
   queue.add(mergeAllExecutor);
 }
 protected void processInChange(Couple<String> key, Change change) {
   LocalChangeList tmpList = myInternalMap.get(key);
   if (tmpList == null) {
     tmpList = myDefaultCopy;
   }
   final String tmpName = tmpList.getName();
   List<Change> list = myListToChangesMap.get(tmpName);
   if (list == null) {
     list = new ArrayList<Change>();
     myListToChangesMap.put(tmpName, list);
     myIncludedListsCopies.put(tmpName, tmpList);
   }
   list.add(change);
 }
  private void recycleChangeList(
      final ShelvedChangeList listCopy, final ShelvedChangeList newList) {
    if (newList != null) {
      for (Iterator<ShelvedBinaryFile> shelvedChangeListIterator =
              listCopy.getBinaryFiles().iterator();
          shelvedChangeListIterator.hasNext(); ) {
        final ShelvedBinaryFile binaryFile = shelvedChangeListIterator.next();
        for (ShelvedBinaryFile newBinary : newList.getBinaryFiles()) {
          if (Comparing.equal(newBinary.BEFORE_PATH, binaryFile.BEFORE_PATH)
              && Comparing.equal(newBinary.AFTER_PATH, binaryFile.AFTER_PATH)) {
            shelvedChangeListIterator.remove();
          }
        }
      }
      for (Iterator<ShelvedChange> iterator = listCopy.getChanges(myProject).iterator();
          iterator.hasNext(); ) {
        final ShelvedChange change = iterator.next();
        for (ShelvedChange newChange : newList.getChanges(myProject)) {
          if (Comparing.equal(change.getBeforePath(), newChange.getBeforePath())
              && Comparing.equal(change.getAfterPath(), newChange.getAfterPath())) {
            iterator.remove();
          }
        }
      }

      // needed only if partial unshelve
      try {
        final CommitContext commitContext = new CommitContext();
        final List<FilePatch> patches = new ArrayList<FilePatch>();
        for (ShelvedChange change : listCopy.getChanges(myProject)) {
          patches.add(change.loadFilePatch(myProject, commitContext));
        }
        writePatchesToFile(myProject, listCopy.PATH, patches, commitContext);
      } catch (IOException e) {
        LOG.info(e);
        // left file as is
      } catch (PatchSyntaxException e) {
        LOG.info(e);
        // left file as is
      }
    }

    if ((!listCopy.getBinaryFiles().isEmpty()) || (!listCopy.getChanges(myProject).isEmpty())) {
      listCopy.setRecycled(true);
      myRecycledShelvedChangeLists.add(listCopy);
      notifyStateChanged();
    }
  }
  private void fillAddedFiles(
      Project project,
      SvnVcs vcs,
      List<VirtualFile> addedVFiles,
      Map<VirtualFile, File> copyFromMap,
      Set<VirtualFile> recursiveItems) {
    final Collection<AddedFileInfo> addedFileInfos = myAddedFiles.remove(project);
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);

    for (AddedFileInfo addedFileInfo : addedFileInfos) {
      final File ioFile = new File(getIOFile(addedFileInfo.myDir), addedFileInfo.myName);
      VirtualFile addedFile = addedFileInfo.myDir.findChild(addedFileInfo.myName);
      if (addedFile == null) {
        addedFile = myLfs.refreshAndFindFileByIoFile(ioFile);
      }
      if (addedFile != null) {
        final SVNStatus fileStatus = getFileStatus(vcs, ioFile);
        if (fileStatus == null || !SvnVcs.svnStatusIs(fileStatus, SVNStatusType.STATUS_IGNORED)) {
          boolean isIgnored = changeListManager.isIgnoredFile(addedFile);
          if (!isIgnored) {
            addedVFiles.add(addedFile);
            copyFromMap.put(addedFile, addedFileInfo.myCopyFrom);
            if (addedFileInfo.myRecursive) {
              recursiveItems.add(addedFile);
            }
          }
        }
      }
    }
  }
 protected void processInChange(Couple<String> key, Change change) {
   final LocalChangeList list = myInternalMap.get(key);
   if (list != null) {
     myIncludedListsCopies.put(list.getName(), list);
     myValidChanges.add(change);
   }
 }
  public ShelvedChangeList importFilePatches(
      final String fileName, final List<FilePatch> patches, final PatchEP[] patchTransitExtensions)
      throws IOException {
    try {
      final File patchPath = getPatchPath(fileName);
      myFileProcessor.savePathFile(
          new CompoundShelfFileProcessor.ContentProvider() {
            public void writeContentTo(final Writer writer, CommitContext commitContext)
                throws IOException {
              UnifiedDiffWriter.write(
                  myProject, patches, writer, "\n", patchTransitExtensions, commitContext);
            }
          },
          patchPath,
          new CommitContext());

      final ShelvedChangeList changeList =
          new ShelvedChangeList(
              patchPath.toString(),
              fileName.replace('\n', ' '),
              new SmartList<ShelvedBinaryFile>());
      myShelvedChangeLists.add(changeList);
      return changeList;
    } finally {
      notifyStateChanged();
    }
  }
 public void clearRecycled() {
   for (ShelvedChangeList list : myRecycledShelvedChangeLists) {
     deleteListImpl(list);
   }
   myRecycledShelvedChangeLists.clear();
   notifyStateChanged();
 }