Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F91218
D7791.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D7791.diff
View Options
diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
--- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
+++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
@@ -885,4 +885,43 @@
->setRejectDetails(null);
}
+ public function loadChangesetsForCommit($identifier) {
+ $vcs = $this->getRepository()->getVersionControlSystem();
+ switch ($vcs) {
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
+ // For git and hg, we can use normal commands.
+ $drequest = DiffusionRequest::newFromDictionary(
+ array(
+ 'repository' => $this->getRepository(),
+ 'user' => $this->getViewer(),
+ 'commit' => $identifier,
+ ));
+ $raw_diff = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest)
+ ->setTimeout(5 * 60)
+ ->setLinesOfContext(0)
+ ->loadRawDiff();
+ break;
+ case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
+ // TODO: This diff has 3 lines of context, which produces slightly
+ // incorrect "added file content" and "removed file content" results.
+ // This may also choke on binaries, but "svnlook diff" does not support
+ // the "--diff-cmd" flag.
+
+ // For subversion, we need to use `svnlook`.
+ list($raw_diff) = execx(
+ 'svnlook diff -t %s %s',
+ $this->subversionTransaction,
+ $this->subversionRepository);
+ break;
+ default:
+ throw new Exception(pht("Unknown VCS '%s!'", $vcs));
+ }
+
+ $parser = new ArcanistDiffParser();
+ $changes = $parser->parseDiff($raw_diff);
+ $diff = DifferentialDiff::newFromRawChanges($changes);
+ return $diff->getChangesets();
+ }
+
}
diff --git a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
--- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
+++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
@@ -4,6 +4,7 @@
private $log;
private $hookEngine;
+ private $changesets;
public function setPushLog(PhabricatorRepositoryPushLog $log) {
$this->log = $log;
@@ -35,6 +36,11 @@
public function getFields() {
return array_merge(
array(
+ self::FIELD_BODY,
+ self::FIELD_DIFF_FILE,
+ self::FIELD_DIFF_CONTENT,
+ self::FIELD_DIFF_ADDED_CONTENT,
+ self::FIELD_DIFF_REMOVED_CONTENT,
self::FIELD_REPOSITORY,
self::FIELD_PUSHER,
self::FIELD_PUSHER_PROJECTS,
@@ -78,6 +84,14 @@
public function getHeraldField($field) {
$log = $this->getObject();
switch ($field) {
+ case self::FIELD_DIFF_FILE:
+ return $this->getDiffContent('name');
+ case self::FIELD_DIFF_CONTENT:
+ return $this->getDiffContent('*');
+ case self::FIELD_DIFF_ADDED_CONTENT:
+ return $this->getDiffContent('+');
+ case self::FIELD_DIFF_REMOVED_CONTENT:
+ return $this->getDiffContent('-');
case self::FIELD_REPOSITORY:
return $this->hookEngine->getRepository()->getPHID();
case self::FIELD_PUSHER:
@@ -89,7 +103,6 @@
return parent::getHeraldField($field);
}
-
public function applyHeraldEffects(array $effects) {
assert_instances_of($effects, 'HeraldEffect');
@@ -117,4 +130,53 @@
return $result;
}
+ private function getDiffContent($type) {
+ if ($this->changesets === null) {
+ try {
+ $this->changesets = $this->hookEngine->loadChangesetsForCommit(
+ $this->log->getRefNew());
+ } catch (Exception $ex) {
+ $this->changesets = $ex;
+ }
+ }
+
+ if ($this->changesets instanceof Exception) {
+ $ex_class = get_class($this->changesets);
+ $ex_message = $this->changesets->getmessage();
+ if ($type === 'name') {
+ return array("<{$ex_class}: {$ex_message}>");
+ } else {
+ return array("<{$ex_class}>" => $ex_message);
+ }
+ }
+
+ $result = array();
+ if ($type === 'name') {
+ foreach ($this->changesets as $change) {
+ $result[] = $change->getFilename();
+ }
+ } else {
+ foreach ($this->changesets as $change) {
+ $lines = array();
+ foreach ($change->getHunks() as $hunk) {
+ switch ($type) {
+ case '-':
+ $lines[] = $hunk->makeOldFile();
+ break;
+ case '+':
+ $lines[] = $hunk->makeNewFile();
+ break;
+ case '*':
+ default:
+ $lines[] = $hunk->makeChanges();
+ break;
+ }
+ }
+ $result[$change->getFilename()] = implode('', $lines);
+ }
+ }
+
+ return $result;
+ }
+
}
diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php
--- a/src/applications/herald/storage/HeraldRule.php
+++ b/src/applications/herald/storage/HeraldRule.php
@@ -16,7 +16,7 @@
protected $ruleType;
protected $isDisabled = 0;
- protected $configVersion = 17;
+ protected $configVersion = 18;
// phids for which this rule has been applied
private $ruleApplied = self::ATTACHABLE;
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/je/ss/tzsk2rbu7ogmtvv2
Default Alt Text
D7791.diff (5 KB)
Attached To
Mode
D7791: Support "changed filename" and "file content" fields for commit content Herald rules
Attached
Detach File
Event Timeline
Log In to Comment