diff --git a/src/IDF/Diff.php b/src/IDF/Diff.php index 4b7f8b2..28139a6 100644 --- a/src/IDF/Diff.php +++ b/src/IDF/Diff.php @@ -47,13 +47,21 @@ class IDF_Diff $lline = 0; $rline = 0; $files = array(); + $indiff = false; // Used to skip the headers in the git patches + $i = 0; // Used to skip the end of a git patch with --\nversion number foreach ($this->lines as $line) { + $i++; + if (0 === strpos($line, '--') and isset($this->lines[$i]) + and preg_match('/^\d+\.\d+\.\d+\.\d+$/', $this->lines[$i])) { + break; + } if (0 === strpos($line, 'diff --git a')) { $current_file = self::getFile($line); $files[$current_file] = array(); $files[$current_file]['chunks'] = array(); $files[$current_file]['chunks_def'] = array(); $current_chunk = 0; + $indiff = true; continue; } else if (preg_match('#^diff -r [^\s]+ -r [^\s]+ (.+)$#', $line, $matches)) { $current_file = $matches[1]; @@ -61,6 +69,7 @@ class IDF_Diff $files[$current_file]['chunks'] = array(); $files[$current_file]['chunks_def'] = array(); $current_chunk = 0; + $indiff = true; continue; } else if (0 === strpos($line, 'Index: ')) { $current_file = self::getSvnFile($line); @@ -68,6 +77,10 @@ class IDF_Diff $files[$current_file]['chunks'] = array(); $files[$current_file]['chunks_def'] = array(); $current_chunk = 0; + $indiff = true; + continue; + } + if (!$indiff) { continue; } if (0 === strpos($line, '@@ ')) { diff --git a/src/IDF/Tests/0001-Some-configuration-variables-have-been-added-in-orde.patch b/src/IDF/Tests/0001-Some-configuration-variables-have-been-added-in-orde.patch new file mode 100644 index 0000000..942396f --- /dev/null +++ b/src/IDF/Tests/0001-Some-configuration-variables-have-been-added-in-orde.patch @@ -0,0 +1,52 @@ +From ec6cb8b19ee3a08f48625181d6a74744b3950e90 Mon Sep 17 00:00:00 2001 +From: Manuel Eidenberger +Date: Mon, 2 Feb 2009 15:11:23 +0100 +Subject: [PATCH] Some configuration variables have been added in order to manually set svn and svnlook binarie paths (see issue 123) + +--- + src/IDF/Scm/Svn.php | 24 ++++++++++++------------ + src/IDF/conf/idf.php-dist | 8 ++++++++ + 2 files changed, 20 insertions(+), 12 deletions(-) + +diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php +index e2f7a61..e1359c7 100644 +--- a/src/IDF/Scm/Svn.php ++++ b/src/IDF/Scm/Svn.php +@@ -108,7 +108,7 @@ class IDF_Scm_Svn + } + + // Else, test the path on revision +- $cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', ++ $cmd = sprintf(Pluf::f('svn_path').' info --xml --username=%s --password=%s %s@%s', + escapeshellarg($this->username), + escapeshellarg($this->password), + escapeshellarg($this->repo.'/'.$path), +@@ -190,7 +190,7 @@ class IDF_Scm_Svn + */ + private function getCommitMessage($file, $rev='HEAD') + { +- $cmd = sprintf('svn log --xml --limit 1 --username=%s --password=%s %s@%s', ++ $cmd = sprintf(Pluf::f('svn_path').' log --xml --limit 1 --username=%s --password=%s %s@%s', + escapeshellarg($this->username), + escapeshellarg($this->password), + escapeshellarg($file), +diff --git a/src/IDF/conf/idf.php-dist b/src/IDF/conf/idf.php-dist +index 8aca31f..abb4ecd 100644 +--- a/src/IDF/conf/idf.php-dist ++++ b/src/IDF/conf/idf.php-dist +@@ -208,4 +208,12 @@ $cfg['allowed_scm'] = array('git' => 'IDF_Scm_Git', + # variables not being set correctly. Note the trailing space. + # $cfg['idf_exec_cmd_prefix'] = '/usr/bin/env -i '; + ++# Path to svn and svnlook binaries. In some cases, it is sometimes ++# necessary to define absolut path to these two binaries, for example: ++# $cfg['svn_path'] = 'svn'; ++# $cfg['svnlook_path'] = 'svnlook_path'; ++# This is only necessary if svn and svnlook binaries are not set in $PATH ++$cfg['svn_path'] = 'svn'; ++$cfg['svnlook_path'] = 'svnlook'; ++ + return $cfg; +-- +1.5.4.3 + diff --git a/src/IDF/Tests/TestDiff.php b/src/IDF/Tests/TestDiff.php index a926d3d..97e4107 100644 --- a/src/IDF/Tests/TestDiff.php +++ b/src/IDF/Tests/TestDiff.php @@ -69,6 +69,14 @@ class IDF_Tests_TestDiff extends UnitTestCase $lline = end($lchunk); $this->assertEqual(array('', '166', '{/if}{/block}'), $lline); - //print_r($diff->mergeChunks($orig_lines, $def, 10)); + } + + public function testDiffWithHeaders() + { + $diff_content = file_get_contents(dirname(__FILE__).'/0001-Some-configuration-variables-have-been-added-in-orde.patch'); + $diff = new IDF_Diff($diff_content); + $diff->parse(); + $this->assertEqual(2, count($diff->files)); + $this->assertEqual(12, count($diff->files['src/IDF/conf/idf.php-dist']['chunks'][0])); } } \ No newline at end of file