Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/binary/PhutilMercurialBinaryAnalyzer.php
<?php | <?php | ||||
final class PhutilMercurialBinaryAnalyzer | final class PhutilMercurialBinaryAnalyzer | ||||
extends PhutilBinaryAnalyzer { | extends PhutilBinaryAnalyzer { | ||||
const BINARY = 'hg'; | const BINARY = 'hg'; | ||||
const CAPABILITY_FILES = 'files'; | const CAPABILITY_FILES = 'files'; | ||||
const CAPABILITY_INJECTION = 'injection'; | const CAPABILITY_INJECTION = 'injection'; | ||||
const CAPABILITY_TEMPLATE_PNODE = 'template_pnode'; | |||||
const CAPABILTIY_ANNOTATE_TEMPLATES = 'annotate_templates'; | |||||
protected function newBinaryVersion() { | protected function newBinaryVersion() { | ||||
$future = id(new ExecFuture('hg --version --quiet')) | $future = id(new ExecFuture('hg --version --quiet')) | ||||
->setEnv( | ->setEnv( | ||||
array( | array( | ||||
'HGPLAIN' => 1, | 'HGPLAIN' => 1, | ||||
)); | )); | ||||
Show All 37 Lines | final class PhutilMercurialBinaryAnalyzer | ||||
} | } | ||||
public function isMercurialVulnerableToInjection() { | public function isMercurialVulnerableToInjection() { | ||||
return self::versionHasCapability( | return self::versionHasCapability( | ||||
$this->requireBinaryVersion(), | $this->requireBinaryVersion(), | ||||
self::CAPABILITY_INJECTION); | self::CAPABILITY_INJECTION); | ||||
} | } | ||||
/** | |||||
* When using `--template` the format for accessing individual parents | |||||
* changed from `{p1node}` to `{p1.node}` in Mercurial 4.9. | |||||
* | |||||
* @return boolean True if the version of Mercurial is new enough to support | |||||
cspeckmimAuthorUnsubmitted Done Inline Actionscspeckmim: >versino
{F9090249} | |||||
* the `{p1.node}` format in templates, or false if otherwise. | |||||
*/ | |||||
public function isMercurialTemplatePnodeAvailable() { | |||||
return self::versionHasCapability( | |||||
$this->requireBinaryVersion(), | |||||
self::CAPABILITY_TEMPLATE_PNODE); | |||||
} | |||||
/** | |||||
* The `hg annotate` command did not accept the `--template` argument until | |||||
* version 4.6. It appears to function in version 4.5 however it's not | |||||
* documented and wasn't announced until the 4.6 release. | |||||
* | |||||
* @return boolean True if the version of Mercurial is new enough to support | |||||
* the `--template` option when using `hg annotate`, or false if otherwise. | |||||
*/ | |||||
public function isMercurialAnnotateTemplatesAvailable() { | |||||
return self::versionHasCapability( | |||||
$this->requireBinaryVersion(), | |||||
self::CAPABILTIY_ANNOTATE_TEMPLATES); | |||||
} | |||||
public static function versionHasCapability( | public static function versionHasCapability( | ||||
$mercurial_version, | $mercurial_version, | ||||
$capability) { | $capability) { | ||||
switch ($capability) { | switch ($capability) { | ||||
case self::CAPABILITY_FILES: | case self::CAPABILITY_FILES: | ||||
return version_compare($mercurial_version, '3.2', '>='); | return version_compare($mercurial_version, '3.2', '>='); | ||||
case self::CAPABILITY_INJECTION: | case self::CAPABILITY_INJECTION: | ||||
return version_compare($mercurial_version, '3.2.4', '<'); | return version_compare($mercurial_version, '3.2.4', '<'); | ||||
case self::CAPABILITY_TEMPLATE_PNODE: | |||||
return version_compare($mercurial_version, '4.9', '>='); | |||||
case self::CAPABILTIY_ANNOTATE_TEMPLATES: | |||||
return version_compare($mercurial_version, '4.6', '>='); | |||||
default: | default: | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unknown Mercurial capability "%s".', | 'Unknown Mercurial capability "%s".', | ||||
$capability)); | $capability)); | ||||
} | } | ||||
} | } | ||||
} | } |