CVS.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // call parent constructor
00043     $this->Diogenes_VCS_RCS($caller,$alias,$login,$init);
00044 
00045     // set CVS environment, fire up pserver
00046     // the pserver suicides after 5mn of inactivity
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     // if asked to, do checkout of the module
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     // check we have a correct checkout
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         // spool check
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     // check directories
00098     if (!$this->checkDir($dir)) {
00099         // error
00100         $this->info("CVS : Error, sanity check for '$dir' failed!");
00101         return false;
00102     }
00103 
00104     // log commit attempt
00105     $this->log("rcs_commit","{$this->alias}:$dir/$file:$message");
00106 
00107     // write to spool file
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     // if the RCS file does not exist, do a cvs add
00122     if (!file_exists($rfile)) {
00123       if ($this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($file))) {
00124         // error
00125         $this->info("Error: could not do CVS add!");
00126         $this->info($this->cmdStatus());
00127         return false;
00128       }
00129     } else {
00130       // do an update to make sure we are up to date
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 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1