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: Switch.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 Switch command manager class
55
 *
56
 * Update the working copy to a different URL.
57
 *
58
 * From 'svn switch --help':
59
 *
60
 * usage: 1. switch URL [PATH]
61
 *        2. switch --relocate FROM TO [PATH...]
62
 *
63
 *   1. Update the working copy to mirror a new URL within the repository.
64
 *      This behaviour is similar to 'svn update', and is the way to
65
 *      move a working copy to a branch or tag within the same repository.
66
 *
67
 *   2. Rewrite working copy URL metadata to reflect a syntactic change only.
68
 *      This is used when repository's root URL changes (such as a schema
69
 *      or hostname change) but your working copy still reflects the same
70
 *      directory within the same repository.
71
 *
72
 * Conversion of the above usage example to VersionControl_SVN_Switch:
73
 *
74
 * <code>
75
 * <?php
76
 * require_once 'VersionControl/SVN.php';
77
 *
78
 * // Setup error handling -- always a good idea!
79
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
80
 *
81
 * // Set up runtime options. Will be passed to all
82
 * // subclasses.
83
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
84
 *
85
 * $switches = array('relocate' => 'true');
86
 * $args = array(
87
 *  'svn://svn.example.com/repos/TestProj/trunk',
88
 *  'svn://svn.example.com/repos/TestProj_Fork/trunk',
89
 *  '/path/to/working/copy'
90
 * );
91
 *
92
 * $svn = VersionControl_SVN::factory(array('switch'), $options);
93
 * print_r($svn->switch->run($args));
94
 *
95
 * if (count($errs = $svnstack->getErrors())) {
96
 *     foreach ($errs as $err) {
97
 *         echo '<br />'.$err['message']."<br />\n";
98
 *         echo "Command used: " . $err['params']['cmd'];
99
 *     }
100
 * }
101
 * ?>
102
 * </code>
103
 *
104
 *
105
 * $switches is an array containing one or more command line options
106
 * defined by the following associative keys:
107
 *
108
 * <code>
109
 *
110
 * $switches = array(
111
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
112
 *                        A revision argument can be one of:
113
 *                           NUMBER       revision number
114
 *                           "{" DATE "}" revision at start of the date
115
 *                           "HEAD"       latest in repository
116
 *                           "BASE"       base rev of item's working copy
117
 *                           "COMMITTED"  last commit at or before BASE
118
 *                           "PREV"       revision just before COMMITTED',
119
 *                      // either 'r' or 'revision' may be used
120
 *  'N'             =>  true|false,
121
 *                      // operate on single directory only
122
 *  'non-recursive' =>  true|false,
123
 *                      // operate on single directory only
124
 *  'q [quiet]'     =>  true|false,
125
 *                      // print as little as possible
126
 *  'diff3-cmd'     =>  'ARG',
127
 *                      // use ARG as merge command
128
 *  'relocate'      =>  true|false,
129
 *                      // relocate via URL-rewriting
130
 *  'username'      =>  'Subversion repository login',
131
 *  'password'      =>  'Subversion repository password',
132
 *  'no-auth-cache' =>  true|false,
133
 *                      // Do not cache authentication tokens
134
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
135
 * );
136
 *
137
 * </code>
138
 *
139
 * Note: Subversion does not offer an XML output option for this subcommand
140
 *
141
 * The non-interactive option available on the command-line
142
 * svn client may also be set (true|false), but it is set to true by default.
143
 *
144
 *
145
 * @package  VersionControl_SVN
146
 * @version  0.3.4
147
 * @category SCM
148
 * @author   Clay Loveless <clay@killersoft.com>
149
 */
150
class VersionControl_SVN_Switch extends VersionControl_SVN
151
{
152
    /**
153
     * Valid switches for svn switch
154
     *
155
     * @var     array
156
     * @access  public
157
     */
158
    var $valid_switches = array('r',
159
                                'revision',
160
                                'N',
161
                                'non-recursive',
162
                                'non_recursive',
163
                                'q',
164
                                'quiet',
165
                                'diff3-cmd',
166
                                'relocate',
167
                                'username',
168
                                'password',
169
                                'no-auth-cache',
170
                                'no_auth_cache',
171
                                'non-interactive',
172
                                'non_interactive',
173
                                'config-dir',
174
                                'config_dir'
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 = 1;
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 'relocate':
258
                    case 'non-recursive':
259
                    case 'non-interactive':
260
                    case 'no-auth-cache':
261
                        if ($val === true) {
262
                            $_switches .= "--$switch ";
263
                        }
264
                        break;
265
                    default:
266
                        // that's all, folks!
267
                        break;
268
                }
269
            } else {
270
                $invalid_switches[] = $switch;
271
            }
272
        }
273
        // We don't want interactive mode
274
        if (strpos($_switches, 'non-interactive') === false) {
275
            $_switches .= '--non-interactive ';
276
        }
277
        $_switches = trim($_switches);
278
        $this->_switches = $_switches;
279
 
280
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
281
        if (!empty($args)) {
282
            $cmd .= ' '. join(' ', $args);
283
        }
284
 
285
        $this->_prepped_cmd = $cmd;
286
        $this->prepared = true;
287
 
288
        $invalid = count($invalid_switches);
289
        if ($invalid > 0) {
290
            $params['was'] = 'was';
291
            $params['is_invalid_switch'] = 'is an invalid switch';
292
            if ($invalid > 1) {
293
                $params['was'] = 'were';
294
                $params['is_invalid_switch'] = 'are invalid switches';
295
            }
296
            $params['list'] = $invalid_switches;
297
            $params['switches'] = $switches;
298
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
299
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
300
        }
301
        return true;
302
    }
303
 
304
    // }}}
305
    // {{{ parseOutput()
306
 
307
    /**
308
     * Handles output parsing of standard and verbose output of command.
309
     *
310
     * @param   array   $out    Array of output captured by exec command in {@link run}.
311
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
312
     *                  if desired fetchmode is not available.
313
     * @access  public
314
     */
315
    function parseOutput($out)
316
    {
317
        $fetchmode = $this->fetchmode;
318
        switch($fetchmode) {
319
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
320
                return join("\n", $out);
321
                break;
322
            case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
323
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
324
                // Temporary, see parseOutputArray below
325
                return join("\n", $out);
326
                break;
327
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
328
                // Temporary, will return object-ified array from
329
                // parseOutputArray
330
                return join("\n", $out);
331
                break;
332
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
333
                // Temporary, will eventually build an XML string
334
                // with XML_Util or XML_Tree
335
                return join("\n", $out);
336
                break;
337
            default:
338
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
339
                return join("\n", $out);
340
                break;
341
        }
342
    }
343
 
344
    /**
345
     * Helper method for parseOutput that parses output into an associative array
346
     *
347
     * @todo Finish this method! : )
348
     */
349
    function parseOutputArray($out)
350
    {
351
        $parsed = array();
352
    }
353
}
354
 
355
// }}}
356
?>