mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
use javahg to retrieve changesets from a mercurial hook
This commit is contained in:
@@ -33,6 +33,16 @@
|
|||||||
|
|
||||||
package sonia.scm.repository;
|
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 ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -50,6 +60,12 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String REV_TIP = "tip";
|
public static final String REV_TIP = "tip";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the logger for HgRepositoryHookEvent
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(HgRepositoryHookEvent.class);
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,8 +78,7 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public HgRepositoryHookEvent(HgRepositoryHandler handler,
|
public HgRepositoryHookEvent(HgRepositoryHandler handler,
|
||||||
String repositoryName, String startRev,
|
String repositoryName, String startRev, RepositoryHookType type)
|
||||||
RepositoryHookType type)
|
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.repositoryName = repositoryName;
|
this.repositoryName = repositoryName;
|
||||||
@@ -84,19 +99,24 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
{
|
{
|
||||||
if (changesets == null)
|
if (changesets == null)
|
||||||
{
|
{
|
||||||
|
HgCommandContext context = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ChangesetPagingResult result =
|
context = createCommandContext();
|
||||||
createChangesetViewer().getChangesets(startRev, REV_TIP);
|
|
||||||
|
|
||||||
if (result != null)
|
HgLogChangesetCommand cmd = HgLogChangesetCommand.on(context.open(),
|
||||||
{
|
handler.getConfig());
|
||||||
changesets = result.getChangesets();
|
|
||||||
}
|
changesets = cmd.rev(startRev.concat(":").concat(REV_TIP)).execute();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
private HgChangesetViewer createChangesetViewer()
|
private HgCommandContext createCommandContext()
|
||||||
{
|
{
|
||||||
File directory = handler.getConfig().getRepositoryDirectory();
|
File directory = handler.getConfig().getRepositoryDirectory();
|
||||||
File repositoryDirectory = new File(directory, repositoryName);
|
File repositoryDirectory = new File(directory, repositoryName);
|
||||||
@@ -131,8 +151,10 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
// use HG_PENDING only for pre receive hooks
|
// use HG_PENDING only for pre receive hooks
|
||||||
boolean pending = type == RepositoryHookType.PRE_RECEIVE;
|
boolean pending = type == RepositoryHookType.PRE_RECEIVE;
|
||||||
|
|
||||||
return handler.getChangesetViewer(repositoryDirectory,
|
Repository repository = getRepository();
|
||||||
new HgContext(pending));
|
|
||||||
|
return new HgCommandContext(handler.getConfig(), repository,
|
||||||
|
repositoryDirectory, pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -80,12 +80,28 @@ public class HgCommandContext implements Closeable
|
|||||||
* @param repository
|
* @param repository
|
||||||
* @param directory
|
* @param directory
|
||||||
*/
|
*/
|
||||||
HgCommandContext(HgConfig config, sonia.scm.repository.Repository repository,
|
public HgCommandContext(HgConfig config,
|
||||||
File directory)
|
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.config = config;
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
encoding = repository.getProperty(PROPERTY_ENCODING);
|
this.encoding = repository.getProperty(PROPERTY_ENCODING);
|
||||||
|
this.pending = pending;
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(encoding))
|
if (Strings.isNullOrEmpty(encoding))
|
||||||
{
|
{
|
||||||
@@ -124,6 +140,7 @@ public class HgCommandContext implements Closeable
|
|||||||
RepositoryConfiguration.DEFAULT;
|
RepositoryConfiguration.DEFAULT;
|
||||||
|
|
||||||
repoConfiguration.addExtension(HgFileviewExtension.class);
|
repoConfiguration.addExtension(HgFileviewExtension.class);
|
||||||
|
repoConfiguration.setEnablePendingChangesets(pending);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -172,6 +189,9 @@ public class HgCommandContext implements Closeable
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private String encoding;
|
private String encoding;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private boolean pending;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Repository repository;
|
private Repository repository;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user