Merged in bugflix/mercurial_pending_changesets (pull request #188)

fixed mercurial PreReceiveRepositoryHooks
This commit is contained in:
René Pfeuffer
2019-02-14 10:23:51 +00:00
4 changed files with 35 additions and 14 deletions

View File

@@ -35,13 +35,10 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.servlet.RequestScoped;
/**
*
* @author Sebastian Sdorra
*/
@RequestScoped
public class HgContext
{

View File

@@ -42,6 +42,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Injection provider for {@link HgContext}.
* This provider returns an instance {@link HgContext} from request scope, if no {@link HgContext} could be found in
* request scope (mostly because the scope is not available) a new {@link HgContext} gets returned.
*
* @author Sebastian Sdorra
*/
@@ -63,22 +66,17 @@ public class HgContextProvider implements Provider<HgContext>
* @return
*/
@Override
public HgContext get()
{
HgContext ctx = context;
if (ctx == null)
{
ctx = new HgContext();
public HgContext get() {
if (contextRequestStore == null) {
logger.trace("context is null, we are probably out of request scope");
return new HgContext();
}
return ctx;
logger.trace("return HgContext from request store");
return contextRequestStore.get();
}
//~--- fields ---------------------------------------------------------------
/** Field description */
@Inject(optional = true)
private HgContext context;
private HgContextRequestStore contextRequestStore;
}

View File

@@ -0,0 +1,24 @@
package sonia.scm.repository;
import com.google.inject.servlet.RequestScoped;
/**
* Holds an instance of {@link HgContext} in the request scope.
*
* <p>The problem seems to be that guice had multiple options for injecting HgContext. {@link HgContextProvider}
* bound via Module and {@link HgContext} bound void {@link RequestScoped} annotation. It looks like that Guice 4
* injects randomly the one or the other, in SCMv1 (Guice 3) everything works as expected.</p>
*
* <p>To fix the problem we have created this class annotated with {@link RequestScoped}, which holds an instance
* of {@link HgContext}. This way only the {@link HgContextProvider} is used for injection.</p>
*/
@RequestScoped
public class HgContextRequestStore {
private final HgContext context = new HgContext();
public HgContext get() {
return context;
}
}

View File

@@ -134,6 +134,8 @@ public final class HgUtil
repoConfiguration.setHgBin(handler.getConfig().getHgBinary());
logger.debug("open hg repository {}: encoding: {}, pending: {}", directory, enc, pending);
return Repository.open(repoConfiguration, directory);
}