protected $isMercurial;
protected $detectBinaryFiles = false;
protected $tryEncoding;
+ protected $rawDiff;
+ protected $writeDiffOnFailure;
protected $changes = array();
private $forcePath;
}
protected function didStartParse($text) {
+ $this->rawDiff = $text;
// Eat leading whitespace. This may happen if the first change in the diff
// is an SVN property change.
$this->text = null;
}
+ public function setWriteDiffOnFailure($write) {
+ $this->writeDiffOnFailure = $write;
+ return $this;
+ }
+
protected function didFailParse($message) {
- $min = max(0, $this->line - 3);
- $max = min($this->line + 3, count($this->text) - 1);
+ $context = 3;
+ $min = max(0, $this->line - $context);
+ $max = min($this->line + $context, count($this->text) - 1);
$context = '';
for ($ii = $min; $ii <= $max; $ii++) {
$this->text[$ii]);
}
- $message = "Parse Exception: {$message}\n\n{$context}\n";
- throw new Exception($message);
+ $out = array();
+ $out[] = "Diff Parse Exception: {$message}";
+
+ if ($this->writeDiffOnFailure) {
+ $temp = new TempFile();
+ $temp->setPreserveFile(true);
+
+ Filesystem::writeFile($temp, $this->rawDiff);
+ $out[] = "Raw input file was written to: ".(string)$temp;
+ }
+
+ $out[] = $context;
+ $out = implode("\n\n", $out);
+
+ throw new Exception($out);
}
/**
protected function generateChanges() {
- $parser = new ArcanistDiffParser();
+ $parser = $this->newDiffParser();
$is_raw = $this->isRawDiffSource();
if ($is_raw) {
// textual data.
if ($change->getNeedsSyntheticGitHunks()) {
$diff = $repository_api->getRawDiffText($path, $moves = false);
- $parser = new ArcanistDiffParser();
+ $parser = $this->newDiffParser();
+
$raw_changes = $parser->parseDiff($diff);
foreach ($raw_changes as $raw_change) {
if ($raw_change->getCurrentPath() == $path) {
$conduit = $this->getConduit();
$repository_api = $this->getRepositoryAPI();
- $parser = new ArcanistDiffParser();
+ $parser = $this->newDiffParser();
$history_messages = $repository_api->getGitHistoryLog();
if (!$history_messages) {
// This can occur on the initial commit.
private function getGitUpdateMessage() {
$repository_api = $this->getRepositoryAPI();
- $parser = new ArcanistDiffParser();
+ $parser = $this->newDiffParser();
$commit_messages = $repository_api->getGitCommitLog();
$commit_messages = $parser->parseDiff($commit_messages);