11package org .scm4j .vcs .svn ;
22
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-
153import org .apache .commons .io .FileUtils ;
164import 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 .*;
246import org .scm4j .vcs .api .exceptions .EVCSBranchExists ;
257import org .scm4j .vcs .api .exceptions .EVCSException ;
268import org .scm4j .vcs .api .exceptions .EVCSFileNotFound ;
279import org .scm4j .vcs .api .exceptions .EVCSTagExists ;
2810import org .scm4j .vcs .api .workingcopy .IVCSLockedWorkingCopy ;
2911import org .scm4j .vcs .api .workingcopy .IVCSRepositoryWorkspace ;
3012import 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 .*;
4114import org .tmatesoft .svn .core .auth .BasicAuthenticationManager ;
4215import org .tmatesoft .svn .core .auth .SVNAuthentication ;
4316import org .tmatesoft .svn .core .auth .SVNPasswordAuthentication ;
4417import org .tmatesoft .svn .core .internal .wc .DefaultSVNOptions ;
4518import org .tmatesoft .svn .core .io .SVNRepository ;
4619import 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 .*;
6828
6929public class SVNVCS implements IVCS {
7030 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
150110 }
151111
152112 public void createBranch (SVNURL fromUrl , SVNURL toUrl , String commitMessage ) {
153- try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
154-
113+ try {
155114 getBranchUrl ("test" ); // for exceptions rethrowing test only
156-
157115 SVNCopyClient copyClient = clientManager .getCopyClient ();
158116 SVNCopySource copySource = new SVNCopySource (SVNRevision .HEAD , SVNRevision .HEAD , fromUrl );
159117 copySource .setCopyContents (false );
@@ -451,7 +409,7 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451409 @ Override
452410 public Set <String > getBranches (String path ) {
453411 try {
454- List <String > entries = listEntries (SVNVCS .BRANCHES_PATH , path == null ? "" : path );
412+ List <String > entries = listEntries (SVNVCS .BRANCHES_PATH + ( path == null ? "" : path ) );
455413 Set <String > tempRes = new HashSet <>(entries );
456414 if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
457415 if (path == null || MASTER_PATH .startsWith (path ) ) {
@@ -470,15 +428,15 @@ public Set<String> getBranches(String path) {
470428 }
471429 }
472430
473- protected List <String > listEntries (String path , String subdirStartsWith ) throws Exception {
431+ protected List <String > listEntries (String path ) throws Exception {
474432 List <String > res = new ArrayList <>();
475- if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
433+ if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
476434 return res ;
477435 }
478436 @ 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 >() {
482440 @ Override
483441 public int compare (SVNDirEntry o1 , SVNDirEntry o2 ) {
484442 if (o1 .getRevision () < o2 .getRevision ()) {
@@ -490,11 +448,13 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
490448 return 0 ;
491449 }
492450 });
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 ()));
496455 }
497456 }
457+
498458 return res ;
499459 }
500460
@@ -638,8 +598,8 @@ public Boolean fileExists(String branchName, String filePath) {
638598
639599 @ Override
640600 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 );
643603 SVNURL dstURL = SVNURL .parseURIEncoded (repoUrl + TAGS_PATH + tagName );
644604 SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
645605 revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
@@ -693,7 +653,7 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
693653 @ Override
694654 public List <VCSTag > getTags () {
695655 try {
696- List <String > entries = listEntries (TAGS_PATH , "" );
656+ List <String > entries = listEntries (TAGS_PATH );
697657
698658 List <VCSTag > res = new ArrayList <>();
699659 SVNTagBaseCommit handler ;
@@ -748,8 +708,19 @@ public void checkout(String branchName, String targetPath, String revision) {
748708 @ Override
749709 public List <VCSTag > getTagsOnRevision (String revision ) {
750710 try {
751- List <String > tagEntries = listEntries (TAGS_PATH , "" );
752711 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+
753724 SVNTagBaseCommit handler ;
754725 for (String tagEntryStr : tagEntries ) {
755726
0 commit comments