Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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: Move.php 286753 2009-08-03 19:37:03Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Move command manager class
55
 *
56
 * Move and/or rename something in working copy or repository.
57
 *
58
 * Note: this subcommand is equivalent to a 'copy' and 'delete'.
59
 *
60
 *   SRC and DST can both be working copy (WC) paths or URLs:
61
 *     WC  -> WC:   move and schedule for addition (with history)
62
 *     URL -> URL:  complete server-side rename.
63
 *
64
 * Copies must include a message option (either with 'm', 'message', 'file' or 'F'
65
 * keys), but the message itself may be blank.
66
 *
67
 * $switches is an array containing one or more command line options
68
 * defined by the following associative keys:
69
 *
70
 * <code>
71
 *
72
 * $switches = array(
73
 *  'm [message]'   =>  'Specified commit message',
74
 *                      // either 'm' or 'message' may be used
75
 *  'F [file]'      =>  'Read commit message data from specified file',
76
 *                      // either 'F' or 'file' may be used
77
 *  'q [quiet]'     =>  true|false,
78
 *                      // prints as little as possible
79
 *  'force'         =>  true|false,
80
 *                      // force operation to run
81
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
82
 *                        A revision argument can be one of:
83
 *                           NUMBER       revision number
84
 *                           "{" DATE "}" revision at start of the date
85
 *                           "HEAD"       latest in repository
86
 *                           "BASE"       base rev of item's working copy
87
 *                           "COMMITTED"  last commit at or before BASE
88
 *                           "PREV"       revision just before COMMITTED',
89
 *                      // either 'r' or 'revision' may be used
90
 *  'force-log'     =>  true|false,
91
 *                      // force validity of log message source
92
 *  'username'      =>  'Subversion repository login',
93
 *  'password'      =>  'Subversion repository password',
94
 *  'no-auth-cache' =>  true|false,
95
 *                      // Do not cache authentication tokens
96
 *  'encoding'      =>  'ARG',
97
 *                      // treat value as being in charset encoding ARG
98
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
99
 * );
100
 *
101
 * </code>
102
 *
103
 * Note: Subversion does not offer an XML output option for this subcommand
104
 *
105
 * The non-interactive option available on the command-line
106
 * svn client may also be set (true|false), but it is set to true by default.
107
 *
108
 * The editor-cmd option available on the command-line svn client is not available
109
 * since this class does not operate as an interactive shell session.
110
 *
111
 * Usage example:
112
 * <code>
113
 * <?php
114
 * require_once 'VersionControl/SVN.php';
115
 *
116
 * // Setup error handling -- always a good idea!
117
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
118
 *
119
 * // Set up runtime options. Will be passed to all
120
 * // subclasses.
121
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
122
 *
123
 * // Pass array of subcommands we need to factory
124
 * $svn = VersionControl_SVN::factory(array('move'), $options);
125
 *
126
 * // Define any switches and aguments we may need
127
 * $switches = array('m' => 'Whoops! How did this get here?', 'username' => 'user', 'password' => 'pass');
128
 * $args = array(
129
 *      'svn://svn.example.com/repos/TestProj/trunk/somedir',           // SRC
130
 *      'svn://svn.example.com/repos/TestProj/trunk/lowerlevel/somedir' // DST
131
 * );
132
 *
133
 * // Run command
134
 * if ($output = $svn->move->run($args, $switches)) {
135
 *     print_r($output);
136
 * } else {
137
 *     if (count($errs = $svnstack->getErrors())) {
138
 *         foreach ($errs as $err) {
139
 *             echo '<br />'.$err['message']."<br />\n";
140
 *             echo "Command used: " . $err['params']['cmd'];
141
 *         }
142
 *     }
143
 * }
144
 * ?>
145
 * </code>
146
 *
147
 * @package  VersionControl_SVN
148
 * @version  0.3.4
149
 * @category SCM
150
 * @author   Clay Loveless <clay@killersoft.com>
151
 */
