summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnKitHistoryClient.java
blob: 0aca8300e420a2cdd0c0ba79e28194d2c13d632a (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
package org.jetbrains.idea.svn.history;

import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.BaseSvnClient;
import org.jetbrains.idea.svn.commandLine.SvnBindException;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc2.SvnTarget;

import java.io.File;

/**
 * @author Konstantin Kolosovsky.
 */
public class SvnKitHistoryClient extends BaseSvnClient implements HistoryClient {

  @Override
  public void doLog(@NotNull SvnTarget target,
                    @NotNull SVNRevision startRevision,
                    @NotNull SVNRevision endRevision,
                    boolean stopOnCopy,
                    boolean discoverChangedPaths,
                    boolean includeMergedRevisions,
                    long limit,
                    @Nullable String[] revisionProperties,
                    @Nullable LogEntryConsumer handler) throws VcsException {
    try {
      // TODO: a bug noticed when testing: we should pass "limit + 1" to get "limit" rows
      SVNLogClient client = myVcs.getSvnKitManager().createLogClient();

      if (target.isFile()) {
        client.doLog(new File[]{target.getFile()}, startRevision, endRevision, target.getPegRevision(), stopOnCopy, discoverChangedPaths,
                     includeMergedRevisions, limit, revisionProperties, toHandler(handler));
      }
      else {
        client.doLog(target.getURL(), ArrayUtil.EMPTY_STRING_ARRAY, target.getPegRevision(), startRevision, endRevision, stopOnCopy,
                     discoverChangedPaths, includeMergedRevisions, limit, revisionProperties, toHandler(handler));
      }
    }
    catch (SVNException e) {
      throw new SvnBindException(e);
    }
  }

  @Nullable
  private static ISVNLogEntryHandler toHandler(@Nullable final LogEntryConsumer handler) {
    ISVNLogEntryHandler result = null;

    if (handler != null) {
      result = new ISVNLogEntryHandler() {
        @Override
        public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
          handler.consume(LogEntry.create(logEntry));
        }
      };
    }

    return result;
  }
}