}
}
-/**
-* Annotation/blame system; constructs an array
-* that is ready for output
-*
-* @package ViewSVN
-* @version $Id$
-*/
-class SVNBlame
-{
- /**
- * Array of blame information
- * @var array
- */
- var $blame = array();
-
- /**
- * Raw "svn blame" output
- * @var array
- */
- var $rawoutput;
-
- /**
- * Constructor: create blame and store data
- *
- * @param string Repository
- * @param string Path
- * @param integer Revision
- */
- function SVNBlame($repos, $path, $revision)
- {
- global $viewsvn;
-
- $this->rawoutput = $viewsvn->svn->blame($repos, $path, $revision);
- $this->process();
- }
-
- /**
- * Returns blame for display
- *
- * @access public
- *
- * @return array Blame data
- */
- function fetch()
- {
- return $this->blame;
- }
-
- /**
- * Parses the blame data
- *
- * @access private
- */
- function process()
- {
- $lineno = 1;
-
- foreach ($this->rawoutput AS $line)
- {
- if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
- {
- $this->blame[] = array(
- 'rev' => $matches[1],
- 'author' => $matches[2],
- 'line' => $matches[3],
- 'lineno' => $lineno++
- );
- }
- // a blank line
- else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
- {
- $this->blame[] = array(
- 'rev' => $matches[1],
- 'author' => $matches[2],
- 'line' => '',
- 'lineno' => $lineno++
- );
- }
- }
- }
-}
-
-/**
-* Log management system; creates a complex list
-* of SVN log information
-*
-* @package ViewSVN
-* @version $Id$
-*/
-class SVNLog
-{
- /**
- * Array of logs
- * @var array
- */
- var $logs = array();
-
- /**
- * Raw "svn log" output
- * @var array
- */
- var $rawoutput;
-
- /**
- * Constructor: create log store for the given file
- *
- * @param string Repository
- * @param string Path
- * @param integer Lower revision
- * @param integer Higher revision
- */
- function SVNLog($repos, $path, $lorev, $hirev)
- {
- global $viewsvn;
-
- $this->rawoutput = $viewsvn->svn->log($repos, $path, $lorev, $hirev);
- $this->process();
- }
-
- /**
- * Returns logs for display
- *
- * @access public
- *
- * @return array Log data
- */
- function fetch()
- {
- return $this->logs;
- }
-
- /**
- * Splits up the raw output into a usable log
- *
- * @access private
- */
- function process()
- {
- $lastrev = 0;
-
- for ($i = 1; $i <= count($this->rawoutput) - 1; $i++)
- {
- $line = $this->rawoutput["$i"];
-
- if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
- {
- if (isset($this->logs["$lastrev"]))
- {
- $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
- }
-
- $this->logs["$matches[1]"] = array(
- 'rev' => $matches[1],
- 'author' => $matches[2],
- 'date' => $matches[3],
- 'timezone' => $matches[4],
- 'lines' => $matches[6],
- 'message' => ''
- );
-
- $lastrev = $matches[1];
- }
- else if (preg_match('#^\s+([ADMR])\s(.*)#', $line, $matches))
- {
- if (preg_match('#(.*) \(from (.*?)\)$#', $matches[2], $amatches))
- {
- $matches[2] = $amatches[1];
- }
-
- $this->logs["$lastrev"]['files'][] = array(
- 'action' => $matches[1],
- 'file' => trim($matches[2]),
- 'from' => (isset($amatches[2]) ? $amatches[2] : '')
- );
- }
- else
- {
- if (trim($line) != 'Changed paths:')
- {
- $this->logs["$lastrev"]['message'] .= $line . "\n";
- }
- }
- }
-
- if (isset($this->logs["$lastrev"]))
- {
- $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
- }
- }
-
- /**
- * Trims the last dash line off a message
- *
- * @access private
- *
- * @param string Message with annoying-ass line
- *
- * @return string Clean string
- */
- function strip_last_line($string)
- {
- return trim(preg_replace("#\n(.*?)\n$#", '', $string));
- }
-}
-
-/**
-* Diff system; constructs a diff array that
-* is ready for output
-*
-* @package ViewSVN
-*/
-class SVNDiff
-{
- /**
- * Array of diff information
- * @var array
- */
- var $diff = array();
-
- /**
- * Raw "svn diff" output
- * @var array
- */
- var $rawoutput;
-
- /**
- * Constructor: create and store diff data
- *
- * @param string Repository
- * @param string Path
- * @param integer Lower revision
- * @param integer Higher revision
- */
- function SVNDiff($repos, $path, $lorev, $hirev)
- {
- global $viewsvn;
-
- $this->rawoutput = $viewsvn->svn->diff($repos, $path, $lorev, $hirev);
- $this->process();
- }
-
- /**
- * Returns diffs for display
- *
- * @access public
- *
- * @return array Diff data
- */
- function fetch()
- {
- return $this->diff;
- }
-
- /**
- * Processes and prepares diff data
- *
- * @access private
- */
- function process()
- {
- global $viewsvn;
-
- $chunk = 0;
- $indexcounter = null;
- $curprop = '';
-
- $delstack = array();
-
- foreach ($this->rawoutput AS $line)
- {
- if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits))
- {
- $property = false;
- $delstack = array();
- $this->diff["$index"][ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4]));
- $lines['old'] = $this->diff["$index"]["$chunk"]['hunk']['old']['line'] - 1;
- $lines['new'] = $this->diff["$index"]["$chunk"]['hunk']['new']['line'] - 1;
- continue;
- }
- else if (preg_match('#^Property changes on: (.*?)$#', $line, $bits))
- {
- $property = true;
- $index = $bits[1];
- $this->diff["$index"]['props'] = array();
- continue;
- }
-
- if ($indexcounter <= 3 AND $indexcounter !== null)
- {
- $indexcounter++;
- continue;
- }
- else if ($indexcounter == 3)
- {
- $indexcounter = null;
- continue;
- }
-
- if (preg_match('#^([\+\- ])(.*)#', $line, $matches) AND !$property)
- {
- $act = $matches[1];
- $content = $matches[2];
-
- if ($act == ' ')
- {
- $this->diff["$index"]["$chunk"][] = array(
- 'line' => $content,
- 'act' => '',
- 'oldlineno' => ++$lines['old'],
- 'newlineno' => ++$lines['new']
- );
-
- $delstack = array();
- }
- else if ($act == '+')
- {
- // potential line delta
- if (count($delstack) > 0)
- {
- $lastline = array_shift($delstack);
-
- if ($delta = @$this->fetch_diff_extent($lastline['line'], $content))
- {
- if (strlen($lastline['line']) > ($delta['start'] - $delta['end']))
- {
- $end = strlen($lastline['line']) + $delta['end'];
- $viewsvn->debug("RM delta- = " . $end);
- $change = '{@-' . '-}' . substr($lastline['line'], $delta['start'], $end - $delta['start']) . '{/@-' . '-}';
- $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr($lastline['line'], 0, $delta['start']) . $change . substr($lastline['line'], $end);
- }
-
- if (strlen($content) > $delta['start'] - $delta['end'])
- {
- $end = strlen($content) + $delta['end'];
- $viewsvn->debug("MK delta+ = " . $end);
- $change = '{@+' . '+}' . substr($content, $delta['start'], $end - $delta['start']) . '{/@+' . '+}';
- $content = substr($content, 0, $delta['start']) . $change . substr($content, $end);
- }
- }
- }
-
- $this->diff["$index"]["$chunk"][] = array(
- 'line' => $content,
- 'act' => '+',
- 'oldlineno' => '',
- 'newlineno' => ++$lines['new']
- );
- }
- else if ($act == '-')
- {
- $this->diff["$index"]["$chunk"][] = $thearray = array(
- 'line' => $content,
- 'act' => '-',
- 'oldlineno' => ++$lines['old'],
- 'newlineno' => ''
- );
-
- $key = count($this->diff["$index"]["$chunk"]) - 2;
- $thearray['INDEX'] = $key;
-
- array_push($delstack, $thearray);
- }
- }
- // whitespace lines
- else
- {
- if (preg_match('#^Index: (.*?)$#', $line, $matches))
- {
- $index = $matches[1];
- $indexcounter = 1;
- $chunk = 0;
- continue;
- }
-
- if ($property)
- {
- if (preg_match('#^__*_$#', trim($line)))
- {
- $viewsvn->debug("skipping: $line");
- continue;
- }
-
- if (preg_match('#Name: (.*?)$#', $line, $matches))
- {
- $curprop = $matches[1];
- $viewsvn->debug("prop: $curprop");
- continue;
- }
- else
- {
- if (preg_match('#^\s+?\+(.*)#', $line, $matches))
- {
- $mode = 'add';
- $this->diff["$index"]['props']["$curprop"]['add'] .= $matches[1];
- }
- else if (preg_match('#^\s+?\-(.*)#', $line, $matches))
- {
- $mode = 'del';
- $this->diff["$index"]['props']["$curprop"]['del'] .= $matches[1];
- }
- else if (!preg_match('#^\s+[\+\- ](.*)#', $line) AND trim($line) != '')
- {
- $this->diff["$index"]['props']["$curprop"]["$mode"] .= "\n" . $line;
- }
- continue;
- }
- }
-
- $this->diff["$index"]["$chunk"][] = array(
- 'line' => '',
- 'act' => '',
- 'oldlineno' => ++$lines['old'],
- 'newlineno' => ++$lines['new']
- );
-
- $delstack = array();
- }
- }
- }
-
- /**
- * Returns the amount of change that occured
- * between two lines
- *
- * @access private
- *
- * @param string Old line
- * @param string New line
- *
- * @return array Difference of positions
- */
- function fetch_diff_extent($old, $new)
- {
- global $viewsvn;
-
- $start = 0;
- $min = min(strlen($old), strlen($new));
-
- $viewsvn->debug("min1 = $min");
-
- while ($start < $min AND $old["$start"] == $new["$start"])
- {
- $start++;
- }
-
- $end = -1;
- $min = $min - $start;
-
- $viewsvn->debug("min2 = $min");
-
- $viewsvn->debug("checking: " . $old[ strlen($old) + $end ] . ' == ' . $new[ strlen($new) + $end ]);
-
- while (-$end <= $min AND $old[ strlen($old) + $end ] == $new[ strlen($new) + $end ])
- {
- $end--;
- }
-
- return array('start' => $start, 'end' => $end + 1);
- }
-}
-
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
}
}
+/**
+* Annotation/blame system; constructs an array
+* that is ready for output
+*
+* @package ViewSVN
+* @version $Id$
+*/
+class SVNBlame
+{
+ /**
+ * Array of blame information
+ * @var array
+ */
+ var $blame = array();
+
+ /**
+ * Raw "svn blame" output
+ * @var array
+ */
+ var $rawoutput;
+
+ /**
+ * Constructor: create blame and store data
+ *
+ * @param string Repository
+ * @param string Path
+ * @param integer Revision
+ */
+ function SVNBlame($repos, $path, $revision)
+ {
+ global $viewsvn;
+
+ $this->rawoutput = $viewsvn->svn->blame($repos, $path, $revision);
+ $this->process();
+ }
+
+ /**
+ * Returns blame for display
+ *
+ * @access public
+ *
+ * @return array Blame data
+ */
+ function fetch()
+ {
+ return $this->blame;
+ }
+
+ /**
+ * Parses the blame data
+ *
+ * @access private
+ */
+ function process()
+ {
+ $lineno = 1;
+
+ foreach ($this->rawoutput AS $line)
+ {
+ if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
+ {
+ $this->blame[] = array(
+ 'rev' => $matches[1],
+ 'author' => $matches[2],
+ 'line' => $matches[3],
+ 'lineno' => $lineno++
+ );
+ }
+ // a blank line
+ else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
+ {
+ $this->blame[] = array(
+ 'rev' => $matches[1],
+ 'author' => $matches[2],
+ 'line' => '',
+ 'lineno' => $lineno++
+ );
+ }
+ }
+ }
+}
+
+/**
+* Log management system; creates a complex list
+* of SVN log information
+*
+* @package ViewSVN
+* @version $Id$
+*/
+class SVNLog
+{
+ /**
+ * Array of logs
+ * @var array
+ */
+ var $logs = array();
+
+ /**
+ * Raw "svn log" output
+ * @var array
+ */
+ var $rawoutput;
+
+ /**
+ * Constructor: create log store for the given file
+ *
+ * @param string Repository
+ * @param string Path
+ * @param integer Lower revision
+ * @param integer Higher revision
+ */
+ function SVNLog($repos, $path, $lorev, $hirev)
+ {
+ global $viewsvn;
+
+ $this->rawoutput = $viewsvn->svn->log($repos, $path, $lorev, $hirev);
+ $this->process();
+ }
+
+ /**
+ * Returns logs for display
+ *
+ * @access public
+ *
+ * @return array Log data
+ */
+ function fetch()
+ {
+ return $this->logs;
+ }
+
+ /**
+ * Splits up the raw output into a usable log
+ *
+ * @access private
+ */
+ function process()
+ {
+ $lastrev = 0;
+
+ for ($i = 1; $i <= count($this->rawoutput) - 1; $i++)
+ {
+ $line = $this->rawoutput["$i"];
+
+ if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
+ {
+ if (isset($this->logs["$lastrev"]))
+ {
+ $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
+ }
+
+ $this->logs["$matches[1]"] = array(
+ 'rev' => $matches[1],
+ 'author' => $matches[2],
+ 'date' => $matches[3],
+ 'timezone' => $matches[4],
+ 'lines' => $matches[6],
+ 'message' => ''
+ );
+
+ $lastrev = $matches[1];
+ }
+ else if (preg_match('#^\s+([ADMR])\s(.*)#', $line, $matches))
+ {
+ if (preg_match('#(.*) \(from (.*?)\)$#', $matches[2], $amatches))
+ {
+ $matches[2] = $amatches[1];
+ }
+
+ $this->logs["$lastrev"]['files'][] = array(
+ 'action' => $matches[1],
+ 'file' => trim($matches[2]),
+ 'from' => (isset($amatches[2]) ? $amatches[2] : '')
+ );
+ }
+ else
+ {
+ if (trim($line) != 'Changed paths:')
+ {
+ $this->logs["$lastrev"]['message'] .= $line . "\n";
+ }
+ }
+ }
+
+ if (isset($this->logs["$lastrev"]))
+ {
+ $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
+ }
+ }
+
+ /**
+ * Trims the last dash line off a message
+ *
+ * @access private
+ *
+ * @param string Message with annoying-ass line
+ *
+ * @return string Clean string
+ */
+ function strip_last_line($string)
+ {
+ return trim(preg_replace("#\n(.*?)\n$#", '', $string));
+ }
+}
+
+/**
+* Diff system; constructs a diff array that
+* is ready for output
+*
+* @package ViewSVN
+*/
+class SVNDiff
+{
+ /**
+ * Array of diff information
+ * @var array
+ */
+ var $diff = array();
+
+ /**
+ * Raw "svn diff" output
+ * @var array
+ */
+ var $rawoutput;
+
+ /**
+ * Constructor: create and store diff data
+ *
+ * @param string Repository
+ * @param string Path
+ * @param integer Lower revision
+ * @param integer Higher revision
+ */
+ function SVNDiff($repos, $path, $lorev, $hirev)
+ {
+ global $viewsvn;
+
+ $this->rawoutput = $viewsvn->svn->diff($repos, $path, $lorev, $hirev);
+ $this->process();
+ }
+
+ /**
+ * Returns diffs for display
+ *
+ * @access public
+ *
+ * @return array Diff data
+ */
+ function fetch()
+ {
+ return $this->diff;
+ }
+
+ /**
+ * Processes and prepares diff data
+ *
+ * @access private
+ */
+ function process()
+ {
+ global $viewsvn;
+
+ $chunk = 0;
+ $indexcounter = null;
+ $curprop = '';
+
+ $delstack = array();
+
+ foreach ($this->rawoutput AS $line)
+ {
+ if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits))
+ {
+ $property = false;
+ $delstack = array();
+ $this->diff["$index"][ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4]));
+ $lines['old'] = $this->diff["$index"]["$chunk"]['hunk']['old']['line'] - 1;
+ $lines['new'] = $this->diff["$index"]["$chunk"]['hunk']['new']['line'] - 1;
+ continue;
+ }
+ else if (preg_match('#^Property changes on: (.*?)$#', $line, $bits))
+ {
+ $property = true;
+ $index = $bits[1];
+ $this->diff["$index"]['props'] = array();
+ continue;
+ }
+
+ if ($indexcounter <= 3 AND $indexcounter !== null)
+ {
+ $indexcounter++;
+ continue;
+ }
+ else if ($indexcounter == 3)
+ {
+ $indexcounter = null;
+ continue;
+ }
+
+ if (preg_match('#^([\+\- ])(.*)#', $line, $matches) AND !$property)
+ {
+ $act = $matches[1];
+ $content = $matches[2];
+
+ if ($act == ' ')
+ {
+ $this->diff["$index"]["$chunk"][] = array(
+ 'line' => $content,
+ 'act' => '',
+ 'oldlineno' => ++$lines['old'],
+ 'newlineno' => ++$lines['new']
+ );
+
+ $delstack = array();
+ }
+ else if ($act == '+')
+ {
+ // potential line delta
+ if (count($delstack) > 0)
+ {
+ $lastline = array_shift($delstack);
+
+ if ($delta = @$this->fetch_diff_extent($lastline['line'], $content))
+ {
+ if (strlen($lastline['line']) > ($delta['start'] - $delta['end']))
+ {
+ $end = strlen($lastline['line']) + $delta['end'];
+ $viewsvn->debug("RM delta- = " . $end);
+ $change = '{@-' . '-}' . substr($lastline['line'], $delta['start'], $end - $delta['start']) . '{/@-' . '-}';
+ $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr($lastline['line'], 0, $delta['start']) . $change . substr($lastline['line'], $end);
+ }
+
+ if (strlen($content) > $delta['start'] - $delta['end'])
+ {
+ $end = strlen($content) + $delta['end'];
+ $viewsvn->debug("MK delta+ = " . $end);
+ $change = '{@+' . '+}' . substr($content, $delta['start'], $end - $delta['start']) . '{/@+' . '+}';
+ $content = substr($content, 0, $delta['start']) . $change . substr($content, $end);
+ }
+ }
+ }
+
+ $this->diff["$index"]["$chunk"][] = array(
+ 'line' => $content,
+ 'act' => '+',
+ 'oldlineno' => '',
+ 'newlineno' => ++$lines['new']
+ );
+ }
+ else if ($act == '-')
+ {
+ $this->diff["$index"]["$chunk"][] = $thearray = array(
+ 'line' => $content,
+ 'act' => '-',
+ 'oldlineno' => ++$lines['old'],
+ 'newlineno' => ''
+ );
+
+ $key = count($this->diff["$index"]["$chunk"]) - 2;
+ $thearray['INDEX'] = $key;
+
+ array_push($delstack, $thearray);
+ }
+ }
+ // whitespace lines
+ else
+ {
+ if (preg_match('#^Index: (.*?)$#', $line, $matches))
+ {
+ $index = $matches[1];
+ $indexcounter = 1;
+ $chunk = 0;
+ continue;
+ }
+
+ if ($property)
+ {
+ if (preg_match('#^__*_$#', trim($line)))
+ {
+ $viewsvn->debug("skipping: $line");
+ continue;
+ }
+
+ if (preg_match('#Name: (.*?)$#', $line, $matches))
+ {
+ $curprop = $matches[1];
+ $viewsvn->debug("prop: $curprop");
+ continue;
+ }
+ else
+ {
+ if (preg_match('#^\s+?\+(.*)#', $line, $matches))
+ {
+ $mode = 'add';
+ $this->diff["$index"]['props']["$curprop"]['add'] .= $matches[1];
+ }
+ else if (preg_match('#^\s+?\-(.*)#', $line, $matches))
+ {
+ $mode = 'del';
+ $this->diff["$index"]['props']["$curprop"]['del'] .= $matches[1];
+ }
+ else if (!preg_match('#^\s+[\+\- ](.*)#', $line) AND trim($line) != '')
+ {
+ $this->diff["$index"]['props']["$curprop"]["$mode"] .= "\n" . $line;
+ }
+ continue;
+ }
+ }
+
+ $this->diff["$index"]["$chunk"][] = array(
+ 'line' => '',
+ 'act' => '',
+ 'oldlineno' => ++$lines['old'],
+ 'newlineno' => ++$lines['new']
+ );
+
+ $delstack = array();
+ }
+ }
+ }
+
+ /**
+ * Returns the amount of change that occured
+ * between two lines
+ *
+ * @access private
+ *
+ * @param string Old line
+ * @param string New line
+ *
+ * @return array Difference of positions
+ */
+ function fetch_diff_extent($old, $new)
+ {
+ global $viewsvn;
+
+ $start = 0;
+ $min = min(strlen($old), strlen($new));
+
+ $viewsvn->debug("min1 = $min");
+
+ while ($start < $min AND $old["$start"] == $new["$start"])
+ {
+ $start++;
+ }
+
+ $end = -1;
+ $min = $min - $start;
+
+ $viewsvn->debug("min2 = $min");
+
+ $viewsvn->debug("checking: " . $old[ strlen($old) + $end ] . ' == ' . $new[ strlen($new) + $end ]);
+
+ while (-$end <= $min AND $old[ strlen($old) + $end ] == $new[ strlen($new) + $end ])
+ {
+ $end--;
+ }
+
+ return array('start' => $start, 'end' => $end + 1);
+ }
+}
+
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$