private void deleteListImpl(final ShelvedChangeList changeList) { File file = new File(changeList.PATH); myFileProcessor.delete(file.getName()); for (ShelvedBinaryFile binaryFile : changeList.getBinaryFiles()) { final String path = binaryFile.SHELVED_PATH; if (path != null) { File binFile = new File(path); myFileProcessor.delete(binFile.getName()); } } }
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 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 ShelvedBinaryFile shelveBinaryFile(final Change change) throws IOException { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); File beforeFile = beforeRevision == null ? null : beforeRevision.getFile().getIOFile(); File afterFile = afterRevision == null ? null : afterRevision.getFile().getIOFile(); String shelvedPath = null; if (afterFile != null) { String shelvedName = FileUtil.getNameWithoutExtension(afterFile.getName()); String shelvedExt = FileUtil.getExtension(afterFile.getName()); File shelvedFile = FileUtil.findSequentNonexistentFile( myFileProcessor.getBaseIODir(), shelvedName, shelvedExt); myFileProcessor.saveFile(afterRevision.getFile().getIOFile(), shelvedFile); shelvedPath = shelvedFile.getPath(); } String beforePath = ChangesUtil.getProjectRelativePath(myProject, beforeFile); String afterPath = ChangesUtil.getProjectRelativePath(myProject, afterFile); return new ShelvedBinaryFile(beforePath, afterPath, shelvedPath); }
private File getPatchPath(@NonNls final String commitMessage) { File file = myFileProcessor.getBaseIODir(); if (!file.exists()) { file.mkdirs(); } return suggestPatchName( myProject, commitMessage.length() > PatchNameChecker.MAX ? (commitMessage.substring(0, PatchNameChecker.MAX)) : commitMessage, file, VcsConfiguration.PATCH); }