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: Merge.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 Merge command manager class
55
 *
56
 * Apply the differences between two sources to a working copy path.
57
 *
58
 * From 'svn merge --help':
59
 *
60
 * usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
61
 *        2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
62
 *        3. merge -r N:M SOURCE [WCPATH]
63
 *
64
 *   1. In the first form, the source URLs are specified at revisions
65
 *      N and M.  These are the two sources to be compared.  The revisions
66
 *      default to HEAD if omitted.
67
 *
68
 *   2. In the second form, the URLs corresponding to the source working
69
 *      copy paths define the sources to be compared.  The revisions must
70
 *      be specified.
71
 *
72
 *   3. In the third form, SOURCE can be a URL, or working copy item
73
 *      in which case the corresponding URL is used.  This URL, at
74
 *      revisions N and M, defines the two sources to be compared.
75
 *
76
 *   WCPATH is the working copy path that will receive the changes.
77
 *   If WCPATH is omitted, a default value of '.' is assumed, unless
78
 *   the sources have identical basenames that match a file within '.':
79
 *   in which case, the differences will be applied to that file.
80
 *
81
 * Conversion of the above usage examples to VersionControl_SVN_Merge:
82
 *
83
 * Example 1:
84
 * <code>
85
 * <?php
86
 * require_once 'VersionControl/SVN.php';
87
 *
88
 * // Setup error handling -- always a good idea!
89
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
90
 *
91
 * // Set up runtime options. Will be passed to all
92
 * // subclasses.
93
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
94
 *
95
 * $args = array(
96
 *  'svn://svn.example.com/repos/TestProj/trunk/example.php@4',   // sourceurl1
97
 *  'svn://svn.example.com/repos/TestProj/branch/example.php@15', // sourceurl2
98
 *  '/path/to/working/copy'                                       // wcpath
99
 * );
100
 *
101
 * $svn = VersionControl_SVN::factory(array('merge'), $options);
102
 * print_r($svn->merge->run($args));
103
 *
104
 * if (count($errs = $svnstack->getErrors())) {
105
 *     foreach ($errs as $err) {
106
 *         echo '<br />'.$err['message']."<br />\n";
107
 *         echo "Command used: " . $err['params']['cmd'];
108
 *     }
109
 * }
110
 * ?>
111
 * </code>
112
 *
113
 * Example 2:
114
 * <code>
115
 * <?php
116
 * require_once 'VersionControl/SVN.php';
117
 *
118
 * // Setup error handling -- always a good idea!
119
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
120
 *
121
 * // Set up runtime options. Will be passed to all
122
 * // subclasses.
123
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
124
 *
125
 * $args = array(
126
 *  '/path/to/working/copy/trunk/example.php@4',    // wcpath1
127
 *  '/path/to/working/copy/branch/example.php@15'   // wcpath2
128
 * );
129
 *
130
 * $svn = VersionControl_SVN::factory(array('merge'), $options);
131
 * print_r($svn->merge->run($args));
132
 *
133
 * if (count($errs = $svnstack->getErrors())) {
134
 *     foreach ($errs as $err) {
135
 *         echo '<br />'.$err['message']."<br />\n";
136
 *         echo "Command used: " . $err['params']['cmd'];
137
 *     }
138
 * }
139
 * ?>
140
 * </code>
141
 *
142
 * Example 3:
143
 * <code>
144
 * <?php
145
 * require_once 'VersionControl/SVN.php';
146
 *
147
 * // Setup error handling -- always a good idea!
148
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
149
 *
150
 * // Set up runtime options. Will be passed to all
151
 * // subclasses.
152
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
153
 *
154
 * $switches = array('r' => '5:8');
155
 * $args = array('svn://svn.example.com/repos/TestProj/trunk/example.php');
156
 *
157
 * $svn = VersionControl_SVN::factory(array('merge'), $options);
158
 * print_r($svn->merge->run($args, $switches));
159
 *
