3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once 'diogenes.rcs.inc.php';
24 /** This class handles Diogenes CVS operations.
26 class DiogenesCvs
extends DiogenesRcs
{
27 /** CVS command options */
30 /** Port for the pserver */
37 * @param login the current user's login
38 * @param init should create this module?
40 function DiogenesCvs(&$caller,$alias,$login,$init = false
) {
42 // call parent constructor
43 $this->DiogenesRcs($caller,$alias,$login,$init);
45 // set CVS environment, fire up pserver
46 // the pserver suicides after 5mn of inactivity
47 $this->cvsopt
= "-d :pserver:{$this->login}@localhost:{$this->port}{$globals->rcsroot}";
48 putenv("CVS_PASSFILE={$globals->spoolroot}/.cvspass");
49 if ($fp = popen(escapeshellcmd("perl ".escapeshellarg("{$globals->root}/cvs.pl")." -p ".escapeshellarg($this->port
)." -r ".escapeshellarg($globals->rcsroot
)." -f -m -s 300"),"r"))
52 // if asked to, do checkout of the module
54 chdir($globals->spoolroot
);
55 if ($this->cmdExec("cvs {$this->cvsopt} co ".escapeshellarg($alias)))
57 $this->info($this->cmdStatus());
58 $this->kill("CVS : Error, checking out CVS module '$alias' failed!");
62 // check we have a correct checkout
63 if ( !is_dir($this->spoolPath("CVS"))
64 ||
!is_writable($this->spoolPath("CVS")) )
65 $this->kill("CVS : Error, checkout for CVS module '$alias' is invalid!");
70 /** Perform sanity check on a CVS directory
71 * and the corresponding checkout in the spool
75 function checkDir($dir) {
76 return is_dir($this->rcsPath($dir))
77 && is_writable($this->rcsPath($dir))
79 && is_dir($this->spoolPath($dir))
80 && is_writable($this->spoolPath($dir))
81 && is_dir($this->spoolPath($dir,"CVS"))
82 && is_writable($this->spoolPath($dir,"CVS"));
86 /** Commit a CVS item. Returns true for succes, false for an error.
88 * @param dir parent directory
89 * @param file the CVS entry
90 * @param content the contents of the new revision
91 * @param message the log message for this revision
93 function commit($dir,$file,$content,$message="")
95 $this->info("CVS : checking in $file..");
98 if (!$this->checkDir($dir)) {
100 $this->info("CVS : Error, sanity check for '$dir' failed!");
104 // log commit attempt
105 $this->log("rcs_commit","{$this->alias}:$dir/$file:$message");
107 // write to spool file
108 $sfile = $this->spoolPath($dir,$file);
109 $rfile = $this->rcsFile($dir,$file);
111 $fp = fopen($sfile,"w");
113 $this->info("CVS : Error, could not open spool file '$sfile' for writing!");
116 fwrite($fp,$content);
119 chdir($this->spoolPath($dir));
121 // if the RCS file does not exist, do a cvs add
122 if (!file_exists($rfile)) {
123 if ($this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($file))) {
125 $this->info("Error: could not do CVS add!");
126 $this->info($this->cmdStatus());
130 // do an update to make sure we are up to date
131 $this->cmdExec("cvs {$this->cvsopt} up ".escapeshellarg($file));
134 $this->cmdExec("cvs {$this->cvsopt} commit -m".escapeshellarg($message)." ".escapeshellarg($file));
140 /** Retrieve differences between two version of a file.
142 * @param dir parent directory
143 * @param file the RCS entry
144 * @param r1 the first revision
145 * @param r2 the second revision
147 function diff($dir,$file,$r1,$r2)
149 chdir($this->spoolPath($dir));
150 $this->info("CVS : diffing '$file' ($r1 to $r2)..");
152 $this->cmdExec("cvs {$this->cvsopt} diff -r".escapeshellarg($r1)." -r".escapeshellarg($r2)." ".escapeshellarg($file));
153 return $this->cmd_output
;
157 /** Returns raw log entries for a CVS item.
159 * @param dir parent directory
160 * @param file the RCS entry
162 function logEntries($dir,$file) {
163 chdir($this->spoolPath($dir));
164 $this->cmdExec("cvs {$this->cvsopt} log ".escapeshellarg($file));
165 return $this->cmd_output
;
169 /** Add a new RCS-managed directory.
171 * @param parent the parent directory
172 * @param dir the directory to add
174 function newdir($parent,$dir)
176 if (!$this->checkDir($parent))
179 @mkdir
($this->spoolPath($parent,$dir),0700);
180 chdir($this->spoolPath($parent));
181 $ret = $this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($dir));