public <T extends TaskRepository> void setRepositories(List<T> repositories) {

    Set<TaskRepository> set = new HashSet<TaskRepository>(myRepositories);
    set.removeAll(repositories);
    myBadRepositories.removeAll(set); // remove all changed reps
    myIssueCache.clear();

    myRepositories.clear();
    myRepositories.addAll(repositories);

    reps:
    for (T repository : repositories) {
      if (repository.isShared() && repository.getUrl() != null) {
        List<TaskProjectConfiguration.SharedServer> servers = getProjectConfiguration().servers;
        TaskRepositoryType type = repository.getRepositoryType();
        for (TaskProjectConfiguration.SharedServer server : servers) {
          if (repository.getUrl().equals(server.url) && type.getName().equals(server.type)) {
            continue reps;
          }
        }
        TaskProjectConfiguration.SharedServer server = new TaskProjectConfiguration.SharedServer();
        server.type = type.getName();
        server.url = repository.getUrl();
        servers.add(server);
      }
    }
  }
  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 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 static void showDiffForChange(
      final Iterable<Change> changes,
      final Condition<Change> selectionChecker,
      final Project project,
      @NotNull ShowDiffUIContext context) {
    int newIndex = -1;
    ChangeForDiffConvertor convertor = new ChangeForDiffConvertor(project, true);
    final List<DiffRequestPresentable> changeList = ContainerUtil.newArrayList();
    for (Change change : changes) {
      if (!directoryOrBinary(change)) { // todo
        DiffRequestPresentable presentable = convertor.convert(change);
        if (presentable != null) {
          if ((newIndex == -1) && selectionChecker.value(change)) {
            newIndex = changeList.size();
          }
          changeList.add(presentable);
        }
      }
    }
    if (changeList.isEmpty()) {
      return;
    }
    if (newIndex < 0) {
      newIndex = 0;
    }

    showDiffImpl(project, changeList, newIndex, context);
  }
  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);
  }
Пример #6
0
  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;
  }
 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;
 }
Пример #8
0
 @Override
 public void onFrameActivated() {
   final List<VirtualFile> folders = ((ChangeListManagerImpl) myClManager).getLockedFolders();
   if (!folders.isEmpty()) {
     myDirtyScopeManager.filesDirty(null, folders);
   }
 }
 @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);
   }
 }
Пример #10
0
  @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 void deleteChangeList(final ShelvedChangeList changeList) {
   deleteListImpl(changeList);
   if (!changeList.isRecycled()) {
     myShelvedChangeLists.remove(changeList);
   } else {
     myRecycledShelvedChangeLists.remove(changeList);
   }
   notifyStateChanged();
 }
 @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 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));
  }
Пример #14
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);
  }
  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;
  }
 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;
 }
Пример #17
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);
 }
 @Override
 public boolean isLocallyClosed(final LocalTask localTask) {
   if (isVcsEnabled()) {
     List<ChangeListInfo> lists = localTask.getChangeLists();
     if (lists.isEmpty()) return true;
     for (ChangeListInfo list : lists) {
       if (StringUtil.isEmpty(list.id)) {
         return true;
       }
     }
   }
   return false;
 }
Пример #19
0
    @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()]));
    }
  @SuppressWarnings({"unchecked"})
  public void loadState(Config config) {
    XmlSerializerUtil.copyBean(config, myConfig);
    myTasks.clear();
    for (LocalTaskImpl task : config.tasks) {
      addTask(task);
    }

    myRepositories.clear();
    Element element = config.servers;
    List<TaskRepository> repositories = loadRepositories(element);
    myRepositories.addAll(repositories);
  }
  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();
    }
  }
 public void clearRecycled() {
   for (ShelvedChangeList list : myRecycledShelvedChangeLists) {
     deleteListImpl(list);
   }
   myRecycledShelvedChangeLists.clear();
   notifyStateChanged();
 }
  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();
    }
  }
