@CalledInAwt @NotNull private ApplyPatchStatus getApplyPatchStatus(@NotNull final TriggerAdditionOrDeletion trigger) { final Ref<ApplyPatchStatus> refStatus = Ref.create(null); try { setConfirmationToDefault(); CommandProcessor.getInstance() .executeCommand( myProject, new Runnable() { @Override public void run() { // consider pre-check status only if not successful, otherwise we could not // detect already applied status if (createFiles() != ApplyPatchStatus.SUCCESS) { refStatus.set(createFiles()); } addSkippedItems(trigger); trigger.prepare(); refStatus.set(ApplyPatchStatus.and(refStatus.get(), executeWritable())); } }, VcsBundle.message("patch.apply.command"), null); } finally { returnConfirmationBack(); VcsFileListenerContextHelper.getInstance(myProject).clearContext(); } final ApplyPatchStatus status = refStatus.get(); return status == null ? ApplyPatchStatus.ALREADY_APPLIED : status; }
public ProjectLevelVcsManagerImpl( Project project, final FileStatusManager manager, MessageBus messageBus, final FileIndexFacade excludedFileIndex) { myProject = project; myMessageBus = messageBus; mySerialization = new ProjectLevelVcsManagerSerialization(); myOptionsAndConfirmations = new OptionsAndConfirmations(); myDefaultVcsRootPolicy = DefaultVcsRootPolicy.getInstance(project); myBackgroundableActionHandlerMap = new EnumMap<VcsBackgroundableActions, BackgroundableActionEnabledHandler>( VcsBackgroundableActions.class); myInitialization = new VcsInitialization(myProject); myMappings = new NewMappings(myProject, myMessageBus, this, manager); myMappingsToRoots = new MappingsToRoots(myMappings, myProject); if (!myProject.isDefault()) { myVcsEventListenerManager = new VcsEventsListenerManagerImpl(); } myVcsHistoryCache = new VcsHistoryCache(); myContentRevisionCache = new ContentRevisionCache(); myConnect = myMessageBus.connect(); myVcsFileListenerContextHelper = VcsFileListenerContextHelper.getInstance(myProject); VcsListener vcsListener = new VcsListener() { @Override public void directoryMappingChanged() { myVcsHistoryCache.clear(); myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss()); } }; myExcludedIndex = excludedFileIndex; myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener); myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener); myConnect.subscribe( UpdatedFilesListener.UPDATED_FILES, new UpdatedFilesListener() { @Override public void consume(Set<String> strings) { myContentRevisionCache.clearCurrent(strings); } }); myAnnotationLocalChangesListener = new VcsAnnotationLocalChangesListenerImpl(myProject, this); }
@CalledInAwt public static ApplyPatchStatus executePatchGroup( final Collection<PatchApplier> group, final LocalChangeList localChangeList) { if (group.isEmpty()) return ApplyPatchStatus.SUCCESS; // ? final Project project = group.iterator().next().myProject; ApplyPatchStatus result = ApplyPatchStatus.SUCCESS; for (PatchApplier patchApplier : group) { result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck()); } final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before patch"); final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project); final Ref<ApplyPatchStatus> refStatus = new Ref<>(result); try { CommandProcessor.getInstance() .executeCommand( project, new Runnable() { @Override public void run() { for (PatchApplier applier : group) { refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.createFiles())); applier.addSkippedItems(trigger); } trigger.prepare(); if (refStatus.get() == ApplyPatchStatus.SUCCESS) { // all pre-check results are valuable only if not successful; actual status we // can receive after executeWritable refStatus.set(null); } for (PatchApplier applier : group) { refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.executeWritable())); if (refStatus.get() == ApplyPatchStatus.ABORT) break; } } }, VcsBundle.message("patch.apply.command"), null); } finally { VcsFileListenerContextHelper.getInstance(project).clearContext(); LocalHistory.getInstance().putSystemLabel(project, "After patch"); } result = refStatus.get(); result = result == null ? ApplyPatchStatus.FAILURE : result; trigger.processIt(); final Set<FilePath> directlyAffected = new HashSet<>(); final Set<VirtualFile> indirectlyAffected = new HashSet<>(); for (PatchApplier applier : group) { directlyAffected.addAll(applier.getDirectlyAffected()); indirectlyAffected.addAll(applier.getIndirectlyAffected()); } directlyAffected.addAll(trigger.getAffected()); final Consumer<Collection<FilePath>> mover = localChangeList == null ? null : createMover(project, localChangeList); refreshPassedFilesAndMoveToChangelist(project, directlyAffected, indirectlyAffected, mover); if (result == ApplyPatchStatus.FAILURE) { suggestRollback(project, group, beforeLabel); } else if (result == ApplyPatchStatus.ABORT) { rollbackUnderProgress(project, project.getBaseDir(), beforeLabel); } showApplyStatus(project, result); return result; }