- browse.php basics in place
[viewsvn.git] / includes / svnlib.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # ViewSVN [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 /**
14 * Command line interface with the SVN commands
15 *
16 * @package ViewSVN
17 */
18
19 /**
20 * Interacts with the command line subsystem to
21 * access SVN information
22 *
23 * @package ViewSVN
24 * @version $Id$
25 */
26 class SVNLib
27 {
28 /**
29 * Path to the SVN binary
30 * @var string
31 */
32 var $svnpath;
33
34 /**
35 * Constructor: validate SVN path
36 *
37 * @param string Path to SVN binary
38 */
39 function SVNLib($svnpath)
40 {
41 global $viewsvn;
42
43 $this->svnpath = $viewsvn->shell->cmd($svnpath);
44
45 $access = $viewsvn->shell->exec($this->svnpath . ' --version');
46
47 if (!$access)
48 {
49 $viewsvn->trigger->error('svn binary could not be found');
50 }
51
52 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
53 {
54 $viewsvn->trigger->error('svn binary does not pass test');
55 }
56 }
57
58 /**
59 * Executes the SVN binary
60 *
61 * @access private
62 *
63 * @param string Command
64 *
65 * @return array Output
66 */
67 function svn($command)
68 {
69 global $viewsvn;
70
71 return $viewsvn->shell->exec($this->svnpath . ' ' . $command . ' 2>&1');
72 }
73
74 /**
75 * SVN Wrapper: standard command system
76 *
77 * @access private
78 *
79 * @param string SVN command
80 * @param string Repository
81 * @param string Path
82 * @param integer Revision
83 *
84 * @return array Lines of output
85 */
86 function std($command, $repos, $path, $revision)
87 {
88 global $viewsvn;
89
90 $revision = $this->rev($revision);
91 $repospath = $viewsvn->repos->fetch_path($repos);
92
93 return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path);
94 }
95
96 /**
97 * SVN Wrapper: blame
98 *
99 * @access protected
100 *
101 * @param string Repository
102 * @param string Path
103 * @param integer Revision
104 *
105 * @return array Lines of blame output
106 */
107 function blame($repos, $path, $revision)
108 {
109 return $this->std('blame', $repos, $path, $revision);
110 }
111
112 /**
113 * SVN Wrapper: cat
114 *
115 * @access protected
116 *
117 * @param string Repository
118 * @param string Path
119 * @param integer Revision
120 *
121 * @return array Lines of cat output
122 */
123 function cat($repos, $path, $revision)
124 {
125 return $this->std('cat', $repos, $path, $revision);
126 }
127
128 /**
129 * SVN Wrapper: ls (list)
130 *
131 * @access protected
132 *
133 * @param string Repository
134 * @param string Path
135 * @param integer Revision
136 *
137 * @return array Lines of list output
138 */
139 function ls($repos, $path, $revision)
140 {
141 return $this->std('list', $repos, $path, $revision);
142 }
143
144 /**
145 * Generates a clean revision number
146 *
147 * @access public
148 *
149 * @param integer Revision number
150 *
151 * @return mixed Cleaned revision or HEAD
152 */
153 function rev($revision)
154 {
155 if (($revision = intval($revision)) < 1)
156 {
157 $revision = 'HEAD';
158 }
159 return $revision;
160 }
161 }
162
163 /*=====================================================================*\
164 || ###################################################################
165 || # $HeadURL$
166 || # $Id$
167 || ###################################################################
168 \*=====================================================================*/
169 ?>