/** * Accomodates the paths opened in editor to the given new path. This should be used only to open * existing directories. * * @param newPath * @param openLast * @param lastRevision * @throws SVNException */ public void accomodate(String newPath, boolean openLast, long lastRevision) throws SVNException { // If there's a file opened, always closing it. if (fileOnTop) { // Checking if we don't want to have the same file opened. if (newPath.equals(pathsStack.peek())) return; editor.closeFile(pathsStack.pop(), null); fileOnTop = false; } // Poping and closing all opened directories which // don't fit into the new path. while ((!pathsStack.empty()) && (!newPath.startsWith(pathsStack.peek()))) { pathsStack.pop(); editor.closeDir(); } // Opening directories from the new path and putting their paths on the // stack. String currentPath = pathsStack.empty() ? "/" : pathsStack.peek(); String[] parts = newPath.substring(currentPath.length()).split("[/]"); for (int i = 0; i < (openLast ? parts.length : parts.length - 1); i++) { /* * A path part may be empty in two cases: * 1. pathStack.peek() is equal to newPath * 2. newPath = properPath + "/" * In both cases we don't want to open the "empty" directory. */ if (!"".equals(parts[i])) { currentPath += Tools.addPaths(parts[i], ""); editor.openDir(currentPath, lastRevision); pathsStack.push(currentPath); } } }
/* * This method performs committing a deletion of a directory. */ private static SVNCommitInfo deleteDir(ISVNEditor editor, String dirPath) throws SVNException { /* * Always called first. Opens the current root directory. It means all * modifications will be applied to this directory until a next entry * (located inside the root) is opened/added. * * -1 - revision is HEAD */ editor.openRoot(-1); /* * Deletes the subdirectory with all its contents. * * dirPath is relative to the root directory. */ editor.deleteEntry(dirPath, -1); /* * Closes the root directory. */ editor.closeDir(); /* * This is the final point in all editor handling. Only now all that new * information previously described with the editor's methods is sent to * the server for committing. As a result the server sends the new * commit information. */ return editor.closeEdit(); }
public void copy( final ISVNEditor commitEditor, final String fromPath, final long fromRevision, final String toPath) throws SVNException { String dir = SVNPathUtil.removeTail(toPath); commitEditor.openDir(dir, -1); commitEditor.addFile(toPath, fromPath, fromRevision); commitEditor.closeDir(); }
public void moveDir( final ISVNEditor commitEditor, final String fromPath, final long baseRevision, final String toPath) throws SVNException { String dir = SVNPathUtil.removeTail(toPath); commitEditor.openDir(dir, -1); commitEditor.deleteEntry(fromPath, baseRevision); commitEditor.addDir(toPath, fromPath, baseRevision); commitEditor.closeDir(); }
public void close() throws SVNException { if (isFileOpened()) { editor.closeFile(pathsStack.pop(), null); } while (!pathsStack.empty()) { editor.closeDir(); pathsStack.pop(); } editor.closeDir(); editor.closeEdit(); }
public void edit( ISVNEditor commitEditor, final String path, final long baseRevision, final InputStream content) throws SVNException { commitEditor.openFile(path, baseRevision); commitEditor.applyTextDelta(path, null); SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); // We don't keep the base around so we can't provide it here. String checksum = deltaGenerator.sendDelta(path, content, commitEditor, true); commitEditor.closeFile(path, checksum); }
@Override public void applyAction(Object context) throws Exception { ISVNEditor editor = (ISVNEditor) context; ISVNEditorUtil.openDirectories(editor, this.path); if (this.file.startsWith("/")) this.file = file.substring(1); editor.addFile(this.path + "/" + this.file, null, -1); editor.applyTextDelta(this.path + "/" + this.file, null); SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); String checksum = deltaGenerator.sendDelta( this.path + "/" + this.file, new ByteArrayInputStream(this.content), editor, true); editor.closeFile(this.path + "/" + this.file, checksum); ISVNEditorUtil.closeDirectories(editor, this.path); }
public PathsStack(ISVNEditor editor) throws SVNException { pathsStack = new Stack<String>(); fileOnTop = false; this.editor = editor; editor.openRoot(-1); }
public void delete(ISVNEditor commitEditor, final String path, final long baseRevision) throws SVNException { try { commitEditor.deleteEntry(path, baseRevision); } catch (SVNException ex) { // We just ignore this - older versions of SVNKit didn't explain at all. if (!SVNErrorCode.FS_NOT_FOUND.equals(ex.getErrorMessage().getErrorCode())) { throw ex; } } }
/* * This method performs how a directory in the repository can be copied to * branch. */ private static SVNCommitInfo copyDir( ISVNEditor editor, String srcDirPath, String dstDirPath, long revision) throws SVNException { /* * Always called first. Opens the current root directory. It means all * modifications will be applied to this directory until a next entry * (located inside the root) is opened/added. * * -1 - revision is HEAD */ editor.openRoot(-1); /* * Adds a new directory that is a copy of the existing one. * * srcDirPath - the source directory path (relative to the root * directory). * * dstDirPath - the destination directory path where the source will be * copied to (relative to the root directory). * * revision - the number of the source directory revision. */ editor.addDir(dstDirPath, srcDirPath, revision); /* * Closes the just added copy of the directory. */ editor.closeDir(); /* * Closes the root directory. */ editor.closeDir(); /* * This is the final point in all editor handling. Only now all that new * information previously described with the editor's methods is sent to * the server for committing. As a result the server sends the new * commit information. */ return editor.closeEdit(); }
public void create(ISVNEditor commitEditor, final String path, final InputStream content) throws SVNException, IOException { final BufferedInputStream bis = new BufferedInputStream(content); final String autoDetectedMimeType = detectMimeType(bis); commitEditor.addFile(path, null, -1); commitEditor.applyTextDelta(path, null); SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); String checksum = deltaGenerator.sendDelta(path, bis, commitEditor, true); final Map<String, String> autoprops = _autoPropertiesApplier.apply(path); for (Map.Entry<String, String> entry : autoprops.entrySet()) { commitEditor.changeFileProperty( path, entry.getKey(), SVNPropertyValue.create(entry.getValue())); } if (!autoprops.containsKey(SVNProperty.MIME_TYPE) && autoDetectedMimeType != null) { commitEditor.changeFileProperty( path, SVNProperty.MIME_TYPE, SVNPropertyValue.create(autoDetectedMimeType)); } commitEditor.closeFile(path, checksum); }
private SVNCommitInfo createSecondCommit() throws SVNException { String logMessage = "test second commit"; ISVNWorkspaceMediator mediator = new PostCommitWorkspaceMediator(); ISVNEditor editor = repository.getCommitEditor(logMessage, mediator); editor.openRoot(1); editor.addFile("dirB/file2.txt", null, -1); editor.applyTextDelta("dirB/file2.txt", null); OutputStream os = editor.textDeltaChunk("dirB/file2.txt", SVNDiffWindow.EMPTY); editor.textDeltaEnd("dirB/file2.txt"); editor.closeFile("dirB/file2.txt", null); return editor.closeEdit(); }
/** * I take no credit for the below code. The creation of the svn repository is provided by the * svnkit library guys at: http://wiki.svnkit.com/Setting_Up_A_Subversion_Repository * * @throws SVNException */ private SVNCommitInfo createSVNRepository() throws Exception { FSRepositoryFactory.setup(); String repoDir = "/tmp/399165/svn"; SVNRepositoryFactoryImpl.setup(); SVNURL repo = SVNRepositoryFactory.createLocalRepository(new File("/tmp/399165"), true, true); repository = SVNRepositoryFactory.create(repo); String logMessage = "test commit message"; ISVNWorkspaceMediator mediator = new PostCommitWorkspaceMediator(); ISVNEditor editor = repository.getCommitEditor(logMessage, mediator); editor.openRoot(-1); editor.addDir("dirB", null, -1); editor.addFile("dirB/file1.txt", null, -1); editor.applyTextDelta("dirB/file1.txt", null); OutputStream os = editor.textDeltaChunk("dirB/file1.txt", SVNDiffWindow.EMPTY); editor.textDeltaEnd("dirB/file1.txt"); editor.closeFile("dirB/file1.txt", null); return editor.closeEdit(); }
public static void replay( FSFS fsfs, FSRoot root, String basePath, long lowRevision, boolean sendDeltas, ISVNEditor editor) throws SVNException { Map fsChanges = root.getChangedPaths(); basePath = basePath.startsWith("/") ? basePath.substring(1) : basePath; Collection interestingPaths = new LinkedList(); Map changedPaths = new HashMap(); for (Iterator paths = fsChanges.keySet().iterator(); paths.hasNext(); ) { String path = (String) paths.next(); FSPathChange change = (FSPathChange) fsChanges.get(path); path = path.startsWith("/") ? path.substring(1) : path; if ("".equals(basePath) || (path.startsWith(basePath) && (path.charAt(basePath.length()) == '/' || path.length() == basePath.length()))) { path = path.startsWith("/") ? path.substring(1) : path; interestingPaths.add(path); changedPaths.put(path, change); } } if (FSRepository.isInvalidRevision(lowRevision)) { lowRevision = 0; } FSRoot compareRoot = null; if (sendDeltas && root instanceof FSRevisionRoot) { FSRevisionRoot revRoot = (FSRevisionRoot) root; compareRoot = fsfs.createRevisionRoot(revRoot.getRevision() - 1); } if (root instanceof FSRevisionRoot) { FSRevisionRoot revRoot = (FSRevisionRoot) root; editor.targetRevision(revRoot.getRevision()); } ISVNCommitPathHandler handler = new FSReplayPathHandler(fsfs, root, compareRoot, changedPaths, basePath, lowRevision); SVNCommitUtil.driveCommitEditor(handler, interestingPaths, editor, -1); }
/* * This method performs committing file modifications. */ private static SVNCommitInfo modifyFile( ISVNEditor editor, String dirPath, String filePath, byte[] oldData, byte[] newData) throws SVNException { /* * Always called first. Opens the current root directory. It means all * modifications will be applied to this directory until a next entry * (located inside the root) is opened/added. * * -1 - revision is HEAD */ editor.openRoot(-1); /* * Opens a next subdirectory (in this example program it's the directory * added in the last commit). Since this moment all changes will be * applied to this directory. * * dirPath is relative to the root directory. * -1 - revision is HEAD */ editor.openDir(dirPath, -1); /* * Opens the file added in the previous commit. * * filePath is also defined as a relative path to the root directory. */ editor.openFile(filePath, -1); /* * The next steps are directed to applying and writing the file delta. */ editor.applyTextDelta(filePath, null); /* * Use delta generator utility class to generate and send delta * * Note that you may use only 'target' data to generate delta when there is no * access to the 'base' (previous) version of the file. However, here we've got 'base' * data, what in case of larger files results in smaller network overhead. * * SVNDeltaGenerator will call editor.textDeltaChunk(...) method for each generated * "diff window" and then editor.textDeltaEnd(...) in the end of delta transmission. * Number of diff windows depends on the file size. * */ SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); String checksum = deltaGenerator.sendDelta( filePath, new ByteArrayInputStream(oldData), 0, new ByteArrayInputStream(newData), editor, true); /* * Closes the file. */ editor.closeFile(filePath, checksum); /* * Closes the directory. */ editor.closeDir(); /* * Closes the root directory. */ editor.closeDir(); /* * This is the final point in all editor handling. Only now all that new * information previously described with the editor's methods is sent to * the server for committing. As a result the server sends the new * commit information. */ return editor.closeEdit(); }
/* * This method performs commiting an addition of a directory containing a * file. */ private static SVNCommitInfo addDir( ISVNEditor editor, String dirPath, String filePath, byte[] data) throws SVNException { /* * Always called first. Opens the current root directory. It means all * modifications will be applied to this directory until a next entry * (located inside the root) is opened/added. * * -1 - revision is HEAD (actually, for a comit editor this number is * irrelevant) */ editor.openRoot(-1); /* * Adds a new directory (in this case - to the root directory for * which the SVNRepository was created). * Since this moment all changes will be applied to this new directory. * * dirPath is relative to the root directory. * * copyFromPath (the 2nd parameter) is set to null and copyFromRevision * (the 3rd) parameter is set to -1 since the directory is not added * with history (is not copied, in other words). */ editor.addDir(dirPath, null, -1); /* * Adds a new file to the just added directory. The file path is also * defined as relative to the root directory. * * copyFromPath (the 2nd parameter) is set to null and copyFromRevision * (the 3rd parameter) is set to -1 since the file is not added with * history. */ editor.addFile(filePath, null, -1); /* * The next steps are directed to applying delta to the file (that is * the full contents of the file in this case). */ editor.applyTextDelta(filePath, null); /* * Use delta generator utility class to generate and send delta * * Note that you may use only 'target' data to generate delta when there is no * access to the 'base' (previous) version of the file. However, using 'base' * data will result in smaller network overhead. * * SVNDeltaGenerator will call editor.textDeltaChunk(...) method for each generated * "diff window" and then editor.textDeltaEnd(...) in the end of delta transmission. * Number of diff windows depends on the file size. * */ SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); String checksum = deltaGenerator.sendDelta(filePath, new ByteArrayInputStream(data), editor, true); /* * Closes the new added file. */ editor.closeFile(filePath, checksum); /* * Closes the new added directory. */ editor.closeDir(); /* * Closes the root directory. */ editor.closeDir(); /* * This is the final point in all editor handling. Only now all that new * information previously described with the editor's methods is sent to * the server for committing. As a result the server sends the new * commit information. */ return editor.closeEdit(); }
public void createDirectory(ISVNEditor commitEditor, final String dir) throws SVNException { commitEditor.addDir(dir, null, -1); }
private SVNCommitInfo tryCommit( final String filePath, SVNRepository repository, final Map<String, String> locks) throws SVNException { ISVNEditor editor = repository.getCommitEditor("commit message", locks, true, null, null); try { editor.openRoot(-1); editor.openDir("Prueba", -1); editor.openDir("Prueba/Modify", -1); editor.openFile(filePath, -1); editor.applyTextDelta(filePath, null); final SVNDeltaGenerator generator = new SVNDeltaGenerator(); final byte[] newContents = "new contents".getBytes(); final String checksum = generator.sendDelta(filePath, new ByteArrayInputStream(newContents), editor, true); editor.closeFile(filePath, checksum); editor.closeDir(); editor.closeDir(); editor.closeDir(); return editor.closeEdit(); } catch (SVNException e) { if (editor != null) { editor.abortEdit(); } throw e; } }