Skip to content

Commit 867787e

Browse files
committed
2 parents c13f08f + 85c6c57 commit 867787e

File tree

3 files changed

+46
-68
lines changed

3 files changed

+46
-68
lines changed

src/main/java/org/scm4j/vcs/svn/SVNVCS.java

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.scm4j.vcs.api.exceptions.*;
77
import org.scm4j.vcs.api.workingcopy.IVCSLockedWorkingCopy;
88
import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
9-
import org.scm4j.vcs.api.workingcopy.IVCSWorkspace;
109
import org.tmatesoft.svn.core.*;
1110
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
1211
import org.tmatesoft.svn.core.auth.SVNAuthentication;
@@ -15,7 +14,10 @@
1514
import org.tmatesoft.svn.core.io.SVNRepository;
1615
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
1716
import org.tmatesoft.svn.core.wc.*;
18-
import org.tmatesoft.svn.core.wc2.*;
17+
import org.tmatesoft.svn.core.wc2.SvnDiff;
18+
import org.tmatesoft.svn.core.wc2.SvnDiffSummarize;
19+
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
20+
import org.tmatesoft.svn.core.wc2.SvnTarget;
1921

2022
import java.io.ByteArrayOutputStream;
2123
import java.io.File;
@@ -35,7 +37,7 @@ public class SVNVCS implements IVCS {
3537

3638
private BasicAuthenticationManager authManager;
3739
private SVNRepository repository;
38-
private ISVNOptions options;
40+
private final ISVNOptions options;
3941
private SVNClientManager clientManager;
4042
private SVNURL trunkSVNUrl;
4143
private SVNAuthentication userPassAuth;
@@ -99,19 +101,9 @@ public SVNURL getBranchUrl(String branchPath) throws SVNException {
99101

100102
@Override
101103
public void createBranch(String srcBranchName, String dstBranchName, String commitMessage) throws EVCSBranchExists {
102-
SVNURL fromUrl;
103-
SVNURL toUrl;
104-
try {
105-
fromUrl = getBranchUrl(srcBranchName);
106-
toUrl = getBranchUrl(dstBranchName);
107-
} catch (SVNException e) {
108-
throw new EVCSException(e);
109-
}
110-
createBranch(fromUrl, toUrl, commitMessage);
111-
}
112-
113-
public void createBranch(SVNURL fromUrl, SVNURL toUrl, String commitMessage) {
114104
try {
105+
SVNURL fromUrl = getBranchUrl(srcBranchName);
106+
SVNURL toUrl = getBranchUrl(dstBranchName);
115107
SVNCopyClient copyClient = clientManager.getCopyClient();
116108
SVNCopySource copySource = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, fromUrl);
117109
copySource.setCopyContents(false);
@@ -123,13 +115,13 @@ public void createBranch(SVNURL fromUrl, SVNURL toUrl, String commitMessage) {
123115
null); // SVNProperties
124116

125117
} catch (SVNException e) {
126-
if (e.getErrorMessage().getErrorCode().getCode() == SVN_ITEM_EXISTS_ERROR_CODE) {
127-
throw new EVCSBranchExists(e);
128-
}
129-
throw new EVCSException(e);
118+
if (e.getErrorMessage().getErrorCode().getCode() == SVN_ITEM_EXISTS_ERROR_CODE) {
119+
throw new EVCSBranchExists(dstBranchName);
120+
}
121+
throw new EVCSException(e);
130122
}
131123
}
132-
124+
133125
@Override
134126
public void deleteBranch(String branchName, String commitMessage) {
135127
try {
@@ -189,11 +181,11 @@ public VCSMergeResult merge(String srcBranchName, String dstBranchName, String c
189181
}
190182
}
191183

192-
protected SVNWCClient getRevertClient(DefaultSVNOptions options) {
184+
SVNWCClient getRevertClient(DefaultSVNOptions options) {
193185
return new SVNWCClient(authManager, options);
194186
}
195187

196-
public void checkout(SVNURL sourceUrl, File destPath, String revision) throws SVNException {
188+
private void checkout(SVNURL sourceUrl, File destPath, String revision) throws SVNException {
197189
SVNUpdateClient updateClient = clientManager.getUpdateClient();
198190
updateClient.setIgnoreExternals(false);
199191
SVNRevision svnRevision = revision == null ? SVNRevision.HEAD : SVNRevision.parse(revision);
@@ -343,14 +335,14 @@ private List<VCSDiffEntry> fillUnifiedDiffs(final String srcBranchName, final St
343335
return res;
344336
}
345337

346-
protected SVNLogEntry getDirFirstCommit(final String dir) throws SVNException {
338+
private SVNLogEntry getDirFirstCommit(final String dir) throws SVNException {
347339
@SuppressWarnings("unchecked")
348340
Collection<SVNLogEntry> entries = repository.log(new String[] { dir }, null, 0 /* start from first commit */,
349341
-1 /* to the head commit */, true, true);
350342
return entries.iterator().next();
351343
}
352344

353-
protected SVNLogEntry getBranchFirstCommit(final String branchPath) throws SVNException {
345+
SVNLogEntry getBranchFirstCommit(final String branchPath) throws SVNException {
354346
return getDirFirstCommit(getBranchName(branchPath));
355347
}
356348

@@ -364,18 +356,14 @@ private List<VCSDiffEntry> getDiffEntries(final String srcBranchName, final Stri
364356
SvnTarget.fromURL(getBranchUrl(dstBranchName), SVNRevision.HEAD),
365357
SvnTarget.fromURL(getBranchUrl(srcBranchName), SVNRevision.HEAD));
366358

367-
summarizeDiff.setReceiver(new ISvnObjectReceiver<SvnDiffStatus>() {
368-
public void receive(SvnTarget target, SvnDiffStatus diffStatus) throws SVNException {
369-
if (diffStatus.getPath().length() == 0) {
370-
return;
371-
}
372-
VCSDiffEntry entry = new VCSDiffEntry(diffStatus.getPath(),
373-
SVNChangeTypeToVCSChangeType(diffStatus.getModificationType()), null);
374-
res.add(entry);
375-
}
376-
377-
378-
});
359+
summarizeDiff.setReceiver((target, diffStatus) -> {
360+
if (diffStatus.getPath().length() == 0) {
361+
return;
362+
}
363+
VCSDiffEntry entry = new VCSDiffEntry(diffStatus.getPath(),
364+
SVNChangeTypeToVCSChangeType(diffStatus.getModificationType()), null);
365+
res.add(entry);
366+
});
379367
summarizeDiff.run();
380368

381369
return res;
@@ -428,7 +416,7 @@ public Set<String> getBranches(String path) {
428416
}
429417

430418
@SuppressWarnings("unchecked")
431-
protected List<String> listEntries(String path) throws SVNException {
419+
List<String> listEntries(String path) throws SVNException {
432420
List<String> res = new ArrayList<>();
433421
if (path == null) {
434422
return res;
@@ -468,12 +456,7 @@ public List<VCSCommit> log(String branchName, int limit) {
468456
getBranchUrl(branchName); // for exception test only
469457
repository.log(new String[] { getBranchName(branchName) },
470458
-1L /* start from head descending */,
471-
0L, true, true, limit, new ISVNLogEntryHandler() {
472-
@Override
473-
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
474-
res.add(svnLogEntryToVCSCommit(logEntry));
475-
}
476-
});
459+
0L, true, true, limit, logEntry -> res.add(svnLogEntryToVCSCommit(logEntry)));
477460
return res;
478461
} catch (SVNException e) {
479462
throw new EVCSException(e);
@@ -498,21 +481,21 @@ public VCSCommit removeFile(String branchName, String filePath, String commitMes
498481
}
499482

500483
@Override
501-
public List<VCSCommit> getCommitsRange(String branchName, String firstCommitId, WalkDirection direction, int limit) {
484+
public List<VCSCommit> getCommitsRange(String branchName, String startRevision, WalkDirection direction, int limit) {
502485
final List<VCSCommit> res = new ArrayList<>();
503486
try {
504-
Long sinceCommit;
505-
Long untilCommit;
487+
Long startRevisionLong;
488+
Long endRevisionLong;
506489
if (direction == WalkDirection.ASC) {
507-
sinceCommit = firstCommitId == null ? getBranchFirstCommit(branchName).getRevision() :
508-
Long.parseLong(firstCommitId);
509-
untilCommit = Long.parseLong(getHeadCommit(branchName).getRevision());
490+
startRevisionLong = startRevision == null ? getBranchFirstCommit(branchName).getRevision() :
491+
Long.parseLong(startRevision);
492+
endRevisionLong = Long.parseLong(getHeadCommit(branchName).getRevision());
510493
} else {
511-
sinceCommit = firstCommitId == null ? Long.parseLong(getHeadCommit(branchName).getRevision()) :
512-
Long.parseLong(firstCommitId);
513-
untilCommit = getBranchFirstCommit(branchName).getRevision();
494+
startRevisionLong = startRevision == null ? Long.parseLong(getHeadCommit(branchName).getRevision()) :
495+
Long.parseLong(startRevision);
496+
endRevisionLong = getBranchFirstCommit(branchName).getRevision();
514497
}
515-
repository.log(new String[] { getBranchName(branchName) }, sinceCommit, untilCommit, true, true, limit,
498+
repository.log(new String[] { getBranchName(branchName) }, startRevisionLong, endRevisionLong, true, true, limit,
516499
logEntry -> {
517500
VCSCommit commit = svnLogEntryToVCSCommit(logEntry);
518501
res.add(commit);
@@ -529,26 +512,21 @@ private VCSCommit svnLogEntryToVCSCommit(SVNLogEntry logEntry) {
529512
}
530513

531514
@Override
532-
public List<VCSCommit> getCommitsRange(String branchName, String firstCommitId, String untilCommitId) {
515+
public List<VCSCommit> getCommitsRange(String branchName, String startRevision, String endRevision) {
533516
final List<VCSCommit> res = new ArrayList<>();
534517
try {
535-
Long sinceCommit = firstCommitId == null ?
518+
Long startRevisionLong = startRevision == null ?
536519
getBranchFirstCommit(branchName).getRevision() :
537-
Long.parseLong(firstCommitId);
538-
Long untilCommit = untilCommitId == null ? -1L : Long.parseLong(untilCommitId);
539-
repository.log(new String[] { getBranchName(branchName) }, sinceCommit, untilCommit, true, true, 0 /* limit */,
520+
Long.parseLong(startRevision);
521+
Long endRevisionLong = endRevision == null ? -1L : Long.parseLong(endRevision);
522+
repository.log(new String[] { getBranchName(branchName) }, startRevisionLong, endRevisionLong, true, true, 0 /* limit */,
540523
logEntry -> res.add(svnLogEntryToVCSCommit(logEntry)));
541524
return res;
542525
} catch (SVNException e) {
543526
throw new EVCSException(e);
544527
}
545528
}
546529

547-
@Override
548-
public IVCSWorkspace getWorkspace() {
549-
return repo.getWorkspace();
550-
}
551-
552530
@Override
553531
public VCSCommit getHeadCommit(String branchName) {
554532
try {
@@ -562,7 +540,7 @@ public VCSCommit getHeadCommit(String branchName) {
562540
}
563541
}
564542

565-
protected SVNLogEntry getDirHeadLogEntry(String dir) throws SVNException {
543+
SVNLogEntry getDirHeadLogEntry(String dir) throws SVNException {
566544
@SuppressWarnings("unchecked")
567545
Collection<SVNLogEntry> entries = repository.log(new String[] { dir }, null, -1 /* start from head commit */,
568546
0 /* to the first commit */, true, true);
@@ -610,7 +588,7 @@ public VCSTag createTag(String branchName, String tagName, String tagMessage, St
610588
}
611589
}
612590

613-
protected SVNLogEntry revToSVNEntry(String branchName, Long rev) throws SVNException {
591+
SVNLogEntry revToSVNEntry(String branchName, Long rev) throws SVNException {
614592
SVNDirEntry info = repository.info(branchName, rev);
615593
@SuppressWarnings("unchecked")
616594
Collection<SVNLogEntry> entries = repository.log(new String[] {branchName}, null, info.getRevision(), info.getRevision(), true, true);
@@ -649,7 +627,7 @@ public void checkout(String branchName, String targetPath, String revision) {
649627
}
650628
}
651629

652-
protected List<VCSTag> getTags(String onRevision) throws SVNException {
630+
List<VCSTag> getTags(String onRevision) throws SVNException {
653631
List<VCSTag> res = new ArrayList<>();
654632
@SuppressWarnings("unchecked")
655633
Collection<SVNDirEntry> dirEntries = repository.getDir(TAGS_PATH, -1 , null, (Collection<SVNDirEntry>) null);

src/test/java/org/scm4j/vcs/svn/SVNVCSTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testCredentials() throws Exception {
112112
testAuth(svn, "user", "pass");
113113
}
114114

115-
public void testAuth(SVNVCS svn, String user, String pass) throws Exception {
115+
private void testAuth(SVNVCS svn, String user, String pass) throws Exception {
116116
SVNRepository repo = svn.getSVNRepository();
117117
SVNAuthentication auth = repo.getAuthenticationManager().getFirstAuthentication("svn.simple", "",
118118
svn.getTrunkSVNUrl());

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14.0-SNAPSHOT
1+
17.0-SNAPSHOT

0 commit comments

Comments
 (0)