Differential D9375 Diff 24738 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
| Show First 20 Lines • Show All 1,173 Lines • ▼ Show 20 Lines | if ($update_xaction) { | ||||
| $config_key_inline = 'metamta.differential.inline-patches'; | $config_key_inline = 'metamta.differential.inline-patches'; | ||||
| $config_inline = PhabricatorEnv::getEnvConfig($config_key_inline); | $config_inline = PhabricatorEnv::getEnvConfig($config_key_inline); | ||||
| $config_key_attach = 'metamta.differential.attach-patches'; | $config_key_attach = 'metamta.differential.attach-patches'; | ||||
| $config_attach = PhabricatorEnv::getEnvConfig($config_key_attach); | $config_attach = PhabricatorEnv::getEnvConfig($config_key_attach); | ||||
| if ($config_inline || $config_attach) { | if ($config_inline || $config_attach) { | ||||
| $patch = $this->renderPatchForMail($diff); | $patch_section = $this->renderPatchForMail($diff); | ||||
| $lines = count(phutil_split_lines($patch)); | $lines = count(phutil_split_lines($patch_section->getPlaintext())); | ||||
epriestley: Prefer `$patch_section`. | |||||
| if ($config_inline && ($lines <= $config_inline)) { | if ($config_inline && ($lines <= $config_inline)) { | ||||
| $body->addTextSection( | $body->addTextSection( | ||||
| pht('CHANGE DETAILS'), | pht('CHANGE DETAILS'), | ||||
| $patch); | $patch_section); | ||||
| } | } | ||||
| if ($config_attach) { | if ($config_attach) { | ||||
| $name = pht('D%s.%s.patch', $object->getID(), $diff->getID()); | $name = pht('D%s.%s.patch', $object->getID(), $diff->getID()); | ||||
| $mime_type = 'text/x-patch; charset=utf-8'; | $mime_type = 'text/x-patch; charset=utf-8'; | ||||
| $body->addAttachment( | $body->addAttachment( | ||||
| new PhabricatorMetaMTAAttachment($patch, $name, $mime_type)); | new PhabricatorMetaMTAAttachment( | ||||
| $patch_section->getPlaintext(), $name, $mime_type)); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return $body; | return $body; | ||||
| } | } | ||||
| public function getMailTagsMap() { | public function getMailTagsMap() { | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | private function renderInlineCommentsForMail( | ||||
| $inline_groups = DifferentialTransactionComment::sortAndGroupInlines( | $inline_groups = DifferentialTransactionComment::sortAndGroupInlines( | ||||
| $inlines, | $inlines, | ||||
| $changesets); | $changesets); | ||||
| if ($show_context) { | if ($show_context) { | ||||
| $hunk_parser = new DifferentialHunkParser(); | $hunk_parser = new DifferentialHunkParser(); | ||||
| } | } | ||||
| $result = array(); | $section = new PhabricatorMetaMTAMailSection(); | ||||
| foreach ($inline_groups as $changeset_id => $group) { | foreach ($inline_groups as $changeset_id => $group) { | ||||
| $changeset = idx($changesets, $changeset_id); | $changeset = idx($changesets, $changeset_id); | ||||
| if (!$changeset) { | if (!$changeset) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| foreach ($group as $inline) { | foreach ($group as $inline) { | ||||
| $comment = $inline->getComment(); | $comment = $inline->getComment(); | ||||
| $file = $changeset->getFilename(); | $file = $changeset->getFilename(); | ||||
| $start = $comment->getLineNumber(); | $start = $comment->getLineNumber(); | ||||
| $len = $comment->getLineLength(); | $len = $comment->getLineLength(); | ||||
| if ($len) { | if ($len) { | ||||
| $range = $start.'-'.($start + $len); | $range = $start.'-'.($start + $len); | ||||
| } else { | } else { | ||||
| $range = $start; | $range = $start; | ||||
| } | } | ||||
| $inline_content = $comment->getContent(); | $inline_content = $comment->getContent(); | ||||
| if (!$show_context) { | if (!$show_context) { | ||||
| $result[] = "{$file}:{$range} {$inline_content}"; | $section->addFragment("{$file}:{$range} {$inline_content}"); | ||||
| } else { | } else { | ||||
| $result[] = '================'; | $patch = $hunk_parser->makeContextDiff( | ||||
| $result[] = 'Comment at: '.$file.':'.$range; | |||||
| $result[] = $hunk_parser->makeContextDiff( | |||||
| $changeset->getHunks(), | $changeset->getHunks(), | ||||
| $comment->getIsNewFile(), | $comment->getIsNewFile(), | ||||
| $comment->getLineNumber(), | $comment->getLineNumber(), | ||||
| $comment->getLineLength(), | $comment->getLineLength(), | ||||
| 1); | 1); | ||||
| $result[] = '----------------'; | |||||
| $result[] = $inline_content; | $section->addFragment('================') | ||||
| $result[] = null; | ->addFragment('Comment at: '.$file.':'.$range) | ||||
| ->addPlaintextFragment($patch) | |||||
| ->addHTMLFragment($this->renderPatchHTMLForMail($patch)) | |||||
| ->addFragment('----------------') | |||||
| ->addFragment($inline_content) | |||||
| ->addFragment(null); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return implode("\n", $result); | return $section; | ||||
| } | } | ||||
| private function loadDiff($phid, $need_changesets = false) { | private function loadDiff($phid, $need_changesets = false) { | ||||
| $query = id(new DifferentialDiffQuery()) | $query = id(new DifferentialDiffQuery()) | ||||
| ->withPHIDs(array($phid)) | ->withPHIDs(array($phid)) | ||||
| ->setViewer($this->getActor()); | ->setViewer($this->getActor()); | ||||
| if ($need_changesets) { | if ($need_changesets) { | ||||
| ▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | private function renderAffectedFilesForMail(DifferentialDiff $diff) { | ||||
| if ($count > $max) { | if ($count > $max) { | ||||
| $filenames = array_slice($filenames, 0, $max); | $filenames = array_slice($filenames, 0, $max); | ||||
| $filenames[] = pht('(%d more files...)', ($count - $max)); | $filenames[] = pht('(%d more files...)', ($count - $max)); | ||||
| } | } | ||||
| return implode("\n", $filenames); | return implode("\n", $filenames); | ||||
| } | } | ||||
| private function renderPatchHTMLForMail($patch) { | |||||
| return phutil_tag('pre', | |||||
| array('style' => 'font-family: monospace;'), $patch); | |||||
| } | |||||
| private function renderPatchForMail(DifferentialDiff $diff) { | private function renderPatchForMail(DifferentialDiff $diff) { | ||||
| $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); | $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); | ||||
| return id(new DifferentialRawDiffRenderer()) | $patch = id(new DifferentialRawDiffRenderer()) | ||||
| ->setViewer($this->getActor()) | ->setViewer($this->getActor()) | ||||
| ->setFormat($format) | ->setFormat($format) | ||||
| ->setChangesets($diff->getChangesets()) | ->setChangesets($diff->getChangesets()) | ||||
| ->buildPatch(); | ->buildPatch(); | ||||
| $section = new PhabricatorMetaMTAMailSection(); | |||||
| $section->addHTMLFragment($this->renderPatchHTMLForMail($patch)); | |||||
| $section->addPlaintextFragment($patch); | |||||
| return $section; | |||||
| } | } | ||||
| } | } | ||||
Prefer $patch_section.