diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java index 285efa5565..0ce3d45f7a 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.util.AssertUtil; +import sonia.scm.util.Util; import sonia.scm.web.HgUtil; //~--- JDK imports ------------------------------------------------------------ @@ -58,11 +59,17 @@ import javax.xml.bind.JAXBContext; public class HgChangesetViewer implements ChangesetViewer { + /** Field description */ + public static final String ENV_PAGE_LIMIT = "SCM_PAGE_LIMIT"; + + /** Field description */ + public static final String ENV_PAGE_START = "SCM_PAGE_START"; + /** Field description */ public static final String ENV_PENDING = "HG_PENDING"; /** Field description */ - public static final String ENV_REVISION_LIMIT = "SCM_REVISION_LIMIT"; + public static final String ENV_REVISION_END = "SCM_REVISION_END"; /** Field description */ public static final String ENV_REVISION_START = "SCM_REVISION_START"; @@ -125,33 +132,53 @@ public class HgChangesetViewer implements ChangesetViewer public ChangesetPagingResult getChangesets(int start, int max) throws IOException { - return getChangesets(String.valueOf(start), String.valueOf(max), false); + return getChangesets(start, max, false); } /** * Method description * * - * @param startRev - * @param limit + * @param start + * @param max * @param pending * * @return * * @throws IOException */ - public ChangesetPagingResult getChangesets(String startRev, String limit, + public ChangesetPagingResult getChangesets(int start, int max, boolean pending) throws IOException { - AssertUtil.assertIsNotEmpty(startRev); - AssertUtil.assertIsNotEmpty(limit); + return getChangesets(String.valueOf(start), String.valueOf(max), null, + null, pending); + } + /** + * Method description + * + * + * @param pageStart + * @param pageLimit + * @param revisionStart + * @param revisionEnd + * @param pending + * + * @return + * + * @throws IOException + */ + public ChangesetPagingResult getChangesets(String pageStart, + String pageLimit, String revisionStart, String revisionEnd, + boolean pending) + throws IOException + { if (logger.isDebugEnabled()) { logger.debug("get changesets for repository {}, start: {}, limit: {}", new Object[] { repositoryDirectory.getName(), - startRev, limit }); + pageStart, pageLimit }); } Map env = new HashMap(); @@ -161,8 +188,10 @@ public class HgChangesetViewer implements ChangesetViewer env.put(ENV_PENDING, repositoryDirectory.getAbsolutePath()); } - env.put(ENV_REVISION_START, startRev); - env.put(ENV_REVISION_LIMIT, limit); + env.put(ENV_PAGE_START, Util.nonNull(pageStart)); + env.put(ENV_PAGE_LIMIT, Util.nonNull(pageLimit)); + env.put(ENV_REVISION_START, Util.nonNull(revisionStart)); + env.put(ENV_REVISION_END, Util.nonNull(revisionEnd)); return HgUtil.getResultFromScript(ChangesetPagingResult.class, changesetPagingResultContext, @@ -174,17 +203,37 @@ public class HgChangesetViewer implements ChangesetViewer * Method description * * - * @param startRev - * @param limit + * + * @param startNode + * @param endNode * * @return * * @throws IOException */ - public ChangesetPagingResult getChangesets(String startRev, String limit) + public ChangesetPagingResult getChangesets(String startNode, String endNode) throws IOException { - return getChangesets(startRev, limit, false); + return getChangesets(startNode, endNode, false); + } + + /** + * Method description + * + * + * @param startNode + * @param endNode + * @param pending + * + * @return + * + * @throws IOException + */ + public ChangesetPagingResult getChangesets(String startNode, String endNode, + boolean pending) + throws IOException + { + return getChangesets(null, null, startNode, endNode, pending); } //~--- fields --------------------------------------------------------------- diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hglog.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hglog.py index bfcbfb2f7b..ec9ab26866 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hglog.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hglog.py @@ -46,31 +46,40 @@ import datetime, time repositoryPath = os.environ['SCM_REPOSITORY_PATH'] repo = hg.repository(ui.ui(), path = repositoryPath) -start = os.environ['SCM_REVISION_START'] -limit = os.environ['SCM_REVISION_LIMIT'] +startNode = os.environ['SCM_REVISION_START'] +endNode = os.environ['SCM_REVISION_END'] total = len(repo) -limit = int(limit) -try: - start = int(start) - startRev = total - start - 1 - if startRev < 0: - startRev = 0 -except ValueError: - startRev = repo[start].rev() +if len(startNode) > 0 and len(endNode) > 0: + # start and end revision + startRev = repo[startNode].rev() -1 + endRev = repo[endNode].rev() + +else: + # paging + start = os.environ['SCM_PAGE_START'] + limit = os.environ['SCM_PAGE_LIMIT'] -endRev = startRev - limit -if endRev < -1: - endRev = -1 + limit = int(limit) + + end = int(start) + endRev = total - end - 1 + + startRev = endRev - limit + +# fix negative start revisions +if startRev < -1: + startRev = -1 # header +print '' print '' print ' ' + str(total) + '' print ' ' # changesets -for i in range(startRev, endRev, -1): +for i in range(endRev, startRev, -1): ctx = repo[i] time = int(ctx.date()[0]) * 1000 branch = ctx.branch()