private static void markDirty( @NotNull VcsDirtyScopeManager vcsDirtyScopeManager, @NotNull Collection<FilePath> directlyAffected, @NotNull Collection<VirtualFile> indirectlyAffected) { vcsDirtyScopeManager.filePathsDirty(directlyAffected, null); vcsDirtyScopeManager.filesDirty(indirectlyAffected, null); }
private void markDirty(final Map<VcsDirtyScopeManager, Couple<HashSet<FilePath>>> outerMap) { for (Map.Entry<VcsDirtyScopeManager, Couple<HashSet<FilePath>>> entry : outerMap.entrySet()) { VcsDirtyScopeManager manager = entry.getKey(); HashSet<FilePath> files = entry.getValue().first; HashSet<FilePath> dirs = entry.getValue().second; manager.filePathsDirty(files, dirs); } }
private boolean checkIfThereAreFakeRevisions(final Project project, final Change[] changes) { boolean needsConvertion = false; for (Change change : changes) { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); if (beforeRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(beforeRevision.getFile()); needsConvertion = true; } if (afterRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(afterRevision.getFile()); needsConvertion = true; } } return needsConvertion; }
/** call in setUp */ public DuringChangeListManagerUpdateTestScheme(final Project project, final String tmpDirPath) { final MockAbstractVcs vcs = new MockAbstractVcs(project); myChangeProvider = new MockDelayingChangeProvider(); vcs.setChangeProvider(myChangeProvider); final File mockVcsRoot = new File(tmpDirPath, "mock"); mockVcsRoot.mkdir(); final VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mockVcsRoot); final ProjectLevelVcsManagerImpl projectLevelVcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project); projectLevelVcsManager.registerVcs(vcs); // projectLevelVcsManager.setDirectoryMapping(mockVcsRoot.getAbsolutePath(), vcs.getName()); final ArrayList<VcsDirectoryMapping> list = new ArrayList<VcsDirectoryMapping>(projectLevelVcsManager.getDirectoryMappings()); list.add(new VcsDirectoryMapping(vRoot.getPath(), vcs.getName())); projectLevelVcsManager.setDirectoryMappings(list); AbstractVcs vcsFound = projectLevelVcsManager.findVcsByName(vcs.getName()); final VirtualFile[] roots = projectLevelVcsManager.getRootsUnderVcs(vcsFound); assert roots.length == 1 : Arrays.asList(roots) + "; " + vcs.getName() + "; " + Arrays.toString(AllVcses.getInstance(project).getAll()); myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project); myClManager = ChangeListManager.getInstance(project); }
@Override public void onFrameActivated() { final List<VirtualFile> folders = ((ChangeListManagerImpl) myClManager).getLockedFolders(); if (!folders.isEmpty()) { myDirtyScopeManager.filesDirty(null, folders); } }
public SvnVcs( final Project project, MessageBus bus, SvnConfiguration svnConfiguration, final SvnLoadedBrachesStorage storage) { super(project, VCS_NAME); myLoadedBranchesStorage = storage; LOG.debug("ct"); myRootsToWorkingCopies = new RootsToWorkingCopies(this); myConfiguration = svnConfiguration; myAuthNotifier = new SvnAuthenticationNotifier(this); dumpFileStatus(FileStatus.ADDED); dumpFileStatus(FileStatus.DELETED); dumpFileStatus(FileStatus.MERGE); dumpFileStatus(FileStatus.MODIFIED); dumpFileStatus(FileStatus.NOT_CHANGED); dumpFileStatus(FileStatus.UNKNOWN); dumpFileStatus(SvnFileStatus.REPLACED); dumpFileStatus(SvnFileStatus.EXTERNAL); dumpFileStatus(SvnFileStatus.OBSTRUCTED); final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project); myAddConfirmation = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, this); myDeleteConfirmation = vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, this); myCheckoutOptions = vcsManager.getStandardOption(VcsConfiguration.StandardOption.CHECKOUT, this); if (myProject.isDefault()) { myChangeListListener = null; myEntriesFileListener = null; } else { myEntriesFileListener = new SvnEntriesFileListener(project); upgradeIfNeeded(bus); myChangeListListener = new SvnChangelistListener(myProject, this); myVcsListener = new VcsListener() { @Override public void directoryMappingChanged() { invokeRefreshSvnRoots(true); } }; } myFrameStateListener = project.isDefault() ? null : new MyFrameStateListener( ChangeListManager.getInstance(project), VcsDirtyScopeManager.getInstance(project)); myWorkingCopiesContent = new WorkingCopiesContent(this); // remove used some time before old notification group ids correctNotificationIds(); myChecker = new SvnExecutableChecker(myProject); }
@CalledInAwt public static void refreshPassedFilesAndMoveToChangelist( @NotNull final Project project, final Collection<FilePath> directlyAffected, final Collection<VirtualFile> indirectlyAffected, final Consumer<Collection<FilePath>> targetChangelistMover) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); for (FilePath filePath : directlyAffected) { lfs.refreshAndFindFileByIoFile(filePath.getIOFile()); } if (project.isDisposed()) return; final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (!directlyAffected.isEmpty() && targetChangelistMover != null) { changeListManager.invokeAfterUpdate( new Runnable() { @Override public void run() { targetChangelistMover.consume(directlyAffected); } }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list"), new Consumer<VcsDirtyScopeManager>() { @Override public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) { markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected); } }, null); } else { markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected); } }
public void doTest(final Runnable runnable) { final TimeoutWaiter waiter = new TimeoutWaiter(); final DuringUpdateTest test = new DuringUpdateTest(waiter, runnable); myChangeProvider.setTest(test); waiter.setControlled(test); myDirtyScopeManager.markEverythingDirty(); myClManager.ensureUpToDate(false); waiter.startTimeout(); if (test.getException() != null) { test.getException().printStackTrace(); } assert test.get() : (test.getException() == null ? null : test.getException().getMessage()); }
@Before public void setUp() throws Exception { System.setProperty("svnkit.wc.17", "false"); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { try { final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); myTempDirFixture = fixtureFactory.createTempDirTestFixture(); myTempDirFixture.setUp(); final File svnRoot = new File(myTempDirFixture.getTempDirPath(), "svnroot"); svnRoot.mkdir(); File pluginRoot = new File(PluginPathManager.getPluginHomePath("svn4idea")); if (!pluginRoot.isDirectory()) { // try standalone mode Class aClass = SvnTestCase.class; String rootPath = PathManager.getResourceRoot( aClass, "/" + aClass.getName().replace('.', '/') + ".class"); pluginRoot = new File(rootPath).getParentFile().getParentFile().getParentFile(); } myClientBinaryPath = new File(pluginRoot, "testData/svn/bin"); ZipUtil.extract(new File(pluginRoot, "testData/svn/newrepo.zip"), svnRoot, null); myWcRoot = new File(myTempDirFixture.getTempDirPath(), "wcroot"); myWcRoot.mkdir(); myRepoUrl = "file:///" + FileUtil.toSystemIndependentName(svnRoot.getPath()); initProject(myWcRoot); activateVCS(SvnVcs17.VCS_NAME); verify(runSvn("co", myRepoUrl, ".")); myGate = new MockChangeListManagerGate(ChangeListManager.getInstance(myProject)); myRefreshCopiesStub = new AtomicSectionsAware() { @Override public void enter() {} @Override public void exit() {} @Override public boolean shouldExitAsap() { return false; } @Override public void checkShouldExit() throws ProcessCanceledException {} }; final SvnVcs17 vcs = SvnVcs17.getInstance(myProject); ((StartupManagerImpl) StartupManager.getInstance(myProject)) .runPostStartupActivities(); // vcs.postStartup(); ((SvnFileUrlMappingImpl17) vcs.getSvnFileUrlMapping()).realRefresh(); } catch (Exception e) { throw new RuntimeException(e); } } }); // there should be kind-a waiting for after change list manager finds all changes and runs inner // refresh of copies in the above method ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); changeListManager.ensureUpToDate(false); }
@Override public void run(final ContinuationContext context) { if (myTheirsBinaryChanges.isEmpty()) return; final Application application = ApplicationManager.getApplication(); final List<FilePath> dirtyPaths = new ArrayList<FilePath>(); for (final Change change : myTheirsBinaryChanges) { try { application.runWriteAction( new ThrowableComputable<Void, VcsException>() { @Override public Void compute() throws VcsException { try { if (change.getAfterRevision() == null) { final FilePath path = change.getBeforeRevision().getFile(); dirtyPaths.add(path); final VirtualFile file = LocalFileSystem.getInstance() .refreshAndFindFileByIoFile(path.getIOFile()); if (file == null) { context.handleException( new VcsException("Can not delete file: " + file.getPath(), true), false); return null; } file.delete(TreeConflictRefreshablePanel.class); } else { final FilePath file = change.getAfterRevision().getFile(); dirtyPaths.add(file); final String parentPath = file.getParentPath().getPath(); final VirtualFile parentFile = VfsUtil.createDirectoryIfMissing(parentPath); if (parentFile == null) { context.handleException( new VcsException("Can not create directory: " + parentPath, true), false); return null; } final VirtualFile child = parentFile.createChildData( TreeConflictRefreshablePanel.class, file.getName()); if (child == null) { context.handleException( new VcsException("Can not create file: " + file.getPath(), true), false); return null; } final BinaryContentRevision revision = (BinaryContentRevision) change.getAfterRevision(); final byte[] content = revision.getBinaryContent(); // actually it was the fix for IDEA-91572 Error saving merged data: Argument 0 // for @NotNull parameter of > com/intellij/ if (content == null) { context.handleException( new VcsException( "Can not load Theirs content for file " + file.getPath()), false); return null; } child.setBinaryContent(content); } } catch (IOException e) { throw new VcsException(e); } return null; } }); } catch (VcsException e) { context.handleException(e, true); return; } } VcsDirtyScopeManager.getInstance(myVcs.getProject()).filePathsDirty(dirtyPaths, null); }
/** * Mark root as dirty * * @param root a vcs root to rescan */ private void markRootDirty(final VirtualFile root) { // Note that the root is invalidated because changes are detected per-root anyway. // Otherwise it is not possible to detect moves. myDirtyScopeManager.dirDirtyRecursively(root); }
/** * Preform a merge commit * * @param project a project * @param root a vcs root * @param added added files * @param removed removed files * @param messageFile a message file for commit * @param author an author * @param exceptions the list of exceptions to report * @param partialOperation * @return true if merge commit was successful */ private static boolean mergeCommit( final Project project, final VirtualFile root, final Set<FilePath> added, final Set<FilePath> removed, final File messageFile, final String author, List<VcsException> exceptions, @NotNull final PartialOperation partialOperation) { HashSet<FilePath> realAdded = new HashSet<FilePath>(); HashSet<FilePath> realRemoved = new HashSet<FilePath>(); // perform diff GitSimpleHandler diff = new GitSimpleHandler(project, root, GitCommand.DIFF); diff.setSilent(true); diff.setStdoutSuppressed(true); diff.addParameters("--diff-filter=ADMRUX", "--name-status", "HEAD"); diff.endOptions(); String output; try { output = diff.run(); } catch (VcsException ex) { exceptions.add(ex); return false; } String rootPath = root.getPath(); for (StringTokenizer lines = new StringTokenizer(output, "\n", false); lines.hasMoreTokens(); ) { String line = lines.nextToken().trim(); if (line.length() == 0) { continue; } String[] tk = line.split("\t"); switch (tk[0].charAt(0)) { case 'M': case 'A': realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[1])); break; case 'D': realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[1], false)); break; default: throw new IllegalStateException("Unexpected status: " + line); } } realAdded.removeAll(added); realRemoved.removeAll(removed); if (realAdded.size() != 0 || realRemoved.size() != 0) { final List<FilePath> files = new ArrayList<FilePath>(); files.addAll(realAdded); files.addAll(realRemoved); final Ref<Boolean> mergeAll = new Ref<Boolean>(); try { GuiUtils.runOrInvokeAndWait( new Runnable() { public void run() { String message = GitBundle.message("commit.partial.merge.message", partialOperation.getName()); SelectFilePathsDialog dialog = new SelectFilePathsDialog( project, files, message, null, "Commit All Files", CommonBundle.getCancelButtonText(), false); dialog.setTitle(GitBundle.getString("commit.partial.merge.title")); dialog.show(); mergeAll.set(dialog.isOK()); } }); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException("Unable to invoke a message box on AWT thread", ex); } if (!mergeAll.get()) { return false; } // update non-indexed files if (!updateIndex(project, root, realAdded, realRemoved, exceptions)) { return false; } for (FilePath f : realAdded) { VcsDirtyScopeManager.getInstance(project).fileDirty(f); } for (FilePath f : realRemoved) { VcsDirtyScopeManager.getInstance(project).fileDirty(f); } } // perform merge commit try { GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT); handler.setStdoutSuppressed(false); handler.addParameters("-F", messageFile.getAbsolutePath()); if (author != null) { handler.addParameters("--author=" + author); } handler.endOptions(); handler.run(); GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(root); } catch (VcsException ex) { exceptions.add(ex); return false; } return true; }