1 19 20 package org.netbeans.modules.subversion.ui.copy; 21 22 import java.io.File ; 23 import org.netbeans.modules.subversion.FileInformation; 24 import org.netbeans.modules.subversion.RepositoryFile; 25 import org.netbeans.modules.subversion.Subversion; 26 import org.netbeans.modules.subversion.client.SvnClient; 27 import org.netbeans.modules.subversion.client.SvnProgressSupport; 28 import org.netbeans.modules.subversion.ui.actions.ContextAction; 29 import org.netbeans.modules.subversion.util.Context; 30 import org.netbeans.modules.subversion.util.SvnUtils; 31 import org.netbeans.modules.versioning.util.Utils; 32 import org.openide.ErrorManager; 33 import org.openide.nodes.Node; 34 import org.tigris.subversion.svnclientadapter.ISVNLogMessage; 35 import org.tigris.subversion.svnclientadapter.SVNClientException; 36 import org.tigris.subversion.svnclientadapter.SVNRevision; 37 import org.tigris.subversion.svnclientadapter.SVNUrl; 38 39 43 public class MergeAction extends ContextAction { 44 45 public MergeAction() { 46 } 47 48 protected String getBaseName(Node[] activatedNodes) { 49 return "CTL_MenuItem_Merge"; } 51 52 protected int getFileEnabledStatus() { 53 return FileInformation.STATUS_MANAGED 54 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 55 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 56 } 57 58 protected int getDirectoryEnabledStatus() { 59 return FileInformation.STATUS_MANAGED 60 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 61 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 62 } 63 64 protected void performContextAction(final Node[] nodes) { 65 Context ctx = getContext(nodes); 66 final File root = ctx.getRootFiles()[0]; 67 SVNUrl url = SvnUtils.getRepositoryRootUrl(root); 68 final RepositoryFile repositoryRoot = new RepositoryFile(url, url, SVNRevision.HEAD); 69 70 final Merge merge = new Merge(repositoryRoot, root); 71 if(merge.showDialog()) { 72 ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) { 73 public void perform() { 74 performMerge(merge, repositoryRoot, root, this); 75 } 76 }; 77 support.start(createRequestProcessor(nodes)); 78 } 79 } 80 81 private void performMerge(Merge merge, RepositoryFile repositoryRoot, File root, SvnProgressSupport support) { 82 File [][] split = Utils.splitFlatOthers(new File [] {root} ); 83 boolean recursive; 84 if(split[0].length > 0) { 86 recursive = false; 87 } else { 88 recursive = true; 89 } 90 91 try { 92 SvnClient client; 93 try { 94 client = Subversion.getInstance().getClient(repositoryRoot.getRepositoryUrl()); 95 } catch (SVNClientException ex) { 96 ErrorManager.getDefault().notify(ex); 97 return; 98 } 99 100 if(support.isCanceled()) { 101 return; 102 } 103 104 SVNUrl endUrl = merge.getMergeEndUrl(); 105 SVNRevision endRevision = merge.getMergeEndRevision(); 106 107 SVNUrl startUrl = merge.getMergeStartUrl(); 108 SVNRevision startRevision; 109 if(startUrl != null) { 110 startRevision = merge.getMergeStartRevision(); 111 } else { 112 startUrl = endUrl; 114 ISVNLogMessage[] log = client.getLogMessages(startUrl, new SVNRevision.Number(0), new SVNRevision.Number(0), SVNRevision.HEAD, true, false, 0L); 115 startRevision = log[0].getRevision(); 116 } 117 if(support.isCanceled()) { 118 return; 119 } 120 121 client.merge(startUrl, 122 startRevision, 123 endUrl, 124 endRevision, 125 root, 126 false, 127 recursive); 128 129 } catch (SVNClientException ex) { 130 support.annotate(ex); 131 } 132 } 133 } 134 | Popular Tags |