Changeset View
Changeset View
Standalone View
Standalone View
src/parser/ArcanistDiffParser.php
| Show First 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | do { | ||||
| $this->setIsMercurial(true); | $this->setIsMercurial(true); | ||||
| $this->parseIndexHunk($change); | $this->parseIndexHunk($change); | ||||
| break; | break; | ||||
| case 'rcsdiff -u': | case 'rcsdiff -u': | ||||
| $this->isRCS = true; | $this->isRCS = true; | ||||
| $this->parseIndexHunk($change); | $this->parseIndexHunk($change); | ||||
| break; | break; | ||||
| default: | default: | ||||
| $this->didFailParse("Unknown diff type."); | $this->didFailParse('Unknown diff type.'); | ||||
| break; | break; | ||||
| } | } | ||||
| } while ($this->getLine() !== null); | } while ($this->getLine() !== null); | ||||
| $this->didFinishParse(); | $this->didFinishParse(); | ||||
| $this->loadSyntheticData(); | $this->loadSyntheticData(); | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | if (!strlen($new)) { | ||||
| $new = null; | $new = null; | ||||
| } | } | ||||
| return array($old, $new); | return array($old, $new); | ||||
| } | } | ||||
| protected function setIsGit($git) { | protected function setIsGit($git) { | ||||
| if ($this->isGit !== null && $this->isGit != $git) { | if ($this->isGit !== null && $this->isGit != $git) { | ||||
| throw new Exception("Git status has changed!"); | throw new Exception('Git status has changed!'); | ||||
| } | } | ||||
| $this->isGit = $git; | $this->isGit = $git; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getIsGit() { | protected function getIsGit() { | ||||
| return $this->isGit; | return $this->isGit; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | do { | ||||
| $line = $this->nextLineTrimmed(); | $line = $this->nextLineTrimmed(); | ||||
| if ($line === '' || $line === null) { | if ($line === '' || $line === null) { | ||||
| // Some versions of Mercurial apparently omit the terminal newline, | // Some versions of Mercurial apparently omit the terminal newline, | ||||
| // although it's unclear if Git will ever do this. In either case, | // although it's unclear if Git will ever do this. In either case, | ||||
| // rely on the base85 check for sanity. | // rely on the base85 check for sanity. | ||||
| $this->nextNonemptyLine(); | $this->nextNonemptyLine(); | ||||
| return; | return; | ||||
| } else if (!preg_match('/^[a-zA-Z]/', $line)) { | } else if (!preg_match('/^[a-zA-Z]/', $line)) { | ||||
| $this->didFailParse("Expected base85 line length character (a-zA-Z)."); | $this->didFailParse('Expected base85 line length character (a-zA-Z).'); | ||||
| } | } | ||||
| } while (true); | } while (true); | ||||
| } | } | ||||
| protected function parseHunkTarget() { | protected function parseHunkTarget() { | ||||
| $line = $this->getLine(); | $line = $this->getLine(); | ||||
| $matches = null; | $matches = null; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | do { | ||||
| if (!$ok) { | if (!$ok) { | ||||
| // It's possible we hit the style of an svn1.7 property change. | // It's possible we hit the style of an svn1.7 property change. | ||||
| // This is a 4-line Index block, followed by an empty line, followed | // This is a 4-line Index block, followed by an empty line, followed | ||||
| // by a "Property changes on:" section similar to svn1.6. | // by a "Property changes on:" section similar to svn1.6. | ||||
| if ($line == '') { | if ($line == '') { | ||||
| $line = $this->nextNonemptyLine(); | $line = $this->nextNonemptyLine(); | ||||
| $ok = preg_match('/^Property changes on:/', $line); | $ok = preg_match('/^Property changes on:/', $line); | ||||
| if (!$ok) { | if (!$ok) { | ||||
| $this->didFailParse("Confused by empty line"); | $this->didFailParse('Confused by empty line'); | ||||
| } | } | ||||
| $line = $this->nextLine(); | $line = $this->nextLine(); | ||||
| return $this->parsePropertyHunk($change); | return $this->parsePropertyHunk($change); | ||||
| } | } | ||||
| $this->didFailParse("Expected hunk header '@@ -NN,NN +NN,NN @@'."); | $this->didFailParse("Expected hunk header '@@ -NN,NN +NN,NN @@'."); | ||||
| } | } | ||||
| $hunk->setOldOffset($matches[1]); | $hunk->setOldOffset($matches[1]); | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | do { | ||||
| default: | default: | ||||
| // We hit something, likely another hunk. | // We hit something, likely another hunk. | ||||
| $hit_next_hunk = true; | $hit_next_hunk = true; | ||||
| break 2; | break 2; | ||||
| } | } | ||||
| } | } | ||||
| if ($old_len || $new_len) { | if ($old_len || $new_len) { | ||||
| $this->didFailParse("Found the wrong number of hunk lines."); | $this->didFailParse('Found the wrong number of hunk lines.'); | ||||
| } | } | ||||
| $corpus = implode('', $real); | $corpus = implode('', $real); | ||||
| $is_binary = false; | $is_binary = false; | ||||
| if ($this->detectBinaryFiles) { | if ($this->detectBinaryFiles) { | ||||
| $is_binary = !phutil_is_utf8($corpus); | $is_binary = !phutil_is_utf8($corpus); | ||||
| $try_encoding = $this->tryEncoding; | $try_encoding = $this->tryEncoding; | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | protected function didStartParse($text) { | ||||
| } | } | ||||
| $this->text = phutil_split_lines($text); | $this->text = phutil_split_lines($text); | ||||
| $this->line = 0; | $this->line = 0; | ||||
| } | } | ||||
| protected function getLine() { | protected function getLine() { | ||||
| if ($this->text === null) { | if ($this->text === null) { | ||||
| throw new Exception("Not parsing!"); | throw new Exception('Not parsing!'); | ||||
| } | } | ||||
| if (isset($this->text[$this->line])) { | if (isset($this->text[$this->line])) { | ||||
| return $this->text[$this->line]; | return $this->text[$this->line]; | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| protected function getLineTrimmed() { | protected function getLineTrimmed() { | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
| protected function didFailParse($message) { | protected function didFailParse($message) { | ||||
| $context = 5; | $context = 5; | ||||
| $min = max(0, $this->line - $context); | $min = max(0, $this->line - $context); | ||||
| $max = min($this->line + $context, count($this->text) - 1); | $max = min($this->line + $context, count($this->text) - 1); | ||||
| $context = ''; | $context = ''; | ||||
| for ($ii = $min; $ii <= $max; $ii++) { | for ($ii = $min; $ii <= $max; $ii++) { | ||||
| $context .= sprintf( | $context .= sprintf( | ||||
| "%8.8s %6.6s %s", | '%8.8s %6.6s %s', | ||||
| ($ii == $this->line) ? '>>> ' : '', | ($ii == $this->line) ? '>>> ' : '', | ||||
| $ii + 1, | $ii + 1, | ||||
| $this->text[$ii]); | $this->text[$ii]); | ||||
| } | } | ||||
| $out = array(); | $out = array(); | ||||
| $out[] = "Diff Parse Exception: {$message}"; | $out[] = "Diff Parse Exception: {$message}"; | ||||
| if ($this->writeDiffOnFailure) { | if ($this->writeDiffOnFailure) { | ||||
| $temp = new TempFile(); | $temp = new TempFile(); | ||||
| $temp->setPreserveFile(true); | $temp->setPreserveFile(true); | ||||
| Filesystem::writeFile($temp, $this->rawDiff); | Filesystem::writeFile($temp, $this->rawDiff); | ||||
| $out[] = "Raw input file was written to: ".(string)$temp; | $out[] = 'Raw input file was written to: '.(string)$temp; | ||||
| } | } | ||||
| $out[] = $context; | $out[] = $context; | ||||
| $out = implode("\n\n", $out); | $out = implode("\n\n", $out); | ||||
| throw new Exception($out); | throw new Exception($out); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | private function stripGitFormatPatch($diff) { | ||||
| // 3. Mail body. | // 3. Mail body. | ||||
| // 4. ("---") | // 4. ("---") | ||||
| // 5. Diff stat section. | // 5. Diff stat section. | ||||
| // 6. ("\n\n") | // 6. ("\n\n") | ||||
| // 7. Actual diff body. | // 7. Actual diff body. | ||||
| // 8. ("--") | // 8. ("--") | ||||
| // 9. Patch footer. | // 9. Patch footer. | ||||
| list($head, $tail) = preg_split("/^---$/m", $diff, 2); | list($head, $tail) = preg_split('/^---$/m', $diff, 2); | ||||
| list($mail_headers, $mail_body) = explode("\n\n", $head, 2); | list($mail_headers, $mail_body) = explode("\n\n", $head, 2); | ||||
| list($body, $foot) = preg_split('/^-- ?$/m', $tail, 2); | list($body, $foot) = preg_split('/^-- ?$/m', $tail, 2); | ||||
| list($stat, $diff) = explode("\n\n", $body, 2); | list($stat, $diff) = explode("\n\n", $body, 2); | ||||
| // Rebuild the commit message by putting the subject line back on top of it, | // Rebuild the commit message by putting the subject line back on top of it, | ||||
| // if we can find one. | // if we can find one. | ||||
| $matches = null; | $matches = null; | ||||
| $pattern = '/^Subject: (?:\[PATCH\] )?(.*)$/mi'; | $pattern = '/^Subject: (?:\[PATCH\] )?(.*)$/mi'; | ||||
| Show All 9 Lines | |||||