]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Provide repository API method for getting changed files
authorvrana <jakubv@fb.com>
Fri, 9 Nov 2012 07:26:27 +0000 (23:26 -0800)
committervrana <jakubv@fb.com>
Tue, 13 Nov 2012 02:17:10 +0000 (18:17 -0800)
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

src/repository/api/ArcanistGitAPI.php
src/repository/api/ArcanistMercurialAPI.php
src/repository/api/ArcanistRepositoryAPI.php
src/repository/api/ArcanistSubversionAPI.php

index 9aedfbf1f4e8f60502bb79f87c3e02993c6a5152..f1849fcd8758f742484a4fe34be84e965cf47130 100644 (file)
@@ -533,6 +533,21 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
       ->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) {
     // TODO: 'git blame' supports --porcelain and we should probably use it.
     list($stdout) = $this->execxLocal(
index 749f753ff5de65812b56b716e14282ebb1aedbbe..62573fe944aab3f9e642718a8c26541ec03b6e16 100644 (file)
@@ -251,6 +251,21 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     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) {
     list($stdout) = $this->execxLocal(
       'annotate -u -v -c --rev %s -- %s',
index 2c0469db9e6d74edda1eff16c5152292c69bbff1..df4e899c885fba8966eeb7a1d26004c9d82651c2 100644 (file)
@@ -188,6 +188,10 @@ abstract class ArcanistRepositoryAPI {
     throw new ArcanistCapabilityNotSupportedException($this);
   }
 
+  public function getChangedFiles($since_commit) {
+    throw new ArcanistCapabilityNotSupportedException($this);
+  }
+
   public function amendCommit($message) {
     throw new ArcanistCapabilityNotSupportedException($this);
   }
index a57c891a272e237eac37032cbd2d45289d465ceb..30d857531601fe1855f280ae0c960dba5a998c63 100644 (file)
@@ -473,6 +473,22 @@ EODIFF;
       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) {
     // NOTE: SVN uses '/' also on Windows.
     if ($path == '' || substr($path, -1) == '/') {