From e183ada66f7b9a7ac0220fa68c6f578f94f64163 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 19 Jan 2012 15:56:53 +0100 Subject: [PATCH] implement mercurial getChangeset --- .../scm/repository/AbstractHgHandler.java | 24 ++++++++++++++ .../scm/repository/HgChangesetViewer.java | 31 +++++++++++++++++-- .../scm/repository/HgRepositoryHandler.java | 11 +++++-- .../src/main/resources/sonia/scm/hglog.py | 10 ++++-- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java index b6a0d8c611..3ba8c53a57 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java @@ -321,6 +321,30 @@ public class AbstractHgHandler protected T getResultFromScript(Class resultType, String scriptResource, Map extraEnv) throws IOException, RepositoryException + { + return getResultFromScript(resultType, scriptResource, jaxbContext, + extraEnv); + } + + /** + * Method description + * + * + * @param resultType + * @param scriptResource + * @param jaxbContext + * @param extraEnv + * @param + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + protected T getResultFromScript(Class resultType, + String scriptResource, JAXBContext jaxbContext, + Map extraEnv) + throws IOException, RepositoryException { Process p = createPythonProcess(extraEnv); T result = null; 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 13d835a966..88d793cc26 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 @@ -74,14 +74,17 @@ public class HgChangesetViewer extends AbstractHgHandler * * @param handler * @param changesetPagingResultContext + * @param changesetContext * @param context * @param repositoryDirectory */ public HgChangesetViewer(HgRepositoryHandler handler, JAXBContext changesetPagingResultContext, - HgContext context, File repositoryDirectory) + JAXBContext changesetContext, HgContext context, + File repositoryDirectory) { super(handler, changesetPagingResultContext, context, repositoryDirectory); + this.changesetContext = changesetContext; } /** @@ -90,15 +93,18 @@ public class HgChangesetViewer extends AbstractHgHandler * * * @param handler + * @param changesetContext * @param context * @param changesetPagingResultContext * @param repository */ public HgChangesetViewer(HgRepositoryHandler handler, JAXBContext changesetPagingResultContext, - HgContext context, Repository repository) + JAXBContext changesetContext, HgContext context, + Repository repository) { super(handler, changesetPagingResultContext, context, repository); + this.changesetContext = changesetContext; } //~--- get methods ---------------------------------------------------------- @@ -110,11 +116,25 @@ public class HgChangesetViewer extends AbstractHgHandler * @param revision * * @return + * + * @throws IOException + * @throws RepositoryException */ @Override public Changeset getChangeset(String revision) + throws IOException, RepositoryException { - throw new UnsupportedOperationException("Not supported yet."); + Map env = new HashMap(); + + env.put(ENV_REVISION, HgUtil.getRevision(revision)); + env.put(ENV_PATH, Util.EMPTY_STRING); + env.put(ENV_PAGE_START, Util.EMPTY_STRING); + env.put(ENV_PAGE_LIMIT, Util.EMPTY_STRING); + env.put(ENV_REVISION_START, Util.EMPTY_STRING); + env.put(ENV_REVISION_END, Util.EMPTY_STRING); + + return getResultFromScript(Changeset.class, RESOURCE_LOG, changesetContext, + env); } /** @@ -231,4 +251,9 @@ public class HgChangesetViewer extends AbstractHgHandler return getChangesets(null, null, null, null, startNode, endNode); } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private JAXBContext changesetContext; } diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java index 9bbdc4f044..ab97cc6509 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java @@ -119,6 +119,7 @@ public class HgRepositoryHandler { this.browserResultContext = JAXBContext.newInstance(BrowserResult.class); this.blameResultContext = JAXBContext.newInstance(BlameResult.class); + this.changesetContext = JAXBContext.newInstance(Changeset.class); this.changesetPagingResultContext = JAXBContext.newInstance(ChangesetPagingResult.class); } @@ -248,8 +249,8 @@ public class HgRepositoryHandler if (TYPE_NAME.equals(type)) { changesetViewer = new HgChangesetViewer(this, - changesetPagingResultContext, hgContextProvider.get(), - repository); + changesetPagingResultContext, changesetContext, + hgContextProvider.get(), repository); } else { @@ -416,7 +417,8 @@ public class HgRepositoryHandler } return new HgChangesetViewer(this, changesetPagingResultContext, - hgContextProvider.get(), repositoryDirectory); + changesetContext, hgContextProvider.get(), + repositoryDirectory); } //~--- set methods ---------------------------------------------------------- @@ -668,6 +670,9 @@ public class HgRepositoryHandler /** Field description */ private JAXBContext browserResultContext; + /** Field description */ + private JAXBContext changesetContext; + /** Field description */ private JAXBContext changesetPagingResultContext; 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 368b4923ef..08e332a2cd 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 @@ -131,8 +131,7 @@ def printFooter(): print ' ' print '' -def printChangesetsForPath(repo, path): - rev = os.environ['SCM_REVISION'] +def printChangesetsForPath(repo, rev, path): if len(rev) <= 0: rev = "tip" @@ -178,9 +177,14 @@ repo = hg.repository(ui.ui(), path = repositoryPath) path = os.environ['SCM_PATH'] startNode = os.environ['SCM_REVISION_START'] endNode = os.environ['SCM_REVISION_END'] +rev = os.environ['SCM_REVISION'] if len(path) > 0: - printChangesetsForPath(repo, path) + printChangesetsForPath(repo, rev, path) +elif len(rev) > 0: + ctx = repo[rev] + print '' + printChangeset(repo, ctx) else: if len(startNode) > 0 and len(endNode) > 0: # start and end revision