mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
fix mercurial pre receive hook
This commit is contained in:
@@ -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<String, String> env = new HashMap<String, String>();
|
||||
@@ -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 ---------------------------------------------------------------
|
||||
|
||||
@@ -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 '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
||||
print '<changeset-paging>'
|
||||
print ' <total>' + str(total) + '</total>'
|
||||
print ' <changesets>'
|
||||
|
||||
# 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()
|
||||
|
||||
Reference in New Issue
Block a user