From 20eb7416f402e61182257d998ee16442cbf1e6ff Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 27 Aug 2005 23:20:42 +0000 Subject: [PATCH] Did base logging stuff --- includes/paths.php | 37 +++++++++-- includes/svnlib.php | 145 +++++++++++++++++++++++++++++++++++++++++++- log.php | 51 ++++++++++++++++ 3 files changed, 227 insertions(+), 6 deletions(-) create mode 100644 log.php diff --git a/includes/paths.php b/includes/paths.php index 210b76a..c887fb4 100644 --- a/includes/paths.php +++ b/includes/paths.php @@ -121,6 +121,32 @@ class Paths return $path; } + /** + * Create path breadcrumb + * + * @access public + * + * @param string Universal path + * + * @return string Breadcrumb HTML + */ + function construct_breadcrumb($path, $doslash) + { + $html = '/ '; + $itembit = '/'; + + $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY); + //krsort($temp); + + foreach ($temp AS $item) + { + $itembit .= '/' . $item . '/'; + $html .= '' . $item . ' / '; + } + + return $html; + } + /** * Returns the name of the repository from a upath * @@ -132,7 +158,7 @@ class Paths */ function fetch_repos($path) { - $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); + $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY); return $temp[0]; } @@ -142,14 +168,15 @@ class Paths * @access public * * @param string Universal path + * @param bool Preceding slash * * @return string Relative path */ - function fetch_path($path) + function fetch_path($path, $doslash = false) { - $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); + $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY); unset($temp[0]); - return '/' . implode('/', $temp); + return ($doslash ? '/' : '') . implode('/', $temp); } /** @@ -191,7 +218,7 @@ class Paths function is_root_path($path) { $path = $this->fetch_path($path); - $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); + $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY); if (count($temp) > 0) { return false; diff --git a/includes/svnlib.php b/includes/svnlib.php index ce6dc6c..4ba6cdd 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -88,7 +88,7 @@ class SVNLib global $viewsvn; $revision = $this->rev($revision); - $repospath = $viewsvn->repos->fetch_path($repos); + $repospath = $viewsvn->repos->fetch_path($repos, false); return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path); } @@ -125,6 +125,42 @@ class SVNLib return $this->std('cat', $repos, $path, $revision); } + /** + * SVN Wrapper: log + * + * @access protected + * + * @param string Repository + * @param string Path + * @param integer Lower revision + * @param integer Higher revision + * + * @return array Lines of log output + */ + function log($repos, $path, $lorev, $hirev) + { + global $viewsvn; + + $hirev = $this->rev($hirev); + $lorev = $this->rev($hirev); + if ($lorev == 'HEAD') + { + $lorev = 0; + } + + if (is_integer($hirev) AND is_integer($lorev)) + { + if ($lorev > $hirev) + { + $lorev = $hirev - 1; + } + } + + $repospath = $viewsvn->repos->fetch_path($repos, false); + + return $this->svn('log -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path); + } + /** * SVN Wrapper: ls (list) * @@ -160,6 +196,113 @@ class SVNLib } } +/** +* 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 + { + $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)); + } +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/log.php b/log.php new file mode 100644 index 0000000..a232b7a --- /dev/null +++ b/log.php @@ -0,0 +1,51 @@ +paths->parse(); +$repos = $viewsvn->paths->fetch_repos($path); +$relpath = $viewsvn->paths->fetch_path($path); + +echo $viewsvn->paths->construct_breadcrumb($path); + +$logs = new SVNLog($repos, $relpath, 0, 0); + +echo ''; + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5