Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/parser/DifferentialChangesetParser.php
| Show First 20 Lines • Show All 1,038 Lines • ▼ Show 20 Lines | if ($this->comments) { | ||||
| } | } | ||||
| } | } | ||||
| foreach ($this->new as $ii => $new) { | foreach ($this->new as $ii => $new) { | ||||
| if (isset($new['line']) && isset($new_mask[$new['line']])) { | if (isset($new['line']) && isset($new_mask[$new['line']])) { | ||||
| $feedback_mask[$ii] = true; | $feedback_mask[$ii] = true; | ||||
| } | } | ||||
| } | } | ||||
epriestley: You could technically revert all these thread/reorder changes if you want. I think they're fine… | |||||
| $this->comments = $this->reorderAndThreadComments($this->comments); | $this->comments = id(new PHUIDiffInlineThreader()) | ||||
| ->reorderAndThreadCommments($this->comments); | |||||
| foreach ($this->comments as $comment) { | foreach ($this->comments as $comment) { | ||||
| $final = $comment->getLineNumber() + | $final = $comment->getLineNumber() + | ||||
| $comment->getLineLength(); | $comment->getLineLength(); | ||||
| $final = max(1, $final); | $final = max(1, $final); | ||||
| if ($this->isCommentOnRightSideWhenDisplayed($comment)) { | if ($this->isCommentOnRightSideWhenDisplayed($comment)) { | ||||
| $new_comments[$final][] = $comment; | $new_comments[$final][] = $comment; | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | for ($ii = 1; $ii <= $max_new_line; $ii++) { | ||||
| } else { | } else { | ||||
| $cursor = $new_back[$ii]; | $cursor = $new_back[$ii]; | ||||
| } | } | ||||
| } | } | ||||
| return array($old_back, $new_back); | return array($old_back, $new_back); | ||||
| } | } | ||||
| private function reorderAndThreadComments(array $comments) { | |||||
| $comments = msort($comments, 'getID'); | |||||
| // Build an empty map of all the comments we actually have. If a comment | |||||
| // is a reply but the parent has gone missing, we don't want it to vanish | |||||
| // completely. | |||||
| $comment_phids = mpull($comments, 'getPHID'); | |||||
| $replies = array_fill_keys($comment_phids, array()); | |||||
| // Now, remove all comments which are replies, leaving only the top-level | |||||
| // comments. | |||||
| foreach ($comments as $key => $comment) { | |||||
| $reply_phid = $comment->getReplyToCommentPHID(); | |||||
| if (isset($replies[$reply_phid])) { | |||||
| $replies[$reply_phid][] = $comment; | |||||
| unset($comments[$key]); | |||||
| } | |||||
| } | |||||
| // For each top level comment, add the comment, then add any replies | |||||
| // to it. Do this recursively so threads are shown in threaded order. | |||||
| $results = array(); | |||||
| foreach ($comments as $comment) { | |||||
| $results[] = $comment; | |||||
| $phid = $comment->getPHID(); | |||||
| $descendants = $this->getInlineReplies($replies, $phid, 1); | |||||
| foreach ($descendants as $descendant) { | |||||
| $results[] = $descendant; | |||||
| } | |||||
| } | |||||
| // If we have anything left, they were cyclic references. Just dump | |||||
| // them in a the end. This should be impossible, but users are very | |||||
| // creative. | |||||
| foreach ($replies as $phid => $comments) { | |||||
| foreach ($comments as $comment) { | |||||
| $results[] = $comment; | |||||
| } | |||||
| } | |||||
| return $results; | |||||
| } | |||||
| private function getInlineReplies(array &$replies, $phid, $depth) { | |||||
| $comments = idx($replies, $phid, array()); | |||||
| unset($replies[$phid]); | |||||
| $results = array(); | |||||
| foreach ($comments as $comment) { | |||||
| $results[] = $comment; | |||||
| $descendants = $this->getInlineReplies( | |||||
| $replies, | |||||
| $comment->getPHID(), | |||||
| $depth + 1); | |||||
| foreach ($descendants as $descendant) { | |||||
| $results[] = $descendant; | |||||
| } | |||||
| } | |||||
| return $results; | |||||
| } | |||||
| private function getOffset(array $map, $line) { | private function getOffset(array $map, $line) { | ||||
| if (!$map) { | if (!$map) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $line = (int)$line; | $line = (int)$line; | ||||
| foreach ($map as $key => $spec) { | foreach ($map as $key => $spec) { | ||||
| if ($spec && isset($spec['line'])) { | if ($spec && isset($spec['line'])) { | ||||
| Show All 10 Lines | |||||
You could technically revert all these thread/reorder changes if you want. I think they're fine to keep (probably a very mild net positive for codebase quality?) but not used in this version of the change (these changes, plus the new PHUIDiffInlineThreader class).