160
 * if (count($errs = $svnstack->getErrors())) {
161
 *     foreach ($errs as $err) {
162
 *         echo '<br />'.$err['message']."<br />\n";
163
 *         echo "Command used: " . $err['params']['cmd'];
164
 *     }
165
 * }
166
 * ?>
167
 * </code>
168
 *
169
 * $switches is an array containing one or more command line options
170
 * defined by the following associative keys:
171
 *
172
 * <code>
173
 *
174
 * $switches = array(
175
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
176
 *                        A revision argument can be one of:
177
 *                           NUMBER       revision number
178
 *                           "{" DATE "}" revision at start of the date
179
 *                           "HEAD"       latest in repository
180
 *                           "BASE"       base rev of item's working copy
181
 *                           "COMMITTED"  last commit at or before BASE
182
 *                           "PREV"       revision just before COMMITTED',
183
 *                      // either 'r' or 'revision' may be used
184
 *  'q [quiet]'     =>  true|false,
185
 *                      // print as little as possible
186
 *  'dry-run'       =>  true|false,
187
 *                      // try operation but make no changes
188
 *  'force'         =>  true|false,
189
 *                      // force operation to run
190
 *  'N'             =>  true|false,
191
 *                      // operate on single directory only
192
 *  'non-recursive' =>  true|false,
193
 *                      // operate on single directory only
194
 *  'diff3-cmd'     =>  'ARG',
195
 *                      // use ARG as merge command
196
 *  'ignore-ancestry' => true|false,
197
 *                      // ignore ancestry when calculating merges
198
 *  'username'      =>  'Subversion repository login',
199
 *  'password'      =>  'Subversion repository password',
200
 *  'no-auth-cache' =>  true|false,
201
 *                      // Do not cache authentication tokens
202
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
203
 * );
204
 *
205
 * </code>
206
 *
207
 * Note: Subversion does not offer an XML output option for this subcommand
208
 *
209
 * The non-interactive option available on the command-line
210
 * svn client may also be set (true|false), but it is set to true by default.
211
 *
212
 *
213
 * @package  VersionControl_SVN
214
 * @version  0.3.4
215
 * @category SCM
216
 * @author   Clay Loveless <clay@killersoft.com>
217
 */
