0

I am using svnkit in java for doing anykind of svn related stuff programatically. I want to commit file only when it is changed. I am using this code snippet:

SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();

        String checksum = deltaGenerator.sendDelta(filePath, new ByteArrayInputStream(oldData), 0, new ByteArrayInputStream(newData), editor, true);

This code is creating new version of the file whenever anyone tries to commit anything. I want to avoid this when the content of the remote file and local file is same. Is there any way using svnkit library? Thanks,

Amandeep

Amandeep Singh
  • 3,754
  • 8
  • 51
  • 72
  • You could compare `oldData` and `newData` to check whether or not they match before allowing the commit. You could do something along the lines of hashing both and checking whether the resulting hash strings match etc... I have no knowledge on the svnkit library however, so I don't know whether it has this functionality available internally. – Ceiling Gecko Mar 31 '14 at 12:39
  • Thanks @CeilingGecko I am new to svnkit as well.I thought of similar solution but since old data and newData are byteArray not sure how I can compare them with complete correctness – Amandeep Singh Mar 31 '14 at 12:54
  • You could use the `MessageDigest` class. [DOCS HERE](http://docs.oracle.com/javase/7/docs/api/java/security/MessageDigest.html) You can check an example: [HERE](http://www.mkyong.com/java/java-md5-hashing-example/) To make it less error prone (because collisions) you can for example switch out the "MD5" to "SHA-256". And to check whether the `oldData` matches `newData` you can then just compare the hashed Strings to see if they match or not. – Ceiling Gecko Mar 31 '14 at 13:37
  • Thanks @CeilingGecko will definetely try this one out. – Amandeep Singh Mar 31 '14 at 15:20

0 Answers0