1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Provide a "--json" flag to 'arc diff'

Summary:
This should be implemented more elegantly, but this is a mostly-reasonable
attempt at it.

Test Plan:
Ran 'arc diff --only --json' with this diff.

Reviewed By: gc3
Reviewers: gc3
CC: aran, epriestley, gc3
Differential Revision: 509
This commit is contained in:
epriestley 2011-06-23 14:37:43 -07:00
parent 7efe723ff5
commit 051ef2c695

View file

@ -184,6 +184,10 @@ EOTEXT
'lint' => true, 'lint' => true,
), ),
), ),
'json' => array(
'help' =>
'Emit machine-readable JSON. EXPERIMENTAL! Probably does not work!',
),
'*' => 'paths', '*' => 'paths',
); );
} }
@ -195,6 +199,13 @@ EOTEXT
$repository_api->setDiffLinesOfContext(3); $repository_api->setDiffLinesOfContext(3);
} }
$output_json = $this->getArgument('json');
if ($output_json) {
// TODO: We should move this to a higher-level and put an indirection
// layer between echoing stuff and stdout.
ob_start();
}
$conduit = $this->getConduit(); $conduit = $this->getConduit();
$this->requireCleanWorkingCopy(); $this->requireCleanWorkingCopy();
@ -343,10 +354,20 @@ EOTEXT
} }
if ($this->shouldOnlyCreateDiff()) { if ($this->shouldOnlyCreateDiff()) {
if (!$output_json) {
echo phutil_console_format( echo phutil_console_format(
"Created a new Differential diff:\n". "Created a new Differential diff:\n".
" **Diff URI:** __%s__\n\n", " **Diff URI:** __%s__\n\n",
$diff_info['uri']); $diff_info['uri']);
} else {
$human = ob_get_clean();
echo json_encode(array(
'diffURI' => $diff_info['uri'],
'diffID' => $diff_info['diffid'],
'human' => $human,
))."\n";
ob_start();
}
} else { } else {
$message = $commit_message; $message = $commit_message;
@ -498,6 +519,10 @@ EOTEXT
$this->diffID = $diff_info['diffid']; $this->diffID = $diff_info['diffid'];
if ($output_json) {
ob_get_clean();
}
return 0; return 0;
} }
@ -595,13 +620,15 @@ EOTEXT
if ($bases) { if ($bases) {
$rev = reset($bases); $rev = reset($bases);
foreach ($bases as $path => $baserev) {
if ($baserev !== $rev) {
$revlist = array(); $revlist = array();
foreach ($bases as $path => $baserev) { foreach ($bases as $path => $baserev) {
$revlist[] = " Revision {$baserev}, {$path}"; $revlist[] = " Revision {$baserev}, {$path}";
} }
$revlist = implode("\n", $revlist); $revlist = implode("\n", $revlist);
foreach ($bases as $path => $baserev) {
if ($baserev !== $rev) {
throw new ArcanistUsageException( throw new ArcanistUsageException(
"Base revisions of changed paths are mismatched. Update all ". "Base revisions of changed paths are mismatched. Update all ".
"paths to the same base revision before creating a diff: ". "paths to the same base revision before creating a diff: ".