Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionServeController.php
Show First 20 Lines • Show All 530 Lines • ▼ Show 20 Lines | if ($cmd == 'getbundle' || | ||||
$body = gzcompress($stdout); | $body = gzcompress($stdout); | ||||
} else if ($cmd == 'unbundle') { | } else if ($cmd == 'unbundle') { | ||||
// This includes diagnostic information and anything echoed by commit | // This includes diagnostic information and anything echoed by commit | ||||
// hooks. We ignore `stdout` since it just has protocol garbage, and | // hooks. We ignore `stdout` since it just has protocol garbage, and | ||||
// substitute `stderr`. | // substitute `stderr`. | ||||
$body = strlen($stderr)."\n".$stderr; | $body = strlen($stderr)."\n".$stderr; | ||||
} else { | } else { | ||||
list($length, $body) = explode("\n", $stdout, 2); | list($length, $body) = explode("\n", $stdout, 2); | ||||
if ($cmd == 'capabilities') { | |||||
$body = $this->removeMercurialBundle2Capability($body); | |||||
} | |||||
} | } | ||||
return id(new DiffusionMercurialResponse())->setContent($body); | return id(new DiffusionMercurialResponse())->setContent($body); | ||||
} | } | ||||
/** If the server version is running 3.4+ it will respond | |||||
* with 'bundle2' capability in the format of "bundle2=(url-encoding)". | |||||
* Until we maange to properly package up bundles to send back we | |||||
* disallow the client from knowing we speak bundle2 by removing it | |||||
* from the capabilities listing. | |||||
* | |||||
* The format of the capabilties string is: "a space separated list | |||||
* of strings representing what commands the server supports" | |||||
* @link https://www.mercurial-scm.org/wiki/CommandServer#Protocol | |||||
* | |||||
* @param string $capabilities - The string of capabilities to | |||||
* strip the bundle2 capability from. This is expected to be | |||||
* the space-separated list of strings resulting from the | |||||
* querying the 'capabilties' command. | |||||
* | |||||
* @return string The resulting space-separated list of capabilities | |||||
* which no longer contains the 'bundle2' capability. This is meant | |||||
* to replace the original $body to send back to client. | |||||
*/ | |||||
public function removeMercurialBundle2Capability($capabilities) { | |||||
$bundle2_arg = 'bundle2='; | |||||
$bundle2_arg_len = strlen($bundle2_arg); | |||||
$capabilities_arr = explode(' ', $capabilities); | |||||
$arrindex = -1; | |||||
$found_bundle2 = false; | |||||
foreach ($capabilities_arr as $capability) { | |||||
$arrindex++; | |||||
if (substr($capability, 0, $bundle2_arg_len) == $bundle2_arg) { | |||||
$found_bundle2 = true; | |||||
break; | |||||
} | |||||
} | |||||
if ($found_bundle2 && $arrindex > -1) { | |||||
unset($capabilities_arr[$arrindex]); | |||||
} | |||||
$capabilities_without_bundle2 = implode(' ', $capabilities_arr); | |||||
return $capabilities_without_bundle2; | |||||
} | |||||
private function getMercurialArguments() { | private function getMercurialArguments() { | ||||
// Mercurial sends arguments in HTTP headers. "Why?", you might wonder, | // Mercurial sends arguments in HTTP headers. "Why?", you might wonder, | ||||
// "Why would you do this?". | // "Why would you do this?". | ||||
$args_raw = array(); | $args_raw = array(); | ||||
for ($ii = 1;; $ii++) { | for ($ii = 1;; $ii++) { | ||||
$header = 'HTTP_X_HGARG_'.$ii; | $header = 'HTTP_X_HGARG_'.$ii; | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |