2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-31 21:07:05 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-10 00:22:25 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Lists open revisions in Differential.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
final class ArcanistListWorkflow extends ArcanistBaseWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**list**
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-02-06 22:08:01 +01:00
|
|
|
Supports: git, svn, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
List your open Differential revisions.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
2012-02-06 22:08:01 +01:00
|
|
|
$revisions = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.query',
|
2011-01-10 00:22:25 +01:00
|
|
|
array(
|
2012-02-06 22:08:01 +01:00
|
|
|
'authors' => array($this->getUserPHID()),
|
|
|
|
'status' => 'status-open',
|
2011-01-10 00:22:25 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
if (!$revisions) {
|
|
|
|
echo "You have no open Differential revisions.\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
$info = array();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$status_len = 0;
|
|
|
|
foreach ($revisions as $key => $revision) {
|
|
|
|
$revision_path = Filesystem::resolvePath($revision['sourcePath']);
|
2011-01-10 00:22:25 +01:00
|
|
|
$current_path = Filesystem::resolvePath($repository_api->getPath());
|
2012-02-06 22:08:01 +01:00
|
|
|
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']));
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$info = isort($info, 'sort');
|
|
|
|
foreach ($info as $key => $spec) {
|
|
|
|
$revision = $revisions[$key];
|
2011-01-10 00:22:25 +01:00
|
|
|
printf(
|
2012-02-06 22:08:01 +01:00
|
|
|
"%s %-".($status_len + 4)."s D%d: %s\n",
|
|
|
|
$spec['here']
|
|
|
|
? phutil_console_format('**%s**', '*')
|
|
|
|
: ' ',
|
|
|
|
$spec['statusColorized'],
|
|
|
|
$revision['id'],
|
|
|
|
$revision['title']);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|