]> src.bluestatic.org Git - viewsvn.git/blob - includes/class_revision.php
Starting to use the peg-revision system so we can actually travel back through time
[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 * Files changed by the revision
85 * @var array
86 */
87 public $files = array();
88
89 // ###################################################################
90 /**
91 * Creates a new revision for a given repository and revision
92 *
93 * @param string Repository
94 * @param integer Revision to get; to get HEAD, specify 0
95 * @param string Path inside the repository to get info for
96 */
97 public function __construct($repos, $rev = 0, $subpath = null)
98 {
99 $this->path = BSRegister::Get('repos')->fetchPath($repos);
100 $this->repos = $repos;
101 $this->subpath = $subpath;
102
103 $this->_fetchRevision($rev);
104 }
105
106 // ###################################################################
107 /**
108 * Returns an array of properties for this revision at a certain path
109 *
110 * @param string Path
111 *
112 * @return array Array of properties
113 */
114 public function getPropsForPath($path)
115 {
116 $output = BSRegister::Get('lib')->run('proplist -v -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path . $path) . '@' . $this->revision);
117 unset($output[0]);
118
119 $proplist = array();
120 foreach ($output AS $line)
121 {
122 if (preg_match('#^\s+(.*)\s:(\s(.*))?#', $line, $matches))
123 {
124 $curprop = $matches[1];
125 $proplist["$curprop"] = $matches[2] . "\n";
126 }
127 else
128 {
129 $proplist["$curprop"] .= $line . "\n";
130 }
131 }
132
133 return $proplist;
134 }
135
136 // ###################################################################
137 /**
138 * Gets the revision information (commit message, author, date) for the
139 * revision
140 */
141 public function getRevisionInfo()
142 {
143 $xml = BSXml::Parse(BSRegister::Get('lib')->run('log --xml -v -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path) . '@' . $this->revision, true));
144 $this->message = FormatLogMessage($xml['log']['logentry']['msg']['value']);
145 $this->messasgeClean = $xml['log']['logentry']['msg']['value'];
146 $this->datetime = FormatSvnDate($xml['log']['logentry']['date']['value']);
147 $this->author = $xml['log']['logentry']['author']['value'];
148 $this->files = $xml['log']['logentry']['paths']['path'];
149 BSXml::UnifyNode($this->files);
150 }
151
152 // ###################################################################
153 /**
154 * Gets the desired XML revision information from the repository
155 *
156 * @param integer Desired revision
157 */
158 private function _fetchRevision($desired)
159 {
160 $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path . $this->subpath) . ($desired > 0 ? '@' . intval($desired) : ''), true));
161 $this->revision = intval($xml['info']['entry']['commit']['revision']);
162 }
163 }
164
165 /*=====================================================================*\
166 || ###################################################################
167 || # $HeadURL$
168 || # $Id$
169 || ###################################################################
170 \*=====================================================================*/
171 ?>