@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 82 lines 1.9 kB view raw
1<?php 2 3final class DifferentialRawDiffRenderer extends Phobject { 4 5 private $changesets; 6 private $format = 'unified'; 7 private $viewer; 8 private $byteLimit; 9 10 public function setFormat($format) { 11 $this->format = $format; 12 return $this; 13 } 14 15 public function getFormat() { 16 return $this->format; 17 } 18 19 /** 20 * @param array<DifferentialChangeset> $changesets 21 */ 22 public function setChangesets(array $changesets) { 23 assert_instances_of($changesets, DifferentialChangeset::class); 24 25 $this->changesets = $changesets; 26 return $this; 27 } 28 29 public function getChangesets() { 30 return $this->changesets; 31 } 32 33 public function setViewer(PhabricatorUser $viewer) { 34 $this->viewer = $viewer; 35 return $this; 36 } 37 38 public function getViewer() { 39 return $this->viewer; 40 } 41 42 public function setByteLimit($byte_limit) { 43 $this->byteLimit = $byte_limit; 44 return $this; 45 } 46 47 public function getByteLimit() { 48 return $this->byteLimit; 49 } 50 51 public function buildPatch() { 52 $diff = new DifferentialDiff(); 53 $diff->attachChangesets($this->getChangesets()); 54 55 $raw_changes = $diff->buildChangesList(); 56 $changes = array(); 57 foreach ($raw_changes as $changedict) { 58 $changes[] = ArcanistDiffChange::newFromDictionary($changedict); 59 } 60 61 $viewer = $this->getViewer(); 62 $loader = id(new PhabricatorFileBundleLoader()) 63 ->setViewer($viewer); 64 65 $bundle = ArcanistBundle::newFromChanges($changes); 66 $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); 67 68 $byte_limit = $this->getByteLimit(); 69 if ($byte_limit) { 70 $bundle->setByteLimit($byte_limit); 71 } 72 73 $format = $this->getFormat(); 74 switch ($format) { 75 case 'git': 76 return $bundle->toGitPatch(); 77 case 'unified': 78 default: 79 return $bundle->toUnifiedDiff(); 80 } 81 } 82}