Пример #24
0
  @Nullable
  private ApplyPatchStatus actualApply(
      final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches,
      final List<Pair<VirtualFile, ApplyFilePatchBase<BinaryType>>> binaryPatches,
      final CommitContext commitContext) {
    final ApplyPatchContext context = new ApplyPatchContext(myBaseDirectory, 0, true, true);
    ApplyPatchStatus status;

    try {
      status = applyList(textPatches, context, null, commitContext);

      if (status == ApplyPatchStatus.ABORT) return status;

      if (myCustomForBinaries == null) {
        status = applyList(binaryPatches, context, status, commitContext);
      } else {
        ApplyPatchStatus patchStatus = myCustomForBinaries.apply(binaryPatches);
        final List<FilePatch> appliedPatches = myCustomForBinaries.getAppliedPatches();
        moveForCustomBinaries(binaryPatches, appliedPatches);

        status = ApplyPatchStatus.and(status, patchStatus);
        myRemainingPatches.removeAll(appliedPatches);
      }
    } catch (IOException e) {
      showError(myProject, e.getMessage(), true);
      return ApplyPatchStatus.ABORT;
    }
    return status;
  }
 private static List<ShelvedBinaryFile> getBinaryFilesToUnshelve(
     final ShelvedChangeList changeList,
     final List<ShelvedBinaryFile> binaryFiles,
     final List<ShelvedBinaryFile> remainingBinaries) {
   if (binaryFiles == null) {
     return new ArrayList<ShelvedBinaryFile>(changeList.getBinaryFiles());
   }
   ArrayList<ShelvedBinaryFile> result = new ArrayList<ShelvedBinaryFile>();
   for (ShelvedBinaryFile file : changeList.getBinaryFiles()) {
     if (binaryFiles.contains(file)) {
       result.add(file);
     } else {
       remainingBinaries.add(file);
     }
   }
   return result;
 }
  public List<VirtualFile> gatherPatchFiles(final Collection<VirtualFile> files) {
    final List<VirtualFile> result = new ArrayList<VirtualFile>();

    final LinkedList<VirtualFile> filesQueue = new LinkedList<VirtualFile>(files);
    while (!filesQueue.isEmpty()) {
      ProgressManager.checkCanceled();
      final VirtualFile file = filesQueue.removeFirst();
      if (file.isDirectory()) {
        filesQueue.addAll(Arrays.asList(file.getChildren()));
        continue;
      }
      if (PatchFileType.NAME.equals(file.getFileType().getName())) {
        result.add(file);
      }
    }

    return result;
  }
Пример #27
0
 @Override
 public void run(ContinuationContext context) {
   try {
     final List<TaskDescriptor> tasks = new LinkedList<TaskDescriptor>();
     final boolean supportsMergeinfo =
         myWcInfo.getFormat().supportsMergeInfo()
             && SvnUtil.doesRepositorySupportMergeinfo(
                 myVcs, SVNURL.parseURIEncoded(mySourceUrl));
     if (!supportsMergeinfo) {
       insertMergeAll(tasks);
     } else {
       tasks.add(new MergeAllOrSelectedChooser());
     }
     context.next(tasks);
   } catch (SVNException e) {
     finishWithError(context, e.getMessage(), true);
   }
 }
Пример #28
0
 @NotNull
 public ApplyPatchStatus nonWriteActionPreCheck() {
   final List<FilePatch> failedPreCheck = myVerifier.nonWriteActionPreCheck();
   myFailedPatches.addAll(failedPreCheck);
   myPatches.removeAll(failedPreCheck);
   final List<FilePatch> skipped = myVerifier.getSkipped();
   final boolean applyAll = skipped.isEmpty();
   myPatches.removeAll(skipped);
   if (!failedPreCheck.isEmpty()) return ApplyPatchStatus.FAILURE;
   return applyAll
       ? ApplyPatchStatus.SUCCESS
       : ((skipped.size() == myPatches.size())
           ? ApplyPatchStatus.ALREADY_APPLIED
           : ApplyPatchStatus.PARTIAL);
 }
 private static void readList(final List<Element> children, final List<ShelvedChangeList> sink)
     throws InvalidDataException {
   for (Element child : children) {
     ShelvedChangeList data = new ShelvedChangeList();
     data.readExternal(child);
     if (new File(data.PATH).exists()) {
       sink.add(data);
     }
   }
 }
Пример #30
0
  /**
   * Returns real working copies roots - if there is <Project Root> -> Subversion setting, and there
   * is one working copy, will return one root
   */
  public List<WCInfo> getAllWcInfos() {
    final SvnFileUrlMapping urlMapping = getSvnFileUrlMapping();

    final List<RootUrlInfo> infoList = urlMapping.getAllWcInfos();
    final List<WCInfo> infos = new ArrayList<WCInfo>();
    for (RootUrlInfo info : infoList) {
      final File file = info.getIoFile();
      infos.add(
          new WCInfo(
              file.getAbsolutePath(),
              info.getAbsoluteUrlAsUrl(),
              info.getFormat(),
              info.getRepositoryUrl(),
              SvnUtil.isWorkingCopyRoot(file),
              info.getType(),
              SvnUtil.getDepth(this, file)));
    }
    return infos;
  }