Select the types of activity you want to include in your feed.
@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
···3939 protected $whitespaceMode = null;
40404141 protected $subparser;
4242- protected $oldChangesetID = null;
4342 protected $noHighlight;
44434544 protected $renderCacheKey = null;
···4746 private $handles;
4847 private $user;
49484949+ private $leftSideChangesetID;
5050+ private $leftSideAttachesToNewFile;
5151+5252+ private $rightSideChangesetID;
5353+ private $rightSideAttachesToNewFile;
5454+5055 const CACHE_VERSION = 4;
51565257 const ATTR_GENERATED = 'attr:generated';
···6065 const WHITESPACE_IGNORE_TRAILING = 'ignore-trailing';
6166 const WHITESPACE_IGNORE_ALL = 'ignore-all';
62676868+ /**
6969+ * Configure which Changeset comments added to the right side of the visible
7070+ * diff will be attached to. The ID must be the ID of a real Differential
7171+ * Changeset.
7272+ *
7373+ * The complexity here is that we may show an arbitrary side of an arbitrary
7474+ * changeset as either the left or right part of a diff. This method allows
7575+ * the left and right halves of the displayed diff to be correctly mapped to
7676+ * storage changesets.
7777+ *
7878+ * @param id The Differential Changeset ID that comments added to the right
7979+ * side of the visible diff should be attached to.
8080+ * @param bool If true, attach new comments to the right side of the storage
8181+ * changeset. Note that this may be false, if the left side of
8282+ * some storage changeset is being shown as the right side of
8383+ * a display diff.
8484+ * @return this
8585+ */
6386 public function setRightSideCommentMapping($id, $is_new) {
6464-8787+ $this->rightSideChangesetID = $id;
8888+ $this->rightSideAttachesToNewFile = $is_new;
8989+ return $this;
6590 }
66919292+ /**
9393+ * See setRightSideCommentMapping(), but this sets information for the left
9494+ * side of the display diff.
9595+ */
6796 public function setLeftSideCommentMapping($id, $is_new) {
6868-9797+ $this->leftSideChangesetID = $id;
9898+ $this->leftSideAttachesToNewFile = $is_new;
9999+ return $this;
69100 }
7010171102 /**
···101132102133 public function setWhitespaceMode($whitespace_mode) {
103134 $this->whitespaceMode = $whitespace_mode;
104104- return $this;
105105- }
106106-107107- public function setOldChangesetID($old_changeset_id) {
108108- $this->oldChangesetID = $old_changeset_id;
109135 return $this;
110136 }
111137···236262 }
237263238264 public function parseInlineComment(DifferentialInlineComment $comment) {
239239- $this->comments[] = $comment;
265265+ // Parse only comments which are actually visible.
266266+ if ($this->isCommentVisibleOnRenderedDiff($comment)) {
267267+ $this->comments[] = $comment;
268268+ }
240269 return $this;
241270 }
242271···837866 $end = $comment->getLineNumber() +
838867 $comment->getLineLength() +
839868 self::LINES_CONTEXT;
840840- $new = $this->isCommentInNewFile($comment);
869869+ $new = $this->isCommentOnRightSideWhenDisplayed($comment);
841870 for ($ii = $start; $ii <= $end; $ii++) {
842871 if ($new) {
843872 $new_mask[$ii] = true;
···862891 foreach ($this->comments as $comment) {
863892 $final = $comment->getLineNumber() +
864893 $comment->getLineLength();
865865- if ($this->isCommentInNewFile($comment)) {
894894+ if ($this->isCommentOnRightSideWhenDisplayed($comment)) {
866895 $new_comments[$final][] = $comment;
867896 } else {
868897 $old_comments[$final][] = $comment;
···881910 return $this->renderChangesetTable($this->changeset, $html);
882911 }
883912884884- private function isCommentInNewFile(DifferentialInlineComment $comment) {
885885- if ($this->oldChangesetID) {
886886- return ($comment->getChangesetID() != $this->oldChangesetID);
887887- } else {
888888- return $comment->getIsNewFile();
913913+ /**
914914+ * Determine if an inline comment will appear on the rendered diff,
915915+ * taking into consideration which halves of which changesets will actually
916916+ * be shown.
917917+ *
918918+ * @param DifferentialInlineComment Comment to test for visibility.
919919+ * @return bool True if the comment is visible on the rendered diff.
920920+ */
921921+ private function isCommentVisibleOnRenderedDiff(
922922+ DifferentialInlineComment $comment) {
923923+924924+ $changeset_id = $comment->getChangesetID();
925925+ $is_new = $comment->getIsNewFile();
926926+927927+ if ($changeset_id == $this->rightSideChangesetID &&
928928+ $is_new == $this->rightSideAttachesToNewFile) {
929929+ return true;
889930 }
931931+932932+ if ($changeset_id == $this->leftSideChangesetID &&
933933+ $is_new == $this->leftSideAttachesToNewFile) {
934934+ return true;
935935+ }
936936+937937+ return false;
938938+ }
939939+940940+941941+ /**
942942+ * Determine if a comment will appear on the right side of the display diff.
943943+ * Note that the comment must appear somewhere on the rendered changeset, as
944944+ * per isCommentVisibleOnRenderedDiff().
945945+ *
946946+ * @param DifferentialInlineComment Comment to test for display location.
947947+ * @return bool True for right, false for left.
948948+ */
949949+ private function isCommentOnRightSideWhenDisplayed(
950950+ DifferentialInlineComment $comment) {
951951+952952+ if (!$this->isCommentVisibleOnRenderedDiff($comment)) {
953953+ throw new Exception("Comment is not visible on changeset!");
954954+ }
955955+956956+ $changeset_id = $comment->getChangesetID();
957957+ $is_new = $comment->getIsNewFile();
958958+959959+ if ($changeset_id == $this->rightSideChangesetID &&
960960+ $is_new == $this->rightSideAttachesToNewFile) {
961961+ return true;
962962+ }
963963+964964+ return false;
890965 }
891966892967 protected function renderShield($message, $more) {
···96110369621037 $range_len = min($range_len, $rows - $range_start);
963103810391039+ // Gaps - compute gaps in the visible display diff, where we will render
10401040+ // "Show more context" spacers. This builds an aggregate $mask of all the
10411041+ // lines we must show (because they are near changed lines, near inline
10421042+ // comments, or the request has explicitly asked for them, i.e. resulting
10431043+ // from the user clicking "show more") and then finds all the gaps between
10441044+ // visible lines. If a gap is smaller than the context size, we just
10451045+ // display it. Otherwise, we record it into $gaps and will render a
10461046+ // "show more context" element instead of diff text below.
10471047+9641048 $gaps = array();
9651049 $gap_start = 0;
9661050 $in_gap = false;
···98910739901074 $gaps = array_reverse($gaps);
9911075992992- $changeset = $this->changesetID;
9931076 $reference = $this->getChangeset()->getRenderingReference();
994107710781078+ $left_id = $this->leftSideChangesetID;
10791079+ $right_id = $this->rightSideChangesetID;
10801080+10811081+ // "N" stands for 'new' and means the comment should attach to the new file
10821082+ // when stored, i.e. DifferentialInlineComment->setIsNewFile().
10831083+ // "O" stands for 'old' and means the comment should attach to the old file.
10841084+10851085+ $left_char = $this->leftSideAttachesToNewFile
10861086+ ? 'N'
10871087+ : 'O';
10881088+ $right_char = $this->rightSideAttachesToNewFile
10891089+ ? 'N'
10901090+ : 'O';
10911091+9951092 for ($ii = $range_start; $ii < $range_start + $range_len; $ii++) {
9961093 if (empty($mask[$ii])) {
10941094+ // If we aren't going to show this line, we've just entered a gap.
10951095+ // Pop information about the next gap off the $gaps stack and render
10961096+ // an appropriate "Show more context" element. This branch eventually
10971097+ // increments $ii by the entire size of the gap and then continues
10981098+ // the loop.
9971099 $gap = array_pop($gaps);
9981100 $top = $gap[0];
9991101 $len = $gap[1];
···11001202 $html[] = $context_not_available;
11011203 }
1102120411031103- if ($o_num && $changeset) {
11041104- $o_id = ' id="C'.$changeset.'OL'.$o_num.'"';
12051205+ if ($o_num && $left_id) {
12061206+ $o_id = ' id="C'.$left_id.$left_char.'L'.$o_num.'"';
11051207 } else {
11061208 $o_id = null;
11071209 }
1108121011091109- if ($n_num && $changeset) {
11101110- $n_id = ' id="C'.$changeset.'NL'.$n_num.'"';
12111211+ if ($n_num && $right_id) {
12121212+ $n_id = ' id="C'.$right_id.$right_char.'L'.$n_num.'"';
11111213 } else {
11121214 $n_id = null;
11131215 }
···11561258 ($comment->getAuthorPHID() == $user->getPHID()) &&
11571259 (!$comment->getCommentID());
1158126011591159- $on_right = $this->isCommentInNewFile($comment);
12611261+ $on_right = $this->isCommentOnRightSideWhenDisplayed($comment);
1160126211611263 return id(new DifferentialInlineCommentView())
11621264 ->setInlineComment($comment)