Transferring a modified file via SVNKit without local verification?

I use SVNKit to get the contents of a file from our repository. I would like to change this content in the code and transfer the changes back without having to check the file first. I have already searched the website and found solutions that require verification on the local file system.

Does anyone know how to do this?

+3
source share
4 answers
Theoretically, this should be feasible, but practical it seems impossible to use SVNKit.

As far as I can see, all registration operations are directly or indirectly based on org.tmatesoft.svn.core.wc.SVNCommitItem and this class requires a working path to the copy file in it.

, , .

-2

TMate Software, , , . , , Subversion, ( -) Subversion , , , Subversion .

, , , . , . , SVNDirEntry , , ; .

SVNDirEntry dirEntry = svnRepository.info(filePath, -1);
ISVNEditor editor = svnRepository.getCommitEditor("example modification", null, true, null);
editor.openRoot(-1);
if(dirEntry.getKind() == SVNNodeKind.NONE)
{
    editor.addFile(filePath, null, -1);
}
else
{
    editor.openFile(filePath, -1);
}
editor.applyTextDelta(filePath, null);
final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
final String checksum = deltaGenerator.sendDelta(filePath, inputStream, editor, true);
editor.closeFile(filePath, checksum);
editor.closeDir(); //close the root
editor.closeEdit();

, closeEdit() try...catch , , - .

, , SVNKIt 1.3.7 (, Maven):

<repositories>
    <repository>
        <id>svnkit-repository</id>
        <name>SVNKit Repository</name>
        <url>http://maven.tmatesoft.com/content/repositories/releases/</url>
    </repository>
</repositories>
...
<dependency>
    <groupId>org.tmatesoft.svnkit</groupId>
    <artifactId>svnkit</artifactId>
    <version>1.3.7</version>
</dependency>
+6

. , SVN checkout-edit-commit. , , , . .

0

I just tried it. You can change the bytes of the file. Change the contents in memory. Finally, check the code. Here is a sniper:

byte[] in = checkOutPom(project+"/"+ destinationPathQualifier + tag+ "/pom.xml");
BufferedReader bin = new BufferedReader(new InputStreamReader(
                new ByteArrayInputStream(in)));
MyPomHandler h = new MyPomHandler(); //replaces strings in the file
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                os));
h.replace(bin, writer, "1.0.0-SNAPSHOT", tag);
ISVNEditor editor = getRepository().getCommitEditor(
                "Patching POM with tag:"+tag, null);
modifyFile(editor, project + "/" +  destinationPathQualifier + tag, project + "/" +  destinationPathQualifier + tag+"/pom.xml",in, os.toByteArray());

==================================================== =

public byte[] checkOutPom(String filename)
            throws SVNException {
    SVNProperties fileProperties = new SVNProperties();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    getRepository().getFile(filename, -1, fileProperties, baos);
    return baos.toByteArray();
}

====================================================

from the svnkit example code:

public SVNCommitInfo modifyFile(ISVNEditor editor, String dirPath,
            String filePath, byte[] oldData, byte[] newData)
            throws SVNException {   
    editor.openRoot(-1);    
    editor.openDir(dirPath, -1);    
    editor.openFile(filePath, -1);  
    editor.applyTextDelta(filePath, null);  
    SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); 
    String checksum = deltaGenerator.sendDelta(filePath,
                new ByteArrayInputStream(oldData), 0, new ByteArrayInputStream(
                        newData), editor, true);    
    editor.closeFile(filePath, checksum);   
    editor.closeDir();  
    editor.closeDir();  
    return editor.closeEdit();
}
0
source

Source: https://habr.com/ru/post/1785866/


All Articles