From 1be91e5a2aefe59dfe4726bbc7d21d2383e640ce Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Wed, 5 Oct 2011 02:42:51 +0200 Subject: [PATCH] Do not split Hg's and git's log output into lines - this will make it impossible for us to detect proper line endings later on. --- src/IDF/Scm/Git.php | 32 +++++++++++--------------------- src/IDF/Scm/Mercurial.php | 31 +++++++++++++++---------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index 53bb417..051085e 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -507,33 +507,23 @@ class IDF_Scm_Git extends IDF_Scm "'".$this->mediumtree_fmt."'", escapeshellarg($commit)); } - $out = array(); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; - self::exec('IDF_Scm_Git::getCommit', $cmd, $out, $ret); - if ($ret != 0 or count($out) == 0) { + $out = self::shell_exec('IDF_Scm_Git::getCommit', $cmd); + if (strlen($out) == 0) { return false; } - if ($getdiff) { - $log = array(); - $change = array(); - $inchange = false; - foreach ($out as $line) { - if (!$inchange and 0 === strpos($line, 'diff --git a')) { - $inchange = true; - } - if ($inchange) { - $change[] = $line; - } else { - $log[] = $line; - } - } - $out = self::parseLog($log); - $out[0]->diff = implode("\n", $change); + + $diffStart = strpos($out, 'diff --git a'); + $diff = ''; + if ($diffStart !== false) { + $log = substr($out, 0, $diffStart); + $diff = substr($out, $diffStart); } else { - $out = self::parseLog($out); - $out[0]->diff = ''; + $log = $out; } + $out = self::parseLog(preg_split('/\r\n|\n/', $log)); + $out[0]->diff = $diff; $out[0]->branch = implode(', ', $this->inBranches($out[0]->commit, null)); return $out[0]; } diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 95ddada..484f3a2 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -408,24 +408,23 @@ class IDF_Scm_Mercurial extends IDF_Scm escapeshellarg($commit), escapeshellarg($this->repo), escapeshellarg($logStyle->get())); - $out = array(); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; - self::exec('IDF_Scm_Mercurial::getCommit', $cmd, $out); - $log = array(); - $change = array(); - $inchange = false; - foreach ($out as $line) { - if (!$inchange and 0 === strpos($line, 'diff -r')) { - $inchange = true; - } - if ($inchange) { - $change[] = $line; - } else { - $log[] = $line; - } + $out = self::shell_exec('IDF_Scm_Mercurial::getCommit', $cmd); + if (strlen($out) == 0) { + return false; } - $out = self::parseLog($log); - $out[0]->diff = implode("\n", $change); + + $diffStart = strpos($out, 'diff -r'); + $diff = ''; + if ($diffStart !== false) { + $log = substr($out, 0, $diffStart); + $diff = substr($out, $diffStart); + } else { + $log = $out; + } + + $out = self::parseLog(preg_split('/\r\n|\n/', $log)); + $out[0]->diff = $diff; return $out[0]; }