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