Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2008-09-03 16:14:17
Size: 19
Editor: 194
Comment:
Revision 6 as of 2008-09-03 17:22:01
Size: 5564
Editor: 194
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
{{{{#!java This example demonstrates how you can merge changes to a branch without specifying revisions.
Line 3: Line 3:
{{{#!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 java.util.Collections;

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.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNCopyClient;
import org.tmatesoft.svn.core.wc.SVNCopySource;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNRevisionRange;
import org.tmatesoft.svn.core.wc.SVNWCClient;


/**
 * @version 1.2.0
 * @author TMate Software Ltd.
 */
public class Merge {

    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 {
            //first create a repository and fill it with data
            SamplesUtility.createRepository(reposRoot);
            SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
            //print out new revision info
            System.out.println(info);

            SVNClientManager clientManager = SVNClientManager.newInstance();
            
            SVNURL reposURL = SVNURL.fromFile(reposRoot);

            //copy A to A_copy in repository (url-to-url copy)
            SVNCopyClient copyClient = clientManager.getCopyClient();
            SVNURL A_URL = reposURL.appendPath("A", true);
            SVNURL copyTargetURL = reposURL.appendPath("A_copy", true);
            SVNCopySource copySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, A_URL);
            info = copyClient.doCopy(new SVNCopySource[] { copySource }, copyTargetURL, false, false, true,
                    "copy A to A_copy", null);
            //print out new revision info
            System.out.println(info);
            
            //checkout the entire repository tree
            SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);

            
            //now make some changes to the A tree
            SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
            SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
            
            SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
            wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
                    SVNDepth.EMPTY, null, null);

            //commit local changes
            SVNCommitClient commitClient = clientManager.getCommitClient();
            commitClient.doCommit(new File[] { wcRoot }, false, "committing changes", null, null, false, false, SVNDepth.INFINITY);
            
            //now diff the base revision of the working copy against the repository
            SVNDiffClient diffClient = clientManager.getDiffClient();
            SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD);
            
            diffClient.doMerge(A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge),
                    new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false);
            
            
            //now make some changes to the A tree again
            //change file contents of iota and A/D/gamma
            SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text2 appended to 'iota'", true);
            SamplesUtility.writeToFile(new File(wcRoot, "A/D/gamma"), "New text in 'gamma'", false);
            //remove A/C from version control
            wcClient.doDelete(new File(wcRoot, "A/C"), false, true, false);

            //commit local changes
            commitClient.doCommit(new File[] { wcRoot }, false, "committing changes again", null, null, false, false, SVNDepth.INFINITY);

            /* do the same merge call, merge-tracking feature will merge only those revisions
             * which were not still merged.
             */
            diffClient.doMerge(A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge),
                    new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false);
            
        } catch (SVNException svne) {
            System.out.println(svne.getErrorMessage());
            System.exit(1);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.exit(1);
        }
    }

}

