]>
src.bluestatic.org Git - viewsvn.git/blob - includes/cachev.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * File container for cacheV class
31 * This class is responsible for interacting with a given cacheV table.
32 * It controls rebuilding from scratch, updates, and querying the cache.
34 * @author Iris Studios, Inc.
35 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
47 var $controller = null ;
56 * Record count - the number of records in cacheV
62 * Memcache for all fetched revisions so we don't have to query-dupe
65 var $memcache = array ( 'revs' => array (), 'nodes' => array ());
67 // ###################################################################
69 * Constructor: initialies the registry
71 * @param object Controller
73 function cacheV (& $controller )
75 $this- > controller
=& $controller ;
79 // ###################################################################
81 * Sets the hash so we know what table we're dealing with
87 $this- > hash
= md5 ( $this- > controller
-> repospath
);
90 // ###################################################################
92 * Returns a node string that has the beginning and ending slashes
93 * removed to allow it to match to the _nodes cacheV table
97 * @param string Original string
99 * @return string Matchable string
101 function fetch_node_string ( $node )
103 return preg_replace ( '#(^/|/$)#' , '' , $node );
106 // ###################################################################
108 * Returns a specific log entry
112 * @param integer Revision number
114 * @return array Complete revision/commit entry
116 function fetch_revision ( $revision )
118 $revision = $this- > controller
-> registry
-> clean ( $revision , TYPE_UINT
);
120 if (! isset ( $this- > memcache
[ 'revs' ][ " $revision" ]))
122 $this- >memcache['revs'][" $revision" ] = $this- > controller
-> registry
-> db
-> query_first ( "SELECT * FROM {$this->hash} _revs " . ( $revision == 0 ? " ORDER BY revision DESC LIMIT 1" : "WHERE revision = $revision" ));
123 $this- >memcache['revs'][" $revision" ][ 'files' ] = unserialize ( $this- > memcache
[ 'revs' ][ " $revision" ]['files']);
126 return $this- >memcache['revs'][" $revision" ];
129 // ###################################################################
131 * Returns the revision entry before the specified one
135 * @param string Node path
136 * @param integer Revision number
138 * @return array Complete revision/commit entry
140 function fetch_prev_revision ( $node , $revision )
142 $data = $this- > fetch_node ( $node );
143 $data = $data [ 'history' ];
145 if ( count ( $data [ 'history' ]) < 1 )
147 return $this- > fetch_revision ( 0 );
150 unset ( $data [ max ( array_keys ( $data )) ]);
152 return $this- > fetch_revision ( max ( array_keys ( $data )));
155 // ###################################################################
157 * Returns the latest revision that the file is at
161 * @param string Node path
163 * @return integer HEAD revision
165 function fetch_head_revision ( $node )
167 $data = $this- > fetch_node ( $node );
168 $data = $data [ 'history' ];
170 return max ( array_keys ( $data ));
173 // ###################################################################
175 * Fetches the latest revision for a given path
179 * @param string Node path
181 * @return integer Latest revision; FALSE if none (not in HEAD)
183 function fetch_node ( $node )
185 $node = $this- > fetch_node_string ( $node );
186 if (! isset ( $this- > memcache
[ 'nodes' ][ " $node" ]))
188 $result = $this- >controller->registry->db->query_first(" SELECT
* FROM {$this
-> hash
} _nodes WHERE name
= '" . $this- >controller->registry->escape( $node ) . "' ");
189 if ( $result == false)
194 $this- >memcache['nodes'][" $node" ] = $result ;
195 $this- > memcache
[ 'nodes' ][ " $node" ]['history'] = unserialize( $this- >memcache['nodes'][" $node" ][ 'history' ]);
198 return $this- > memcache
[ 'nodes' ][ " $node" ];
201 // ###################################################################
203 * Checks to see if a given node is a directory. Returns TRUE if so.
207 * @param string Node path
209 * @return bool TRUE if directory, FALSE if not
211 function isdir( $node )
213 $node = $this- >fetch_node( $node );
214 if ( $node ['node'] == 'dir')
222 // ###################################################################
224 * Checks to see if it's necessary to rebuild the cacheV table for the
225 * current repository. This is done by making sure $count > 0. If not,
226 * then rebuild() is run. This also checks against the cacheV table
227 * to make sure that it's up-to-date against the root repository.
231 function exec_build()
233 $result = $this- >controller->registry->db->query_first(" SELECT
MAX ( revision
) AS max FROM {$this
-> hash
} _revs
");
234 $this- >count = $result ['max'];
236 // time to go from the start
237 if ( $this- >count == 0)
243 // send an Xquery to SVN to see if we need to update
244 $query = $this- >controller->library->svn('info --xml ' . $this- >controller->repospath);
245 $query = implode(" \n
", $query );
247 $tree = $this- >controller->registry->xml->parse( $query );
249 if ( $tree ['info']['entry']['revision'] != $this- >count)
251 $this- >build( $this- >count);
256 // ###################################################################
258 * Builds the cacheV table. This can be used to build only part of the
259 * cache or the entire thing, if the revision is set to NULL.
263 * @param integer Lower (current) revision
265 function build( $revision )
267 $start = microtime();
270 $output = $this- >controller->registry->svn->svn('log --xml -v ' . ( $revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this- >controller->registry->repos->fetch_path( $this- >controller->registry->paths->repos));
271 $output = implode(" \n
", $output );
272 $tree = $this- >controller->registry->xml->parse( $output );
275 $output = $this- >controller->registry->svn->svn('info --xml -R ' . ( $revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this- >controller->registry->repos->fetch_path( $this- >controller->registry->paths->repos));
276 $output = implode(" \n
", $output );
277 $infolist = $this- >controller->registry->xml->parse( $output );
279 // other part of _nodes: properties
280 $output = $this- >controller->registry->svn->svn('proplist -v -R ' . ( $revision !== null ? ' -r' . $revision . ':HEAD ' : '') . $this- >controller->registry->repos->fetch_path( $this- >controller->registry->paths->repos));
281 foreach ( $output AS $line )
283 if (preg_match('#^Properties on \' (.*?) \' :$#', $line , $bits ))
285 $proplist [" $index" ][ " $curprop" ] = trim( $proplist [" $index" ][ " $curprop" ]);
286 $index = str_replace( $this- >controller->registry->repos->fetch_path( $this- >controller->registry->paths->repos), '', $bits [1]);
291 if (preg_match('#^\s+(.*)\s:\s(.*)#', $line , $matches ))
293 $curprop = $matches [1];
294 $proplist [" $index" ][ " $curprop" ] = $matches [2] . " \n
";
297 else if ( $capture == true)
299 $proplist [" $index" ][ " $curprop" ] .= $line . " \n
";
304 // construct _revs inserts and the list of add revisions
305 foreach ( $tree ['log']['logentry'] AS $log )
307 $this- >controller->registry->xml->unify_node( $log ['paths']['path']);
309 $inserts ['revs'][] = " ( $log [ revision
], ' {$log['author']['value']} ' , ' {$log['date']['value']} ' , '" . $this- >controller->registry->escape( $log [' msg
'][' value
']) . "' , '" . $this- >controller->registry->escape(serialize( $log [' paths
'][' path
'])) . "' ) ";
311 foreach ( $log ['paths']['path'] AS $path )
313 if (trim( $path ['action']) == 'A')
315 $path ['value'] = preg_replace('#^/#', '', $path ['value']);
316 $addlist [" $path [ value
] "] = $log ['revision'];
321 // construct list of HEAD nodes for _nodes
322 foreach ( $infolist ['info']['entry'] AS $node )
324 $history = $this- >controller->registry->svn->svn('log --xml ' . $node ['url']['value']);
325 $history = implode(" \n
", $history );
326 $history = $this- >controller->registry->xml->parse( $history );
330 foreach ( $history ['log']['logentry'] AS $log )
332 $loglist [" $log [ revision
] "] = array(
333 'revision' => $log ['revision'],
334 'author' => $log ['author']['value'],
335 'date' => $log ['date']['value'],
336 'message' => $log ['msg']['value']
340 $inserts ['nodes'][] = " ( ' $node [path]' , '" . $node [' kind
'] . "' , " . $node ['commit']['revision'] . " , '" . $this- >controller->registry->escape(serialize( $loglist )) . "' , '" . $this- >controller->registry->escape(serialize( $proplist [" $node [path]"])) . "' ) ";
344 $this- >controller->registry->db->query("
345 REPLACE INTO {$this
-> hash
} _revs
346 ( revision
, author
, dateline
, message
, files
)
348 " . implode(" ,\n ", $inserts ['revs'])
352 $this- >controller->registry->db->query("
353 REPLACE INTO {$this
-> hash
} _nodes
354 ( name
, node
, revision
, history
, properties
)
356 " . implode(" ,\n ", $inserts ['nodes'])
359 $this- >controller->registry->debug(" TIME
TO ( RE
) BUILD
: " . $this- >controller->registry->funct->fetch_microtime_diff( $start ));
363 /*=====================================================================*\
364 || ###################################################################
367 || ###################################################################
368 \*=====================================================================*/