diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHookEvent.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHookEvent.java index 0df116509a..d0b070b5a5 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHookEvent.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHookEvent.java @@ -33,6 +33,16 @@ package sonia.scm.repository; +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.io.Closeables; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import sonia.scm.repository.spi.HgCommandContext; +import sonia.scm.repository.spi.javahg.HgLogChangesetCommand; + //~--- JDK imports ------------------------------------------------------------ import java.io.File; @@ -50,6 +60,12 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent /** Field description */ public static final String REV_TIP = "tip"; + /** + * the logger for HgRepositoryHookEvent + */ + private static final Logger logger = + LoggerFactory.getLogger(HgRepositoryHookEvent.class); + //~--- constructors --------------------------------------------------------- /** @@ -62,8 +78,7 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent * @param type */ public HgRepositoryHookEvent(HgRepositoryHandler handler, - String repositoryName, String startRev, - RepositoryHookType type) + String repositoryName, String startRev, RepositoryHookType type) { this.handler = handler; this.repositoryName = repositoryName; @@ -84,19 +99,24 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent { if (changesets == null) { + HgCommandContext context = null; + try { - ChangesetPagingResult result = - createChangesetViewer().getChangesets(startRev, REV_TIP); + context = createCommandContext(); - if (result != null) - { - changesets = result.getChangesets(); - } + HgLogChangesetCommand cmd = HgLogChangesetCommand.on(context.open(), + handler.getConfig()); + + changesets = cmd.rev(startRev.concat(":").concat(REV_TIP)).execute(); } catch (Exception ex) { - throw new RuntimeException("could not load changesets", ex); + logger.error("could not retrieve changesets", ex); + } + finally + { + Closeables.closeQuietly(context); } } @@ -123,7 +143,7 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent * * @return */ - private HgChangesetViewer createChangesetViewer() + private HgCommandContext createCommandContext() { File directory = handler.getConfig().getRepositoryDirectory(); File repositoryDirectory = new File(directory, repositoryName); @@ -131,8 +151,10 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent // use HG_PENDING only for pre receive hooks boolean pending = type == RepositoryHookType.PRE_RECEIVE; - return handler.getChangesetViewer(repositoryDirectory, - new HgContext(pending)); + Repository repository = getRepository(); + + return new HgCommandContext(handler.getConfig(), repository, + repositoryDirectory, pending); } //~--- fields --------------------------------------------------------------- diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java index 65adf9b2c7..9b9cf86043 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java @@ -80,12 +80,28 @@ public class HgCommandContext implements Closeable * @param repository * @param directory */ - HgCommandContext(HgConfig config, sonia.scm.repository.Repository repository, - File directory) + public HgCommandContext(HgConfig config, + sonia.scm.repository.Repository repository, File directory) + { + this(config, repository, directory, false); + } + + /** + * Constructs ... + * + * + * @param config + * @param repository + * @param directory + * @param pending + */ + public HgCommandContext(HgConfig config, + sonia.scm.repository.Repository repository, File directory, boolean pending) { this.config = config; this.directory = directory; - encoding = repository.getProperty(PROPERTY_ENCODING); + this.encoding = repository.getProperty(PROPERTY_ENCODING); + this.pending = pending; if (Strings.isNullOrEmpty(encoding)) { @@ -124,6 +140,7 @@ public class HgCommandContext implements Closeable RepositoryConfiguration.DEFAULT; repoConfiguration.addExtension(HgFileviewExtension.class); + repoConfiguration.setEnablePendingChangesets(pending); try { @@ -172,6 +189,9 @@ public class HgCommandContext implements Closeable /** Field description */ private String encoding; + /** Field description */ + private boolean pending; + /** Field description */ private Repository repository; }