Commits

Sebastian Sdorra  committed 70d73be

support for mercurial 2.1

  • Participants
  • Parent commits d1fe477

Comments (0)

Files changed (4)

File scm-core/src/main/java/sonia/scm/web/cgi/CGIExecutor.java

    *
    *
    * @return
+   * @since 1.12
+   */
+  public boolean isContentLengthWorkaround();
+
+  /**
+   * Method description
+   *
+   *
+   * @return
    */
   public boolean isIgnoreExitCode();
 
 
   /**
    * Method description
+   * @since 1.12
+   *
+   * @param contentLengthWorkaround
+   */
+  public void setContentLengthWorkaround(boolean contentLengthWorkaround);
+
+  /**
+   * Method description
    *
    *
    * @param environment

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgCGIServlet.java

 import sonia.scm.repository.HgHookManager;
 import sonia.scm.repository.HgRepositoryHandler;
 import sonia.scm.repository.Repository;
+import sonia.scm.repository.RepositoryProvider;
 import sonia.scm.repository.RepositoryRequestListenerUtil;
-import sonia.scm.repository.RepositoryProvider;
 import sonia.scm.util.AssertUtil;
 import sonia.scm.web.cgi.CGIExecutor;
 import sonia.scm.web.cgi.CGIExecutorFactory;
     CGIExecutor executor = cgiExecutorFactory.createExecutor(configuration,
                              getServletContext(), request, response);
 
+    executor.setContentLengthWorkaround(true);
     executor.getEnvironment().set(ENV_REPOSITORY_NAME, name);
     executor.getEnvironment().set(ENV_REPOSITORY_PATH,
                                   directory.getAbsolutePath());

File scm-webapp/src/main/java/sonia/scm/web/cgi/DefaultCGIExecutor.java

     File command = new File(cmd);
     EnvList env = new EnvList(environment);
 
+    // workaround for mercurial 2.1
+    if (isContentLengthWorkaround())
+    {
+      env.set(ENV_CONTENT_LENGTH, Integer.toString(request.getContentLength()));
+    }
+
     if (workDirectory == null)
     {
       workDirectory = command.getParentFile();
 
       if (logger.isTraceEnabled())
       {
-        logger.trace(environment.toString());
+        logger.trace(env.toString());
       }
     }
 
 
     try
     {
-      p = Runtime.getRuntime().exec(execCmd, environment.getEnvArray(),
-                                    workDirectory);
+      p = Runtime.getRuntime().exec(execCmd, env.getEnvArray(), workDirectory);
       execute(p);
     }
     catch (Throwable ex)
     return exceptionHandler;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public boolean isContentLengthWorkaround()
+  {
+    return contentLengthWorkaround;
+  }
+
   //~--- set methods ----------------------------------------------------------
 
   /**
    * Method description
    *
    *
+   *
+   * @param contentLengthWorkaround
+   */
+  @Override
+  public void setContentLengthWorkaround(boolean contentLengthWorkaround)
+  {
+    this.contentLengthWorkaround = contentLengthWorkaround;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param exceptionHandler
    */
   @Override
   private ScmConfiguration configuration;
 
   /** Field description */
+  private boolean contentLengthWorkaround = false;
+
+  /** Field description */
   private ServletContext context;
 
   /** Field description */

File scm-webapp/src/test/java/sonia/scm/it/ChangesetViewerITCase.java

   {
     RepositoryClient rc = createRepositoryClient();
 
-    rc.checkout();
+    rc.init();
     addTestFile(rc, "a", 1, false);
   }