| 1 |
lars |
1 |
<refentry id="{@id}">
|
|
|
2 |
<refnamediv>
|
|
|
3 |
<refname>Introduction to using VersionControl_SVN</refname>
|
|
|
4 |
<refpurpose>Using VersionControl_SVN to manage a Subversion repository</refpurpose>
|
|
|
5 |
</refnamediv>
|
|
|
6 |
<refsynopsisdiv>
|
|
|
7 |
<refsynopsisdivinfo>
|
|
|
8 |
<author>
|
|
|
9 |
Clay Loveless
|
|
|
10 |
<authorblurb>{@link mailto:clay@killersoft.com clay@killersoft.com}</authorblurb>
|
|
|
11 |
</author>
|
|
|
12 |
<copyright>Copyright 2004, Clay Loveless</copyright>
|
|
|
13 |
</refsynopsisdivinfo>
|
|
|
14 |
</refsynopsisdiv>
|
|
|
15 |
{@toc}
|
|
|
16 |
<refsect1 id="{@id intro}">
|
|
|
17 |
<title>Introduction</title>
|
|
|
18 |
<para>
|
|
|
19 |
VersionControl_SVN is a simple Object-Oriented interface for the <literal>svn</literal>
|
|
|
20 |
command-line application that makes up the core of {@link http://subversion.tigris.org/ Subversion},
|
|
|
21 |
a free/open-source version control system.
|
|
|
22 |
</para>
|
|
|
23 |
<para>
|
|
|
24 |
Subversion can be used to manage trees of source code, text files, image files --
|
|
|
25 |
just about <emphasis>any</emphasis> collection of files.
|
|
|
26 |
</para>
|
|
|
27 |
<para>
|
|
|
28 |
VersionControl_SVN's features include:
|
|
|
29 |
<unorderedlist>
|
|
|
30 |
<listitem><para>Full support of <literal>svn</literal> subcommands.</para></listitem>
|
|
|
31 |
<listitem><para>Flexible error reporting provided by {@link http://pear.php.net/manual/en/core.pear.pear-errorstack.php PEAR_ErrorStack}</para></listitem>
|
|
|
32 |
<listitem><para>Multi-object factory design.</para></listitem>
|
|
|
33 |
<listitem><para>Fully documented source code</para></listitem>
|
|
|
34 |
</unorderedlist>
|
|
|
35 |
The power of a version control system like Subversion, when accessed through VersionControl_SVN, can be
|
|
|
36 |
extended far beyond typical "source code" repositories.
|
|
|
37 |
</para>
|
|
|
38 |
<simpara>
|
|
|
39 |
For example, what content management system (CMS) couldn't benefit from version control functionality?
|
|
|
40 |
For many non-programmers, version control is a confusing subject to get a firm grasp on. With VersionControl_SVN,
|
|
|
41 |
developers are now able to customize the interface to Subversion with the ease-of-use goals of their
|
|
|
42 |
particular audience in mind. VersionControl_SVN lets you leverage the strengths of version control without burdening
|
|
|
43 |
end-users with the learning curve of change control fundamentals.
|
|
|
44 |
</simpara>
|
|
|
45 |
</refsect1>
|
|
|
46 |
<refsect1 id="{@id example1}">
|
|
|
47 |
<title>A Simple Example</title>
|
|
|
48 |
<para>
|
|
|
49 |
So you've got Subversion repository set up somewhere, and you want to take a look at what's
|
|
|
50 |
inside with a PHP script. With the {@link VersionControl_SVN::VersionControl_SVN_List()} command,
|
|
|
51 |
you're just a few steps away.
|
|
|
52 |
</para>
|
|
|
53 |
<para>
|
|
|
54 |
<programlisting role="php">
|
|
|
55 |
<![CDATA[
|
|
|
56 |
<?php
|
|
|
57 |
require_once 'VersionControl/SVN.php';
|
|
|
58 |
|
|
|
59 |
// Setup error handling -- always a good idea!
|
|
|
60 |
$svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
|
|
|
61 |
|
|
|
62 |
// Set up runtime options.
|
|
|
63 |
$options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY);
|
|
|
64 |
// Request list class from factory
|
|
|
65 |
$svn = VersionControl_SVN::factory('list', $options);
|
|
|
66 |
|
|
|
67 |
// Define any switches and aguments we may need
|
|
|
68 |
$switches = array('username' => 'user', 'password' => 'pass');
|
|
|
69 |
$args = array('svn://svn.example.com/repos/TestProject');
|
|
|
70 |
|
|
|
71 |
// Run command
|
|
|
72 |
if ($output = $svn->run($args, $switches)) {
|
|
|
73 |
print_r($output);
|
|
|
74 |
} else {
|
|
|
75 |
if (count($errs = $svnstack->getErrors())) {
|
|
|
76 |
foreach ($errs as $err) {
|
|
|
77 |
echo '<br />'.$err['message']."<br />\n";
|
|
|
78 |
echo "Command used: " . $err['params']['cmd'];
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
?>
|
|
|
83 |
]]>
|
|
|
84 |
</programlisting>
|
|
|
85 |
</para>
|
|
|
86 |
<simpara>
|
|
|
87 |
If your example repository above happened to have the VersionControl_SVN source in it,
|
|
|
88 |
your output would be something like this:
|
|
|
89 |
</simpara>
|
|
|
90 |
<para>
|
|
|
91 |
<programlisting role="php">
|
|
|
92 |
<![CDATA[
|
|
|
93 |
<?php
|
|
|
94 |
Array
|
|
|
95 |
(
|
|
|
96 |
[0] => Array
|
|
|
97 |
(
|
|
|
98 |
[name] => docs
|
|
|
99 |
[type] => D
|
|
|
100 |
)
|
|
|
101 |
|
|
|
102 |
[1] => Array
|
|
|
103 |
(
|
|
|
104 |
[name] => package.xml
|
|
|
105 |
[type] => F
|
|
|
106 |
)
|
|
|
107 |
|
|
|
108 |
[2] => Array
|
|
|
109 |
(
|
|
|
110 |
[name] => SVN.php
|
|
|
111 |
[type] => F
|
|
|
112 |
)
|
|
|
113 |
|
|
|
114 |
[3] => Array
|
|
|
115 |
(
|
|
|
116 |
[name] => SVN
|
|
|
117 |
[type] => D
|
|
|
118 |
)
|
|
|
119 |
|
|
|
120 |
[4] => Array
|
|
|
121 |
(
|
|
|
122 |
[name] => tests
|
|
|
123 |
[type] => D
|
|
|
124 |
)
|
|
|
125 |
|
|
|
126 |
)
|
|
|
127 |
?>
|
|
|
128 |
]]>
|
|
|
129 |
</programlisting>
|
|
|
130 |
</para>
|
|
|
131 |
<para>
|
|
|
132 |
Note that in the above output, directories are flagged as type <literal>D</literal>, and
|
|
|
133 |
files are flagged as type <literal>F</literal>.
|
|
|
134 |
</para>
|
|
|
135 |
<para>
|
|
|
136 |
<emphasis>Note:</emphasis> For additional information in the output, try setting <literal>verbose</literal> to
|
|
|
137 |
<literal>true</literal> in your <literal>$options</literal> array.
|
|
|
138 |
</para>
|
|
|
139 |
</refsect1>
|
|
|
140 |
<refsect1 id="{@id example1}">
|
|
|
141 |
<title>One Factory To Rule Them All</title>
|
|
|
142 |
<para>
|
|
|
143 |
Have a script that needs to utilize several VersionControl_SVN subclasses? At the expense of a little overhead, you
|
|
|
144 |
can be sure your <literal>$svn</literal> objects are fully-loaded by using the {@link VersionControl_SVN::factory()} command
|
|
|
145 |
keyword <emphasis><literal>__ALL__</literal></emphasis>.
|
|
|
146 |
</para>
|
|
|
147 |
<para>
|
|
|
148 |
For example, in a basic script to get the list of current files in a repository, you just need the {@link VersionControl_SVN::VersionControl_SVN_List()}
|
|
|
149 |
subclass.
|
|
|
150 |
</para>
|
|
|
151 |
<para>
|
|
|
152 |
<programlisting role="php">
|
|
|
153 |
<![CDATA[
|
|
|
154 |
<?php
|
|
|
155 |
require_once 'VersionControl/SVN.php';
|
|
|
156 |
|
|
|
157 |
// Setup error handling -- always a good idea!
|
|
|
158 |
$svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
|
|
|
159 |
|
|
|
160 |
// Set up runtime options.
|
|
|
161 |
$options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY);
|
|
|
162 |
|
|
|
163 |
// Request list class from factory
|
|
|
164 |
$svn = VersionControl_SVN::factory('list', $options);
|
|
|
165 |
|
|
|
166 |
// Define any switches and aguments we may need
|
|
|
167 |
$switches = array('username' => 'user', 'password' => 'pass');
|
|
|
168 |
$args = array('svn://svn.example.com/repos/TestProject');
|
|
|
169 |
|
|
|
170 |
// Run command
|
|
|
171 |
if ($output = $svn->run($args, $switches)) {
|
|
|
172 |
print_r($output);
|
|
|
173 |
} else {
|
|
|
174 |
if (count($errs = $svnstack->getErrors())) {
|
|
|
175 |
foreach ($errs as $err) {
|
|
|
176 |
echo '<br />'.$err['message']."<br />\n";
|
|
|
177 |
echo "Command used: " . $err['params']['cmd'];
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
?>
|
|
|
182 |
]]>
|
|
|
183 |
</programlisting>
|
|
|
184 |
</para>
|
|
|
185 |
<simpara>
|
|
|
186 |
However, if you need to get a recursive list of files in a repository, look up the recent log activity for those files,
|
|
|
187 |
and view the annotated source for those files, you've got two options.
|
|
|
188 |
</simpara>
|
|
|
189 |
<para>
|
|
|
190 |
<programlisting role="php">
|
|
|
191 |
<![CDATA[
|
|
|
192 |
<?php
|
|
|
193 |
require_once 'VersionControl/SVN.php';
|
|
|
194 |
|
|
|
195 |
// Setup error handling -- always a good idea!
|
|
|
196 |
$svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
|
|
|
197 |
|
|
|
198 |
// Set up runtime options.
|
|
|
199 |
$options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
|
|
|
200 |
|
|
|
201 |
// METHOD ONE: Lowest Overhead
|
|
|
202 |
// Create svn object with subcommands we need listed out individually
|
|
|
203 |
$svn = VersionControl_SVN::factory(array('list', 'log', 'blame'), $options);
|
|
|
204 |
|
|
|
205 |
// Define any switches and aguments we may need
|
|
|
206 |
$switches = array('username' => 'user', 'password' => 'pass');
|
|
|
207 |
$args = array('svn://svn.example.com/repos/TestProject');
|
|
|
208 |
|
|
|
209 |
print_r($svn->list->run($args, $switches));
|
|
|
210 |
|
|
|
211 |
// Pick files out of the above output, and see who did what
|
|
|
212 |
$args = array('svn://svn.example.com/repos/TestProject/trunk/index.php');
|
|
|
213 |
|
|
|
214 |
echo "<pre>" . $svn->blame->run($args) . "</pre>";
|
|
|
215 |
|
|
|
216 |
// METHOD TWO: Put all available commands at your disposal
|
|
|
217 |
// Load up all subcommands - higher overhead, but convenient for certain occasions
|
|
|
218 |
$svn = VersionControl_SVN::factory('__ALL__', $options);
|
|
|
219 |
|
|
|
220 |
// Now you may run whatever you need to ...
|
|
|
221 |
$svn->cat->run($args, $switches);
|
|
|
222 |
$svn->info->run($args, $switches);
|
|
|
223 |
// ... and so on.
|
|
|
224 |
?>
|
|
|
225 |
]]>
|
|
|
226 |
</programlisting>
|
|
|
227 |
</para>
|
|
|
228 |
</refsect1>
|
|
|
229 |
<refsect1 id="{@id reading}">
|
|
|
230 |
<title>Further Reading</title>
|
|
|
231 |
<para>
|
|
|
232 |
If you are interested in learning more about Subversion, see the following:
|
|
|
233 |
<unorderedlist>
|
|
|
234 |
<listitem><para>{@link http://svnbook.red-bean.com/ Version Control with Subversion} - The primary reference
|
|
|
235 |
manual for all things related to Subversion, from general use to repository administration.</para></listitem>
|
|
|
236 |
<listitem><para>{@link http://subversion.tigris.org/ Subversion Website} - The official Subversion website
|
|
|
237 |
offers a FAQ, mailing list, and of course, the Subversion source code. Also included are links to
|
|
|
238 |
GUI Subversion applications.</para></listitem>
|
|
|
239 |
</unorderedlist>
|
|
|
240 |
</para>
|
|
|
241 |
</refsect1>
|
|
|
242 |
</refentry>
|