1
1
package org .scm4j .vcs .svn ;
2
2
3
- import java .io .ByteArrayOutputStream ;
4
- import java .io .File ;
5
- import java .io .FileWriter ;
6
- import java .nio .charset .StandardCharsets ;
7
- import java .util .ArrayList ;
8
- import java .util .Collection ;
9
- import java .util .Collections ;
10
- import java .util .Comparator ;
11
- import java .util .HashSet ;
12
- import java .util .List ;
13
- import java .util .Set ;
14
-
15
3
import org .apache .commons .io .FileUtils ;
16
4
import org .apache .commons .lang3 .StringUtils ;
17
- import org .scm4j .vcs .api .IVCS ;
18
- import org .scm4j .vcs .api .VCSChangeType ;
19
- import org .scm4j .vcs .api .VCSCommit ;
20
- import org .scm4j .vcs .api .VCSDiffEntry ;
21
- import org .scm4j .vcs .api .VCSMergeResult ;
22
- import org .scm4j .vcs .api .VCSTag ;
23
- import org .scm4j .vcs .api .WalkDirection ;
5
+ import org .scm4j .vcs .api .*;
24
6
import org .scm4j .vcs .api .exceptions .EVCSBranchExists ;
25
7
import org .scm4j .vcs .api .exceptions .EVCSException ;
26
8
import org .scm4j .vcs .api .exceptions .EVCSFileNotFound ;
27
9
import org .scm4j .vcs .api .exceptions .EVCSTagExists ;
28
10
import org .scm4j .vcs .api .workingcopy .IVCSLockedWorkingCopy ;
29
11
import org .scm4j .vcs .api .workingcopy .IVCSRepositoryWorkspace ;
30
12
import org .scm4j .vcs .api .workingcopy .IVCSWorkspace ;
31
- import org .tmatesoft .svn .core .ISVNLogEntryHandler ;
32
- import org .tmatesoft .svn .core .SVNCommitInfo ;
33
- import org .tmatesoft .svn .core .SVNDepth ;
34
- import org .tmatesoft .svn .core .SVNDirEntry ;
35
- import org .tmatesoft .svn .core .SVNException ;
36
- import org .tmatesoft .svn .core .SVNLogEntry ;
37
- import org .tmatesoft .svn .core .SVNLogEntryPath ;
38
- import org .tmatesoft .svn .core .SVNNodeKind ;
39
- import org .tmatesoft .svn .core .SVNProperties ;
40
- import org .tmatesoft .svn .core .SVNURL ;
13
+ import org .tmatesoft .svn .core .*;
41
14
import org .tmatesoft .svn .core .auth .BasicAuthenticationManager ;
42
15
import org .tmatesoft .svn .core .auth .SVNAuthentication ;
43
16
import org .tmatesoft .svn .core .auth .SVNPasswordAuthentication ;
44
17
import org .tmatesoft .svn .core .internal .wc .DefaultSVNOptions ;
45
18
import org .tmatesoft .svn .core .io .SVNRepository ;
46
19
import org .tmatesoft .svn .core .io .SVNRepositoryFactory ;
47
- import org .tmatesoft .svn .core .wc .ISVNConflictHandler ;
48
- import org .tmatesoft .svn .core .wc .ISVNOptions ;
49
- import org .tmatesoft .svn .core .wc .SVNClientManager ;
50
- import org .tmatesoft .svn .core .wc .SVNConflictChoice ;
51
- import org .tmatesoft .svn .core .wc .SVNConflictDescription ;
52
- import org .tmatesoft .svn .core .wc .SVNConflictResult ;
53
- import org .tmatesoft .svn .core .wc .SVNCopyClient ;
54
- import org .tmatesoft .svn .core .wc .SVNCopySource ;
55
- import org .tmatesoft .svn .core .wc .SVNDiffClient ;
56
- import org .tmatesoft .svn .core .wc .SVNRevision ;
57
- import org .tmatesoft .svn .core .wc .SVNRevisionRange ;
58
- import org .tmatesoft .svn .core .wc .SVNStatusType ;
59
- import org .tmatesoft .svn .core .wc .SVNUpdateClient ;
60
- import org .tmatesoft .svn .core .wc .SVNWCClient ;
61
- import org .tmatesoft .svn .core .wc .SVNWCUtil ;
62
- import org .tmatesoft .svn .core .wc2 .ISvnObjectReceiver ;
63
- import org .tmatesoft .svn .core .wc2 .SvnDiff ;
64
- import org .tmatesoft .svn .core .wc2 .SvnDiffStatus ;
65
- import org .tmatesoft .svn .core .wc2 .SvnDiffSummarize ;
66
- import org .tmatesoft .svn .core .wc2 .SvnOperationFactory ;
67
- import org .tmatesoft .svn .core .wc2 .SvnTarget ;
20
+ import org .tmatesoft .svn .core .wc .*;
21
+ import org .tmatesoft .svn .core .wc2 .*;
22
+
23
+ import java .io .ByteArrayOutputStream ;
24
+ import java .io .File ;
25
+ import java .io .FileWriter ;
26
+ import java .nio .charset .StandardCharsets ;
27
+ import java .util .*;
68
28
69
29
public class SVNVCS implements IVCS {
70
30
private static final int SVN_PATH_IS_NOT_WORKING_COPY_ERROR_CODE = 155007 ;
@@ -150,10 +110,8 @@ public void createBranch(String srcBranchName, String dstBranchName, String comm
150
110
}
151
111
152
112
public void createBranch (SVNURL fromUrl , SVNURL toUrl , String commitMessage ) {
153
- try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
154
-
113
+ try {
155
114
getBranchUrl ("test" ); // for exceptions rethrowing test only
156
-
157
115
SVNCopyClient copyClient = clientManager .getCopyClient ();
158
116
SVNCopySource copySource = new SVNCopySource (SVNRevision .HEAD , SVNRevision .HEAD , fromUrl );
159
117
copySource .setCopyContents (false );
@@ -451,7 +409,7 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451
409
@ Override
452
410
public Set <String > getBranches (String path ) {
453
411
try {
454
- List <String > entries = listEntries (SVNVCS .BRANCHES_PATH , path == null ? "" : path );
412
+ List <String > entries = listEntries (SVNVCS .BRANCHES_PATH + ( path == null ? "" : path ) );
455
413
Set <String > tempRes = new HashSet <>(entries );
456
414
if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
457
415
if (path == null || MASTER_PATH .startsWith (path ) ) {
@@ -470,15 +428,15 @@ public Set<String> getBranches(String path) {
470
428
}
471
429
}
472
430
473
- protected List <String > listEntries (String path , String subdirStartsWith ) throws Exception {
431
+ protected List <String > listEntries (String path ) throws Exception {
474
432
List <String > res = new ArrayList <>();
475
- if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
433
+ if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
476
434
return res ;
477
435
}
478
436
@ SuppressWarnings ("unchecked" )
479
- Collection <SVNDirEntry > subEntries = repository .getDir (path , -1 , null , (Collection <SVNDirEntry >) null );
480
- List <SVNDirEntry > list = new ArrayList <>(subEntries );
481
- Collections .sort (list , new Comparator <SVNDirEntry >() {
437
+ Collection <SVNDirEntry > entries = repository .getDir (path , -1 , null , (Collection <SVNDirEntry >) null );
438
+ List <SVNDirEntry > entriesList = new ArrayList <>(entries );
439
+ Collections .sort (entriesList , new Comparator <SVNDirEntry >() {
482
440
@ Override
483
441
public int compare (SVNDirEntry o1 , SVNDirEntry o2 ) {
484
442
if (o1 .getRevision () < o2 .getRevision ()) {
@@ -490,11 +448,13 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
490
448
return 0 ;
491
449
}
492
450
});
493
- for (SVNDirEntry entry : list ) {
494
- if (entry .getKind () == SVNNodeKind .DIR && entry .getName ().startsWith (subdirStartsWith )) {
495
- res .add (path + entry .getName ());
451
+ for (SVNDirEntry entry : entriesList ) {
452
+ if (entry .getKind () == SVNNodeKind .DIR ) {
453
+ res .add ((path .isEmpty () ? "" : StringUtils .appendIfMissing (path , "/" )) + entry .getName ());
454
+ res .addAll (listEntries ((path .equals ("" )) ? entry .getName () : path + entry .getName ()));
496
455
}
497
456
}
457
+
498
458
return res ;
499
459
}
500
460
@@ -638,8 +598,8 @@ public Boolean fileExists(String branchName, String filePath) {
638
598
639
599
@ Override
640
600
public VCSTag createTag (String branchName , String tagName , String tagMessage , String revisionToTag ) throws EVCSTagExists {
641
- try ( IVCSLockedWorkingCopy wc = repo . getVCSLockedWorkingCopy ()) {
642
- SVNURL srcURL = getBranchUrl (branchName );
601
+ try {
602
+ SVNURL srcURL = getBranchUrl (branchName );
643
603
SVNURL dstURL = SVNURL .parseURIEncoded (repoUrl + TAGS_PATH + tagName );
644
604
SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
645
605
revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
@@ -693,7 +653,7 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
693
653
@ Override
694
654
public List <VCSTag > getTags () {
695
655
try {
696
- List <String > entries = listEntries (TAGS_PATH , "" );
656
+ List <String > entries = listEntries (TAGS_PATH );
697
657
698
658
List <VCSTag > res = new ArrayList <>();
699
659
SVNTagBaseCommit handler ;
@@ -748,8 +708,19 @@ public void checkout(String branchName, String targetPath, String revision) {
748
708
@ Override
749
709
public List <VCSTag > getTagsOnRevision (String revision ) {
750
710
try {
751
- List <String > tagEntries = listEntries (TAGS_PATH , "" );
752
711
List <VCSTag > res = new ArrayList <>();
712
+ if (repository .checkPath (TAGS_PATH , -1 ) == SVNNodeKind .NONE ) {
713
+ return res ;
714
+ }
715
+ List <String > tagEntries = new ArrayList <>();
716
+ @ SuppressWarnings ("unchecked" )
717
+ Collection <SVNDirEntry > entries = repository .getDir (TAGS_PATH , -1 , null , (Collection <SVNDirEntry >) null );
718
+ for (SVNDirEntry entry : entries ) {
719
+ if (entry .getKind () == SVNNodeKind .DIR ) {
720
+ tagEntries .add (TAGS_PATH + entry .getName ());
721
+ }
722
+ }
723
+
753
724
SVNTagBaseCommit handler ;
754
725
for (String tagEntryStr : tagEntries ) {
755
726
0 commit comments