mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +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 org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.util.AssertUtil;
|
import sonia.scm.util.AssertUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.HgUtil;
|
import sonia.scm.web.HgUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -58,11 +59,17 @@ import javax.xml.bind.JAXBContext;
|
|||||||
public class HgChangesetViewer implements ChangesetViewer
|
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 */
|
/** Field description */
|
||||||
public static final String ENV_PENDING = "HG_PENDING";
|
public static final String ENV_PENDING = "HG_PENDING";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_REVISION_LIMIT = "SCM_REVISION_LIMIT";
|
public static final String ENV_REVISION_END = "SCM_REVISION_END";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ENV_REVISION_START = "SCM_REVISION_START";
|
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)
|
public ChangesetPagingResult getChangesets(int start, int max)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return getChangesets(String.valueOf(start), String.valueOf(max), false);
|
return getChangesets(start, max, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param startRev
|
* @param start
|
||||||
* @param limit
|
* @param max
|
||||||
* @param pending
|
* @param pending
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getChangesets(String startRev, String limit,
|
public ChangesetPagingResult getChangesets(int start, int max,
|
||||||
boolean pending)
|
boolean pending)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
AssertUtil.assertIsNotEmpty(startRev);
|
return getChangesets(String.valueOf(start), String.valueOf(max), null,
|
||||||
AssertUtil.assertIsNotEmpty(limit);
|
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())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("get changesets for repository {}, start: {}, limit: {}",
|
logger.debug("get changesets for repository {}, start: {}, limit: {}",
|
||||||
new Object[] { repositoryDirectory.getName(),
|
new Object[] { repositoryDirectory.getName(),
|
||||||
startRev, limit });
|
pageStart, pageLimit });
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> env = new HashMap<String, String>();
|
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_PENDING, repositoryDirectory.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
env.put(ENV_REVISION_START, startRev);
|
env.put(ENV_PAGE_START, Util.nonNull(pageStart));
|
||||||
env.put(ENV_REVISION_LIMIT, limit);
|
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,
|
return HgUtil.getResultFromScript(ChangesetPagingResult.class,
|
||||||
changesetPagingResultContext,
|
changesetPagingResultContext,
|
||||||
@@ -174,17 +203,37 @@ public class HgChangesetViewer implements ChangesetViewer
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param startRev
|
*
|
||||||
* @param limit
|
* @param startNode
|
||||||
|
* @param endNode
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getChangesets(String startRev, String limit)
|
public ChangesetPagingResult getChangesets(String startNode, String endNode)
|
||||||
throws IOException
|
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 ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -46,31 +46,40 @@ import datetime, time
|
|||||||
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
|
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
|
||||||
repo = hg.repository(ui.ui(), path = repositoryPath)
|
repo = hg.repository(ui.ui(), path = repositoryPath)
|
||||||
|
|
||||||
start = os.environ['SCM_REVISION_START']
|
startNode = os.environ['SCM_REVISION_START']
|
||||||
limit = os.environ['SCM_REVISION_LIMIT']
|
endNode = os.environ['SCM_REVISION_END']
|
||||||
|
|
||||||
total = len(repo)
|
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)
|
limit = int(limit)
|
||||||
|
|
||||||
try:
|
end = int(start)
|
||||||
start = int(start)
|
endRev = total - end - 1
|
||||||
startRev = total - start - 1
|
|
||||||
if startRev < 0:
|
|
||||||
startRev = 0
|
|
||||||
except ValueError:
|
|
||||||
startRev = repo[start].rev()
|
|
||||||
|
|
||||||
endRev = startRev - limit
|
startRev = endRev - limit
|
||||||
if endRev < -1:
|
|
||||||
endRev = -1
|
# fix negative start revisions
|
||||||
|
if startRev < -1:
|
||||||
|
startRev = -1
|
||||||
|
|
||||||
# header
|
# header
|
||||||
|
print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
||||||
print '<changeset-paging>'
|
print '<changeset-paging>'
|
||||||
print ' <total>' + str(total) + '</total>'
|
print ' <total>' + str(total) + '</total>'
|
||||||
print ' <changesets>'
|
print ' <changesets>'
|
||||||
|
|
||||||
# changesets
|
# changesets
|
||||||
for i in range(startRev, endRev, -1):
|
for i in range(endRev, startRev, -1):
|
||||||
ctx = repo[i]
|
ctx = repo[i]
|
||||||
time = int(ctx.date()[0]) * 1000
|
time = int(ctx.date()[0]) * 1000
|
||||||
branch = ctx.branch()
|
branch = ctx.branch()
|
||||||
|
|||||||
Reference in New Issue
Block a user