14
14
15
15
import org .apache .commons .io .FileUtils ;
16
16
import org .tmatesoft .svn .core .ISVNLogEntryHandler ;
17
+ import org .tmatesoft .svn .core .SVNCommitInfo ;
17
18
import org .tmatesoft .svn .core .SVNDepth ;
18
19
import org .tmatesoft .svn .core .SVNDirEntry ;
19
20
import org .tmatesoft .svn .core .SVNException ;
51
52
52
53
import com .projectkaiser .scm .vcs .api .IVCS ;
53
54
import com .projectkaiser .scm .vcs .api .VCSChangeType ;
55
+ import com .projectkaiser .scm .vcs .api .VCSCommit ;
54
56
import com .projectkaiser .scm .vcs .api .VCSDiffEntry ;
55
57
import com .projectkaiser .scm .vcs .api .VCSMergeResult ;
56
58
import com .projectkaiser .scm .vcs .api .exceptions .EVCSBranchExists ;
@@ -113,11 +115,11 @@ public SVNRepository getRepository() {
113
115
}
114
116
115
117
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 ));
117
119
}
118
120
119
121
private String getBranchPath (String branchPath ) {
120
- return branchPath == null ? MASTER_PATH : BRANCHES_PATH + branchPath ;
122
+ return getBranchName ( branchPath ) ;
121
123
}
122
124
123
125
@ Override
@@ -267,8 +269,8 @@ public void setProxy(String host, int port, String proxyUser, String proxyPasswo
267
269
public String getFileContent (String branchName , String filePath , String encoding ) {
268
270
ByteArrayOutputStream baos = new ByteArrayOutputStream ( );
269
271
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 );
272
274
return baos .toString (encoding );
273
275
} catch (SVNException e ) {
274
276
if (e .getErrorMessage ().getErrorCode ().getCode () == SVN_FILE_NOT_FOUND_ERROR_CODE ) {
@@ -281,13 +283,17 @@ public String getFileContent(String branchName, String filePath, String encoding
281
283
282
284
}
283
285
286
+ private String getBranchName (String branchName ) {
287
+ return branchName == null ? MASTER_PATH : BRANCHES_PATH + branchName ;
288
+ }
289
+
284
290
@ Override
285
291
public String getFileContent (String branchName , String filePath ) {
286
292
return getFileContent (branchName , filePath , StandardCharsets .UTF_8 .name ());
287
293
}
288
294
289
295
@ 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 ) {
291
297
try {
292
298
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
293
299
checkout (getBranchUrl (branchName ), wc .getFolder ());
@@ -310,10 +316,11 @@ public void setFileContent(String branchName, String filePath, String content, S
310
316
false , false , SVNDepth .EMPTY , false , true );
311
317
}
312
318
313
- clientManager
319
+ SVNCommitInfo res = clientManager
314
320
.getCommitClient ()
315
321
.doCommit (new File [] { wc .getFolder () }, false , commitMessage ,
316
322
new SVNProperties (), null , false , false , SVNDepth .INFINITY );
323
+ return Long .toString (res .getNewRevision ());
317
324
}
318
325
} catch (SVNException e ) {
319
326
throw new EVCSException (e );
@@ -475,7 +482,7 @@ private void listEntries(Set<String> entries, String path) throws SVNException {
475
482
public List <String > getCommitMessages (String branchName , Integer limit ) {
476
483
final List <String > res = new ArrayList <>();
477
484
try {
478
- repository .log (new String [] { branchName == null ? MASTER_PATH : BRANCHES_PATH + branchName },
485
+ repository .log (new String [] { getBranchName ( branchName ) },
479
486
-1 /* start from head descending */ ,
480
487
0 , true , true , limit , new ISVNLogEntryHandler () {
481
488
@ Override
@@ -497,12 +504,13 @@ public String getVCSTypeString() {
497
504
}
498
505
499
506
@ Override
500
- public void removeFile (String branchName , String filePath , String commitMessage ) {
507
+ public String removeFile (String branchName , String filePath , String commitMessage ) {
501
508
try {
502
509
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
503
- clientManager
510
+ SVNCommitInfo res = clientManager
504
511
.getCommitClient ()
505
512
.doDelete (new SVNURL [] {getBranchUrl (branchName ).appendPath (filePath , true )}, commitMessage );
513
+ return Long .toString (res .getNewRevision ());
506
514
}
507
515
} catch (SVNException e ) {
508
516
throw new EVCSException (e );
@@ -511,4 +519,30 @@ public void removeFile(String branchName, String filePath, String commitMessage)
511
519
}
512
520
513
521
}
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
+ }
514
548
}
0 commit comments