From afae68a6626923c434d8b8ffb7e29b79f931715e Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 15 Nov 2011 21:32:38 +0100 Subject: [PATCH] fix wrong file history view in subversion --- .../scm/repository/SvnChangesetViewer.java | 105 ++++++++++++++---- 1 file changed, 83 insertions(+), 22 deletions(-) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java index 8e604ee9ca..6fd809c082 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java @@ -44,6 +44,8 @@ import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; +import sonia.scm.util.Util; + //~--- JDK imports ------------------------------------------------------------ import java.io.File; @@ -93,26 +95,6 @@ public class SvnChangesetViewer implements ChangesetViewer @Override public ChangesetPagingResult getChangesets(int start, int max) { - return getChangesets("", null, start, max); - } - - /** - * Method description - * - * - * @param path - * @param revision - * @param start - * @param max - * - * @return - */ - @Override - public ChangesetPagingResult getChangesets(String path, String revision, - int start, int max) - { - - // TODO implement revision ChangesetPagingResult changesets = null; File directory = handler.getDirectory(repostory); SVNRepository repository = null; @@ -131,8 +113,8 @@ public class SvnChangesetViewer implements ChangesetViewer } List changesetList = new ArrayList(); - Collection entries = repository.log(new String[] { path }, - null, startRev, endRev, true, true); + Collection entries = repository.log(null, null, startRev, + endRev, true, true); for (SVNLogEntry entry : entries) { @@ -154,6 +136,85 @@ public class SvnChangesetViewer implements ChangesetViewer return changesets; } + /** + * Method description + * + * + * @param path + * @param revision + * @param start + * @param max + * + * @return + */ + @Override + public ChangesetPagingResult getChangesets(String path, String revision, + int start, int max) + { + ChangesetPagingResult changesets = null; + File directory = handler.getDirectory(repostory); + SVNRepository repository = null; + + try + { + repository = SVNRepositoryFactory.create(SVNURL.fromFile(directory)); + + long startRev = repository.getLatestRevision(); + long endRev = 0; + long maxRev = startRev; + + if (Util.isNotEmpty(revision)) + { + try + { + maxRev = Long.parseLong(revision); + } + catch (NumberFormatException ex) + { + logger.error("could not parse revision ".concat(revision), ex); + } + } + + List changesetList = new ArrayList(); + Collection entries = repository.log(new String[] { path }, + null, startRev, endRev, true, true); + + for (SVNLogEntry entry : entries) + { + if (entry.getRevision() <= maxRev) + { + changesetList.add(SvnUtil.createChangeset(entry)); + } + } + + int total = changesetList.size(); + int end = total - start; + + if (end > max) + { + end = max; + } + + if (start < 0) + { + start = 0; + } + + changesetList = changesetList.subList(start, end); + changesets = new ChangesetPagingResult(total, changesetList); + } + catch (SVNException ex) + { + logger.error("could not open repository", ex); + } + finally + { + repository.closeSession(); + } + + return changesets; + } + //~--- fields --------------------------------------------------------------- /** Field description */