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; } }
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 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); }
public void write(byte[] b, int off, int len) throws IOException { myMD5Digest.update(b, off, len); mySHA1Digest.update(b, off, len); myRepSize += len; int toWrite = 0; while (len > 0) { toWrite = len; myTextBuffer.write(b, off, toWrite); if (myTextBuffer.size() >= WRITE_BUFFER_SIZE) { try { ByteArrayInputStream target = new ByteArrayInputStream(myTextBuffer.toByteArray()); myDeltaGenerator.sendDelta(null, mySourceStream, mySourceOffset, target, this, false); } catch (SVNException svne) { throw new IOException(svne.getMessage()); } myTextBuffer.reset(); } off += toWrite; len -= toWrite; } }
/* * 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 close() throws IOException { if (myIsClosed) { return; } myIsClosed = true; final long truncateToSize[] = new long[] {-1}; try { ByteArrayInputStream target = new ByteArrayInputStream(myTextBuffer.toByteArray()); myDeltaGenerator.sendDelta(null, mySourceStream, mySourceOffset, target, this, false); final FSRepresentation rep = new FSRepresentation(); rep.setOffset(myRepOffset); long offset = myTargetFileOS.getPosition(); rep.setSize(offset - myDeltaStart); rep.setExpandedSize(myRepSize); rep.setTxnId(myRevNode.getId().getTxnID()); String uniqueSuffix = myTxnRoot.getNewTxnNodeId(); String uniquifier = rep.getTxnId() + '/' + uniqueSuffix; rep.setUniquifier(uniquifier); rep.setRevision(SVNRepository.INVALID_REVISION); rep.setMD5HexDigest(SVNFileUtil.toHexDigest(myMD5Digest)); rep.setSHA1HexDigest(SVNFileUtil.toHexDigest(mySHA1Digest)); FSFS fsfs = myTxnRoot.getOwner(); final IFSRepresentationCacheManager reposCacheManager = fsfs.getRepositoryCacheManager(); if (reposCacheManager != null) { try { reposCacheManager.runReadTransaction( new IFSSqlJetTransaction() { public void run() throws SVNException { final FSRepresentation oldRep = reposCacheManager.getRepresentationByHash(rep.getSHA1HexDigest()); if (oldRep != null) { oldRep.setUniquifier(rep.getUniquifier()); oldRep.setMD5HexDigest(rep.getMD5HexDigest()); truncateToSize[0] = myRepOffset; myRevNode.setTextRepresentation(oldRep); } } }); } catch (SVNException e) { // explicitly ignore. SVNDebugLog.getDefaultLog().logError(SVNLogType.FSFS, e); } } if (truncateToSize[0] < 0) { myTargetFileOS.write("ENDREP\n".getBytes("UTF-8")); myRevNode.setTextRepresentation(rep); } myRevNode.setIsFreshTxnRoot(false); fsfs.putTxnRevisionNode(myRevNode.getId(), myRevNode); } catch (SVNException svne) { throw new IOException(svne.getMessage()); } finally { closeStreams(truncateToSize[0]); try { myTxnLock.unlock(); } catch (SVNException e) { // } FSWriteLock.release(myTxnLock); } }