00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'VCS/RCS.php';
00023
00026 class Diogenes_VCS_CVS extends Diogenes_VCS_RCS {
00028 var $cvsopt;
00029
00031 var $port = 9000;
00032
00040 function Diogenes_VCS_CVS(&$caller,$alias,$login,$init = false) {
00041 global $globals;
00042
00043 $this->Diogenes_VCS_RCS($caller,$alias,$login,$init);
00044
00045
00046
00047 $this->cvsopt = "-d :pserver:{$this->login}@localhost:{$this->port}{$globals->rcsroot}";
00048 putenv("CVS_PASSFILE={$globals->spoolroot}/.cvspass");
00049 if ($fp = popen(escapeshellcmd("perl ".escapeshellarg("{$globals->root}/cvs.pl")." -p ".escapeshellarg($this->port)." -r ".escapeshellarg($globals->rcsroot)." -f -m -s 300"),"r"))
00050 pclose($fp);
00051
00052
00053 if ($init) {
00054 chdir($globals->spoolroot);
00055 if ($this->cmdExec("cvs {$this->cvsopt} co ".escapeshellarg($alias)))
00056 {
00057 $this->info($this->cmdStatus());
00058 $this->kill("CVS : Error, checking out CVS module '$alias' failed!");
00059 }
00060 }
00061
00062
00063 if ( !is_dir($this->spoolPath("CVS"))
00064 || !is_writable($this->spoolPath("CVS")) )
00065 $this->kill("CVS : Error, checkout for CVS module '$alias' is invalid!");
00066
00067 }
00068
00069
00075 function checkDir($dir) {
00076 return is_dir($this->rcsPath($dir))
00077 && is_writable($this->rcsPath($dir))
00078
00079 && is_dir($this->spoolPath($dir))
00080 && is_writable($this->spoolPath($dir))
00081 && is_dir($this->spoolPath($dir,"CVS"))
00082 && is_writable($this->spoolPath($dir,"CVS"));
00083 }
00084
00085
00093 function commit($dir,$file,$content,$message="")
00094 {
00095 $this->info("CVS : checking in $file..");
00096
00097
00098 if (!$this->checkDir($dir)) {
00099
00100 $this->info("CVS : Error, sanity check for '$dir' failed!");
00101 return false;
00102 }
00103
00104
00105 $this->log("rcs_commit","{$this->alias}:$dir/$file:$message");
00106
00107
00108 $sfile = $this->spoolPath($dir,$file);
00109 $rfile = $this->rcsFile($dir,$file);
00110
00111 $fp = fopen($sfile,"w");
00112 if (!$fp) {
00113 $this->info("CVS : Error, could not open spool file '$sfile' for writing!");
00114 return false;
00115 }
00116 fwrite($fp,$content);
00117 fclose($fp);
00118
00119 chdir($this->spoolPath($dir));
00120
00121
00122 if (!file_exists($rfile)) {
00123 if ($this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($file))) {
00124
00125 $this->info("Error: could not do CVS add!");
00126 $this->info($this->cmdStatus());
00127 return false;
00128 }
00129 } else {
00130
00131 $this->cmdExec("cvs {$this->cvsopt} up ".escapeshellarg($file));
00132 }
00133
00134 $this->cmdExec("cvs {$this->cvsopt} commit -m".escapeshellarg($message)." ".escapeshellarg($file));
00135
00136 return true;
00137 }
00138
00139
00147 function diff($dir,$file,$r1,$r2)
00148 {
00149 chdir($this->spoolPath($dir));
00150 $this->info("CVS : diffing '$file' ($r1 to $r2)..");
00151
00152 $this->cmdExec("cvs {$this->cvsopt} diff -r".escapeshellarg($r1)." -r".escapeshellarg($r2)." ".escapeshellarg($file));
00153 return $this->cmd_output;
00154 }
00155
00156
00162 function logEntries($dir,$file) {
00163 chdir($this->spoolPath($dir));
00164 $this->cmdExec("cvs {$this->cvsopt} log ".escapeshellarg($file));
00165 return $this->cmd_output;
00166 }
00167
00168
00174 function newdir($parent,$dir)
00175 {
00176 if (!$this->checkDir($parent))
00177 return false;
00178
00179 @mkdir($this->spoolPath($parent,$dir),0700);
00180 chdir($this->spoolPath($parent));
00181 $ret = $this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($dir));
00182 return $ret;
00183 }
00184
00185 }
00186
00187 ?>