= Performing 'svn diff -rHEAD' with SVNKit = This is an example of performing diff on an entire working copy against the repository. Below we will enumerate the main steps performed by this example program, and reflect those steps in code comments as well, so that you could keep track of what the program does. 1. We create a brand-new repository. 2. Then populate it with a [[Greek Tree|greek tree]] not using file system directories and files. All this initializing work is done with the help of the utility class called [[SamplesUtility]]. 3. Then checkout a working copy. 4. Then make text changes in two files and set a property on a directory. 5. Then we diff our working copy against the repository. {{{#!java /* * ==================================================================== * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://svnkit.com/license.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * ==================================================================== */ package org.tmatesoft.svn.examples.wc; import java.io.File; import java.io.IOException; import org.tmatesoft.svn.core.SVNCommitInfo; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNPropertyValue; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.wc.SVNClientManager; import org.tmatesoft.svn.core.wc.SVNDiffClient; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNWCClient; /** * This examples demonstrate how you can run WORKING:HEAD diff. * * @version 1.2.0 * @author TMate Software Ltd. */ public class DiffWCToRepository { /** * Pass the absolute path of the base directory where all example data will be created in * arg[0]. The sample will create: * * - arg[0]/exampleRepository - repository with some test data * - arg[0]/exampleWC - working copy checked out from exampleRepository */ public static void main (String[] args) { //initialize SVNKit to work through file:/// protocol SamplesUtility.initializeFSFSprotocol(); File baseDirectory = new File(args[0]); File reposRoot = new File(baseDirectory, "exampleRepository"); File wcRoot = new File(baseDirectory, "exampleWC"); try { //1. first create a repository and fill it with data SamplesUtility.createRepository(reposRoot); //2. populate the repository with the greek tree in a single transaction SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot); //pring out the commit information System.out.println(info); //3. checkout the entire repository tree SVNURL reposURL = SVNURL.fromFile(reposRoot); SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot); //4. now make some changes to the working copy SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true); SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false); SVNClientManager clientManager = SVNClientManager.newInstance(); SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient(); //set some property on a working copy directory wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false, SVNDepth.EMPTY, null, null); //5. now run diff the working copy against the repository SVNDiffClient diffClient = clientManager.getDiffClient(); /* * This corresponds to 'svn diff -rHEAD'. */ diffClient.doDiff(wcRoot, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD, SVNDepth.INFINITY, true, System.out, null); } catch (SVNException svne) { System.out.println(svne.getErrorMessage()); System.exit(1); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(1); } } } }}} What we do with the SVNDiffClient here in this example is equivalent to calling the command line client with the following parameters: {{{ $svn diff -rHEAD }}} Now here come several comments on the ''doDiff()'' method itself. * We used the pegged version of ''doDiff()'' which runs diff on different revisions of the same tree (or file). * As the second parameter we pass ''SVNRevision.UNKWNOWN'' what denotes that we do not provide any special [[Peg revision|peg revision]]. This will automatically default to the HEAD revision. * Then we provide ''SVNRevision.WORKING'' and ''SVNRevision.HEAD'' as we want to diff working tree with the one located in the repository at HEAD revision. * ''SVNDepth.INFINITY'' says that want to diff the entire tree recursively. * Then comes the ''useAncestry'' flag - in this example we want to diff only related object, so we pass ''true''. * System.out - this is a diff output receiver stream. * And at last we do not have changelists in our working copy and want diff to operate on the entire tree, not just on members of some changelist (in case we had one). So, we pass ''null''. When you run the program you will see an output like this: {{{ r1 by 'alex' at Wed Sep 03 18:34:52 CEST 2008 Property changes on: /home/alex/workspace/tmp/exampleWC/A/B ___________________________________________________________________ Added: spam + egg Index: /home/alex/workspace/tmp/exampleWC/A/mu =================================================================== --- /home/alex/workspace/tmp/exampleWC/A/mu (revision 1) +++ /home/alex/workspace/tmp/exampleWC/A/mu (working copy) @@ -1 +1 @@ -This is the file 'A/mu'. +New text in 'mu' \ No newline at end of file Index: /home/alex/workspace/tmp/exampleWC/iota =================================================================== --- /home/alex/workspace/tmp/exampleWC/iota (revision 1) +++ /home/alex/workspace/tmp/exampleWC/iota (working copy) @@ -1 +1,2 @@ This is the file 'iota'. +New text appended to 'iota' \ No newline at end of file }}}