2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Covers your professional reputation by blaming changes to locate reviewers.
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistCoverWorkflow extends ArcanistWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'cover';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-03-13 01:04:20 +01:00
|
|
|
**cover** [--rev __revision__] [__path__ ...]
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-10-12 16:41:20 +02:00
|
|
|
Supports: svn, git, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
Cover your... professional reputation. Show blame for the lines you
|
2012-03-13 01:04:20 +01:00
|
|
|
changed in your working copy (svn) or since some commit (hg, git).
|
|
|
|
This will take a minute because blame takes a minute, especially under
|
|
|
|
SVN.
|
2011-01-10 00:22:25 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-03-13 01:04:20 +01:00
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'rev' => array(
|
|
|
|
'param' => 'revision',
|
|
|
|
'help' => 'Cover changes since a specific revision.',
|
|
|
|
'supports' => array(
|
|
|
|
'git',
|
|
|
|
'hg',
|
|
|
|
),
|
|
|
|
'nosupport' => array(
|
2014-05-23 22:53:05 +02:00
|
|
|
'svn' => 'cover does not currently support --rev in svn.',
|
2012-03-13 01:04:20 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'*' => 'paths',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-03-13 01:04:20 +01:00
|
|
|
$in_paths = $this->getArgument('paths');
|
|
|
|
$in_rev = $this->getArgument('rev');
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-03-13 01:04:20 +01:00
|
|
|
if ($in_rev) {
|
2012-12-17 21:54:08 +01:00
|
|
|
$this->parseBaseCommitArgument(array($in_rev));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 01:04:20 +01:00
|
|
|
$paths = $this->selectPathsForWorkflow(
|
|
|
|
$in_paths,
|
|
|
|
$in_rev,
|
|
|
|
ArcanistRepositoryAPI::FLAG_UNTRACKED |
|
|
|
|
ArcanistRepositoryAPI::FLAG_ADDED);
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
if (!$paths) {
|
|
|
|
throw new ArcanistNoEffectException(
|
|
|
|
"You're covered, you didn't change anything.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$covers = array();
|
|
|
|
foreach ($paths as $path) {
|
2012-03-13 01:04:20 +01:00
|
|
|
if (is_dir($repository_api->getPath($path))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-05 00:22:17 +01:00
|
|
|
$lines = $this->getChangedLines($path, 'cover');
|
|
|
|
if (!$lines) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-13 01:04:20 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$blame = $repository_api->getBlame($path);
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
list($author, $revision) = idx($blame, $line, array(null, null));
|
|
|
|
if (!$author) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!isset($covers[$author])) {
|
|
|
|
$covers[$author] = array();
|
|
|
|
}
|
|
|
|
if (!isset($covers[$author][$path])) {
|
|
|
|
$covers[$author][$path] = array(
|
|
|
|
'lines' => array(),
|
|
|
|
'revisions' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$covers[$author][$path]['lines'][] = $line;
|
|
|
|
$covers[$author][$path]['revisions'][] = $revision;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($covers)) {
|
|
|
|
foreach ($covers as $author => $files) {
|
|
|
|
echo phutil_console_format(
|
|
|
|
"**%s**\n",
|
|
|
|
$author);
|
|
|
|
foreach ($files as $file => $info) {
|
2012-06-12 03:33:19 +02:00
|
|
|
$line_noun = pht('line(s)', count($info['lines']));
|
2011-01-10 00:22:25 +01:00
|
|
|
$lines = $this->readableSequenceFromLineNumbers($info['lines']);
|
|
|
|
echo " {$file}: {$line_noun} {$lines}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "You're covered, your changes didn't touch anyone else's code.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function readableSequenceFromLineNumbers(array $array) {
|
|
|
|
$sequence = array();
|
|
|
|
$last = null;
|
|
|
|
$seq = null;
|
|
|
|
$array = array_unique(array_map('intval', $array));
|
|
|
|
sort($array);
|
|
|
|
foreach ($array as $element) {
|
|
|
|
if ($seq !== null && $element == ($seq + 1)) {
|
|
|
|
$seq++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($seq === null) {
|
|
|
|
$last = $element;
|
|
|
|
$seq = $element;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($seq > $last) {
|
|
|
|
$sequence[] = $last.'-'.$seq;
|
|
|
|
} else {
|
|
|
|
$sequence[] = $last;
|
|
|
|
}
|
|
|
|
|
|
|
|
$last = $element;
|
|
|
|
$seq = $element;
|
|
|
|
}
|
|
|
|
if ($last !== null && $seq > $last) {
|
|
|
|
$sequence[] = $last.'-'.$seq;
|
|
|
|
} else if ($last !== null) {
|
|
|
|
$sequence[] = $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(', ', $sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|