fix text for default barrel stylesheet
[diogenes.git] / include / diogenes.cvs.inc.php
CommitLineData
6855525e
JL
1<?php
2/*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
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.
10 *
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.
15 *
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
19 */
20
21
22require_once 'diogenes.rcs.inc.php';
23
24/** This class handles Diogenes CVS operations.
25 */
26class DiogenesCvs extends DiogenesRcs {
27 /** CVS command options */
28 var $cvsopt;
29
30 /** Port for the pserver */
31 var $port = 9000;
32
33 /** The constructor.
34 *
35 * @param caller
36 * @param alias
37 * @param login the current user's login
38 * @param init should create this module?
39 */
40 function DiogenesCvs(&$caller,$alias,$login,$init = false) {
41 global $globals;
42 // call parent constructor
43 $this->DiogenesRcs($caller,$alias,$login,$init);
44
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"))
50 pclose($fp);
51
52 // if asked to, do checkout of the module
53 if ($init) {
54 chdir($globals->spoolroot);
55 if ($this->cmdExec("cvs {$this->cvsopt} co ".escapeshellarg($alias)))
56 {
57 $this->info($this->cmdStatus());
58 $this->kill("CVS : Error, checking out CVS module '$alias' failed!");
59 }
60 }
61
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!");
66
67 }
68
69
70 /** Perform sanity check on a CVS directory
71 * and the corresponding checkout in the spool
72 *
73 * @param dir
74 */
75 function checkDir($dir) {
76 return is_dir($this->rcsPath($dir))
77 && is_writable($this->rcsPath($dir))
78 // spool check
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"));
83 }
84
85
86 /** Commit a CVS item. Returns true for succes, false for an error.
87 *
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
92 */
93 function commit($dir,$file,$content,$message="")
94 {
95 $this->info("CVS : checking in $file..");
96
97 // check directories
98 if (!$this->checkDir($dir)) {
99 // error
100 $this->info("CVS : Error, sanity check for '$dir' failed!");
101 return false;
102 }
103
104 // log commit attempt
105 $this->log("rcs_commit","{$this->alias}:$dir/$file:$message");
106
107 // write to spool file
108 $sfile = $this->spoolPath($dir,$file);
109 $rfile = $this->rcsFile($dir,$file);
110
111 $fp = fopen($sfile,"w");
112 if (!$fp) {
113 $this->info("CVS : Error, could not open spool file '$sfile' for writing!");
114 return false;
115 }
116 fwrite($fp,$content);
117 fclose($fp);
118
119 chdir($this->spoolPath($dir));
120
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))) {
124 // error
125 $this->info("Error: could not do CVS add!");
126 $this->info($this->cmdStatus());
127 return false;
128 }
129 } else {
130 // do an update to make sure we are up to date
131 $this->cmdExec("cvs {$this->cvsopt} up ".escapeshellarg($file));
132 }
133
134 $this->cmdExec("cvs {$this->cvsopt} commit -m".escapeshellarg($message)." ".escapeshellarg($file));
135
136 return true;
137 }
138
139
140 /** Retrieve differences between two version of a file.
141 *
142 * @param dir parent directory
143 * @param file the RCS entry
144 * @param r1 the first revision
145 * @param r2 the second revision
146 */
147 function diff($dir,$file,$r1,$r2)
148 {
149 chdir($this->spoolPath($dir));
150 $this->info("CVS : diffing '$file' ($r1 to $r2)..");
151
152 $this->cmdExec("cvs {$this->cvsopt} diff -r".escapeshellarg($r1)." -r".escapeshellarg($r2)." ".escapeshellarg($file));
153 return $this->cmd_output;
154 }
155
156
157 /** Returns raw log entries for a CVS item.
158 *
159 * @param dir parent directory
160 * @param file the RCS entry
161 */
162 function logEntries($dir,$file) {
163 chdir($this->spoolPath($dir));
164 $this->cmdExec("cvs {$this->cvsopt} log ".escapeshellarg($file));
165 return $this->cmd_output;
166 }
167
168
169 /** Add a new RCS-managed directory.
170 *
171 * @param parent the parent directory
172 * @param dir the directory to add
173 */
174 function newdir($parent,$dir)
175 {
176 if (!$this->checkDir($parent))
177 return false;
178
179 @mkdir($this->spoolPath($parent,$dir),0700);
180 chdir($this->spoolPath($parent));
181 $ret = $this->cmdExec("cvs {$this->cvsopt} add ".escapeshellarg($dir));
182 return $ret;
183 }
184
185}
186
187?>