152
class VersionControl_SVN_Move extends VersionControl_SVN
153
{
154
    /**
155
     * Valid switches for svn move
156
     *
157
     * @var     array
158
     * @access  public
159
     */
160
    var $valid_switches = array('m',
161
                                'message',
162
                                'F',
163
                                'file',
164
                                'r',
165
                                'revision',
166
                                'q',
167
                                'quiet',
168
                                'force',
169
                                'username',
170
                                'password',
171
                                'no-auth-cache',
172
                                'no_auth_cache',
173
                                'non-interactive',
174
                                'non_interactive',
175
                                'config-dir',
176
                                'config_dir',
177
                                'encoding',
178
                                'force-log',
179
                                'force_log'
180
                                );
181
 
182
    /**
183
     * Command-line arguments that should be passed
184
     * <b>outside</b> of those specified in {@link switches}.
185
     *
186
     * @var     array
187
     * @access  public
188
     */
189
    var $args = array();
190
 
191
    /**
192
     * Minimum number of args required by this subcommand.
193
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
194
     * Subversion Complete Reference for details on arguments for this subcommand.
195
     * @var     int
196
     * @access  public
197
     */
198
    var $min_args = 2;
199
 
200
    /**
201
     * Switches required by this subcommand.
202
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
203
     * Subversion Complete Reference for details on arguments for this subcommand.
204
     * @var     array
205
     * @access  public
206
     */
207
    var $required_switches = array('m|message|F|file');
208
 
209
    /**
210
     * Use exec or passthru to get results from command.
211
     * @var     bool
212
     * @access  public
213
     */
214
    var $passthru = false;
215
 
216
    /**
217
     * Prepare the svn subcommand switches.
218
     *
219
     * Defaults to non-interactive mode, and will auto-set the
220
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
221
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
222
     *
223
     * @param   void
224
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
225
     *                 for error details, if any.
226
     */
227
    function prepare()
228
    {
229
        $meets_requirements = $this->checkCommandRequirements();
230
        if (!$meets_requirements) {
231
            return false;
232
        }
233
 
234
        $valid_switches     = $this->valid_switches;
235
        $switches           = $this->switches;
236
        $args               = $this->args;
237
        $fetchmode          = $this->fetchmode;
238
        $invalid_switches   = array();
239
        $_switches          = '';
240
 
241
        foreach ($switches as $switch => $val) {
242
            if (in_array($switch, $valid_switches)) {
243
                $switch = str_replace('_', '-', $switch);
244
                switch ($switch) {
245
                    case 'revision':
246
                    case 'username':
247
                    case 'password':
248
                    case 'encoding':
249
                    case 'config-dir':
250
                        $_switches .= "--$switch $val ";
251
                        break;
252
                    case 'r':
253
                        $_switches .= "-$switch $val ";
254
                        break;
255
                    case 'F':
256
                    case 'm':
257
                        $_switches .= "-$switch \"$val\" ";
258
                        break;
259
                    case 'file':
260
                    case 'message':
261
                        $_switches .= "--$switch \"$val\" ";
262
                        break;
263
                    case 'quiet':
264
                    case 'force':
265
                    case 'non-interactive':
266
                    case 'force-log':
267
                    case 'no-auth-cache':
268
                        if ($val === true) {
269
                            $_switches .= "--$switch ";
270
                        }
271
                        break;
272
                    case 'q':
273
                        if ($val === true) {
274
                            $_switches .= "-$switch ";
275
                        }
276
                        break;
277
                    default:
278
                        // that's all, folks!
279
                        break;
280
                }
281
            } else {
282
                $invalid_switches[] = $switch;
283
            }
284
        }
285
 
286
        $_switches = trim($_switches);
287
        $this->_switches = $_switches;
288
 
289
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
290
        if (!empty($args)) {
291
            $cmd .= ' '. join(' ', $args);
292
        }
293
 
294
        $this->_prepped_cmd = $cmd;
295
        $this->prepared = true;
296
 
297
        $invalid = count($invalid_switches);
298
        if ($invalid > 0) {
299
            $params['was'] = 'was';
300
            $params['is_invalid_switch'] = 'is an invalid switch';
301
            if ($invalid > 1) {
302
                $params['was'] = 'were';
303
                $params['is_invalid_switch'] = 'are invalid switches';
304
            }
305
            $params['list'] = $invalid_switches;
306
            $params['switches'] = $switches;
307
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
308
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
309
        }
310
        return true;
311
    }
312
 
313
    // }}}
314
    // {{{ parseOutput()
315
 
316
    /**
317
     * Handles output parsing of standard and verbose output of command.
318
     *
319
     * @param   array   $out    Array of output captured by exec command in {@link run}.
320
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
321
     *                  if desired fetchmode is not available.
322
     * @access  public
323
     */
324
    function parseOutput($out)
325
    {
326
        $fetchmode = $this->fetchmode;
327
        switch($fetchmode) {
328
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
329
                return join("\n", $out);
330
                break;
331
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
332
                // Temporary, see parseOutputArray below
333
                return join("\n", $out);
334
                break;
335
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
336
                // Temporary, will return object-ified array from
337
                // parseOutputArray
338
                return join("\n", $out);
339
                break;
340
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
341
                // Temporary, will eventually build an XML string
342
                // with XML_Util or XML_Tree
343
                return join("\n", $out);
344
                break;
345
            default:
346
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
347
                return join("\n", $out);
348
                break;
349
        }
350
    }
351
 
352
    /**
353
     * Helper method for parseOutput that parses output into an associative array
354
     *
355
     * @todo Finish this method! : )
356
     */
357
    function parseOutputArray($out)
358
    {
359
        $parsed = array();
360
    }
361
}
362
 
363
// }}}
364
?>