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: Cleanup.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 Cleanup command manager class
55
 *
56
 * Recursively clean up the working copy indicated by PATH, removing
57
 * locks, resuming unfinished operations, etc.
58
 *
59
 * $options is an array containing one or more options
60
 * defined by the following associative keys:
61
 *
62
 * <code>
63
 *
64
 * $switches = array(
65
 *  'config-dir'    =>  'Path to a Subversion configuration directory',
66
 *  'diff3-cmd'     =>  'ARG'
67
 *                      // Use ARG as merge command.
68
 * );
69
 *
70
 * </code>
71
 *
72
 * If a path is not used in the $args array, the default path of '.' will
73
 * be assumed.
74
 *
75
 * Note: Subversion does not offer an XML output option for this subcommand
76
 *
77
 * Note: There is no output from the svn cleanup command!
78
 *
79
 * Usage example:
80
 * <code>
81
 * <?php
82
 * require_once 'VersionControl/SVN.php';
83
 *
84
 * // Setup error handling -- always a good idea!
85
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
86
 *
87
 * // Pass array of subcommands we need to factory
88
 * $svn = VersionControl_SVN::factory(array('cleanup'), $options);
89
 *
90
 * // Define any switches and aguments we may need
91
 * $args = array('/path/to/working_copy');
92
 *
93
 * // Run command
94
 * if ($output = $svn->cleanup->run($args)) {
95
 *     print_r($output);
96
 * } else {
97
 *     if (count($errs = $svnstack->getErrors())) {
98
 *         foreach ($errs as $err) {
99
 *             echo '<br />'.$err['message']."<br />\n";
100
 *             echo "Command used: " . $err['params']['cmd'];
101
 *         }
102
 *     }
103
 * }
104
 * ?>
105
 * </code>
106
 *
107
 * @package  VersionControl_SVN
108
 * @version  0.3.4
109
 * @category SCM
110
 * @author   Clay Loveless <clay@killersoft.com>
111
 */
112
class VersionControl_SVN_Cleanup extends VersionControl_SVN
113
{
114
    /**
115
     * Valid switches for svn cleanup
116
     *
117
     * @var     array
118
     * @access  public
119
     */
120
    var $valid_switches = array('config-dir',
121
                                'config_dir',
122
                                'diff3-cmd'
123
                                );
124
 
125
    /**
126
     * Command-line arguments that should be passed
127
     * <b>outside</b> of those specified in {@link switches}.
128
     *
129
     * @var     array
130
     * @access  public
131
     */
132
    var $args = array();
133
 
134
    /**
135
     * Minimum number of args required by this subcommand.
136
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
137
     * Subversion Complete Reference for details on arguments for this subcommand.
138
     * @var     int
139
     * @access  public
140
     */
141
    var $min_args = 0;
142
 
143
    /**
144
     * Switches required by this subcommand.
145
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
146
     * Subversion Complete Reference for details on arguments for this subcommand.
147
     * @var     array
148
     * @access  public
149
     */
150
    var $required_switches = array();
151
 
152
    /**
153
     * Use exec or passthru to get results from command.
154
     * @var     bool
155
     * @access  public
156
     */
157
    var $passthru = false;
158
 
159
    /**
160
     * Prepare the svn subcommand switches.
161
     *
162
     * @param   void
163
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
164
     *                 for error details, if any.
165
     */
166
    function prepare()
167
    {
168
 
169
        $meets_requirements = $this->checkCommandRequirements();
170
        if (!$meets_requirements) {
171
            return false;
172
        }
173
 
174
        $valid_switches     = $this->valid_switches;
175
        $switches           = $this->switches;
176
        $args               = $this->args;
177
        $fetchmode          = $this->fetchmode;
178
        $invalid_switches   = array();
179
        $_switches          = '';
180
 
181
        foreach ($switches as $switch => $val) {
182
            if (in_array($switch, $valid_switches)) {
183
                $switch = str_replace('_', '-', $switch);
184
                switch ($switch) {
185
                    case 'config-dir':
186
                    case 'diff3-cmd':
187
                        $_switches .= "--$switch $val ";
188
                        break;
189
                    default:
190
                        // that's all, folks!
191
                        break;
192
                }
193
            } else {
194
                $invalid_switches[] = $switch;
195
            }
196
        }
197
 
198
        $_switches = trim($_switches);
199
        $this->_switches = $_switches;
200
 
201
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
202
        if (!empty($args)) {
203
            $cmd .= ' '. join(' ', $args);
204
        }
205
        $this->_prepped_cmd = $cmd;
206
        $this->prepared = true;
207
 
208
        $invalid = count($invalid_switches);
209
        if ($invalid > 0) {
210
            $params['was'] = 'was';
211
            $params['is_invalid_switch'] = 'is an invalid switch';
212
            if ($invalid > 1) {
213
                $params['was'] = 'were';
214
                $params['is_invalid_switch'] = 'are invalid switches';
215
            }
216
            $params['list'] = $invalid_switches;
217
            $params['switches'] = $switches;
218
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
219
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
220
        }
221
        return true;
222
    }
223
 
224
    /// }}}
225
}
226
 
227
/// }}}
228
?>