From 6dd511d0ef0fe8e43c994e51018e43c05709e002 Mon Sep 17 00:00:00 2001 From: Nick Harper Date: Tue, 13 Mar 2012 16:05:57 -0700 Subject: [PATCH] [svn1.7] Handle changes to svn properties in svn1.7 working copies Summary: svn changed the format of property changes for svn1.7. Test Plan: arc diff on a working copy with svn property changes Reviewers: epriestley, jungejason Reviewed By: epriestley CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1885 --- src/parser/diff/ArcanistDiffParser.php | 25 +++++++++++++++++-- .../__tests__/ArcanistDiffParserTestCase.php | 9 +++++++ src/parser/diff/__tests__/__init__.php | 1 + .../data/svn-1.7-property-added.svndiff | 23 +++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/parser/diff/__tests__/data/svn-1.7-property-added.svndiff diff --git a/src/parser/diff/ArcanistDiffParser.php b/src/parser/diff/ArcanistDiffParser.php index 231f6576..716139a9 100644 --- a/src/parser/diff/ArcanistDiffParser.php +++ b/src/parser/diff/ArcanistDiffParser.php @@ -402,19 +402,28 @@ final class ArcanistDiffParser { if ($done) { break; } + $prop_index = 2; $trimline = ltrim($line); + if ($trimline && $trimline[0] == '#') { + // in svn1.7, a line like ## -0,0 +1 ## is put between the Added: line + // and the line with the property change. If we have such a line, we'll + // just ignore it (: + $line = $this->nextLine(); + $prop_index = 1; + $trimline = ltrim($line); + } if ($trimline && $trimline[0] == '+') { if ($op == 'Deleted') { $this->didFailParse('Unexpected "+" section in property deletion.'); } $target = 'new'; - $line = substr($trimline, 2); + $line = substr($trimline, $prop_index); } else if ($trimline && $trimline[0] == '-') { if ($op == 'Added') { $this->didFailParse('Unexpected "-" section in property addition.'); } $target = 'old'; - $line = substr($trimline, 2); + $line = substr($trimline, $prop_index); } else if (!strncmp($trimline, 'Merged', 6)) { if ($op == 'Added') { $target = 'new'; @@ -758,6 +767,18 @@ final class ArcanistDiffParser { $matches); if (!$ok) { + // 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 + // by a "Property changes on:" section similar to svn1.6. + if ($line == '') { + $line = $this->nextNonemptyLine(); + $ok = preg_match('/^Property changes on:/', $line); + if (!$ok) { + $this->didFailParse("Confused by empty line"); + } + $line = $this->nextLine(); + return $this->parsePropertyHunk($change); + } $this->didFailParse("Expected hunk header '@@ -NN,NN +NN,NN @@'."); } diff --git a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php index 58bba54b..3903de08 100644 --- a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php @@ -515,6 +515,15 @@ EOTEXT ArcanistDiffChangeType::TYPE_CHANGE, $change->getType()); break; + case 'svn-1.7-property-added.svndiff': + $this->assertEqual(1, count($changes)); + $change = head($changes); + $new_properties = $change->getNewProperties(); + $this->assertEqual(2, count($new_properties)); + $this->assertEqual('*', idx($new_properties, 'svn:executable')); + $this->assertEqual('text/html', idx($new_properties, 'svn:mime-type')); + print_r($changes); + break; default: throw new Exception("No test block for diff file {$diff_file}."); break; diff --git a/src/parser/diff/__tests__/__init__.php b/src/parser/diff/__tests__/__init__.php index 70b73e47..9661fc5f 100644 --- a/src/parser/diff/__tests__/__init__.php +++ b/src/parser/diff/__tests__/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('arcanist', 'parser/diff/changetype'); phutil_require_module('arcanist', 'unit/engine/phutil/testcase'); phutil_require_module('phutil', 'filesystem'); +phutil_require_module('phutil', 'utils'); phutil_require_source('ArcanistDiffParserTestCase.php'); diff --git a/src/parser/diff/__tests__/data/svn-1.7-property-added.svndiff b/src/parser/diff/__tests__/data/svn-1.7-property-added.svndiff new file mode 100644 index 00000000..17cee658 --- /dev/null +++ b/src/parser/diff/__tests__/data/svn-1.7-property-added.svndiff @@ -0,0 +1,23 @@ +Index: test/testing +=================================================================== +--- test/testing (revision 0) ++++ test/testing (working copy) +@@ -0,0 +1,4 @@ ++This ++is ++a ++test +Index: test/testing +=================================================================== +--- test/testing (revision 0) ++++ test/testing (working copy) + +Property changes on: test/testing +___________________________________________________________________ +Added: svn:executable +## -0,0 +1 ## ++* +Added: svn:mime-type +## -0,0 +1 ## ++text/html +