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 .Iterator ;
13
- import java .util .List ;
14
- import java .util .Set ;
15
-
16
3
import org .apache .commons .io .FileUtils ;
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 ;
4
+ import org .scm4j .vcs .api .*;
24
5
import org .scm4j .vcs .api .exceptions .EVCSBranchExists ;
25
6
import org .scm4j .vcs .api .exceptions .EVCSException ;
26
7
import org .scm4j .vcs .api .exceptions .EVCSFileNotFound ;
27
8
import org .scm4j .vcs .api .exceptions .EVCSTagExists ;
28
9
import org .scm4j .vcs .api .workingcopy .IVCSLockedWorkingCopy ;
29
10
import org .scm4j .vcs .api .workingcopy .IVCSRepositoryWorkspace ;
30
11
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 ;
12
+ import org .tmatesoft .svn .core .*;
41
13
import org .tmatesoft .svn .core .auth .BasicAuthenticationManager ;
42
14
import org .tmatesoft .svn .core .auth .SVNAuthentication ;
43
15
import org .tmatesoft .svn .core .auth .SVNPasswordAuthentication ;
44
16
import org .tmatesoft .svn .core .internal .wc .DefaultSVNOptions ;
45
17
import org .tmatesoft .svn .core .io .SVNRepository ;
46
18
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 ;
19
+ import org .tmatesoft .svn .core .wc .*;
20
+ import org .tmatesoft .svn .core .wc2 .*;
68
21
69
22
import java .io .ByteArrayOutputStream ;
70
23
import java .io .File ;
@@ -502,13 +455,12 @@ public void listEntries(List<String> entries, String path) throws Exception {
502
455
public int compare (SVNDirEntry o1 , SVNDirEntry o2 ) {
503
456
if (o1 .getRevision () < o2 .getRevision ()) {
504
457
return -1 ;
505
- }
458
+ }
506
459
if (o1 .getRevision () > o2 .getRevision ()) {
507
460
return 1 ;
508
461
}
509
462
return 0 ;
510
463
}
511
-
512
464
});
513
465
for (SVNDirEntry entry : list ) {
514
466
if (entry .getKind () == SVNNodeKind .DIR ) {
@@ -626,7 +578,7 @@ public VCSCommit getHeadCommit(String branchName) {
626
578
try {
627
579
SVNLogEntry entry = revToSVNEntry (getBranchName (branchName ), -1L );
628
580
if (entry != null ) {
629
- return new VCSCommit (Long .toString (entry .getRevision ()), entry .getMessage (),
581
+ return new VCSCommit (Long .toString (entry .getRevision ()), entry .getMessage (),
630
582
entry .getAuthor ());
631
583
}
632
584
return null ;
@@ -680,7 +632,7 @@ public VCSTag createTag(String branchName, String tagName, String tagMessage) th
680
632
}
681
633
}
682
634
683
- private SVNLogEntry revToSVNEntry (String branchName , Long rev ) throws Exception {
635
+ protected SVNLogEntry revToSVNEntry (String branchName , Long rev ) throws Exception {
684
636
SVNDirEntry info = repository .info (branchName , rev );
685
637
@ SuppressWarnings ("unchecked" )
686
638
Collection <SVNLogEntry > entries = repository .log (new String [] {branchName }, null , info .getRevision (), info .getRevision (), true , true );
@@ -706,8 +658,8 @@ class SVNTagBaseCommit implements ISVNLogEntryHandler {
706
658
707
659
@ Override
708
660
public void handleLogEntry (SVNLogEntry logEntry ) throws SVNException {
709
- for (Iterator <?> changedPaths = logEntry .getChangedPaths ().keySet (). iterator (); changedPaths . hasNext (); ) {
710
- SVNLogEntryPath entryPath = ( SVNLogEntryPath ) logEntry .getChangedPaths ().get (changedPaths . next () );
661
+ for (String s : logEntry .getChangedPaths ().keySet ()) {
662
+ SVNLogEntryPath entryPath = logEntry .getChangedPaths ().get (s );
711
663
copyFromRevision = entryPath .getCopyRevision ();
712
664
}
713
665
}
@@ -730,4 +682,31 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
730
682
throw new RuntimeException (e );
731
683
}
732
684
}
685
+
686
+
687
+ @ Override
688
+ public VCSTag getLastTag () {
689
+ try {
690
+ SVNLogEntry entry = revToSVNEntry (TAGS_PATH , -1L );
691
+
692
+ Long copyFromRevision = -1L ;
693
+ for (String s : entry .getChangedPaths ().keySet ()) {
694
+ SVNLogEntryPath entryPath = entry .getChangedPaths ().get (s );
695
+ copyFromRevision = entryPath .getCopyRevision ();
696
+ }
697
+
698
+ SVNLogEntry copyFromEntry = revToSVNEntry ("" , copyFromRevision );
699
+ String tagName = "" ;
700
+ for (String name : revToSVNEntry (TAGS_PATH , -1L ).getChangedPaths ().keySet ()) {
701
+ tagName = name .replace ("/" + TAGS_PATH , "" ) ;
702
+ }
703
+
704
+ return new VCSTag (tagName , entry .getMessage (), entry .getAuthor (), new VCSCommit (Long .toString (copyFromEntry .getRevision ()),
705
+ copyFromEntry .getMessage (), copyFromEntry .getAuthor ()));
706
+ } catch (SVNException e ) {
707
+ throw new EVCSException (e );
708
+ } catch (Exception e ) {
709
+ throw new RuntimeException (e );
710
+ }
711
+ }
733
712
}
0 commit comments