1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
<?php
/**
* VC_rcs implementation.
*
* Copyright 2004-2006 Jeff Schwentner <jeffrey.schwentner@lmco.com>
*
* $Horde: framework/VC/VC/rcs.php,v 1.3.8.5 2006/01/01 21:28:42 jan Exp $
*
* @author Jeff Schwentner <jeffrey.schwentner@lmco.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @package VC
*/
class VC_rcs extends VC {
/**
* Checks an RCS file in with a specified change log.
*
* @param string $filepath Location of file to check in.
* @param string $message Log of changes since last version.
* @param string $user The user name to use for the check in.
* @param boolean $newBinary Does the change involve binary data?
*
* @return string|object The new revision number on success, or a
* PEAR_Error object on failure.
*/
function ci($filepath, $message, $user = null, $newBinary = false)
{
if ($user) {
putenv('LOGNAME=' . $user);
} else {
putenv('LOGNAME=guest');
}
$Q = VC_WINDOWS ? '"' : "'" ;
$ci_cmd = $this->getPath('ci') . ' ' . $Q . $filepath . $Q.' 2>&1';
$rcs_cmd = $this->getPath('rcs') . ' -i -kb ' . $Q . $filepath . $Q.' 2>&1';
$output = '';
$message_lines = explode("\n", $message);
$pipe_def = array(0 => array("pipe", 'r'),
1 => array("pipe", 'w'));
if ($newBinary) {
$process = proc_open($rcs_cmd, $pipe_def, $pipes);
} else {
$process = proc_open($ci_cmd, $pipe_def, $pipes);
}
if (is_resource($process)) {
foreach ($message_lines as $line) {
if ($line == '.\n') {
$line = '. \n';
}
fwrite($pipes[0], $line);
}
fwrite($pipes[0], "\n.\n");
fclose($pipes[0]);
while (!feof($pipes[1])) {
$output .= fread($pipes[1], 8192);
}
fclose($pipes[1]);
proc_close($process);
} else {
return PEAR::raiseError('Failed to open pipe in ci()');
}
if ($newBinary) {
exec($ci_cmd . ' 2>&1', $return_array, $retval);
if ($retval) {
return PEAR::raiseError("Unable to spawn ci on $filepath from ci()");
} else {
foreach ($return_array as $line) {
$output .= $line;
}
}
}
$rev_start = strpos($output, 'new revision: ');
// If no new revision, see if this is an initial checkin.
if ($rev_start === false) {
$rev_start = strpos($output, 'initial revision: ');
$rev_end = strpos($output, ' ', $rev_start);
} else {
$rev_end = strpos($output, ';', $rev_start);
}
if ($rev_start !== false && $rev_end !== false) {
$rev_start += 14;
return substr($output, $rev_start, $rev_end - $rev_start);
} else {
unlock($filepath);
$temp_pos = strpos($output, 'file is unchanged');
if ($temp_pos !== false) {
return PEAR::raiseError('Check-in Failure: ' . basename($filepath) . ' has not been modified');
} else {
return PEAR::raiseError("Failed to checkin $filepath, $ci_cmd, $output");
}
}
}
/**
* Checks the locks on a CVS/RCS file.
*
* @param string $filepath Location of file.
* @param string &$locked_by Returns the username holding the lock.
*
* @return boolean|object True on success, or a PEAR_Error on failure.
*/
function isLocked($filepath, &$locked_by)
{
$rlog_cmd = $this->getPath('rlog');
$rlog_flag = ' -L ';
$Q = VC_WINDOWS ? '"' : "'";
$cmd = $rlog_cmd . $rlog_flag . $Q . $filepath . $Q;
exec($cmd.' 2>&1', $return_array, $retval);
if ($retval) {
return PEAR::raiseError("Unable to spawn rlog on $filepath from isLocked()");
} else {
$output = '';
foreach ($return_array as $line) {
$output .= $line;
}
$start_name = strpos($output, 'locked by: ');
$end_name = strpos($output, ';', $start_name);
if ($start_name !== false && $end_name !== false) {
$start_name += 11;
$locked_by = substr($output, $start_name, $end_name - $start_name);
return true;
} elseif (strlen($output) == 0) {
return false;
} else {
return PEAR::raiseError('Failure running rlog in isLocked()');
}
}
}
/**
* Locks a CVS/RCS file.
*
* @param string $filepath Location of file.
* @param string $user User name to lock the file with
*
* @return boolean|object True on success, or a PEAR_Error on failure.
*/
function lock($filepath, $user = null)
{
// Get username for RCS tag.
if ($user) {
putenv('LOGNAME=' . $user);
} else {
putenv('LOGNAME=guest');
}
$rcs_cmd = $this->getPath('rcs');
$rcs_flag = ' -l ';
$Q = VC_WINDOWS ? '"' : "'" ;
$cmd = $rcs_cmd . $rcs_flag . $Q . $filepath . $Q;
exec($cmd.' 2>&1', $return_array, $retval);
if ($retval) {
return PEAR::raiseError('Failed to spawn rcs ("' . $cmd . '") on "' . $filepath . '" (returned ' . $retval . ')');
} else {
$output = '';
foreach ($return_array as $line) {
$output .= $line;
}
$locked_pos = strpos($output, 'locked');
if ($locked_pos !== false) {
return true;
} else {
return PEAR::raiseError('Failed to lock "' . $filepath . '" (Ran "' . $cmd . '", got return code ' . $retval . ', output: ' . $output . ')');
}
}
}
/**
* Unlocks a CVS/RCS file.
*
* @param string $filepath Location of file.
* @param string $user User name to unlock the file with
*
* @return boolean|object True on success, or a PEAR_Error on failure.
*/
function unlock($filepath, $user = null)
{
// Get username for RCS tag.
if ($user) {
putenv('LOGNAME=' . $user);
} else {
putenv('LOGNAME=guest');
}
$rcs_cmd = $this->getPath('rcs');
$rcs_flag = ' -u ';
$Q = VC_WINDOWS ? '"' : "'" ;
$cmd = $rcs_cmd . $rcs_flag . $Q . $filepath . $Q;
exec($cmd . ' 2>&1', $return_array, $retval);
if ($retval) {
return PEAR::raiseError('Failed to spawn rcs ("' . $cmd . '") on "' . $filepath . '" (returned ' . $retval . ')');
} else {
$output = '';
foreach ($return_array as $line) {
$output .= $line;
}
$unlocked_pos = strpos($output, 'unlocked');
if ($unlocked_pos !== false) {
return true;
} else {
// Already unlocked.
return true;
}
}
}
}
|