IDEADEV-41714 ("Collecting Information on Changes" hangs entire GUI) r=yole
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / integrate / SvnIntegrateChangesActionPerformer.java
blob91eab8163f030131cd2fe8e2a77653707b474333
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn.integrate;
18 import com.intellij.openapi.progress.ProgressManager;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.ui.Messages;
21 import com.intellij.openapi.util.Pair;
22 import org.jetbrains.annotations.Nullable;
23 import org.jetbrains.idea.svn.SvnBranchConfiguration;
24 import org.jetbrains.idea.svn.SvnBundle;
25 import org.jetbrains.idea.svn.SvnVcs;
26 import org.jetbrains.idea.svn.actions.SelectBranchPopup;
27 import org.jetbrains.idea.svn.branchConfig.SvnBranchConfigurationNew;
28 import org.tmatesoft.svn.core.SVNException;
29 import org.tmatesoft.svn.core.SVNURL;
31 public class SvnIntegrateChangesActionPerformer implements SelectBranchPopup.BranchSelectedCallback {
32 private final SvnVcs myVcs;
33 private final MergerFactory myMergerFactory;
35 private final SVNURL myCurrentBranch;
37 public SvnIntegrateChangesActionPerformer(final Project project, final SVNURL currentBranchUrl, final MergerFactory mergerFactory) {
38 myVcs = SvnVcs.getInstance(project);
39 myCurrentBranch = currentBranchUrl;
40 myMergerFactory = mergerFactory;
43 public void branchSelected(final Project project, final SvnBranchConfigurationNew configuration, final String url, final long revision) {
44 onBranchSelected(url, null, null);
47 public void onBranchSelected(final String url, final String selectedLocalBranchPath, final String dialogTitle) {
48 if (myCurrentBranch.toString().equals(url)) {
49 Messages.showErrorDialog(SvnBundle.message("action.Subversion.integrate.changes.error.source.and.target.same.text"),
50 SvnBundle.message("action.Subversion.integrate.changes.messages.title"));
51 return;
54 final Pair<WorkingCopyInfo,SVNURL> pair = IntegratedSelectedOptionsDialog.selectWorkingCopy(myVcs.getProject(), myCurrentBranch, url, true,
55 selectedLocalBranchPath, dialogTitle);
56 if (pair == null) {
57 return;
60 final WorkingCopyInfo info = pair.first;
61 final SVNURL realTargetUrl = pair.second;
63 final SVNURL sourceUrl = correctSourceUrl(url, realTargetUrl.toString());
64 if (sourceUrl == null) {
65 // should not occur
66 return;
68 final SvnIntegrateChangesTask task = new SvnIntegrateChangesTask(myVcs, info, myMergerFactory, sourceUrl);
69 ProgressManager.getInstance().run(task);
72 @Nullable
73 private SVNURL correctSourceUrl(final String targetUrl, final String realTargetUrl) {
74 try {
75 if (realTargetUrl.length() > targetUrl.length()) {
76 if (realTargetUrl.startsWith(targetUrl)) {
77 return myCurrentBranch.appendPath(realTargetUrl.substring(targetUrl.length()), true);
79 } else if (realTargetUrl.equals(targetUrl)) {
80 return myCurrentBranch;
83 catch (SVNException e) {
84 // tracked by return value
86 return null;