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: Log.php 286956 2009-08-09 17:41:08Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Log command manager class
55
 *
56
 * $switches is an array containing one or more command line options
57
 * defined by the following associative keys:
58
 *
59
 * <code>
60
 *
61
 * $switches = array(
62
 *  'username'      =>  'Subversion repository login',
63
 *  'password'      =>  'Subversion repository password',
64
 *  'config-dir'    =>  'Path to a Subversion configuration directory',
65
 *                      // [DEFAULT: null]
66
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
67
 *                        A revision argument can be one of:
68
 *                           NUMBER       revision number
69
 *                           "{" DATE "}" revision at start of the date
70
 *                           "HEAD"       latest in repository
71
 *                           "BASE"       base rev of item's working copy
72
 *                           "COMMITTED"  last commit at or before BASE
73
 *                           "PREV"       revision just before COMMITTED',
74
 *                      // either 'r' or 'revision' may be used
75
 *  'q [quiet]'     =>  true|false,
76
 *                     // prints as little as possible
77
 *  'v [verbose]'   =>  true|false,
78
 *                      // prints extra information
79
 *  'targets'       =>  'ARG',
80
 *                      // passes contents of file ARG as additional arguments
81
 *  'stop-on-copy'  =>  true|false,
82
 *                      // do not cross copies while traversing history
83
 *  'incremental'   =>  true|false,
84
 *                      // gives output suitable for concatenation
85
 *  'xml'           =>  true|false,
86
 *                      // output in XML. Auto-set by fetchmodes VERSIONCONTROL_SVN_FETCHMODE_ASSOC,
87
 *                      // VERSIONCONTROL_SVN_FETCHMODE_XML and VERSIONCONTROL_SVN_FETCHMODE_OBJECT
88
 *  'no-auth-cache' =>  true|false
89
 *                      // Do not cache authentication tokens
90
 *
91
 * );
92
 *
93
 * </code>
94
 *
95
 * The non-interactive option available on the command-line
96
 * svn client may also be set (true|false), but it is set to true by default.
97
 *
98
 * Usage example:
99
 * <code>
100
 * <?php
101
 * require_once 'VersionControl/SVN.php';
102
 *
103
 * // Setup error handling -- always a good idea!
104
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
105
 *
106
 * // Set up runtime options. Will be passed to all
107
 * // subclasses.
108
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC);
109
 *
110
 * // Pass array of subcommands we need to factory
111
 * $svn = VersionControl_SVN::factory(array('log'), $options);
112
 *
113
 * // Define any switches and aguments we may need
114
 * $switches = array('verbose' => true);
115
 * $args = array('svn://svn.example.com/repos/TestProject');
116
 *
117
 * // Run command
118
 * if ($output = $svn->log->run($args, $switches)) {
119
 *     print_r($output);
120
 * } else {
121
 *     if (count($errs = $svnstack->getErrors())) {
122
 *         foreach ($errs as $err) {
123
 *             echo '<br />'.$err['message']."<br />\n";
124
 *             echo "Command used: " . $err['params']['cmd'];
125
 *         }
126
 *     }
127
 * }
128
 * ?>
129
 * </code>
130
 *
131
 * @package  VersionControl_SVN
132
 * @version  0.3.4
133
 * @category SCM
134
 * @author   Clay Loveless <clay@killersoft.com>
135
 */
