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: Revert.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 Revert command manager class
55
 *
56
 * Restore pristine working copy file (undo most local edits).
57
 *
58
 * Note: This subcommand does not require network access, and resolves
59
 * any conflicted states. However, it does not restore removed directories.
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
 *  'targets'       =>  'ARG',
68
 *                      // pass contents of file ARG as additional args
69
 *  'R'             =>  true|false,
70
 *                      // descend recursively
71
 *  'recursive'     =>  true|false,
72
 *                      // descend recursively
73
 *  'q [quiet]'     =>  true|false,
74
 *                      // prints as little as possible
75
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
76
 * );
77
 *
78
 * </code>
79
 *
80
 * Note: Subversion does not offer an XML output option for this subcommand
81
 *
82
 * The non-interactive option available on the command-line
83
 * svn client may also be set (true|false), but it is set to true by default.
84
 *
85
 * Usage example:
86
 * <code>
87
 * <?php
88
 * require_once 'VersionControl/SVN.php';
89
 *
90
 * // Setup error handling -- always a good idea!
91
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
92
 *
93
 * // Set up runtime options. Will be passed to all
94
 * // subclasses.
95
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
96
 *
97
 * // Pass array of subcommands we need to factory
98
 * $svn = VersionControl_SVN::factory(array('revert'), $options);
99
 *
100
 * // Define any switches and aguments we may need
101
 * $switches = array('R' => true);
102
 * $args = array('/path/to/working/copy/TestProj/trunk');
103
 *
104
 * // Run command
105
 * if ($output = $svn->revert->run($args, $switches)) {
106
 *     print_r($output);
107
 * } else {
108
 *     if (count($errs = $svnstack->getErrors())) {
109
 *         foreach ($errs as $err) {
110
 *             echo '<br />'.$err['message']."<br />\n";
111
 *             echo "Command used: " . $err['params']['cmd'];
112
 *         }
113
 *     }
114
 * }
115
 * ?>
116
 * </code>
117
 *
118
 * @package  VersionControl_SVN
119
 * @version  0.3.4
120
 * @category SCM
121
 * @author   Clay Loveless <clay@killersoft.com>
122
 */
123
class VersionControl_SVN_Revert extends VersionControl_SVN
124
{
125
    /**
126
     * Valid switches for svn revert
127
     *
128
     * @var     array
129
     * @access  public
130
     */
131
    var $valid_switches = array('R',
132
                                'recursive',
133
                                'quiet',
134
                                'q',
135
                                'targets',
136
                                'config-dir'
137
                                );
138
 
139
    /**
140
     * Command-line arguments that should be passed
141
     * <b>outside</b> of those specified in {@link switches}.
142
     *
143
     * @var     array
144
     * @access  public
145
     */
146
    var $args = array();
147
 
148
    /**
149
     * Minimum number of args required by this subcommand.
150
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
151
     * Subversion Complete Reference for details on arguments for this subcommand.
152
     * @var     int
153
     * @access  public
154
     */
155
    var $min_args = 1;
156
 
157
    /**
158
     * Switches required by this subcommand.
159
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
160
     * Subversion Complete Reference for details on arguments for this subcommand.
161
     * @var     array
162
     * @access  public
163
     */
164
    var $required_switches = array();
165
 
166
    /**
167
     * Use exec or passthru to get results from command.
168
     * @var     bool
169
     * @access  public
170
     */
171
    var $passthru = false;
172
 
173
    /**
174
     * Prepare the svn subcommand switches.
175
     *
176
     * Defaults to non-interactive mode, and will auto-set the
177
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
178
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
179
     *
180
     * @param   void
181
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
182
     *                 for error details, if any.
183
     */
184
    function prepare()
185
    {
186
        $meets_requirements = $this->checkCommandRequirements();
187
        if (!$meets_requirements) {
188
            return false;
189
        }
190
 
191
        $valid_switches     = $this->valid_switches;
192
        $switches           = $this->switches;
193
        $args               = $this->args;
194
        $fetchmode          = $this->fetchmode;
195
        $invalid_switches   = array();
196
        $_switches          = '';
197
 
198
        foreach ($switches as $switch => $val) {
199
            if (in_array($switch, $valid_switches)) {
200
                $switch = str_replace('_', '-', $switch);
201
                switch ($switch) {
202
                    case 'targets':
203
                    case 'config-dir':
204
                        $_switches .= "--$switch $val ";
205
                        break;
206
                    case 'recursive':
207
                    case 'quiet':
208
                        if ($val === true) {
209
                            $_switches .= "--$switch ";
210
                        }
211
                        break;
212
                    case 'R':
213
                    case 'v':
214
                    case 'q':
215
                        if ($val === true) {
216
                            $_switches .= "-$switch ";
217
                        }
218
                        break;
219
                    default:
220
                        // that's all, folks!
221
                        break;
222
                }
223
            } else {
224
                $invalid_switches[] = $switch;
225
            }
226
        }
227
 
228
        $_switches = trim($_switches);
229
        $this->_switches = $_switches;
230
 
231
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
232
        if (!empty($args)) {
233
            $cmd .= ' '. join(' ', $args);
234
        }
235
 
236
        $this->_prepped_cmd = $cmd;
237
        $this->prepared = true;
238
 
239
        $invalid = count($invalid_switches);
240
        if ($invalid > 0) {
241
            $params['was'] = 'was';
242
            $params['is_invalid_switch'] = 'is an invalid switch';
243
            if ($invalid > 1) {
244
                $params['was'] = 'were';
245
                $params['is_invalid_switch'] = 'are invalid switches';
246
            }
247
            $params['list'] = $invalid_switches;
248
            $params['switches'] = $switches;
249
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
250
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
251
        }
252
        return true;
253
    }
254
 
255
    // }}}
256
    // {{{ parseOutput()
257
 
258
    /**
259
     * Handles output parsing of standard and verbose output of command.
260
     *
261
     * @param   array   $out    Array of output captured by exec command in {@link run}.
262
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
263
     *                  if desired fetchmode is not available.
264
     * @access  public
265
     */
266
    function parseOutput($out)
267
    {
268
        $fetchmode = $this->fetchmode;
269
        switch($fetchmode) {
270
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
271
                return join("\n", $out);
272
                break;
273
            case VERSIONCONTROL_SVN_FETCHMODE_ARRAY:
274
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
275
                // Temporary, see parseOutputArray below
276
                return join("\n", $out);
277
                break;
278
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
279
                // Temporary, will return object-ified array from
280
                // parseOutputArray
281
                return join("\n", $out);
282
                break;
283
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
284
                // Temporary, will eventually build an XML string
285
                // with XML_Util or XML_Tree
286
                return join("\n", $out);
287
                break;
288
            default:
289
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
290
                return join("\n", $out);
291
                break;
292
        }
293
    }
294
 
295
    /**
296
     * Helper method for parseOutput that parses output into an associative array
297
     *
298
     * @todo Finish this method! : )
299
     */
300
    function parseOutputArray($out)
301
    {
302
        $parsed = array();
303
    }
304
}
305
 
306
// }}}
307
?>