We now can get revision information:
[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 subpath inside the repository we're getting info for
49 * @var string
50 */
51 private $subpath;
52
53 /**
54 * The revision number
55 * @var integer
56 */
57 public $revision;
58
59 /**
60 * The commmit message for this revision
61 * @var string
62 */
63 public $message;
64
65 /**
66 * The unparsed/unformatted log message
67 * @var string
68 */
69 public $messageClean;
70
71 /**
72 * Author who committed the revision
73 * @var string
74 */
75 public $author;
76
77 /**
78 * The date and time this revision was made
79 * @var string
80 */
81 public $datetime;
82
83 // ###################################################################
84 /**
85 * Creates a new revision for a given repository and revision
86 *
87 * @param string Repository
88 * @param integer Revision to get; to get HEAD, specify 0
89 * @param string Path inside the repository to get info for
90 */
91 public function __construct($repos, $rev = 0, $subpath = null)
92 {
93 $this->path = BSRegister::Get('repos')->fetchPath($repos);
94 $this->repos = $repos;
95 $this->subpath = $subpath;
96
97 $this->_fetchRevision($rev);
98 }
99
100 // ###################################################################
101 /**
102 * Returns an array of properties for this revision at a certain path
103 *
104 * @param string Path
105 *
106 * @return array Array of properties
107 */
108 public function getPropsForPath($path)
109 {
110 $output = BSRegister::Get('lib')->run('proplist -v -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path . $path));
111 unset($output[0]);
112
113 $proplist = array();
114 foreach ($output AS $line)
115 {
116 if (preg_match('#^\s+(.*)\s:(\s(.*))?#', $line, $matches))
117 {
118 $curprop = $matches[1];
119 $proplist["$curprop"] = $matches[2] . "\n";
120 }
121 else
122 {
123 $proplist["$curprop"] .= $line . "\n";
124 }
125 }
126
127 return $proplist;
128 }
129
130 // ###################################################################
131 /**
132 * Gets the revision information (commit message, author, date) for the
133 * revision
134 */
135 public function getRevisionInfo()
136 {
137 $xml = BSXml::Parse(BSRegister::Get('lib')->run('log --xml -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path), true));
138 $this->message = FormatLogMessage($xml['log']['logentry']['msg']['value']);
139 $this->messasgeClean = $xml['log']['logentry']['msg']['value'];
140 $this->datetime = FormatSvnDate($xml['log']['logentry']['date']['value']);
141 $this->author = $xml['log']['logentry']['author']['value'];
142 }
143
144 // ###################################################################
145 /**
146 * Gets the desired XML revision information from the repository
147 *
148 * @param integer Desired revision
149 */
150 private function _fetchRevision($desired)
151 {
152 $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path . $this->subpath), true));
153 $this->revision = intval($xml['info']['entry']['commit']['revision']);
154 }
155 }
156
157 /*=====================================================================*\
158 || ###################################################################
159 || # $HeadURL$
160 || # $Id$
161 || ###################################################################
162 \*=====================================================================*/
163 ?>