| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +----------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 5 |
|
|
|
5 |
// +----------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (c) 2004-2007, Clay Loveless |
|
|
|
7 |
// | All rights reserved. |
|
|
|
8 |
// +----------------------------------------------------------------------+
|
|
|
9 |
// | This LICENSE is in the BSD license style. |
|
|
|
10 |
// | http://www.opensource.org/licenses/bsd-license.php |
|
|
|
11 |
// | |
|
|
|
12 |
// | Redistribution and use in source and binary forms, with or without |
|
|
|
13 |
// | modification, are permitted provided that the following conditions |
|
|
|
14 |
// | are met: |
|
|
|
15 |
// | |
|
|
|
16 |
// | * Redistributions of source code must retain the above copyright |
|
|
|
17 |
// | notice, this list of conditions and the following disclaimer. |
|
|
|
18 |
// | |
|
|
|
19 |
// | * Redistributions in binary form must reproduce the above |
|
|
|
20 |
// | copyright notice, this list of conditions and the following |
|
|
|
21 |
// | disclaimer in the documentation and/or other materials provided |
|
|
|
22 |
// | with the distribution. |
|
|
|
23 |
// | |
|
|
|
24 |
// | * Neither the name of Clay Loveless nor the names of contributors |
|
|
|
25 |
// | may be used to endorse or promote products derived from this |
|
|
|
26 |
// | software without specific prior written permission. |
|
|
|
27 |
// | |
|
|
|
28 |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
|
29 |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
|
30 |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
|
|
31 |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
|
|
32 |
// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
|
|
33 |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
|
|
34 |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
|
|
35 |
// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
|
|
36 |
// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
37 |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
|
|
38 |
// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
|
|
39 |
// | POSSIBILITY OF SUCH DAMAGE. |
|
|
|
40 |
// +----------------------------------------------------------------------+
|
|
|
41 |
// | Author: Clay Loveless <clay@killersoft.com> |
|
|
|
42 |
// +----------------------------------------------------------------------+
|
|
|
43 |
//
|
|
|
44 |
// $Id: Update.php 300848 2010-06-29 07:23:08Z mrook $
|
|
|
45 |
//
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* @package VersionControl_SVN
|
|
|
49 |
* @category VersionControl
|
|
|
50 |
* @author Clay Loveless <clay@killersoft.com>
|
|
|
51 |
*/
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Subversion Update command manager class
|
|
|
55 |
*
|
|
|
56 |
* Bring changes from the repository into the working copy.
|
|
|
57 |
*
|
|
|
58 |
* From 'svn update --help':
|
|
|
59 |
*
|
|
|
60 |
* usage: update [PATH...]
|
|
|
61 |
*
|
|
|
62 |
* If no revision given, bring working copy up-to-date with HEAD rev.
|
|
|
63 |
* Else synchronize working copy to revision given by -r.
|
|
|
64 |
*
|
|
|
65 |
* For each updated item a line will start with a character reporting the
|
|
|
66 |
* action taken. These characters have the following meaning:
|
|
|
67 |
*
|
|
|
68 |
* A Added
|
|
|
69 |
* D Deleted
|
|
|
70 |
* U Updated
|
|
|
71 |
* C Conflict
|
|
|
72 |
* G Merged
|
|
|
73 |
*
|
|
|
74 |
* A character in the first column signifies an update to the actual file,
|
|
|
75 |
* while updates to the file's properties are shown in the second column.
|
|
|
76 |
*
|
|
|
77 |
* Conversion of the above usage example to VersionControl_SVN_Switch:
|
|
|
78 |
*
|
|
|
79 |
* <code>
|
|
|
80 |
* <?php
|
|
|
81 |
* require_once 'VersionControl/SVN.php';
|
|
|
82 |
*
|
|
|
83 |
* // Setup error handling -- always a good idea!
|
|
|
84 |
* $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
|
|
|
85 |
*
|
|
|
86 |
* // Set up runtime options. Will be passed to all
|
|
|
87 |
* // subclasses.
|
|
|
88 |
* $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
|
|
|
89 |
*
|
|
|
90 |
* $switches = array('r' => '30');
|
|
|
91 |
* $args = array('/path/to/working/copy');
|
|
|
92 |
*
|
|
|
93 |
* $svn = VersionControl_SVN::factory(array('update'), $options);
|
|
|
94 |
* print_r($svn->update->run($args));
|
|
|
95 |
*
|
|
|
96 |
* if (count($errs = $svnstack->getErrors())) {
|
|
|
97 |
* foreach ($errs as $err) {
|
|
|
98 |
* echo '<br />'.$err['message']."<br />\n";
|
|
|
99 |
* echo "Command used: " . $err['params']['cmd'];
|
|
|
100 |
* }
|
|
|
101 |
* }
|
|
|
102 |
* ?>
|
|
|
103 |
* </code>
|
|
|
104 |
*
|
|
|
105 |
*
|
|
|
106 |
* $switches is an array containing one or more command line options
|
|
|
107 |
* defined by the following associative keys:
|
|
|
108 |
*
|
|
|
109 |
* <code>
|
|
|
110 |
*
|
|
|
111 |
* $switches = array(
|
|
|
112 |
* 'r [revision]' => 'ARG (some commands also take ARG1:ARG2 range)
|
|
|
113 |
* A revision argument can be one of:
|
|
|
114 |
* NUMBER revision number
|
|
|
115 |
* "{" DATE "}" revision at start of the date
|
|
|
116 |
* "HEAD" latest in repository
|
|
|
117 |
* "BASE" base rev of item's working copy
|
|
|
118 |
* "COMMITTED" last commit at or before BASE
|
|
|
119 |
* "PREV" revision just before COMMITTED',
|
|
|
120 |
* // either 'r' or 'revision' may be used
|
|
|
121 |
* 'N' => true|false,
|
|
|
122 |
* // operate on single directory only
|
|
|
123 |
* 'non-recursive' => true|false,
|
|
|
124 |
* // operate on single directory only
|
|
|
125 |
* 'q [quiet]' => true|false,
|
|
|
126 |
* // print as little as possible
|
|
|
127 |
* 'diff3-cmd' => 'ARG',
|
|
|
128 |
* // use ARG as merge command
|
|
|
129 |
* 'username' => 'Subversion repository login',
|
|
|
130 |
* 'password' => 'Subversion repository password',
|
|
|
131 |
* 'no-auth-cache' => true|false,
|
|
|
132 |
* // Do not cache authentication tokens
|
|
|
133 |
* 'config-dir' => 'Path to a Subversion configuration directory'
|
|
|
134 |
* );
|
|
|
135 |
*
|
|
|
136 |
* </code>
|
|
|
137 |
*
|
|
|
138 |
* Note: Subversion does not offer an XML output option for this subcommand
|
|
|
139 |
*
|
|
|
140 |
* The non-interactive option available on the command-line
|
|
|
141 |
* svn client may also be set (true|false), but it is set to true by default.
|
|
|
142 |
*
|
|
|
143 |
*
|
|
|
144 |
* @package VersionControl_SVN
|
|
|
145 |
* @version 0.3.4
|
|
|
146 |
* @category SCM
|
|
|
147 |
* @author Clay Loveless <clay@killersoft.com>
|
|
|
148 |
*/
|
|
|
149 |
class VersionControl_SVN_Update extends VersionControl_SVN
|
|
|
150 |
{
|
|
|
151 |
/**
|
|
|
152 |
* Valid switches for svn update
|
|
|
153 |
*
|
|
|
154 |
* @var array
|
|
|
155 |
* @access public
|
|
|
156 |
*/
|
|
|
157 |
var $valid_switches = array('r',
|
|
|
158 |
'revision',
|
|
|
159 |
'N',
|
|
|
160 |
'non-recursive',
|
|
|
161 |
'non_recursive',
|
|
|
162 |
'q',
|
|
|
163 |
'quiet',
|
|
|
164 |
'diff3-cmd',
|
|
|
165 |
'username',
|
|
|
166 |
'password',
|
|
|
167 |
'ignore-externals',
|
|
|
168 |
'no-auth-cache',
|
|
|
169 |
'no_auth_cache',
|
|
|
170 |
'non-interactive',
|
|
|
171 |
'non_interactive',
|
|
|
172 |
'config-dir',
|
|
|
173 |
'config_dir',
|
|
|
174 |
'force'
|
|
|
175 |
);
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* Command-line arguments that should be passed
|
|
|
180 |
* <b>outside</b> of those specified in {@link switches}.
|
|
|
181 |
*
|
|
|
182 |
* @var array
|
|
|
183 |
* @access public
|
|
|
184 |
*/
|
|
|
185 |
var $args = array();
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* Minimum number of args required by this subcommand.
|
|
|
189 |
* See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
|
|
|
190 |
* Subversion Complete Reference for details on arguments for this subcommand.
|
|
|
191 |
* @var int
|
|
|
192 |
* @access public
|
|
|
193 |
*/
|
|
|
194 |
var $min_args = 0;
|
|
|
195 |
|
|
|
196 |
/**
|
|
|
197 |
* Switches required by this subcommand.
|
|
|
198 |
* See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
|
|
|
199 |
* Subversion Complete Reference for details on arguments for this subcommand.
|
|
|
200 |
* @var array
|
|
|
201 |
* @access public
|
|
|
202 |
*/
|
|
|
203 |
var $required_switches = array();
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
* Use exec or passthru to get results from command.
|
|
|
207 |
* @var bool
|
|
|
208 |
* @access public
|
|
|
209 |
*/
|
|
|
210 |
var $passthru = false;
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
* Prepare the svn subcommand switches.
|
|
|
214 |
*
|
|
|
215 |
* Defaults to non-interactive mode, and will auto-set the
|
|
|
216 |
* --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
|
|
|
217 |
* VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
|
|
|
218 |
*
|
|
|
219 |
* @param void
|
|
|
220 |
* @return int true on success, false on failure. Check PEAR_ErrorStack
|
|
|
221 |
* for error details, if any.
|
|
|
222 |
*/
|
|
|
223 |
function prepare()
|
|
|
224 |
{
|
|
|
225 |
$meets_requirements = $this->checkCommandRequirements();
|
|
|
226 |
if (!$meets_requirements) {
|
|
|
227 |
return false;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
$valid_switches = $this->valid_switches;
|
|
|
231 |
$switches = $this->switches;
|
|
|
232 |
$args = $this->args;
|
|
|
233 |
$fetchmode = $this->fetchmode;
|
|
|
234 |
$invalid_switches = array();
|
|
|
235 |
$_switches = '';
|
|
|
236 |
|
|
|
237 |
foreach ($switches as $switch => $val) {
|
|
|
238 |
if (in_array($switch, $valid_switches)) {
|
|
|
239 |
$switch = str_replace('_', '-', $switch);
|
|
|
240 |
switch ($switch) {
|
|
|
241 |
case 'revision':
|
|
|
242 |
case 'username':
|
|
|
243 |
case 'password':
|
|
|
244 |
case 'diff3-cmd':
|
|
|
245 |
case 'config-dir':
|
|
|
246 |
$_switches .= "--$switch $val ";
|
|
|
247 |
break;
|
|
|
248 |
case 'r':
|
|
|
249 |
$_switches .= "-$switch $val ";
|
|
|
250 |
break;
|
|
|
251 |
case 'N':
|
|
|
252 |
case 'q':
|
|
|
253 |
if ($val === true) {
|
|
|
254 |
$_switches .= "-$switch ";
|
|
|
255 |
}
|
|
|
256 |
break;
|
|
|
257 |
case 'non-recursive':
|
|
|
258 |
case 'non-interactive':
|
|
|
259 |
case 'no-auth-cache':
|
|
|
260 |
if ($val === true) {
|
|
|
261 |
$_switches .= "--$switch ";
|
|
|
262 |
}
|
|
|
263 |
break;
|
|
|
264 |
default:
|
|
|
265 |
// that's all, folks!
|
|
|
266 |
break;
|
|
|
267 |
}
|
|
|
268 |
} else {
|
|
|
269 |
$invalid_switches[] = $switch;
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
// We don't want interactive mode
|
|
|
273 |
if (strpos($_switches, 'non-interactive') === false) {
|
|
|
274 |
$_switches .= '--non-interactive ';
|
|
|
275 |
}
|
|
|
276 |
$_switches = trim($_switches);
|
|
|
277 |
$this->_switches = $_switches;
|
|
|
278 |
|
|
|
279 |
$cmd = "$this->svn_path $this->_svn_cmd $_switches";
|
|
|
280 |
if (!empty($args)) {
|
|
|
281 |
$cmd .= ' '. join(' ', $args);
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
$this->_prepped_cmd = $cmd;
|
|
|
285 |
$this->prepared = true;
|
|
|
286 |
|
|
|
287 |
$invalid = count($invalid_switches);
|
|
|
288 |
if ($invalid > 0) {
|
|
|
289 |
$params['was'] = 'was';
|
|
|
290 |
$params['is_invalid_switch'] = 'is an invalid switch';
|
|
|
291 |
if ($invalid > 1) {
|
|
|
292 |
$params['was'] = 'were';
|
|
|
293 |
$params['is_invalid_switch'] = 'are invalid switches';
|
|
|
294 |
}
|
|
|
295 |
$params['list'] = $invalid_switches;
|
|
|
296 |
$params['switches'] = $switches;
|
|
|
297 |
$params['_svn_cmd'] = ucfirst($this->_svn_cmd);
|
|
|
298 |
$this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
|
|
|
299 |
}
|
|
|
300 |
return true;
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
// }}}
|
|
|
304 |
// {{{ parseOutput()
|
|
|
305 |
|
|
|
306 |
/**
|
|
|
307 |
* Handles output parsing of standard and verbose output of command.
|
|
|
308 |
*
|
|
|
309 |
* @param array $out Array of output captured by exec command in {@link run}.
|
|
|
310 |
* @return mixed Returns output requested by fetchmode (if available), or raw output
|
|
|
311 |
* if desired fetchmode is not available.
|
|
|
312 |
* @access public
|
|
|
313 |
*/
|
|
|
314 |
function parseOutput($out)
|
|
|
315 |
{
|
|
|
316 |
$fetchmode = $this->fetchmode;
|
|
|
317 |
switch($fetchmode) {
|
|
|
318 |
case VERSIONCONTROL_SVN_FETCHMODE_RAW:
|
|
|
319 |
return join("\n", $out);
|
|
|
320 |
break;
|
|
|
321 |
case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
|
|
|
322 |
case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
|
|
|
323 |
// Temporary, see parseOutputArray below
|
|
|
324 |
return join("\n", $out);
|
|
|
325 |
break;
|
|
|
326 |
case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
|
|
|
327 |
// Temporary, will return object-ified array from
|
|
|
328 |
// parseOutputArray
|
|
|
329 |
return join("\n", $out);
|
|
|
330 |
break;
|
|
|
331 |
case VERSIONCONTROL_SVN_FETCHMODE_XML:
|
|
|
332 |
// Temporary, will eventually build an XML string
|
|
|
333 |
// with XML_Util or XML_Tree
|
|
|
334 |
return join("\n", $out);
|
|
|
335 |
break;
|
|
|
336 |
default:
|
|
|
337 |
// What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
|
|
|
338 |
return join("\n", $out);
|
|
|
339 |
break;
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
/**
|
|
|
344 |
* Helper method for parseOutput that parses output into an associative array
|
|
|
345 |
*
|
|
|
346 |
* @todo Finish this method! : )
|
|
|
347 |
*/
|
|
|
348 |
function parseOutputArray($out)
|
|
|
349 |
{
|
|
|
350 |
$parsed = array();
|
|
|
351 |
}
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
// }}}
|
|
|
355 |
?>
|