1414
1515import org .apache .commons .io .FileUtils ;
1616import org .tmatesoft .svn .core .ISVNLogEntryHandler ;
17+ import org .tmatesoft .svn .core .SVNCommitInfo ;
1718import org .tmatesoft .svn .core .SVNDepth ;
1819import org .tmatesoft .svn .core .SVNDirEntry ;
1920import org .tmatesoft .svn .core .SVNException ;
5152
5253import com .projectkaiser .scm .vcs .api .IVCS ;
5354import com .projectkaiser .scm .vcs .api .VCSChangeType ;
55+ import com .projectkaiser .scm .vcs .api .VCSCommit ;
5456import com .projectkaiser .scm .vcs .api .VCSDiffEntry ;
5557import com .projectkaiser .scm .vcs .api .VCSMergeResult ;
5658import com .projectkaiser .scm .vcs .api .exceptions .EVCSBranchExists ;
@@ -113,11 +115,11 @@ public SVNRepository getRepository() {
113115 }
114116
115117 private SVNURL getBranchUrl (String branchPath ) throws SVNException {
116- return SVNURL .parseURIEncoded (repoUrl + ( branchPath == null ? MASTER_PATH : BRANCHES_PATH + branchPath ));
118+ return SVNURL .parseURIEncoded (repoUrl + getBranchName ( branchPath ));
117119 }
118120
119121 private String getBranchPath (String branchPath ) {
120- return branchPath == null ? MASTER_PATH : BRANCHES_PATH + branchPath ;
122+ return getBranchName ( branchPath ) ;
121123 }
122124
123125 @ Override
@@ -267,8 +269,8 @@ public void setProxy(String host, int port, String proxyUser, String proxyPasswo
267269 public String getFileContent (String branchName , String filePath , String encoding ) {
268270 ByteArrayOutputStream baos = new ByteArrayOutputStream ( );
269271 try {
270- repository .getFile (new File ((branchName == null ? MASTER_PATH : BRANCHES_PATH + branchName ),
271- filePath ). getPath (). replace ( " \\ " , "/" ), -1 , new SVNProperties (), baos );
272+ repository .getFile (new File (getBranchName (branchName ), filePath ). getPath (). replace ( " \\ " , "/" ),
273+ -1 , new SVNProperties (), baos );
272274 return baos .toString (encoding );
273275 } catch (SVNException e ) {
274276 if (e .getErrorMessage ().getErrorCode ().getCode () == SVN_FILE_NOT_FOUND_ERROR_CODE ) {
@@ -281,13 +283,17 @@ public String getFileContent(String branchName, String filePath, String encoding
281283
282284 }
283285
286+ private String getBranchName (String branchName ) {
287+ return branchName == null ? MASTER_PATH : BRANCHES_PATH + branchName ;
288+ }
289+
284290 @ Override
285291 public String getFileContent (String branchName , String filePath ) {
286292 return getFileContent (branchName , filePath , StandardCharsets .UTF_8 .name ());
287293 }
288294
289295 @ Override
290- public void setFileContent (String branchName , String filePath , String content , String commitMessage ) {
296+ public String setFileContent (String branchName , String filePath , String content , String commitMessage ) {
291297 try {
292298 try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
293299 checkout (getBranchUrl (branchName ), wc .getFolder ());
@@ -310,10 +316,11 @@ public void setFileContent(String branchName, String filePath, String content, S
310316 false , false , SVNDepth .EMPTY , false , true );
311317 }
312318
313- clientManager
319+ SVNCommitInfo res = clientManager
314320 .getCommitClient ()
315321 .doCommit (new File [] { wc .getFolder () }, false , commitMessage ,
316322 new SVNProperties (), null , false , false , SVNDepth .INFINITY );
323+ return Long .toString (res .getNewRevision ());
317324 }
318325 } catch (SVNException e ) {
319326 throw new EVCSException (e );
@@ -475,7 +482,7 @@ private void listEntries(Set<String> entries, String path) throws SVNException {
475482 public List <String > getCommitMessages (String branchName , Integer limit ) {
476483 final List <String > res = new ArrayList <>();
477484 try {
478- repository .log (new String [] { branchName == null ? MASTER_PATH : BRANCHES_PATH + branchName },
485+ repository .log (new String [] { getBranchName ( branchName ) },
479486 -1 /* start from head descending */ ,
480487 0 , true , true , limit , new ISVNLogEntryHandler () {
481488 @ Override
@@ -497,12 +504,13 @@ public String getVCSTypeString() {
497504 }
498505
499506 @ Override
500- public void removeFile (String branchName , String filePath , String commitMessage ) {
507+ public String removeFile (String branchName , String filePath , String commitMessage ) {
501508 try {
502509 try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
503- clientManager
510+ SVNCommitInfo res = clientManager
504511 .getCommitClient ()
505512 .doDelete (new SVNURL [] {getBranchUrl (branchName ).appendPath (filePath , true )}, commitMessage );
513+ return Long .toString (res .getNewRevision ());
506514 }
507515 } catch (SVNException e ) {
508516 throw new EVCSException (e );
@@ -511,4 +519,30 @@ public void removeFile(String branchName, String filePath, String commitMessage)
511519 }
512520
513521 }
522+
523+ @ Override
524+ public List <VCSCommit > getCommitsRange (String branchName , String afterCommitId , String untilCommitId ) {
525+ final List <VCSCommit > res = new ArrayList <>();
526+ try {
527+ String bn = getBranchName (branchName );
528+ Long sinceCommit = afterCommitId == null ?
529+ getBranchFirstCommit (bn ).getRevision () :
530+ Long .parseLong (afterCommitId );
531+ Long untilCommit = untilCommitId == null ? -1L : Long .parseLong (untilCommitId );
532+ repository .log (new String [] { getBranchName (branchName ) },
533+ sinceCommit , untilCommit , true , true , 0 /* limit */ , new ISVNLogEntryHandler () {
534+ @ Override
535+ public void handleLogEntry (SVNLogEntry logEntry ) throws SVNException {
536+ VCSCommit commit = new VCSCommit (Long .toString (logEntry .getRevision ()), logEntry .getMessage (),
537+ logEntry .getAuthor ());
538+ res .add (commit );
539+ }
540+ });
541+ return res ;
542+ } catch (SVNException e ) {
543+ throw new EVCSException (e );
544+ } catch (Exception e ) {
545+ throw new RuntimeException (e );
546+ }
547+ }
514548}
0 commit comments