Changeset View
Changeset View
Standalone View
Standalone View
src/parser/ArcanistBaseCommitParser.php
| Show All 16 Lines | private function tokenizeBaseCommitSpecification($raw_spec) { | ||||
| } | } | ||||
| $spec = preg_split('/\s*,\s*/', $raw_spec); | $spec = preg_split('/\s*,\s*/', $raw_spec); | ||||
| $spec = array_filter($spec); | $spec = array_filter($spec); | ||||
| foreach ($spec as $rule) { | foreach ($spec as $rule) { | ||||
| if (strpos($rule, ':') === false) { | if (strpos($rule, ':') === false) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Rule '{$rule}' is invalid, it must have a type and name like ". | pht( | ||||
| "'arc:upstream'."); | "Rule '%s' is invalid, it must have a type and name like '%s'.", | ||||
| $rule, | |||||
| 'arc:upstream')); | |||||
| } | } | ||||
| } | } | ||||
| return $spec; | return $spec; | ||||
| } | } | ||||
| private function log($message) { | private function log($message) { | ||||
| if ($this->verbose) { | if ($this->verbose) { | ||||
| Show All 21 Lines | $this->try = array( | ||||
| 'user', | 'user', | ||||
| 'system', | 'system', | ||||
| ); | ); | ||||
| while ($this->try) { | while ($this->try) { | ||||
| $source = head($this->try); | $source = head($this->try); | ||||
| if (!idx($specs, $source)) { | if (!idx($specs, $source)) { | ||||
| $this->log("No rules left from source '{$source}'."); | $this->log(pht("No rules left from source '%s'.", $source)); | ||||
| array_shift($this->try); | array_shift($this->try); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $this->log("Trying rules from source '{$source}'."); | $this->log(pht("Trying rules from source '%s'.", $source)); | ||||
| $rules = &$specs[$source]; | $rules = &$specs[$source]; | ||||
| while ($rule = array_shift($rules)) { | while ($rule = array_shift($rules)) { | ||||
| $this->log("Trying rule '{$rule}'."); | $this->log(pht("Trying rule '%s'.", $rule)); | ||||
| $commit = $this->resolveRule($rule, $source); | $commit = $this->resolveRule($rule, $source); | ||||
| if ($commit === false) { | if ($commit === false) { | ||||
| // If a rule returns false, it means to go to the next ruleset. | // If a rule returns false, it means to go to the next ruleset. | ||||
| break; | break; | ||||
| } else if ($commit !== null) { | } else if ($commit !== null) { | ||||
| $this->log("Resolved commit '{$commit}' from rule '{$rule}'."); | $this->log(pht( | ||||
| "Resolved commit '%s' from rule '%s'.", | |||||
| $commit, | |||||
| $rule)); | |||||
| return $commit; | return $commit; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| Show All 10 Lines | switch ($type) { | ||||
| return $name; | return $name; | ||||
| case 'git': | case 'git': | ||||
| case 'hg': | case 'hg': | ||||
| return $this->api->resolveBaseCommitRule($rule, $source); | return $this->api->resolveBaseCommitRule($rule, $source); | ||||
| case 'arc': | case 'arc': | ||||
| return $this->resolveArcRule($rule, $name, $source); | return $this->resolveArcRule($rule, $name, $source); | ||||
| default: | default: | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Base commit rule '{$rule}' (from source '{$source}') ". | pht( | ||||
| "is not a recognized rule."); | "Base commit rule '%s' (from source '%s') ". | ||||
| "is not a recognized rule.", | |||||
| $rule, | |||||
| $source)); | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Handle resolving "arc:*" rules. | * Handle resolving "arc:*" rules. | ||||
| */ | */ | ||||
| private function resolveArcRule($rule, $name, $source) { | private function resolveArcRule($rule, $name, $source) { | ||||
| $name = $this->updateLegacyRuleName($name); | $name = $this->updateLegacyRuleName($name); | ||||
| switch ($name) { | switch ($name) { | ||||
| case 'verbose': | case 'verbose': | ||||
| $this->verbose = true; | $this->verbose = true; | ||||
| $this->log('Enabled verbose mode.'); | $this->log(pht('Enabled verbose mode.')); | ||||
| break; | break; | ||||
| case 'prompt': | case 'prompt': | ||||
| $reason = 'it is what you typed when prompted.'; | $reason = pht('it is what you typed when prompted.'); | ||||
| $this->api->setBaseCommitExplanation($reason); | $this->api->setBaseCommitExplanation($reason); | ||||
| return phutil_console_prompt('Against which commit?'); | return phutil_console_prompt(pht('Against which commit?')); | ||||
| case 'local': | case 'local': | ||||
| case 'user': | case 'user': | ||||
| case 'project': | case 'project': | ||||
| case 'runtime': | case 'runtime': | ||||
| case 'system': | case 'system': | ||||
| // Push the other source on top of the list. | // Push the other source on top of the list. | ||||
| array_unshift($this->try, $name); | array_unshift($this->try, $name); | ||||
| $this->log("Switching to source '{$name}'."); | $this->log(pht("Switching to source '%s'.", $name)); | ||||
| return false; | return false; | ||||
| case 'yield': | case 'yield': | ||||
| // Cycle this source to the end of the list. | // Cycle this source to the end of the list. | ||||
| $this->try[] = array_shift($this->try); | $this->try[] = array_shift($this->try); | ||||
| $this->log("Yielding processing of rules from '{$source}'."); | $this->log(pht("Yielding processing of rules from '%s'.", $source)); | ||||
| return false; | return false; | ||||
| case 'halt': | case 'halt': | ||||
| // Dump the whole stack. | // Dump the whole stack. | ||||
| $this->try = array(); | $this->try = array(); | ||||
| $this->log('Halting all rule processing.'); | $this->log(pht('Halting all rule processing.')); | ||||
| return false; | return false; | ||||
| case 'skip': | case 'skip': | ||||
| return null; | return null; | ||||
| case 'empty': | case 'empty': | ||||
| case 'upstream': | case 'upstream': | ||||
| case 'outgoing': | case 'outgoing': | ||||
| case 'bookmark': | case 'bookmark': | ||||
| case 'amended': | case 'amended': | ||||
| Show All 11 Lines | switch ($name) { | ||||
| } else { | } else { | ||||
| return null; | return null; | ||||
| } | } | ||||
| } else if (preg_match('/^nodiff\((.*)\)$/', $name, $matches)) { | } else if (preg_match('/^nodiff\((.*)\)$/', $name, $matches)) { | ||||
| return $this->api->resolveBaseCommitRule($rule, $source); | return $this->api->resolveBaseCommitRule($rule, $source); | ||||
| } | } | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Base commit rule '{$rule}' (from source '{$source}') ". | pht( | ||||
| "is not a recognized rule."); | "Base commit rule '%s' (from source '%s') ". | ||||
| "is not a recognized rule.", | |||||
| $rule, | |||||
| $source)); | |||||
| } | } | ||||
| } | } | ||||
| private function updateLegacyRuleName($name) { | private function updateLegacyRuleName($name) { | ||||
| $updated = array( | $updated = array( | ||||
| 'global' => 'user', | 'global' => 'user', | ||||
| 'args' => 'runtime', | 'args' => 'runtime', | ||||
| ); | ); | ||||
| $new_name = idx($updated, $name); | $new_name = idx($updated, $name); | ||||
| if ($new_name) { | if ($new_name) { | ||||
| $this->log("translating legacy name '$name' to '$new_name'"); | $this->log(pht("Translating legacy name '%s' to '%s'", $name, $new_name)); | ||||
| return $new_name; | return $new_name; | ||||
| } | } | ||||
| return $name; | return $name; | ||||
| } | } | ||||
| } | } | ||||