2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * Command line interface with the SVN commands
29 * Interacts with the command line subsystem to
30 * access SVN information
38 * Path to the SVN binary
51 * Constructor: validate SVN path
53 * @param object Controller
55 function SVNLib(&$controller)
57 $this->controller
=& $controller;
59 $this->svnpath
= $this->controller
->xquery
->cmd($svnpath);
61 $access = $this->controller
->xquery
->exec($this->svnpath
. ' --version');
65 $this->controller
->registry
->trigger
->error($this->controller
->registry
->lang
->string('The SVN binary could not be located'));
68 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
70 $this->controller
->registry
->trigger
->error($this->controller
->registry
->lang
->string('The SVN binary does not appear to be valid (it failed our tests)'));
75 * Executes the SVN binary
79 * @param string Command
81 * @return array Output
83 function svn($command)
85 $output = $this->controller
->xquery
->exec($this->svnpath
. ' ' . $command . ' 2>&1');
87 // make sure that we keep escaped chars
88 //$output = str_replace(array('\t', '\n', '\r'), array('\\\t', '\\\n', '\\\r'), $output);
89 //$output = preg_replace('#\\\(.)#', '\\\\\\\\' . '\1', $output);
90 //$output = str_replace('\\', '\\\\', $output);
92 $temp = implode("\n", $output);
93 if (strpos($temp, '(apr' . '_err=') !== false
)
95 $this->controller
->registry
->trigger
->error(nl2br($temp));
101 * SVN Wrapper: standard command system
105 * @param string SVN command
106 * @param string Repository
108 * @param integer Revision
110 * @return array Lines of output
112 function std($command, $repos, $path, $revision)
116 $revision = $this->rev($revision);
117 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
119 return $this->svn($command . ' ' . $repospath . $path . '@' . $revision);
127 * @param string Repository
129 * @param integer Revision
131 * @return array Lines of blame output
133 function blame($repos, $path, $revision)
135 return $this->std('blame', $repos, $path, $revision);
143 * @param string Repository
145 * @param integer Revision
147 * @return array Lines of cat output
149 function cat($repos, $path, $revision)
151 return $this->std('cat', $repos, $path, $revision);
159 * @param string Repository
161 * @param integer Lower revision
162 * @param integer Higher revision
164 * @return array Lines of diff output
166 function diff($repos, $path, $lorev, $hirev)
170 $hirev = $this->rev($hirev);
171 $lorev = $this->rev($lorev);
172 if ($lorev == 'HEAD')
177 if (is_integer($hirev) AND is_integer($lorev))
183 if ($lorev == $hirev)
189 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
191 return $this->svn('diff -r' . $lorev . ':' . $hirev . ' ' . $repospath . $path);
199 * @param string Repository
201 * @param integer Lower revision
202 * @param integer Higher revision
204 * @return array Lines of log output
206 function log($repos, $path, $lorev, $hirev)
210 $hirev = $this->rev($hirev);
211 $lorev = $this->rev($hirev);
212 if ($lorev == 'HEAD')
217 if (is_integer($hirev) AND is_integer($lorev))
223 if ($lorev == $hirev)
229 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
231 return $this->svn('log -v -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
235 * SVN Wrapper: ls (list)
239 * @param string Repository
241 * @param integer Revision
243 * @return array Lines of list output
245 function ls($repos, $path, $revision)
247 return $this->std('list', $repos, $path, $revision);
251 * Generates a clean revision number
255 * @param integer Revision number
257 * @return mixed Cleaned revision or HEAD
259 function rev($revision)
261 if (($revision = intval($revision)) < 1)
269 /*=====================================================================*\
270 || ###################################################################
273 || ###################################################################
274 \*=====================================================================*/