This example demonstrates how you can merge changes to a branch without specifying revisions.

   1 /*
   2  * ====================================================================
   3  * Copyright (c) 2004-2008 TMate Software Ltd.  All rights reserved.
   4  *
   5  * This software is licensed as described in the file COPYING, which
   6  * you should have received as part of this distribution.  The terms
   7  * are also available at http://svnkit.com/license.html.
   8  * If newer versions of this license are posted there, you may use a
   9  * newer version instead, at your option.
  10  * ====================================================================
  11  */
  12 package org.tmatesoft.svn.examples.wc;
  13 
  14 import java.io.File;
  15 import java.io.IOException;
  16 import java.util.Collections;
  17 
  18 import org.tmatesoft.svn.core.SVNCommitInfo;
  19 import org.tmatesoft.svn.core.SVNDepth;
  20 import org.tmatesoft.svn.core.SVNException;
  21 import org.tmatesoft.svn.core.SVNPropertyValue;
  22 import org.tmatesoft.svn.core.SVNURL;
  23 import org.tmatesoft.svn.core.wc.SVNClientManager;
  24 import org.tmatesoft.svn.core.wc.SVNCommitClient;
  25 import org.tmatesoft.svn.core.wc.SVNCopyClient;
  26 import org.tmatesoft.svn.core.wc.SVNCopySource;
  27 import org.tmatesoft.svn.core.wc.SVNDiffClient;
  28 import org.tmatesoft.svn.core.wc.SVNRevision;
  29 import org.tmatesoft.svn.core.wc.SVNRevisionRange;
  30 import org.tmatesoft.svn.core.wc.SVNWCClient;
  31 
  32 
  33 /**
  34  * @version 1.2.0
  35  * @author  TMate Software Ltd.
  36  */
  37 public class Merge {
  38 
  39     public static void main (String[] args) {
  40         //initialize SVNKit to work through file:/// protocol
  41         SamplesUtility.initializeFSFSprotocol();
  42         
  43         File baseDirectory = new File(args[0]);
  44         File reposRoot = new File(baseDirectory, "exampleRepository");
  45         File wcRoot = new File(baseDirectory, "exampleWC");
  46         
  47         try {
  48             //first create a repository and fill it with data
  49             SamplesUtility.createRepository(reposRoot);
  50             SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
  51             //print out new revision info
  52             System.out.println(info);
  53 
  54             SVNClientManager clientManager = SVNClientManager.newInstance();
  55             
  56             SVNURL reposURL = SVNURL.fromFile(reposRoot);
  57 
  58             //copy A to A_copy in repository (url-to-url copy)
  59             SVNCopyClient copyClient = clientManager.getCopyClient();
  60             SVNURL A_URL = reposURL.appendPath("A", true);
  61             SVNURL copyTargetURL = reposURL.appendPath("A_copy", true);
  62             SVNCopySource copySource = new SVNCopySource(SVNRevision.UNDEFINED, SVNRevision.HEAD, A_URL); 
  63             info = copyClient.doCopy(new SVNCopySource[] { copySource }, copyTargetURL, false, false, true, 
  64                     "copy A to A_copy", null);
  65             //print out new revision info
  66             System.out.println(info);
  67             
  68             //checkout the entire repository tree
  69             SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);
  70 
  71             
  72             //now make some changes to the A tree
  73             SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
  74             SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
  75             
  76             SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
  77             wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false, 
  78                     SVNDepth.EMPTY, null, null);
  79 
  80             //commit local changes
  81             SVNCommitClient commitClient = clientManager.getCommitClient();
  82             commitClient.doCommit(new File[] { wcRoot }, false, "committing changes", null, null, false, false, SVNDepth.INFINITY);
  83             
  84             //now diff the base revision of the working copy against the repository
  85             SVNDiffClient diffClient = clientManager.getDiffClient();
  86             SVNRevisionRange rangeToMerge = new SVNRevisionRange(SVNRevision.create(1), SVNRevision.HEAD);
  87             
  88             diffClient.doMerge(A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge), 
  89                     new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false);
  90             
  91             
  92             //now make some changes to the A tree again
  93             //change file contents of iota and A/D/gamma
  94             SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text2 appended to 'iota'", true);
  95             SamplesUtility.writeToFile(new File(wcRoot, "A/D/gamma"), "New text in 'gamma'", false);
  96             //remove A/C from version control
  97             wcClient.doDelete(new File(wcRoot, "A/C"), false, true, false);
  98 
  99             //commit local changes
 100             commitClient.doCommit(new File[] { wcRoot }, false, "committing changes again", null, null, false, false, SVNDepth.INFINITY);
 101 
 102             /* do the same merge call, merge-tracking feature will merge only those revisions
 103              * which were not still merged.
 104              */ 
 105             diffClient.doMerge(A_URL, SVNRevision.HEAD, Collections.singleton(rangeToMerge), 
 106                     new File(wcRoot, "A_copy"), SVNDepth.UNKNOWN, true, false, false, false);
 107             
 108         } catch (SVNException svne) {
 109             System.out.println(svne.getErrorMessage());
 110             System.exit(1);
 111         } catch (IOException ioe) {
 112             ioe.printStackTrace();
 113             System.exit(1);
 114         }
 115     }
 116 
 117 }

Merging from trunk to a branch (last edited 2008-09-04 15:57:55 by 194)