mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Parsing rcsdiff -u
Summary: Added some sample rcsdiffs for adding and deleting a line from a file. Wrote some test cases to be tested by ArcanistDiffParser. Test Plan: By making all the test cases pass. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Differential Revision: https://secure.phabricator.com/D5324
This commit is contained in:
parent
b06237cb2d
commit
e0702d17c2
4 changed files with 62 additions and 0 deletions
|
@ -13,6 +13,7 @@ final class ArcanistDiffParser {
|
|||
protected $lineSaved;
|
||||
protected $isGit;
|
||||
protected $isMercurial;
|
||||
protected $isRCS;
|
||||
protected $detectBinaryFiles = false;
|
||||
protected $tryEncoding;
|
||||
protected $rawDiff;
|
||||
|
@ -205,6 +206,8 @@ final class ArcanistDiffParser {
|
|||
// This is a git diff, probably from "git show" or "git diff".
|
||||
// Note that the filenames may appear quoted.
|
||||
'(?P<type>diff --git) (?P<oldnew>.*)',
|
||||
// RCS Diff
|
||||
'(?P<type>rcsdiff -u) (?P<oldnew>.*)',
|
||||
// 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 '.
|
||||
|
@ -303,6 +306,10 @@ final class ArcanistDiffParser {
|
|||
$this->setIsMercurial(true);
|
||||
$this->parseIndexHunk($change);
|
||||
break;
|
||||
case 'rcsdiff -u':
|
||||
$this->isRCS = true;
|
||||
$this->parseIndexHunk($change);
|
||||
break;
|
||||
default:
|
||||
$this->didFailParse("Unknown diff type.");
|
||||
break;
|
||||
|
@ -734,9 +741,20 @@ final class ArcanistDiffParser {
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->isRCS) {
|
||||
// Skip the RCS headers.
|
||||
$this->nextLine();
|
||||
$this->nextLine();
|
||||
$this->nextLine();
|
||||
}
|
||||
|
||||
$old_file = $this->parseHunkTarget();
|
||||
$new_file = $this->parseHunkTarget();
|
||||
|
||||
if ($this->isRCS) {
|
||||
$change->setCurrentPath($new_file);
|
||||
}
|
||||
|
||||
$change->setOldPath($old_file);
|
||||
|
||||
$this->parseChangeset($change);
|
||||
|
@ -775,12 +793,15 @@ final class ArcanistDiffParser {
|
|||
// Something like "Fri Aug 26 01:20:50 2005 -0700", don't bother trying
|
||||
// to parse it.
|
||||
$remainder = '\t.*';
|
||||
} else if ($this->isRCS) {
|
||||
$remainder = '\s.*';
|
||||
}
|
||||
|
||||
$ok = preg_match(
|
||||
'@^[-+]{3} (?:[ab]/)?(?P<path>.*?)'.$remainder.'$@',
|
||||
$line,
|
||||
$matches);
|
||||
|
||||
if (!$ok) {
|
||||
$this->didFailParse(
|
||||
"Expected hunk target '+++ path/to/file.ext (revision N)'.");
|
||||
|
|
|
@ -549,6 +549,20 @@ EOTEXT
|
|||
case 'svn-property-windows.svndiff':
|
||||
$this->assertEqual(1, count($changes));
|
||||
break;
|
||||
case 'rcs-addline.rcsdiff':
|
||||
$this->assertEqual(1, count($changes));
|
||||
$change = array_shift($changes);
|
||||
$this->assertEqual(
|
||||
ArcanistDiffChangeType::TYPE_CHANGE,
|
||||
$change->getType());
|
||||
break;
|
||||
case 'rcs-deleteline.rcsdiff':
|
||||
$this->assertEqual(1, count($changes));
|
||||
$change = array_shift($changes);
|
||||
$this->assertEqual(
|
||||
ArcanistDiffChangeType::TYPE_CHANGE,
|
||||
$change->getType());
|
||||
break;
|
||||
default:
|
||||
throw new Exception("No test block for diff file {$diff_file}.");
|
||||
break;
|
||||
|
|
14
src/parser/__tests__/diff/rcs-addline.rcsdiff
Normal file
14
src/parser/__tests__/diff/rcs-addline.rcsdiff
Normal file
|
@ -0,0 +1,14 @@
|
|||
rcsdiff -u a/testing.php
|
||||
===================================================================
|
||||
RCS file: a/RCS/testing.php,v
|
||||
retrieving revision 1.3
|
||||
diff -u -r1.3 a/testing.php
|
||||
--- a/testing.php 2013/03/14 09:05:54 1.3
|
||||
+++ a/testing.php 2013/03/14 09:08:45
|
||||
@@ -2,4 +2,5 @@
|
||||
echo "Hello World";
|
||||
echo "How are you doing today?";
|
||||
echo "thanks";
|
||||
+echo "thanks";
|
||||
?>
|
||||
|
13
src/parser/__tests__/diff/rcs-deleteline.rcsdiff
Normal file
13
src/parser/__tests__/diff/rcs-deleteline.rcsdiff
Normal file
|
@ -0,0 +1,13 @@
|
|||
rcsdiff -u a/testing.php
|
||||
===================================================================
|
||||
RCS file: a/RCS/testing.php,v
|
||||
retrieving revision 1.3
|
||||
diff -u -r1.3 a/testing.php
|
||||
--- a/testing.php 2013/03/14 09:05:54 1.3
|
||||
+++ a/testing.php 2013/03/14 09:09:18
|
||||
@@ -1,5 +1,3 @@
|
||||
<?php
|
||||
echo "Hello World";
|
||||
-echo "How are you doing today?";
|
||||
-echo "thanks";
|
||||
?>
|
Loading…
Reference in a new issue