mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
mercurial support for directory structures
This commit is contained in:
@@ -77,7 +77,6 @@ public class UnixHgInstaller extends AbstractHgInstaller
|
|||||||
super.install(baseDirectory, config);
|
super.install(baseDirectory, config);
|
||||||
|
|
||||||
// search mercurial (hg)
|
// search mercurial (hg)
|
||||||
|
|
||||||
if (Util.isEmpty(config.getHgBinary()))
|
if (Util.isEmpty(config.getHgBinary()))
|
||||||
{
|
{
|
||||||
String hg = IOUtil.search(COMMAND_HG);
|
String hg = IOUtil.search(COMMAND_HG);
|
||||||
@@ -102,7 +101,6 @@ public class UnixHgInstaller extends AbstractHgInstaller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// search python
|
// search python
|
||||||
|
|
||||||
if (Util.isEmpty(config.getPythonBinary()))
|
if (Util.isEmpty(config.getPythonBinary()))
|
||||||
{
|
{
|
||||||
config.setPythonBinary(IOUtil.search(COMMAND_PYTHON));
|
config.setPythonBinary(IOUtil.search(COMMAND_PYTHON));
|
||||||
|
|||||||
@@ -272,8 +272,9 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
IOUtil.copy(templateDirectory, new File(libDir, FILE_TEMPLATES));
|
IOUtil.copy(templateDirectory, new File(libDir, FILE_TEMPLATES));
|
||||||
}
|
}
|
||||||
|
|
||||||
File hg = new File( hgDirectory, FILE_MERCURIAL_EXE );
|
File hg = new File(hgDirectory, FILE_MERCURIAL_EXE);
|
||||||
if ( hg.exists() )
|
|
||||||
|
if (hg.exists())
|
||||||
{
|
{
|
||||||
config.setHgBinary(hg.getAbsolutePath());
|
config.setHgBinary(hg.getAbsolutePath());
|
||||||
}
|
}
|
||||||
@@ -323,7 +324,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
{
|
{
|
||||||
File directory = null;
|
File directory = null;
|
||||||
|
|
||||||
if ( Util.isNotEmpty(hgBinary) )
|
if (Util.isNotEmpty(hgBinary))
|
||||||
{
|
{
|
||||||
File hg = new File(hgBinary);
|
File hg = new File(hgBinary);
|
||||||
|
|
||||||
@@ -333,7 +334,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( directory == null )
|
if (directory == null)
|
||||||
{
|
{
|
||||||
directory = getMercurialDirectoryFromRegistry();
|
directory = getMercurialDirectoryFromRegistry();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ package sonia.scm.web;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import sonia.scm.config.ScmConfiguration;
|
import sonia.scm.config.ScmConfiguration;
|
||||||
@@ -55,7 +56,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
@@ -103,6 +103,7 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
* @param cgiExecutorFactory
|
* @param cgiExecutorFactory
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* @param repositoryManager
|
* @param repositoryManager
|
||||||
|
* @param repositoryProvider
|
||||||
* @param handler
|
* @param handler
|
||||||
* @param hookManager
|
* @param hookManager
|
||||||
*/
|
*/
|
||||||
@@ -110,11 +111,13 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
public HgCGIServlet(CGIExecutorFactory cgiExecutorFactory,
|
public HgCGIServlet(CGIExecutorFactory cgiExecutorFactory,
|
||||||
ScmConfiguration configuration,
|
ScmConfiguration configuration,
|
||||||
RepositoryManager repositoryManager,
|
RepositoryManager repositoryManager,
|
||||||
|
Provider<Repository> repositoryProvider,
|
||||||
HgRepositoryHandler handler, HgHookManager hookManager)
|
HgRepositoryHandler handler, HgHookManager hookManager)
|
||||||
{
|
{
|
||||||
this.cgiExecutorFactory = cgiExecutorFactory;
|
this.cgiExecutorFactory = cgiExecutorFactory;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.repositoryManager = repositoryManager;
|
this.repositoryManager = repositoryManager;
|
||||||
|
this.repositoryProvider = repositoryProvider;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.hookManager = hookManager;
|
this.hookManager = hookManager;
|
||||||
}
|
}
|
||||||
@@ -149,7 +152,7 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
HttpServletResponse response)
|
HttpServletResponse response)
|
||||||
throws ServletException, IOException
|
throws ServletException, IOException
|
||||||
{
|
{
|
||||||
Repository repository = getRepository(request);
|
Repository repository = repositoryProvider.get();
|
||||||
|
|
||||||
if (repository == null)
|
if (repository == null)
|
||||||
{
|
{
|
||||||
@@ -244,33 +247,6 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
return python;
|
return python;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Repository getRepository(HttpServletRequest request)
|
|
||||||
{
|
|
||||||
Repository repository = null;
|
|
||||||
String uri = request.getRequestURI();
|
|
||||||
|
|
||||||
uri = uri.substring(request.getContextPath().length());
|
|
||||||
|
|
||||||
Matcher m = PATTERN_REPOSITORYNAME.matcher(uri);
|
|
||||||
|
|
||||||
if (m.matches())
|
|
||||||
{
|
|
||||||
String repositoryname = m.group(1);
|
|
||||||
|
|
||||||
repository = getRepository(repositoryname);
|
|
||||||
}
|
|
||||||
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -303,4 +279,7 @@ public class HgCGIServlet extends HttpServlet
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private RepositoryManager repositoryManager;
|
private RepositoryManager repositoryManager;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Provider<Repository> repositoryProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import sonia.scm.repository.RepositoryManager;
|
|||||||
import sonia.scm.repository.RepositoryNotFoundException;
|
import sonia.scm.repository.RepositoryNotFoundException;
|
||||||
import sonia.scm.security.CipherUtil;
|
import sonia.scm.security.CipherUtil;
|
||||||
import sonia.scm.util.HttpUtil;
|
import sonia.scm.util.HttpUtil;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.security.WebSecurityContext;
|
import sonia.scm.web.security.WebSecurityContext;
|
||||||
|
|
||||||
@@ -80,6 +81,9 @@ public class HgHookCallbackServlet extends HttpServlet
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String HGHOOK_PRE_RECEIVE = "pretxnchangegroup";
|
public static final String HGHOOK_PRE_RECEIVE = "pretxnchangegroup";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String PARAM_REPOSITORYPATH = "repositoryPath";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String PARAM_CHALLENGE = "challenge";
|
private static final String PARAM_CHALLENGE = "challenge";
|
||||||
|
|
||||||
@@ -91,7 +95,7 @@ public class HgHookCallbackServlet extends HttpServlet
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final Pattern REGEX_URL =
|
private static final Pattern REGEX_URL =
|
||||||
Pattern.compile("^/hook/hg/([^/]+)/([^/]+)$");
|
Pattern.compile("^/hook/hg/([^/]+)$");
|
||||||
|
|
||||||
/** the logger for HgHookCallbackServlet */
|
/** the logger for HgHookCallbackServlet */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
@@ -144,8 +148,8 @@ public class HgHookCallbackServlet extends HttpServlet
|
|||||||
|
|
||||||
if (m.matches())
|
if (m.matches())
|
||||||
{
|
{
|
||||||
String repositoryId = m.group(1);
|
String repositoryId = getRepositoryName(request);
|
||||||
String type = m.group(2);
|
String type = m.group(1);
|
||||||
String challenge = request.getParameter(PARAM_CHALLENGE);
|
String challenge = request.getParameter(PARAM_CHALLENGE);
|
||||||
|
|
||||||
if (Util.isNotEmpty(challenge))
|
if (Util.isNotEmpty(challenge))
|
||||||
@@ -316,6 +320,43 @@ public class HgHookCallbackServlet extends HttpServlet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getRepositoryName(HttpServletRequest request)
|
||||||
|
{
|
||||||
|
String name = null;
|
||||||
|
String path = request.getParameter(PARAM_REPOSITORYPATH);
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(path))
|
||||||
|
{
|
||||||
|
int directoryLength =
|
||||||
|
handler.getConfig().getRepositoryDirectory().getAbsolutePath().length();
|
||||||
|
|
||||||
|
if (directoryLength < path.length())
|
||||||
|
{
|
||||||
|
name = IOUtil.trimSeperatorChars(path.substring(directoryLength));
|
||||||
|
}
|
||||||
|
else if (logger.isWarnEnabled())
|
||||||
|
{
|
||||||
|
logger.warn("path is shorter as the main hg repository path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (logger.isWarnEnabled())
|
||||||
|
{
|
||||||
|
logger.warn("no repository path parameter found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -39,9 +39,8 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||||
import sonia.scm.web.filter.RegexPermissionFilter;
|
|
||||||
import sonia.scm.web.security.WebSecurityContext;
|
import sonia.scm.web.security.WebSecurityContext;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -53,7 +52,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class HgPermissionFilter extends RegexPermissionFilter
|
public class HgPermissionFilter extends ProviderPermissionFilter
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,30 +60,18 @@ public class HgPermissionFilter extends RegexPermissionFilter
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param securityContextProvider
|
* @param securityContextProvider
|
||||||
* @param repositoryManager
|
* @param repositoryProvider
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public HgPermissionFilter(
|
public HgPermissionFilter(
|
||||||
Provider<WebSecurityContext> securityContextProvider,
|
Provider<WebSecurityContext> securityContextProvider,
|
||||||
RepositoryManager repositoryManager)
|
Provider<Repository> repositoryProvider)
|
||||||
{
|
{
|
||||||
super(securityContextProvider, repositoryManager);
|
super(securityContextProvider, repositoryProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected String getType()
|
|
||||||
{
|
|
||||||
return HgRepositoryHandler.TYPE_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs)
|
|||||||
failure = True
|
failure = True
|
||||||
if node != None:
|
if node != None:
|
||||||
try:
|
try:
|
||||||
url = baseUrl + os.path.basename(repo.root) + "/" + hooktype
|
url = baseUrl + hooktype
|
||||||
ui.debug( "send scm-hook to " + url + " and " + node + "\n" )
|
ui.debug( "send scm-hook to " + url + " and " + node + "\n" )
|
||||||
data = urllib.urlencode({'node': node, 'challenge': challenge, 'credentials': credentials})
|
data = urllib.urlencode({'node': node, 'challenge': challenge, 'credentials': credentials, 'repositoryPath': repo.root})
|
||||||
conn = urllib.urlopen(url, data);
|
conn = urllib.urlopen(url, data);
|
||||||
if conn.code >= 200 and conn.code < 300:
|
if conn.code >= 200 and conn.code < 300:
|
||||||
ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" )
|
ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" )
|
||||||
|
|||||||
Reference in New Issue
Block a user