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