// This is a git commit message, probably from "git show".
'(?P<type>commit) (?P<hash>[a-f0-9]+)',
// This is a git diff, probably from "git show" or "git diff".
- '(?P<type>diff --git) [abicwo12]/(?P<old>.+) [abicwo12]/(?P<cur>.+)',
+ // Note that the filenames may appear quoted.
+ '(?P<type>diff --git) '.
+ '(?P<old>"?[abicwo12]/.+"?) '.
+ '(?P<cur>"?[abicwo12]/.+"?)',
// This is a unified diff, probably from "diff -u" or synthetic diffing.
'(?P<type>---) (?P<old>.+)\s+\d{4}-\d{2}-\d{2}.*',
'(?P<binary>Binary) files '.
"'diff --git' (git diff), or '--- filename' (unified diff).");
}
+ if (isset($match['type'])) {
+ if ($match['type'] == 'diff --git') {
+ if (isset($match['old'])) {
+ $match['old'] = $this->unescapeFilename($match['old']);
+ $match['old'] = substr($match['old'], 2);
+ }
+ if (isset($match['cur'])) {
+ $match['cur'] = $this->unescapeFilename($match['cur']);
+ $match['cur'] = substr($match['cur'], 2);
+ }
+ }
+ }
+
$change = $this->buildChange(idx($match, 'cur'));
if (isset($match['old'])) {
}
if (!empty($match['old'])) {
+ $match['old'] = $this->unescapeFilename($match['old']);
$change->setOldPath($match['old']);
}
if (!empty($match['cur'])) {
+ $match['cur'] = $this->unescapeFilename($match['cur']);
$change->setCurrentPath($match['cur']);
}
$message = "Parse Exception: {$message}\n\n{$context}\n";
throw new Exception($message);
}
+
+ /**
+ * Unescape escaped filenames, e.g. from "git diff".
+ */
+ private function unescapeFilename($name) {
+ if (preg_match('/^".+"$/', $name)) {
+ return stripcslashes(substr($name, 1, -1));
+ } else {
+ return $name;
+ }
+ }
}
ArcanistDiffChangeType::FILE_BINARY,
$change->getFileType());
break;
+ case 'git-odd-filename.gitdiff':
+ $this->assertEqual(2, count($changes));
+ $change = reset($changes);
+ $this->assertEqual(
+ 'old/'."\342\210\206".'.jpg',
+ $change->getOldPath());
+ $this->assertEqual(
+ 'new/'."\342\210\206".'.jpg',
+ $change->getCurrentPath());
+ break;
case 'hg-binary-change.hgdiff':
case 'hg-solo-binary-change.hgdiff':
$this->assertEqual(1, count($changes));