* Generates a colored status name
*/
public function getFormattedStatus() {
- return phutil_console_format(
- '<fg:'.$this->getColorForStatus().'>%s</fg>',
- $this->status);
+ return self::renderColorizedRevisionStatus($this->status);
}
/**
* Assigns a pretty color based on the status
*/
- private function getColorForStatus() {
+ private static function getColorForStatus($status) {
static $status_to_color = array(
'Committed' => 'cyan',
'Needs Review' => 'magenta',
'No Revision' => 'blue',
'Abandoned' => 'default',
);
- return idx($status_to_color, $this->status, 'default');
+ return idx($status_to_color, $status, 'default');
+ }
+
+ public static function renderColorizedRevisionStatus($status) {
+ return phutil_console_format(
+ '<fg:'.self::getColorForStatus($status).'>%s</fg>',
+ $status);
}
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
**list**
- Supports: git, svn
+ Supports: git, svn, hg
List your open Differential revisions.
EOTEXT
);
}
public function run() {
-
- $conduit = $this->getConduit();
- $repository_api = $this->getRepositoryAPI();
-
- $revision_future = $conduit->callMethod(
- 'differential.find',
+ $revisions = $this->getConduit()->callMethodSynchronous(
+ 'differential.query',
array(
- 'guids' => array($this->getUserPHID()),
- 'query' => 'open',
+ 'authors' => array($this->getUserPHID()),
+ 'status' => 'status-open',
));
- $revisions = array();
- foreach ($revision_future->resolve() as $revision_dict) {
- $revisions[] = ArcanistDifferentialRevisionRef::newFromDictionary(
- $revision_dict);
- }
-
if (!$revisions) {
echo "You have no open Differential revisions.\n";
return 0;
}
+ $repository_api = $this->getRepositoryAPI();
+
+ $info = array();
- foreach ($revisions as $revision) {
- $revision_path = Filesystem::resolvePath($revision->getSourcePath());
+ $status_len = 0;
+ foreach ($revisions as $key => $revision) {
+ $revision_path = Filesystem::resolvePath($revision['sourcePath']);
$current_path = Filesystem::resolvePath($repository_api->getPath());
- $from_here = ($revision_path == $current_path);
+ if ($revision_path == $current_path) {
+ $info[$key]['here'] = 1;
+ } else {
+ $info[$key]['here'] = 0;
+ }
+ $info[$key]['sort'] = sprintf(
+ '%d%04d%08d',
+ $info[$key]['here'],
+ $revision['status'],
+ $revision['id']);
+ $info[$key]['statusColorized'] =
+ BranchInfo::renderColorizedRevisionStatus(
+ $revision['statusName']);
+ $status_len = max(
+ $status_len,
+ strlen($info[$key]['statusColorized']));
+ }
+ $info = isort($info, 'sort');
+ foreach ($info as $key => $spec) {
+ $revision = $revisions[$key];
printf(
- " %15s | %s | D%d | %s\n",
- $revision->getStatusName(),
- $from_here ? '*' : ' ',
- $revision->getID(),
- $revision->getName());
+ "%s %-".($status_len + 4)."s D%d: %s\n",
+ $spec['here']
+ ? phutil_console_format('**%s**', '*')
+ : ' ',
+ $spec['statusColorized'],
+ $revision['id'],
+ $revision['title']);
}
return 0;
-phutil_require_module('arcanist', 'differential/revision');
+phutil_require_module('arcanist', 'branch');
phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'filesystem');
+phutil_require_module('phutil', 'utils');
phutil_require_source('ArcanistListWorkflow.php');