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: Import.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 Import command manager class
55
 *
56
 * Recursively commit an unversioned file or tree into the repository
57
 *
58
 * Commits must include a commit message option (either with 'm', 'message', 'file' or 'F'
59
 * keys), but the message itself may be blank.
60
 *
61
 * If the 'path' argument is omitted, '.' is assumed. Parent directories are
62
 * created as necessary in the repository.
63
 *
64
 * $switches is an array containing one or more command line options
65
 * defined by the following associative keys:
66
 *
67
 * <code>
68
 *
69
 * $switches = array(
70
 *  'm [message]'   =>  'Specified commit message',
71
 *                      // either 'm' or 'message' may be used
72
 *  'F [file]'      =>  'Read commit message data from specified file',
73
 *                      // either 'F' or 'file' may be used
74
 *  'q [quiet]'     =>  true|false,
75
 *                      // prints as little as possible
76
 *  'N'             =>  true|false,
77
 *                      // operate on single directory only
78
 *  'non-recursive' =>  true|false,
79
 *                      // operate on single directory only
80
 *  'force-log'     =>  true|false,
81
 *                      // force validity of log message source
82
 *  'username'      =>  'Subversion repository login',
83
 *  'password'      =>  'Subversion repository password',
84
 *  'no-auth-cache' =>  true|false,
85
 *                      // Do not cache authentication tokens
86
 *  'encoding'      =>  'ARG',
87
 *                      // treat value as being in charset encoding ARG
88
 *  'auto-props'    =>  true|false,
89
 *                      // enable automatic properties. Setting to false IS NOT the same
90
 *                      // as setting no-auto-props to true.
91
 *  'no-auto-props' =>  true|false,
92
 *                      // disable automatic properties. Setting to false IS NOT the same
93
 *                      // as setting auto-props to true.
94
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
95
 * );
96
 *
97
 * </code>
98
 *
99
 * Note: Subversion does not offer an XML output option for this subcommand
100
 *
101
 * The non-interactive option available on the command-line
102
 * svn client may also be set (true|false), but it is set to true by default.
103
 *
104
 * The editor-cmd option available on the command-line svn client is not available
105
 * since this class does not operate as an interactive shell session.
106
 *
107
 * Usage example:
108
 * <code>
109
 * <?php
110
 * require_once 'VersionControl/SVN.php';
111
 *
112
 * // Setup error handling -- always a good idea!
113
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
114
 *
115
 * // Set up runtime options. Will be passed to all
116
 * // subclasses.
117
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
118
 *
119
 * // Pass array of subcommands we need to factory
120
 * $svn = VersionControl_SVN::factory(array('import'), $options);
121
 *
122
 * // Define any switches and aguments we may need
123
 * $switches = array('m' => 'Initial Import - and awwwaaay we go!',
124
 *                   'username' => 'user', 'password' => 'pass');
125
 * $args = array('/path/to/working_copy',
126
 *               'svn://svn.example.com/repos/NewProject/');
127
 *
128
 * // Run command
129
 * if ($output = $svn->import->run($args, $switches)) {
130
 *     print_r($output);
131
 * } else {
132
 *     if (count($errs = $svnstack->getErrors())) {
133
 *         foreach ($errs as $err) {
134
 *             echo '<br />'.$err['message']."<br />\n";
135
 *             echo "Command used: " . $err['params']['cmd'];
136
 *         }
137
 *     }
138
 * }
139
 * ?>
140
 * </code>
141
 *
142
 * @package  VersionControl_SVN
143
 * @version  0.3.4
144
 * @category SCM
145
 * @author   Clay Loveless <clay@killersoft.com>
146
 */
147
class VersionControl_SVN_Import extends VersionControl_SVN
148
{
149
    /**
150
     * Valid switches for svn import
151
     *
152
     * @var     array
153
     * @access  public
154
     */
155
    var $valid_switches = array('m',
156
                                'message',
157
                                'F',
158
                                'file',
159
                                'q',
160
                                'quiet',
161
                                'N',
162
                                'non-recursive',
163
                                'non_recursive',
164
                                'username',
165
                                'password',
166
                                'no-auth-cache',
167
                                'no_auth_cache',
168
                                'non-interactive',
169
                                'non_interactive',
170
                                'force-log',
171
                                'force_log',
172
                                'encoding',
173
                                'auto_props',
174
                                'no-auto-props',
175
                                'no_auto_props',
176
                                'config-dir',
177
                                'config_dir'
178
                                );
179
 
180
 
181
    /**
182
     * Command-line arguments that should be passed
183
     * <b>outside</b> of those specified in {@link switches}.
184
     *
185
     * @var     array
186
     * @access  public
187
     */
188
    var $args = array();
189
 
190
    /**
191
     * Minimum number of args required by this subcommand.
192
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
193
     * Subversion Complete Reference for details on arguments for this subcommand.
194
     * @var     int
195
     * @access  public
196
     */
197
    var $min_args = 1;
198
 
199
    /**
200
     * Switches required by this subcommand.
201
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
202
     * Subversion Complete Reference for details on arguments for this subcommand.
203
     * @var     array
204
     * @access  public
205
     */
206
    var $required_switches = array('m|message|F|file');
207
 
208
    /**
209
     * Use exec or passthru to get results from command.
210
     * @var     bool
211
     * @access  public
212
     */
213
    var $passthru = false;
214
 
215
    /**
216
     * Prepare the svn subcommand switches.
217
     *
218
     * Defaults to non-interactive mode, and will auto-set the
219
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
220
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
221
     *
222
     * @param   void
223
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
224
     *                 for error details, if any.
225
     */
226
    function prepare()
227
    {
228
        $meets_requirements = $this->checkCommandRequirements();
229
        if (!$meets_requirements) {
230
            return false;
231
        }
232
 
233
        $valid_switches     = $this->valid_switches;
234
        $switches           = $this->switches;
235
        $args               = $this->args;
236
        $fetchmode          = $this->fetchmode;
237
        $invalid_switches   = array();
238
        $_switches          = '';
239
 
240
        foreach ($switches as $switch => $val) {
241
            if (in_array($switch, $valid_switches)) {
242
                $switch = str_replace('_', '-', $switch);
243
                switch ($switch) {
244
                    case 'username':
245
                    case 'password':
246
                    case 'encoding':
247
                    case 'config-dir':
248
                        $_switches .= "--$switch $val ";
249
                        break;
250
                    case 'F':
251
                    case 'm':
252
                        $_switches .= "-$switch \"$val\" ";
253
                        break;
254
                    case 'file':
255
                    case 'message':
256
                        $_switches .= "--$switch \"$val\" ";
257
                        break;
258
                    case 'quiet':
259
                    case 'non-recursive':
260
                    case 'no-auth-cache':
261
                    case 'force-log':
262
                        if ($val === true) {
263
                            $_switches .= "--$switch ";
264
                        }
265
                        break;
266
                    case 'q':
267
                    case 'N':
268
                        if ($val === true) {
269
                            $_switches .= "-$switch ";
270
                        }
271
                        break;
272
                    default:
273
                        // that's all, folks!
274
                        break;
275
                }
276
            } else {
277
                $invalid_switches[] = $switch;
278
            }
279
        }
280
 
281
        // We don't want interactive mode
282
        if (strpos($_switches, 'non-interactive') === false) {
283
            $_switches .= '--non-interactive ';
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
?>