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: Commit.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 Commit command manager class
55
 *
56
 * Send changes from a working copy to 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
 * $switches is an array containing one or more command line options
62
 * defined by the following associative keys:
63
 *
64
 * <code>
65
 *
66
 * $switches = array(
67
 *  'm [message]'   =>  'Specified commit message',
68
 *                      // either 'm' or 'message' may be used
69
 *  'F [file]'      =>  'Read commit message data from specified file',
70
 *                      // either 'F' or 'file' may be used
71
 *  'q [quiet]'     =>  true|false,
72
 *                      // prints as little as possible
73
 *  'N'             =>  true|false,
74
 *                      // operate on single directory only
75
 *  'non-recursive' =>  true|false,
76
 *                      // operate on single directory only
77
 *  'targets'       =>  'ARG',
78
 *                      // pass contents of file ARG as additional args
79
 *  'force-log'     =>  true|false,
80
 *                      // force validity of log message source
81
 *  'username'      =>  'Subversion repository login',
82
 *  'password'      =>  'Subversion repository password',
83
 *  'no-auth-cache' =>  true|false,
84
 *                      // Do not cache authentication tokens
85
 *  'encoding'      =>  'ARG',
86
 *                      // treat value as being in charset encoding ARG
87
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
88
 * );
89
 *
90
 * </code>
91
 *
92
 * If a path is not used in the $args array, the default path of '.' will
93
 * be assumed.
94
 *
95
 * Note: Subversion does not offer an XML output option for this subcommand
96
 *
97
 * The non-interactive option available on the command-line
98
 * svn client may also be set (true|false), but it is set to true by default.
99
 *
100
 * The editor-cmd option available on the command-line svn client is not available
101
 * since this class does not operate as an interactive shell session.
102
 *
103
 * Usage example:
104
 * <code>
105
 * <?php
106
 * require_once 'VersionControl/SVN.php';
107
 *
108
 * // Setup error handling -- always a good idea!
109
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
110
 *
111
 * // Set up runtime options. Will be passed to all
112
 * // subclasses.
113
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
114
 *
115
 * // Pass array of subcommands we need to factory
116
 * $svn = VersionControl_SVN::factory(array('checkout'), $options);
117
 *
118
 * // Define any switches and aguments we may need
119
 * $switches = array('m' => 'Bug #1234 fixed!', 'username' => 'user', 'password' => 'pass');
120
 * $args = array('/path/to/working_copy');
121
 *
122
 * // Run command
123
 * if ($output = $svn->commit->run($args, $switches)) {
124
 *     print_r($output);
125
 * } else {
126
 *     if (count($errs = $svnstack->getErrors())) {
127
 *         foreach ($errs as $err) {
128
 *             echo '<br />'.$err['message']."<br />\n";
129
 *             echo "Command used: " . $err['params']['cmd'];
130
 *         }
131
 *     }
132
 * }
133
 * ?>
134
 * </code>
135
 *
136
 * @package  VersionControl_SVN
137
 * @version  0.3.4
138
 * @category SCM
139
 * @author   Clay Loveless <clay@killersoft.com>
140
 */
