merge with default branch

This commit is contained in:
Sebastian Sdorra
2011-11-19 13:02:05 +01:00
320 changed files with 7673 additions and 484 deletions

View File

@@ -399,6 +399,7 @@ public class AbstractHgHandler
}
msg.append("]");
logger.debug(msg.toString());
}
ProcessBuilder pb = new ProcessBuilder(cmdList);

View File

@@ -35,7 +35,11 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.util.Util;
import sonia.scm.web.HgUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -58,6 +62,10 @@ public class HgChangesetViewer extends AbstractHgHandler
/** Field description */
public static final String RESOURCE_LOG = "/sonia/scm/hglog.py";
/** the logger for HgChangesetViewer */
private static final Logger logger =
LoggerFactory.getLogger(HgChangesetViewer.class);
//~--- constructors ---------------------------------------------------------
/**
@@ -110,14 +118,55 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(int start, int max)
throws IOException, RepositoryException
{
return getChangesets(String.valueOf(start), String.valueOf(max), null,
null);
if (logger.isDebugEnabled())
{
logger.debug("fetch changesets. start: {}, max: {}", start, max);
}
return getChangesets(null, null, String.valueOf(start),
String.valueOf(max), null, null);
}
/**
* Method description
*
*
* @param path
* @param revision
* @param start
* @param max
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public ChangesetPagingResult getChangesets(String path, String revision,
int start, int max)
throws IOException, RepositoryException
{
revision = HgUtil.getRevision(revision);
if (logger.isDebugEnabled())
{
logger.debug(
"fetch changesets for path {} and revision {}. start: {}, max: {}",
new Object[] { path,
revision, start, max });
}
return getChangesets(path, revision, String.valueOf(start),
String.valueOf(max), null, null);
}
/**
* Method description
*
*
*
* @param path
* @param revision
* @param pageStart
* @param pageLimit
* @param revisionStart
@@ -128,12 +177,15 @@ public class HgChangesetViewer extends AbstractHgHandler
* @throws IOException
* @throws RepositoryException
*/
public ChangesetPagingResult getChangesets(String pageStart,
String pageLimit, String revisionStart, String revisionEnd)
public ChangesetPagingResult getChangesets(String path, String revision,
String pageStart, String pageLimit, String revisionStart,
String revisionEnd)
throws IOException, RepositoryException
{
Map<String, String> env = new HashMap<String, String>();
env.put(ENV_PATH, Util.nonNull(path));
env.put(ENV_REVISION, Util.nonNull(revision));
env.put(ENV_PAGE_START, Util.nonNull(pageStart));
env.put(ENV_PAGE_LIMIT, Util.nonNull(pageLimit));
env.put(ENV_REVISION_START, Util.nonNull(revisionStart));
@@ -157,6 +209,12 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(String startNode, String endNode)
throws IOException, RepositoryException
{
return getChangesets(null, null, startNode, endNode);
if (logger.isDebugEnabled())
{
logger.debug("fetch changesets. start-node: {}, end-node: {}", startNode,
endNode);
}
return getChangesets(null, null, null, null, startNode, endNode);
}
}

View File

