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 6f029f0732..04ca3bd6f1 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 @@ -110,21 +110,38 @@ public class HgChangesetViewer extends AbstractHgHandler public ChangesetPagingResult getChangesets(int start, int max) throws IOException, RepositoryException { - return getChangesets(String.valueOf(start), String.valueOf(max), null, - null); + return getChangesets(null, null, String.valueOf(start), + String.valueOf(max), null, null); } - @Override - public ChangesetPagingResult getChangesets(String path, int start, int max) - throws IOException, RepositoryException { - // TODO Auto-generated method stub - return null; - } - /** * Method description * * + * @param path + * @param start + * @param max + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public ChangesetPagingResult getChangesets(String path, int start, int max) + throws IOException, RepositoryException + { + return getChangesets(path, null, String.valueOf(start), + String.valueOf(max), null, null); + } + + /** + * Method description + * + * + * + * @param path + * @param revision * @param pageStart * @param pageLimit * @param revisionStart @@ -135,12 +152,15 @@ public class HgChangesetViewer extends AbstractHgHandler * @throws IOException * @throws RepositoryException */ - public ChangesetPagingResult getChangesets(String pageStart, - String pageLimit, String revisionStart, String revisionEnd) + public ChangesetPagingResult getChangesets(String path, String revision, + String pageStart, String pageLimit, String revisionStart, + String revisionEnd) throws IOException, RepositoryException { Map env = new HashMap(); + env.put(ENV_PATH, Util.nonNull(path)); + env.put(ENV_REVISION, Util.nonNull(revision)); env.put(ENV_PAGE_START, Util.nonNull(pageStart)); env.put(ENV_PAGE_LIMIT, Util.nonNull(pageLimit)); env.put(ENV_REVISION_START, Util.nonNull(revisionStart)); @@ -164,6 +184,6 @@ public class HgChangesetViewer extends AbstractHgHandler public ChangesetPagingResult getChangesets(String startNode, String endNode) throws IOException, RepositoryException { - return getChangesets(null, null, startNode, endNode); + return getChangesets(null, null, null, null, startNode, endNode); } } 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 ec9ab26866..03d42897d0 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 @@ -29,8 +29,10 @@ # # +# import basic packages import sys, os +# create python path pythonPath = os.environ['SCM_PYTHON_PATH'] if len(pythonPath) > 0: @@ -38,49 +40,21 @@ if len(pythonPath) > 0: for i in range(len(pathParts)): sys.path.insert(i, pathParts[i]) +# import mercurial packages from mercurial import hg, ui, commands from mercurial.node import hex from xml.sax.saxutils import escape import datetime, time -repositoryPath = os.environ['SCM_REPOSITORY_PATH'] -repo = hg.repository(ui.ui(), path = repositoryPath) - -startNode = os.environ['SCM_REVISION_START'] -endNode = os.environ['SCM_REVISION_END'] - -total = len(repo) - -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'] - - 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 ' ' +def printHeader(total): + print '' + print '' + print ' ' + str(total) + '' + print ' ' -# changesets -for i in range(endRev, startRev, -1): - ctx = repo[i] +# changeset +def printChangeset(repo, ctx): time = int(ctx.date()[0]) * 1000 branch = ctx.branch() tags = ctx.tags() @@ -99,7 +73,7 @@ for i in range(endRev, startRev, -1): authorName = authorName[0:s].strip() print ' ' - print ' ' + str(i) + ':' + hex(ctx.node()[:6]) + '' + print ' ' + str(ctx.rev()) + ':' + hex(ctx.node()[:6]) + '' print ' ' + escape(ctx.user()) + '' print ' ' + escape(ctx.description()) + '' print ' ' + str(time).split('.')[0] + '' @@ -147,7 +121,79 @@ for i in range(endRev, startRev, -1): print ' ' print ' ' - + # footer -print ' ' -print '' +def printFooter(): + print ' ' + print '' + +def printChangesetsForPath(repo, path): + rev = os.environ['SCM_REVISION'] + if len(rev) <= 0: + rev = "tip" + fctxs = repo[rev].filectx(path) + revs = [] + for i in fctxs.filelog(): + fctx = fctxs.filectx(i) + revs.append(fctx.changectx()) + + # reverse changesets + revs.reverse() + + total = len(revs) + + # handle paging + start = os.environ['SCM_PAGE_START'] + limit = os.environ['SCM_PAGE_LIMIT'] + + if len(start) > 0: + revs = revs[int(start):] + + if len(limit) > 0: + revs = revs[:int(limit)] + + # output + printHeader(total) + for ctx in revs: + printChangeset(repo, ctx) + printFooter() + +def printChangesetsForStartAndEnd(repo, startRev, endRev): + printHeader(len(repo)) + for i in range(endRev, startRev, -1): + printChangeset(repo, repo[i]) + printFooter() + +repositoryPath = os.environ['SCM_REPOSITORY_PATH'] +repo = hg.repository(ui.ui(), path = repositoryPath) + +path = os.environ['SCM_PATH'] +startNode = os.environ['SCM_REVISION_START'] +endNode = os.environ['SCM_REVISION_END'] + +if len(path) > 0: + printChangesetsForPath(repo, path) +else: + 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'] + + limit = int(limit) + + end = int(start) + endRev = len(repo) - end - 1 + + startRev = endRev - limit + + # fix negative start revisions + if startRev < -1: + startRev = -1 + + # print + printChangesetsForStartAndEnd(repo, startRev, endRev) +