summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/SvnKitMergeClient.java
blob: e3635ff8827bc8e49e28cf2df405791be7bda642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package org.jetbrains.idea.svn.integrate;

import com.intellij.openapi.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.BaseSvnClient;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.ISVNEventHandler;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNDiffOptions;
import org.tmatesoft.svn.core.wc.SVNRevisionRange;
import org.tmatesoft.svn.core.wc2.SvnTarget;

import java.io.File;
import java.util.Collections;

/**
 * @author Konstantin Kolosovsky.
 */
public class SvnKitMergeClient extends BaseSvnClient implements MergeClient {

  public void merge(@NotNull SvnTarget source,
                    @NotNull File destination,
                    boolean dryRun,
                    @Nullable SVNDiffOptions diffOptions,
                    @Nullable ISVNEventHandler handler) throws VcsException {
    assertUrl(source);

    try {
      createClient(diffOptions, handler).doMergeReIntegrate(source.getURL(), source.getPegRevision(), destination, dryRun);
    }
    catch (SVNException e) {
      throw new VcsException(e);
    }
  }

  @Override
  public void merge(@NotNull SvnTarget source,
                    @NotNull SVNRevisionRange range,
                    @NotNull File destination,
                    @Nullable SVNDepth depth,
                    boolean dryRun,
                    boolean recordOnly,
                    boolean force,
                    @Nullable SVNDiffOptions diffOptions,
                    @Nullable ISVNEventHandler handler) throws VcsException {
    assertUrl(source);

    try {
      createClient(diffOptions, handler).doMerge(source.getURL(), source.getPegRevision(), Collections.singletonList(range), destination,
                                                 depth, true, force, dryRun, recordOnly);
    }
    catch (SVNException e) {
      throw new VcsException(e);
    }
  }

  @Override
  public void merge(@NotNull SvnTarget source1,
                    @NotNull SvnTarget source2,
                    @NotNull File destination,
                    @Nullable SVNDepth depth,
                    boolean useAncestry,
                    boolean dryRun,
                    boolean recordOnly,
                    boolean force,
                    @Nullable SVNDiffOptions diffOptions,
                    @Nullable ISVNEventHandler handler) throws VcsException {
    assertUrl(source1);
    assertUrl(source2);

    try {
      createClient(diffOptions, handler).doMerge(source1.getURL(), source1.getPegRevision(), source2.getURL(), source2.getPegRevision(),
                                                 destination, depth, useAncestry, force, dryRun, recordOnly);
    }
    catch (SVNException e) {
      throw new VcsException(e);
    }
  }

  @NotNull
  private SVNDiffClient createClient(@Nullable SVNDiffOptions diffOptions, @Nullable ISVNEventHandler handler) {
    SVNDiffClient client = myVcs.getSvnKitManager().createDiffClient();

    client.setMergeOptions(diffOptions);
    client.setEventHandler(handler);

    return client;
  }
}