Properties now work:
[viewsvn.git] / includes / class_revision.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Revision
24 *
25 * This class represents one revision in a given repository
26 *
27 * @author Blue Static
28 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
29 * @version $Revision$
30 * @package ViewSVN
31 *
32 */
33 class Revision
34 {
35 /**
36 * Repository path
37 * @var string
38 */
39 private $path;
40
41 /**
42 * Repository name
43 * @var string
44 */
45 private $repos;
46
47 /**
48 * The revision number
49 * @var integer
50 */
51 public $revision;
52
53 // ###################################################################
54 /**
55 * Creates a new revision for a given repository and revision
56 *
57 * @param string Repository
58 * @param integer Revision to get; to get HEAD, specify 0
59 */
60 public function __construct($repos, $rev = 0)
61 {
62 $this->path = BSRegister::Get('repos')->fetchPath($repos);
63 $this->repos = $repos;
64
65 $this->_fetchRevision($rev);
66 }
67
68 // ###################################################################
69 /**
70 * Returns an array of properties for this revision at a certain path
71 *
72 * @param string Path
73 *
74 * @return array Array of properties
75 */
76 public function getPropsForPath($path)
77 {
78 $output = BSRegister::Get('lib')->run('proplist -v -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path . $path));
79 unset($output[0]);
80
81 $proplist = array();
82 foreach ($output AS $line)
83 {
84 if (preg_match('#^\s+(.*)\s:(\s(.*))?#', $line, $matches))
85 {
86 $curprop = $matches[1];
87 $proplist["$curprop"] = $matches[2] . "\n";
88 }
89 else
90 {
91 $proplist["$curprop"] .= $line . "\n";
92 }
93 }
94
95 return $proplist;
96 }
97
98 // ###################################################################
99 /**
100 * Gets the desired XML revision information from the repository
101 *
102 * @param integer Desired revision
103 */
104 private function _fetchRevision($desired)
105 {
106 $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path), true));
107 $this->revision = intval($xml['info']['entry']['commit']['revision']);
108 }
109 }
110
111 /*=====================================================================*\
112 || ###################################################################
113 || # $HeadURL$
114 || # $Id$
115 || ###################################################################
116 \*=====================================================================*/
117 ?>