136
class VersionControl_SVN_Log extends VersionControl_SVN
137
{
138
    /**
139
     * Valid switches for svn log
140
     *
141
     * @var     array
142
     * @access  public
143
     */
144
    var $valid_switches = array('r',
145
                                'q',
146
                                'v',
147
                                'revision',
148
                                'quiet',
149
                                'verbose',
150
                                'targets',
151
                                'stop-on-copy',
152
                                'stop_on_copy',
153
                                'incremental',
154
                                'xml',
155
                                'username',
156
                                'password',
157
                                'no-auth-cache',
158
                                'no_auth_cache',
159
                                'non-interactive',
160
                                'non_interactive',
161
                                'config-dir',
162
                                'config_dir',
163
                                'limit'
164
                                );
165
 
166
 
167
    /**
168
     * Command-line arguments that should be passed
169
     * <b>outside</b> of those specified in {@link switches}.
170
     *
171
     * @var     array
172
     * @access  public
173
     */
174
    var $args = array();
175
 
176
    /**
177
     * Minimum number of args required by this subcommand.
178
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
179
     * Subversion Complete Reference for details on arguments for this subcommand.
180
     * @var     int
181
     * @access  public
182
     */
183
    var $min_args = 0;
184
 
185
    /**
186
     * Switches required by this subcommand.
187
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
188
     * Subversion Complete Reference for details on arguments for this subcommand.
189
     * @var     array
190
     * @access  public
191
     */
192
    var $required_switches = array();
193
 
194
    /**
195
     * Use exec or passthru to get results from command.
196
     * @var     bool
197
     * @access  public
198
     */
199
    var $passthru = false;
200
 
201
    /**
202
     * Prepare the svn subcommand switches.
203
     *
204
     * Defaults to non-interactive mode, and will auto-set the
205
     * --xml switch if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
206
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
207
     *
208
     * @param   void
209
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
210
     *                 for error details, if any.
211
     */
212
    function prepare()
213
    {
214
        $meets_requirements = $this->checkCommandRequirements();
215
        if (!$meets_requirements) {
216
            return false;
217
        }
218
 
219
        $valid_switches     = $this->valid_switches;
220
        $switches           = $this->switches;
221
        $args               = $this->args;
222
        $fetchmode          = $this->fetchmode;
223
        $invalid_switches   = array();
224
        $_switches          = '';
225
 
226
        foreach ($switches as $switch => $val) {
227
            if (in_array($switch, $valid_switches)) {
228
                $switch = str_replace('_', '-', $switch);
229
                switch ($switch) {
230
                    case 'revision':
231
                    case 'targets':
232
                    case 'username':
233
                    case 'password':
234
                    case 'config-dir':
235
                    case 'limit':
236
                        $_switches .= "--$switch $val ";
237
                        break;
238
                    case 'r':
239
                        $_switches .= "-$switch $val ";
240
                        break;
241
                    case 'quiet':
242
                    case 'verbose':
243
                    case 'xml':
244
                    case 'no-auth-cache':
245
                    case 'stop-on-copy':
246
                    case 'non-interactive':
247
                        if ($val === true) {
248
                            $_switches .= "--$switch ";
249
                        }
250
                        break;
251
                    case 'q':
252
                    case 'v':
253
                        if ($val === true) {
254
                            $_switches .= "-$switch ";
255
                        }
256
                        break;
257
                    default:
258
                        // that's all, folks!
259
                        break;
260
                }
261
            } else {
262
                $invalid_switches[] = $switch;
263
            }
264
        }
265
        // We don't want interactive mode
266
        if (strpos($_switches, 'non-interactive') === false) {
267
            $_switches .= '--non-interactive ';
268
        }
269
 
270
        $this->xml_avail = true;
271
        if ($fetchmode == VERSIONCONTROL_SVN_FETCHMODE_ARRAY  ||
272
            $fetchmode == VERSIONCONTROL_SVN_FETCHMODE_ASSOC  ||
273
            $fetchmode == VERSIONCONTROL_SVN_FETCHMODE_OBJECT ||
274
            $fetchmode == VERSIONCONTROL_SVN_FETCHMODE_XML)
275
        {
276
            if (strpos($_switches, 'xml') === false) {
277
                $_switches .= '--xml ';
278
            }
279
        }
280
 
281
        $_switches = trim($_switches);
282
        $this->_switches = $_switches;
283
 
284
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
285
        if (!empty($args)) {
286
            $cmd .= ' '. join(' ', $args);
287
        }
288
 
289
        $this->_prepped_cmd = $cmd;
290
        $this->_prepared = true;
291
 
292
        $invalid = count($invalid_switches);
293
        if ($invalid > 0) {
294
            $params['was'] = 'was';
295
            $params['is_invalid_switch'] = 'is an invalid switch';
296
            if ($invalid > 1) {
297
                $params['was'] = 'were';
298
                $params['is_invalid_switch'] = 'are invalid switches';
299
            }
300
            $params['list'] = $invalid_switches;
301
            $params['switches'] = $switches;
302
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
303
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
304
        }
305
        return true;
306
    }
307
 
308
    // }}}
309
    // {{{ parseOutput()
310
 
311
    /**
312
     * Handles output parsing of output of Log command.
313
     *
314
     * @param   array   $out    Array of output captured by exec command in {@link run}.
315
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
316
     *                  if desired fetchmode is not available.
317
     * @access  public
318
     */
319
    function parseOutput($out)
320
    {
321
        $fetchmode = $this->fetchmode;
322
        $dir = realpath(dirname(__FILE__)) . '/Parsers';
323
        switch($fetchmode) {
324
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
325
                return join("\n", $out);
326
                break;
327
            case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
328
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
329
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
330
                require_once $dir.'/Log.php';
331
                $parser =& new VersionControl_SVN_Log_Parser;
332
                $parser->parseString(join("\n", $out));
333
                if ($fetchmode == VERSIONCONTROL_SVN_FETCHMODE_OBJECT) {
334
                    return (object) $parser->log;
335
                }
336
                return $parser->log;
337
                break;
338
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
339
                // Return command's native XML output
340
                return join("\n", $out);
341
                break;
342
            default:
343
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
344
                return join("\n", $out);
345
                break;
346
        }
347
    }
348
    // }}}
349
}
350
 
351
// }}}
352
 
353
?>