@@ -41,9 +41,12 @@ import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConfigChangedListener;
import sonia.scm.SCMContextProvider;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.io.RegexResourceProcessor;
import sonia.scm.io.ResourceProcessor;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.IOUtil;
import sonia.scm.web.HgWebConfigWriter;
@@ -64,7 +67,7 @@ import javax.servlet.http.HttpServletRequest;
* @author Sebastian Sdorra
*/
@Singleton
public class HgHookManager
public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
{
/** Field description */
@@ -81,15 +84,31 @@ public class HgHookManager
*
*
* @param context
* @param configuration
*/
@Inject
public HgHookManager(SCMContextProvider context)
public HgHookManager(SCMContextProvider context,
ScmConfiguration configuration)
{
this.context = context;
this.configuration = configuration;
this.configuration.addListener(this);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param config
*/
@Override
public void configChanged(ScmConfiguration config)
{
this.changed = true;
}
/**
* TODO check if file exists
*
@@ -106,10 +125,7 @@ public class HgHookManager
{
if (isScriptWriteAble())
{
StringBuilder url = new StringBuilder(request.getScheme());
url.append("://localhost:").append(request.getServerPort());
url.append(request.getContextPath()).append("/hook/hg/");
String url = createUrl(request);
if (hgHookScript == null)
{
@@ -121,10 +137,12 @@ public class HgHookManager
if (logger.isDebugEnabled())
{
logger.debug("write hg hook script to '{}'", hgHookScript);
logger.debug("write hg hook script for '{}' to '{}'", url,
hgHookScript);
}
writeScript(hgHookScript, url.toString());
changed = false;
}
}
}
@@ -158,6 +176,35 @@ public class HgHookManager
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
*
* @return
*/
private String createUrl(HttpServletRequest request)
{
String url = null;
if (configuration.isForceBaseUrl())
{
url = HttpUtil.getUriWithoutEndSeperator(
configuration.getBaseUrl()).concat("/hook/hg/");
}
else
{
StringBuilder sb = new StringBuilder(request.getScheme());
sb.append("://localhost:").append(request.getLocalPort());
sb.append(request.getContextPath()).append("/hook/hg/");
url = sb.toString();
}
return url;
}
/**
* Method description
*
@@ -202,14 +249,20 @@ public class HgHookManager
*/
private boolean isScriptWriteAble()
{
return (hgHookScript == null) ||!hgHookScript.exists();
return (hgHookScript == null) ||!hgHookScript.exists() || changed;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean changed = false;
/** Field description */
private String challenge = UUID.randomUUID().toString();
/** Field description */
private ScmConfiguration configuration;
/** Field description */
private SCMContextProvider context;

View File

@@ -29,8 +29,10 @@
#
#
# import basic packages
import sys, os
# create python path
pythonPath = os.environ['SCM_PYTHON_PATH']
if len(pythonPath) > 0:
@@ -38,49 +40,21 @@ if len(pythonPath) > 0:
for i in range(len(pathParts)):
sys.path.insert(i, pathParts[i])
# import mercurial packages
from mercurial import hg, ui, commands
from mercurial.node import hex
from xml.sax.saxutils import escape
import datetime, time
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
repo = hg.repository(ui.ui(), path = repositoryPath)
startNode = os.environ['SCM_REVISION_START']
endNode = os.environ['SCM_REVISION_END']
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)
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>'
def printHeader(total):
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(endRev, startRev, -1):
ctx = repo[i]
# changeset
def printChangeset(repo, ctx):
time = int(ctx.date()[0]) * 1000
branch = ctx.branch()
tags = ctx.tags()
@@ -99,7 +73,7 @@ for i in range(endRev, startRev, -1):
authorName = authorName[0:s].strip()
print ' <changeset>'
print ' <id>' + str(i) + ':' + hex(ctx.node()[:6]) + '</id>'
print ' <id>' + str(ctx.rev()) + ':' + hex(ctx.node()[:6]) + '</id>'
print ' <author>' + escape(ctx.user()) + '</author>'
print ' <description>' + escape(ctx.description()) + '</description>'
print ' <date>' + str(time).split('.')[0] + '</date>'
@@ -147,7 +121,83 @@ for i in range(endRev, startRev, -1):
print ' </modifications>'
print ' </changeset>'
# footer
print ' </changesets>'
print '</changeset-paging>'
def printFooter():
print ' </changesets>'
print '</changeset-paging>'
def printChangesetsForPath(repo, path):
rev = os.environ['SCM_REVISION']
if len(rev) <= 0:
rev = "tip"
fctxs = repo[rev].filectx(path)
maxRev = fctxs.rev()
revs = []
for i in fctxs.filelog():
fctx = fctxs.filectx(i)
if fctx.rev() <= maxRev:
revs.append(fctx.changectx())
# reverse changesets
revs.reverse()
total = len(revs)
# handle paging
start = os.environ['SCM_PAGE_START']
limit = os.environ['SCM_PAGE_LIMIT']
if len(start) > 0:
revs = revs[int(start):]
if len(limit) > 0:
revs = revs[:int(limit)]
# output
printHeader(total)
for ctx in revs:
printChangeset(repo, ctx)
printFooter()
def printChangesetsForStartAndEnd(repo, startRev, endRev):
printHeader(len(repo))
for i in range(endRev, startRev, -1):
printChangeset(repo, repo[i])
printFooter()
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
repo = hg.repository(ui.ui(), path = repositoryPath)
path = os.environ['SCM_PATH']
startNode = os.environ['SCM_REVISION_START']
endNode = os.environ['SCM_REVISION_END']
if len(path) > 0:
printChangesetsForPath(repo, path)
else:
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)
end = int(start)
endRev = len(repo) - end - 1
startRev = endRev - limit
# fix negative start revisions
if startRev < -1:
startRev = -1
# print
printChangesetsForStartAndEnd(repo, startRev, endRev)