141
class VersionControl_SVN_Commit extends VersionControl_SVN
142
{
143
    /**
144
     * Valid switches for svn commit
145
     *
146
     * @var     array
147
     * @access  public
148
     */
149
    var $valid_switches = array('m',
150
                                'message',
151
                                'q',
152
                                'quiet',
153
                                'N',
154
                                'non-recursive',
155
                                'non_recursive',
156
                                'username',
157
                                'password',
158
                                'no-auth-cache',
159
                                'no_auth_cache',
160
                                'non-interactive',
161
                                'non_interactive',
162
                                'config-dir',
163
                                'config_dir',
164
                                'targets',
165
                                'file',
166
                                'F',
167
                                'encoding',
168
                                'force-log',
169
                                'force_log'
170
                                );
171
 
172
    /**
173
     * Command-line arguments that should be passed
174
     * <b>outside</b> of those specified in {@link switches}.
175
     *
176
     * @var     array
177
     * @access  public
178
     */
179
    var $args = array();
180
 
181
    /**
182
     * Minimum number of args required by this subcommand.
183
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
184
     * Subversion Complete Reference for details on arguments for this subcommand.
185
     * @var     int
186
     * @access  public
187
     */
188
    var $min_args = 0;
189
 
190
    /**
191
     * Switches 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     array
195
     * @access  public
196
     */
197
    var $required_switches = array('m|message|F|file');
198
 
199
    /**
200
     * Use exec or passthru to get results from command.
201
     * @var     bool
202
     * @access  public
203
     */
204
    var $passthru = false;
205
 
206
    /**
207
     * Prepare the svn subcommand switches.
208
     *
209
     * Defaults to non-interactive mode, and will auto-set the
210
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
211
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
212
     *
213
     * @param   void
214
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
215
     *                 for error details, if any.
216
     */
217
    function prepare()
218
    {
219
        $meets_requirements = $this->checkCommandRequirements();
220
        if (!$meets_requirements) {
221
            return false;
222
        }
223
 
224
        $valid_switches     = $this->valid_switches;
225
        $switches           = $this->switches;
226
        $args               = $this->args;
227
        $fetchmode          = $this->fetchmode;
228
        $invalid_switches   = array();
229
        $_switches          = '';
230
 
231
        foreach ($switches as $switch => $val) {
232
            if (in_array($switch, $valid_switches)) {
233
                $switch = str_replace('_', '-', $switch);
234
                switch ($switch) {
235
                    case 'username':
236
                    case 'password':
237
                    case 'encoding':
238
                    case 'config-dir':
239
                    case 'targets':
240
                        $_switches .= "--$switch $val ";
241
                        break;
242
                    case 'F':
243
                    case 'm':
244
                        $_switches .= "-$switch \"$val\" ";
245
                        break;
246
                    case 'file':
247
                    case 'message':
248
                        $_switches .= "--$switch \"$val\" ";
249
                        break;
250
                    case 'quiet':
251
                    case 'no-auth-cache':
252
                    case 'force-log':
253
                    case 'non-recursive':
254
                        if ($val === true) {
255
                            $_switches .= "--$switch ";
256
                        }
257
                        break;
258
                    case 'q':
259
                    case 'N':
260
                        if ($val === true) {
261
                            $_switches .= "-$switch ";
262
                        }
263
                        break;
264
                    default:
265
                        // that's all, folks!
266
                        break;
267
                }
268
            } else {
269
                $invalid_switches[] = $switch;
270
            }
271
        }
272
 
273
        // We don't want interactive mode
274
        if (strpos($_switches, 'non-interactive') === false) {
275
            $_switches .= '--non-interactive ';
276
        }
277
 
278
        $_switches = trim($_switches);
279
        $this->_switches = $_switches;
280
 
281
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
282
        if (!empty($args)) {
283
            $cmd .= ' '. join(' ', $args);
284
        }
285
 
286
        $this->_prepped_cmd = $cmd;
287
        $this->prepared = true;
288
 
289
        $invalid = count($invalid_switches);
290
        if ($invalid > 0) {
291
            $params['was'] = 'was';
292
            $params['is_invalid_switch'] = 'is an invalid switch';
293
            if ($invalid > 1) {
294
                $params['was'] = 'were';
295
                $params['is_invalid_switch'] = 'are invalid switches';
296
            }
297
            $params['list'] = $invalid_switches;
298
            $params['switches'] = $switches;
299
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
300
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
301
        }
302
        return true;
303
    }
304
 
305
    // }}}
306
    // {{{ parseOutput()
307
 
308
    /**
309
     * Handles output parsing of standard and verbose output of command.
310
     *
311
     * @param   array   $out    Array of output captured by exec command in {@link run}.
312
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
313
     *                  if desired fetchmode is not available.
314
     * @access  public
315
     */
316
    function parseOutput($out)
317
    {
318
        $fetchmode = $this->fetchmode;
319
        switch($fetchmode) {
320
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
321
                return join("\n", $out);
322
                break;
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
?>