218
class VersionControl_SVN_Merge extends VersionControl_SVN
219
{
220
    /**
221
     * Valid switches for svn merge
222
     *
223
     * @var     array
224
     * @access  public
225
     */
226
    var $valid_switches = array('r',
227
                                'revision',
228
                                'N',
229
                                'non-recursive',
230
                                'non_recursive',
231
                                'q',
232
                                'quiet',
233
                                'force',
234
                                'dry-run',
235
                                'dry_run',
236
                                'diff3-cmd',
237
                                'ignore-ancestry',
238
                                'ignore_ancestry',
239
                                'username',
240
                                'password',
241
                                'no-auth-cache',
242
                                'no_auth_cache',
243
                                'non-interactive',
244
                                'non_interactive',
245
                                'config-dir',
246
                                'config_dir'
247
                                );
248
 
249
 
250
    /**
251
     * Command-line arguments that should be passed
252
     * <b>outside</b> of those specified in {@link switches}.
253
     *
254
     * @var     array
255
     * @access  public
256
     */
257
    var $args = array();
258
 
259
    /**
260
     * Minimum number of args required by this subcommand.
261
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
262
     * Subversion Complete Reference for details on arguments for this subcommand.
263
     * @var     int
264
     * @access  public
265
     */
266
    var $min_args = 1;
267
 
268
    /**
269
     * Switches required by this subcommand.
270
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
271
     * Subversion Complete Reference for details on arguments for this subcommand.
272
     * @var     array
273
     * @access  public
274
     */
275
    var $required_switches = array();
276
 
277
    /**
278
     * Use exec or passthru to get results from command.
279
     * @var     bool
280
     * @access  public
281
     */
282
    var $passthru = false;
283
 
284
    /**
285
     * Prepare the svn subcommand switches.
286
     *
287
     * Defaults to non-interactive mode, and will auto-set the
288
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
289
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
290
     *
291
     * @param   void
292
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
293
     *                 for error details, if any.
294
     */
295
    function prepare()
296
    {
297
        $meets_requirements = $this->checkCommandRequirements();
298
        if (!$meets_requirements) {
299
            return false;
300
        }
301
 
302
        $valid_switches     = $this->valid_switches;
303
        $switches           = $this->switches;
304
        $args               = $this->args;
305
        $fetchmode          = $this->fetchmode;
306
        $invalid_switches   = array();
307
        $_switches          = '';
308
 
309
        foreach ($switches as $switch => $val) {
310
            if (in_array($switch, $valid_switches)) {
311
                $switch = str_replace('_', '-', $switch);
312
                switch ($switch) {
313
                    case 'revision':
314
                    case 'username':
315
                    case 'password':
316
                    case 'diff3-cmd':
317
                    case 'config-dir':
318
                        $_switches .= "--$switch $val ";
319
                        break;
320
                    case 'r':
321
                        $_switches .= "-$switch $val ";
322
                        break;
323
                    case 'N':
324
                    case 'q':
325
                        if ($val === true) {
326
                            $_switches .= "-$switch ";
327
                        }
328
                        break;
329
                    case 'force':
330
                    case 'dry-run':
331
                    case 'non-recursive':
332
                    case 'non-interactive':
333
                    case 'ignore-ancestry':
334
                    case 'no-auth-cache':
335
                        if ($val === true) {
336
                            $_switches .= "--$switch ";
337
                        }
338
                        break;
339
                    default:
340
                        // that's all, folks!
341
                        break;
342
                }
343
            } else {
344
                $invalid_switches[] = $switch;
345
            }
346
        }
347
        // We don't want interactive mode
348
        if (strpos($_switches, 'non-interactive') === false) {
349
            $_switches .= '--non-interactive ';
350
        }
351
        $_switches = trim($_switches);
352
        $this->_switches = $_switches;
353
 
354
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
355
        if (!empty($args)) {
356
            $cmd .= ' '. join(' ', $args);
357
        }
358
 
359
        $this->_prepped_cmd = $cmd;
360
        $this->prepared = true;
361
 
362
        $invalid = count($invalid_switches);
363
        if ($invalid > 0) {
364
            $params['was'] = 'was';
365
            $params['is_invalid_switch'] = 'is an invalid switch';
366
            if ($invalid > 1) {
367
                $params['was'] = 'were';
368
                $params['is_invalid_switch'] = 'are invalid switches';
369
            }
370
            $params['list'] = $invalid_switches;
371
            $params['switches'] = $switches;
372
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
373
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
374
        }
375
        return true;
376
    }
377
 
378
    // }}}
379
    // {{{ parseOutput()
380
 
381
    /**
382
     * Handles output parsing of standard and verbose output of command.
383
     *
384
     * @param   array   $out    Array of output captured by exec command in {@link run}.
385
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
386
     *                  if desired fetchmode is not available.
387
     * @access  public
388
     */
389
    function parseOutput($out)
390
    {
391
        $fetchmode = $this->fetchmode;
392
        switch($fetchmode) {
393
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
394
                return join("\n", $out);
395
                break;
396
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
397
                // Temporary, see parseOutputArray below
398
                return join("\n", $out);
399
                break;
400
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
401
                // Temporary, will return object-ified array from
402
                // parseOutputArray
403
                return join("\n", $out);
404
                break;
405
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
406
                // Temporary, will eventually build an XML string
407
                // with XML_Util or XML_Tree
408
                return join("\n", $out);
409
                break;
410
            default:
411
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
412
                return join("\n", $out);
413
                break;
414
        }
415
    }
416
 
417
    /**
418
     * Helper method for parseOutput that parses output into an associative array
419
     *
420
     * @todo Finish this method! : )
421
     */
422
    function parseOutputArray($out)
423
    {
424
        $parsed = array();
425
    }
426
}
427
 
428
// }}}
429
?>