1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-24 06:20:55 +01:00

Provide repository API method for getting changed files

Test Plan:
  print_r($api->getChangedFiles('HEAD~36')); // Under Git.

Verified that deleted files are false.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2038

Differential Revision: https://secure.phabricator.com/D3941
This commit is contained in:
vrana 2012-11-08 23:26:27 -08:00
parent d3f351caae
commit 58e3e928d1
4 changed files with 50 additions and 0 deletions

View file

@ -533,6 +533,21 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
->setDelimiter("\0"); ->setDelimiter("\0");
} }
public function getChangedFiles($since_commit) {
list($stdout) = $this->execxLocal(
'diff --name-status -z %s',
$since_commit);
$return = array();
foreach (array_chunk(explode("\0", $stdout), 2) as $val) {
if (count($val) != 2) {
break;
}
list($status, $path) = $val;
$return[$path] = ($status == 'D' ? false : true);
}
return $return;
}
public function getBlame($path) { public function getBlame($path) {
// TODO: 'git blame' supports --porcelain and we should probably use it. // TODO: 'git blame' supports --porcelain and we should probably use it.
list($stdout) = $this->execxLocal( list($stdout) = $this->execxLocal(

View file

@ -251,6 +251,21 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
return new LinesOfALargeExecFuture($future); return new LinesOfALargeExecFuture($future);
} }
public function getChangedFiles($since_commit) {
list($stdout) = $this->execxLocal(
'status --rev %s -0',
$since_commit);
$return = array();
foreach (explode("\0", $stdout) as $val) {
$match = null;
if (preg_match('/^(.) (.+)/', $val, $match)) {
list(, $status, $path) = $match;
$return[$path] = ($status == 'R' ? false : true);
}
}
return $return;
}
public function getBlame($path) { public function getBlame($path) {
list($stdout) = $this->execxLocal( list($stdout) = $this->execxLocal(
'annotate -u -v -c --rev %s -- %s', 'annotate -u -v -c --rev %s -- %s',

View file

@ -188,6 +188,10 @@ abstract class ArcanistRepositoryAPI {
throw new ArcanistCapabilityNotSupportedException($this); throw new ArcanistCapabilityNotSupportedException($this);
} }
public function getChangedFiles($since_commit) {
throw new ArcanistCapabilityNotSupportedException($this);
}
public function amendCommit($message) { public function amendCommit($message) {
throw new ArcanistCapabilityNotSupportedException($this); throw new ArcanistCapabilityNotSupportedException($this);
} }

View file

@ -473,6 +473,22 @@ EODIFF;
array($this, 'filterFiles')); array($this, 'filterFiles'));
} }
public function getChangedFiles($since_commit) {
// TODO: Handle paths with newlines.
list($stdout) = $this->execxLocal(
'diff --revision %s:HEAD',
$since_commit);
$return = array();
foreach (explode("\n", $stdout) as $val) {
$match = null;
if (preg_match('/^(.)\S*\s+(.+)/', $val, $match)) {
list(, $status, $path) = $match;
$return[$path] = ($status == 'D' ? false : true);
}
}
return $return;
}
public function filterFiles($path) { public function filterFiles($path) {
// NOTE: SVN uses '/' also on Windows. // NOTE: SVN uses '/' also on Windows.
if ($path == '' || substr($path, -1) == '/') { if ($path == '' || substr($path, -1) == '/') {