Differential D21679 Diff 51621 src/applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | list($stdout) = $repository->execxLocalCommand( | ||||
gitsprintf('%s', $this->identifier)); | gitsprintf('%s', $this->identifier)); | ||||
return preg_split('/\s+/', trim($stdout)); | return preg_split('/\s+/', trim($stdout)); | ||||
} | } | ||||
private function loadMercurialParents() { | private function loadMercurialParents() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$hg_analyzer = PhutilBinaryAnalyzer::getForBinary('hg'); | |||||
if ($hg_analyzer->isMercurialTemplatePnodeAvailable()) { | |||||
$hg_log_template = '{p1.node} {p2.node}'; | |||||
} else { | |||||
$hg_log_template = '{p1node} {p2node}'; | |||||
} | |||||
list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
'log --debug --limit 1 --template={parents} --rev %s', | 'log --limit 1 --template %s --rev %s', | ||||
$hg_log_template, | |||||
$this->identifier); | $this->identifier); | ||||
$stdout = DiffusionMercurialCommandEngine::filterMercurialDebugOutput( | |||||
$stdout); | |||||
$hashes = preg_split('/\s+/', trim($stdout)); | $hashes = preg_split('/\s+/', trim($stdout)); | ||||
foreach ($hashes as $key => $value) { | foreach ($hashes as $key => $value) { | ||||
// Mercurial parents look like "23:ad9f769d6f786fad9f76d9a" -- we want | // We get 40-character hashes but also get the "000000..." hash for | ||||
// to strip out the local rev part. | // missing parents; ignore it. | ||||
list($local, $global) = explode(':', $value); | if (preg_match('/^0+\z/', $value)) { | ||||
epriestley: This has no effect, since `$hashes[$key]` necessarily already has the value `$value` as we… | |||||
Done Inline Actionscspeckmim: {F9094166}
Got a little too focused on the refactor and not the context | |||||
$hashes[$key] = $global; | |||||
// With --debug we get 40-character hashes but also get the "000000..." | |||||
// hash for missing parents; ignore it. | |||||
if (preg_match('/^0+$/', $global)) { | |||||
unset($hashes[$key]); | unset($hashes[$key]); | ||||
} | } | ||||
Not Done Inline ActionsThis is extremely minor, but prefer \z (end of input) over $ (end of input, or newline and then end of input) when you do not expect to match a newline. This almost never matters, but using \z is more precise, and using $ can occasionally cause input validation issues. I think it once caused a minor-but-material bug somewhere in auth where something like "user@domain.com\n" was accepted as a properly formed email address. (I can't dig up the original issue offhand, it was a long time ago.) epriestley: This is extremely minor, but prefer `\z` (end of input) over `$` (end of input, or newline and… | |||||
Done Inline ActionsAh interesting, I'll update these cspeckmim: Ah interesting, I'll update these | |||||
} | } | ||||
return $hashes; | return $hashes; | ||||
} | } | ||||
private function loadSubversionParents() { | private function loadSubversionParents() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$identifier = $this->identifier; | $identifier = $this->identifier; | ||||
Show All 23 Lines |
This has no effect, since $hashes[$key] necessarily already has the value $value as we enter the loop.