diff --git a/conf/default.conf.php b/conf/default.conf.php index 892dc6987d..af4f7519d1 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -231,10 +231,20 @@ return array( 'metamta.differential.subject-prefix' => '[Differential]', // Set this to true if you want patches to be attached to mail from - // Differential. This won't work if you are using SendGrid as your mail + // Differential. This won't work if you are using SendGrid as your mail // adapter. 'metamta.differential.attach-patches' => false, + // To include patches in email bodies, set this to a positive integer. Patches + // will be inlined if they are at most that many lines. For instance, a value + // of 100 means "inline patches if they are no longer than 100 lines". By + // default, patches are not inlined. + 'metamta.differential.inline-patches' => 0, + + // If you enable either of the options above, you can choose what format + // patches are sent in. Valid options are 'unified' (like diff -u) or 'git'. + 'metamta.differential.patch-format' => 'unified', + // Prefix prepended to mail sent by Diffusion. 'metamta.diffusion.subject-prefix' => '[Diffusion]', diff --git a/src/applications/differential/mail/reviewrequest/DifferentialReviewRequestMail.php b/src/applications/differential/mail/reviewrequest/DifferentialReviewRequestMail.php index 4e6a124f36..b2a7f5ae04 100644 --- a/src/applications/differential/mail/reviewrequest/DifferentialReviewRequestMail.php +++ b/src/applications/differential/mail/reviewrequest/DifferentialReviewRequestMail.php @@ -77,41 +77,64 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail { $body[] = null; } + $inline_key = 'metamta.differential.inline-patches'; + $inline_max_length = PhabricatorEnv::getEnvConfig($inline_key); + if ($inline_max_length) { + $patch = $this->buildPatch(); + if (count(explode("\n", $patch)) <= $inline_max_length) { + $body[] = 'CHANGE DETAILS'; + $body[] = $patch; + } + } + return implode("\n", $body); } protected function buildAttachments() { $attachments = array(); + if (PhabricatorEnv::getEnvConfig('metamta.differential.attach-patches')) { - $revision = $this->getRevision(); - $revision_id = $revision->getID(); - - $diffs = $revision->loadDiffs(); - $diff_number = count($diffs); - $diff = array_pop($diffs); - - $filename = "D{$revision_id}.{$diff_number}.patch"; - - $diff->attachChangesets($diff->loadChangesets()); - // TODO: We could batch this to improve performance. - foreach ($diff->getChangesets() as $changeset) { - $changeset->attachHunks($changeset->loadHunks()); - } - $diff_dict = $diff->getDiffDict(); - - $changes = array(); - foreach ($diff_dict['changes'] as $changedict) { - $changes[] = ArcanistDiffChange::newFromDictionary($changedict); - } - $bundle = ArcanistBundle::newFromChanges($changes); - $unified_diff = $bundle->toUnifiedDiff(); - $attachments[] = new PhabricatorMetaMTAAttachment( - $unified_diff, - $filename, + $this->buildPatch(), + "D{$revision_id}.{$diff_number}.patch", 'text/x-patch; charset=utf-8' ); } + return $attachments; } + + private function buildPatch() { + $revision = $this->getRevision(); + $revision_id = $revision->getID(); + + $diffs = $revision->loadDiffs(); + $diff_number = count($diffs); + $diff = array_pop($diffs); + + $diff->attachChangesets($diff->loadChangesets()); + // TODO: We could batch this to improve performance. + foreach ($diff->getChangesets() as $changeset) { + $changeset->attachHunks($changeset->loadHunks()); + } + $diff_dict = $diff->getDiffDict(); + + $changes = array(); + foreach ($diff_dict['changes'] as $changedict) { + $changes[] = ArcanistDiffChange::newFromDictionary($changedict); + } + $bundle = ArcanistBundle::newFromChanges($changes); + + $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); + switch ($format) { + case 'git': + return $bundle->toGitPatch(); + break; + case 'unified': + default: + return $bundle->toUnifiedDiff(); + break; + } + } + }