286 |
07 May 07 |
peter |
// $Id$ |
286 |
07 May 07 |
peter |
2 |
|
286 |
07 May 07 |
peter |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2023 Peter Johansson |
286 |
07 May 07 |
peter |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
286 |
07 May 07 |
peter |
8 |
|
286 |
07 May 07 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
286 |
07 May 07 |
peter |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
286 |
07 May 07 |
peter |
(at your option) any later version. |
286 |
07 May 07 |
peter |
13 |
|
286 |
07 May 07 |
peter |
svndigest is distributed in the hope that it will be useful, but |
286 |
07 May 07 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
286 |
07 May 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
286 |
07 May 07 |
peter |
General Public License for more details. |
286 |
07 May 07 |
peter |
18 |
|
286 |
07 May 07 |
peter |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
286 |
07 May 07 |
peter |
21 |
*/ |
286 |
07 May 07 |
peter |
22 |
|
1619 |
12 Mar 23 |
peter |
23 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
24 |
|
286 |
07 May 07 |
peter |
25 |
#include "Trac.h" |
286 |
07 May 07 |
peter |
26 |
|
286 |
07 May 07 |
peter |
27 |
#include "Configuration.h" |
465 |
24 Aug 07 |
peter |
28 |
#include "Functor.h" |
286 |
07 May 07 |
peter |
29 |
#include "HtmlStream.h" |
286 |
07 May 07 |
peter |
30 |
#include "html_utility.h" |
1237 |
23 Oct 10 |
peter |
31 |
#include "utility.h" |
286 |
07 May 07 |
peter |
32 |
|
286 |
07 May 07 |
peter |
33 |
namespace theplu{ |
286 |
07 May 07 |
peter |
34 |
namespace svndigest{ |
286 |
07 May 07 |
peter |
35 |
|
286 |
07 May 07 |
peter |
36 |
Trac::Trac(HtmlStream& hs) |
1513 |
23 Sep 12 |
peter |
37 |
: hs_(hs) |
286 |
07 May 07 |
peter |
38 |
{} |
286 |
07 May 07 |
peter |
39 |
|
317 |
17 May 07 |
peter |
40 |
std::string Trac::anchor_text(std::string::const_iterator first, |
317 |
17 May 07 |
peter |
41 |
std::string::const_iterator last, |
317 |
17 May 07 |
peter |
42 |
std::string::const_iterator last_trunc) |
317 |
17 May 07 |
peter |
43 |
{ |
317 |
17 May 07 |
peter |
44 |
if (last>last_trunc) { // truncate |
317 |
17 May 07 |
peter |
45 |
std::string str(first, last_trunc); |
317 |
17 May 07 |
peter |
46 |
str+="..."; |
317 |
17 May 07 |
peter |
47 |
return str; |
317 |
17 May 07 |
peter |
48 |
} |
317 |
17 May 07 |
peter |
49 |
return std::string(first, last); |
317 |
17 May 07 |
peter |
50 |
} |
317 |
17 May 07 |
peter |
51 |
|
317 |
17 May 07 |
peter |
52 |
|
1513 |
23 Sep 12 |
peter |
53 |
bool Trac::changeset(const std::string::const_iterator& first, |
768 |
31 Jan 09 |
peter |
54 |
std::string::const_iterator& iter, |
317 |
17 May 07 |
peter |
55 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
56 |
const std::string::const_iterator& last_trunc) |
292 |
08 May 07 |
peter |
57 |
{ |
768 |
31 Jan 09 |
peter |
58 |
if (changeset1(first, iter, last, last_trunc)) |
292 |
08 May 07 |
peter |
59 |
return true; |
768 |
31 Jan 09 |
peter |
60 |
if (changeset2(iter, last, last_trunc)) |
292 |
08 May 07 |
peter |
61 |
return true; |
768 |
31 Jan 09 |
peter |
62 |
if (changeset3(iter, last, last_trunc)) |
292 |
08 May 07 |
peter |
63 |
return true; |
292 |
08 May 07 |
peter |
64 |
return false; |
292 |
08 May 07 |
peter |
65 |
} |
292 |
08 May 07 |
peter |
66 |
|
292 |
08 May 07 |
peter |
67 |
|
1513 |
23 Sep 12 |
peter |
68 |
bool Trac::changeset1(const std::string::const_iterator& first, |
768 |
31 Jan 09 |
peter |
69 |
std::string::const_iterator& iter, |
317 |
17 May 07 |
peter |
70 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
71 |
const std::string::const_iterator& last_trunc) |
292 |
08 May 07 |
peter |
72 |
{ |
768 |
31 Jan 09 |
peter |
73 |
if (iter==last) |
292 |
08 May 07 |
peter |
74 |
return false; |
768 |
31 Jan 09 |
peter |
75 |
if (*iter != 'r') |
292 |
08 May 07 |
peter |
76 |
return false; |
768 |
31 Jan 09 |
peter |
77 |
if (iter!=first && isalnum(*(iter-1))) |
292 |
08 May 07 |
peter |
78 |
return false; |
768 |
31 Jan 09 |
peter |
79 |
const std::string::const_iterator iter_orig(iter); |
768 |
31 Jan 09 |
peter |
80 |
++iter; |
768 |
31 Jan 09 |
peter |
81 |
std::string rev = match(iter, last, Digit()); |
768 |
31 Jan 09 |
peter |
82 |
if (rev.empty() || (iter!=last && (std::isalnum(*iter) || *iter==':')) ){ |
768 |
31 Jan 09 |
peter |
83 |
iter = iter_orig; |
768 |
31 Jan 09 |
peter |
84 |
return false; |
292 |
08 May 07 |
peter |
85 |
} |
292 |
08 May 07 |
peter |
86 |
std::string href(Configuration::instance().trac_root()+"changeset/"+rev); |
1513 |
23 Sep 12 |
peter |
87 |
hs_.stream() << anchor(href, anchor_text(iter_orig, iter, last_trunc)); |
292 |
08 May 07 |
peter |
88 |
return true; |
292 |
08 May 07 |
peter |
89 |
} |
292 |
08 May 07 |
peter |
90 |
|
292 |
08 May 07 |
peter |
91 |
|
1513 |
23 Sep 12 |
peter |
92 |
bool Trac::changeset2(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
93 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
94 |
const std::string::const_iterator& last_trunc) |
292 |
08 May 07 |
peter |
95 |
{ |
292 |
08 May 07 |
peter |
96 |
if (first==last) |
292 |
08 May 07 |
peter |
97 |
return false; |
292 |
08 May 07 |
peter |
98 |
if (*first != '[') |
292 |
08 May 07 |
peter |
99 |
return false; |
292 |
08 May 07 |
peter |
100 |
const std::string::const_iterator first_orig(first); |
292 |
08 May 07 |
peter |
101 |
++first; |
292 |
08 May 07 |
peter |
102 |
std::string rev = match(first, last, Digit()); |
292 |
08 May 07 |
peter |
103 |
if (rev.empty() || first==last || *first!=']'){ |
292 |
08 May 07 |
peter |
104 |
first = first_orig; |
292 |
08 May 07 |
peter |
105 |
return false; |
292 |
08 May 07 |
peter |
106 |
} |
292 |
08 May 07 |
peter |
107 |
++first; |
292 |
08 May 07 |
peter |
108 |
std::string href(Configuration::instance().trac_root()+"changeset/"+rev); |
1513 |
23 Sep 12 |
peter |
109 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
292 |
08 May 07 |
peter |
110 |
return true; |
292 |
08 May 07 |
peter |
111 |
} |
292 |
08 May 07 |
peter |
112 |
|
292 |
08 May 07 |
peter |
113 |
|
1513 |
23 Sep 12 |
peter |
114 |
bool Trac::changeset3(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
115 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
116 |
const std::string::const_iterator& last_trunc) |
292 |
08 May 07 |
peter |
117 |
{ |
292 |
08 May 07 |
peter |
118 |
if (first==last) |
292 |
08 May 07 |
peter |
119 |
return false; |
292 |
08 May 07 |
peter |
120 |
const std::string::const_iterator first_orig(first); |
309 |
12 May 07 |
peter |
121 |
if (match(first, last, std::string("changeset:")).empty()){ |
292 |
08 May 07 |
peter |
122 |
first = first_orig; |
292 |
08 May 07 |
peter |
123 |
return false; |
292 |
08 May 07 |
peter |
124 |
} |
292 |
08 May 07 |
peter |
125 |
std::string rev = match(first, last, Digit()); |
292 |
08 May 07 |
peter |
126 |
if (rev.empty()){ |
292 |
08 May 07 |
peter |
127 |
first = first_orig; |
292 |
08 May 07 |
peter |
128 |
return false; |
292 |
08 May 07 |
peter |
129 |
} |
292 |
08 May 07 |
peter |
130 |
std::string href(Configuration::instance().trac_root()+"changeset/"+rev); |
1513 |
23 Sep 12 |
peter |
131 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
292 |
08 May 07 |
peter |
132 |
return true; |
292 |
08 May 07 |
peter |
133 |
} |
292 |
08 May 07 |
peter |
134 |
|
292 |
08 May 07 |
peter |
135 |
|
1513 |
23 Sep 12 |
peter |
136 |
bool Trac::comment(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
137 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
138 |
const std::string::const_iterator& last_trunc) |
291 |
08 May 07 |
peter |
139 |
{ |
291 |
08 May 07 |
peter |
140 |
if (first==last) |
291 |
08 May 07 |
peter |
141 |
return false; |
291 |
08 May 07 |
peter |
142 |
|
291 |
08 May 07 |
peter |
143 |
const std::string::const_iterator first_orig(first); |
309 |
12 May 07 |
peter |
144 |
if (match(first, last, std::string("comment:ticket:")).empty()){ |
291 |
08 May 07 |
peter |
145 |
first = first_orig; |
291 |
08 May 07 |
peter |
146 |
return false; |
291 |
08 May 07 |
peter |
147 |
} |
1513 |
23 Sep 12 |
peter |
148 |
|
308 |
12 May 07 |
peter |
149 |
std::string ticket = match(first, last, AlNum()); |
291 |
08 May 07 |
peter |
150 |
if (ticket.empty() || first == last || *first != ':') { |
291 |
08 May 07 |
peter |
151 |
first = first_orig; |
291 |
08 May 07 |
peter |
152 |
return false; |
291 |
08 May 07 |
peter |
153 |
} |
291 |
08 May 07 |
peter |
154 |
++first; |
291 |
08 May 07 |
peter |
155 |
std::string comment = match(first, last, Digit()); |
291 |
08 May 07 |
peter |
156 |
if (comment.empty() ) { |
291 |
08 May 07 |
peter |
157 |
first = first_orig; |
291 |
08 May 07 |
peter |
158 |
return false; |
291 |
08 May 07 |
peter |
159 |
} |
291 |
08 May 07 |
peter |
160 |
std::string href(Configuration::instance().trac_root()+"ticket/"+ticket+ |
291 |
08 May 07 |
peter |
161 |
"#comment:"+comment); |
1513 |
23 Sep 12 |
peter |
162 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
291 |
08 May 07 |
peter |
163 |
return true; |
291 |
08 May 07 |
peter |
164 |
} |
291 |
08 May 07 |
peter |
165 |
|
291 |
08 May 07 |
peter |
166 |
|
1513 |
23 Sep 12 |
peter |
167 |
bool Trac::diff(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
168 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
169 |
const std::string::const_iterator& last_trunc) |
294 |
08 May 07 |
peter |
170 |
{ |
317 |
17 May 07 |
peter |
171 |
if (diff3(first, last, last_trunc)) |
309 |
12 May 07 |
peter |
172 |
return true; |
317 |
17 May 07 |
peter |
173 |
if (diff1(first, last, last_trunc)) |
294 |
08 May 07 |
peter |
174 |
return true; |
317 |
17 May 07 |
peter |
175 |
if (diff2(first, last, last_trunc)) |
294 |
08 May 07 |
peter |
176 |
return true; |
294 |
08 May 07 |
peter |
177 |
return false; |
294 |
08 May 07 |
peter |
178 |
} |
294 |
08 May 07 |
peter |
179 |
|
294 |
08 May 07 |
peter |
180 |
|
1513 |
23 Sep 12 |
peter |
181 |
bool Trac::diff1(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
182 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
183 |
const std::string::const_iterator& last_trunc) |
294 |
08 May 07 |
peter |
184 |
{ |
294 |
08 May 07 |
peter |
185 |
if (first==last) |
294 |
08 May 07 |
peter |
186 |
return false; |
294 |
08 May 07 |
peter |
187 |
|
294 |
08 May 07 |
peter |
188 |
const std::string::const_iterator first_orig(first); |
309 |
12 May 07 |
peter |
189 |
if (match(first, last, std::string("diff:")).empty()){ |
294 |
08 May 07 |
peter |
190 |
first = first_orig; |
294 |
08 May 07 |
peter |
191 |
return false; |
294 |
08 May 07 |
peter |
192 |
} |
294 |
08 May 07 |
peter |
193 |
std::string node = match(first, last, notChar('@')); |
294 |
08 May 07 |
peter |
194 |
if (first==last){ |
294 |
08 May 07 |
peter |
195 |
first = first_orig; |
294 |
08 May 07 |
peter |
196 |
return false; |
294 |
08 May 07 |
peter |
197 |
} |
1513 |
23 Sep 12 |
peter |
198 |
++first; |
308 |
12 May 07 |
peter |
199 |
std::string old_rev = match(first, last, AlNum()); |
294 |
08 May 07 |
peter |
200 |
if (old_rev.empty() || first == last || *first != ':') { |
294 |
08 May 07 |
peter |
201 |
first = first_orig; |
294 |
08 May 07 |
peter |
202 |
return false; |
294 |
08 May 07 |
peter |
203 |
} |
294 |
08 May 07 |
peter |
204 |
++first; |
308 |
12 May 07 |
peter |
205 |
std::string new_rev = match(first, last, AlNum()); |
294 |
08 May 07 |
peter |
206 |
if (new_rev.empty() ) { |
294 |
08 May 07 |
peter |
207 |
first = first_orig; |
294 |
08 May 07 |
peter |
208 |
return false; |
294 |
08 May 07 |
peter |
209 |
} |
294 |
08 May 07 |
peter |
210 |
std::string href; |
294 |
08 May 07 |
peter |
211 |
if (node.empty()) |
294 |
08 May 07 |
peter |
212 |
href = std::string(Configuration::instance().trac_root()+ |
400 |
28 Jun 07 |
peter |
213 |
"changeset?new="+new_rev+"&old="+old_rev); |
294 |
08 May 07 |
peter |
214 |
else |
294 |
08 May 07 |
peter |
215 |
href = std::string(Configuration::instance().trac_root()+ |
400 |
28 Jun 07 |
peter |
216 |
"changeset?new="+new_rev+"&new_path="+node+ |
400 |
28 Jun 07 |
peter |
217 |
"&old="+old_rev+"&old_path="+node); |
1513 |
23 Sep 12 |
peter |
218 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
294 |
08 May 07 |
peter |
219 |
return true; |
294 |
08 May 07 |
peter |
220 |
} |
294 |
08 May 07 |
peter |
221 |
|
294 |
08 May 07 |
peter |
222 |
|
1513 |
23 Sep 12 |
peter |
223 |
bool Trac::diff2(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
224 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
225 |
const std::string::const_iterator& last_trunc) |
294 |
08 May 07 |
peter |
226 |
{ |
294 |
08 May 07 |
peter |
227 |
if (first==last) |
294 |
08 May 07 |
peter |
228 |
return false; |
294 |
08 May 07 |
peter |
229 |
|
294 |
08 May 07 |
peter |
230 |
const std::string::const_iterator first_orig(first); |
309 |
12 May 07 |
peter |
231 |
if (match(first, last, std::string("diff:")).empty()){ |
294 |
08 May 07 |
peter |
232 |
first = first_orig; |
294 |
08 May 07 |
peter |
233 |
return false; |
294 |
08 May 07 |
peter |
234 |
} |
294 |
08 May 07 |
peter |
235 |
std::string old_path(match(first, last, not2Str("//", " "))); |
294 |
08 May 07 |
peter |
236 |
std::string new_path; |
294 |
08 May 07 |
peter |
237 |
if (first==last || *first==' ') |
294 |
08 May 07 |
peter |
238 |
new_path = old_path; |
294 |
08 May 07 |
peter |
239 |
else { |
294 |
08 May 07 |
peter |
240 |
first += 2; |
294 |
08 May 07 |
peter |
241 |
new_path = match(first, last, notChar(' ')); |
294 |
08 May 07 |
peter |
242 |
} |
294 |
08 May 07 |
peter |
243 |
if (new_path.empty() || old_path.empty()){ |
294 |
08 May 07 |
peter |
244 |
first = first_orig; |
294 |
08 May 07 |
peter |
245 |
return false; |
294 |
08 May 07 |
peter |
246 |
} |
294 |
08 May 07 |
peter |
247 |
std::string href(Configuration::instance().trac_root()+ |
400 |
28 Jun 07 |
peter |
248 |
"changeset?new_path="+new_path+"&old_path="+old_path); |
1513 |
23 Sep 12 |
peter |
249 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
294 |
08 May 07 |
peter |
250 |
return true; |
294 |
08 May 07 |
peter |
251 |
} |
294 |
08 May 07 |
peter |
252 |
|
294 |
08 May 07 |
peter |
253 |
|
1513 |
23 Sep 12 |
peter |
254 |
bool Trac::diff3(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
255 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
256 |
const std::string::const_iterator& last_trunc) |
294 |
08 May 07 |
peter |
257 |
{ |
294 |
08 May 07 |
peter |
258 |
if (first==last) |
294 |
08 May 07 |
peter |
259 |
return false; |
294 |
08 May 07 |
peter |
260 |
|
294 |
08 May 07 |
peter |
261 |
const std::string::const_iterator first_orig(first); |
309 |
12 May 07 |
peter |
262 |
if (match(first, last, std::string("diff:")).empty()){ |
294 |
08 May 07 |
peter |
263 |
first = first_orig; |
294 |
08 May 07 |
peter |
264 |
return false; |
294 |
08 May 07 |
peter |
265 |
} |
294 |
08 May 07 |
peter |
266 |
std::string old_path(match(first, last, not2Char('@', ' '))); |
294 |
08 May 07 |
peter |
267 |
if (*first!='@'){ |
294 |
08 May 07 |
peter |
268 |
first = first_orig; |
294 |
08 May 07 |
peter |
269 |
return false; |
294 |
08 May 07 |
peter |
270 |
} |
294 |
08 May 07 |
peter |
271 |
++first; |
308 |
12 May 07 |
peter |
272 |
std::string old_rev(match(first, last, AlNum())); |
309 |
12 May 07 |
peter |
273 |
if (match(first, last, std::string("//")).empty()) { |
294 |
08 May 07 |
peter |
274 |
first = first_orig; |
294 |
08 May 07 |
peter |
275 |
return false; |
294 |
08 May 07 |
peter |
276 |
} |
294 |
08 May 07 |
peter |
277 |
std::string new_path = match(first, last, not2Char('@', ' ')); |
294 |
08 May 07 |
peter |
278 |
if (*first!='@'){ |
294 |
08 May 07 |
peter |
279 |
first = first_orig; |
294 |
08 May 07 |
peter |
280 |
return false; |
294 |
08 May 07 |
peter |
281 |
} |
294 |
08 May 07 |
peter |
282 |
++first; |
308 |
12 May 07 |
peter |
283 |
std::string new_rev(match(first, last, AlNum())); |
294 |
08 May 07 |
peter |
284 |
if (new_rev.empty()){ |
294 |
08 May 07 |
peter |
285 |
first = first_orig; |
294 |
08 May 07 |
peter |
286 |
return false; |
294 |
08 May 07 |
peter |
287 |
} |
1513 |
23 Sep 12 |
peter |
288 |
|
294 |
08 May 07 |
peter |
289 |
std::string href(Configuration::instance().trac_root()+ |
400 |
28 Jun 07 |
peter |
290 |
"changeset?new="+new_rev+"&new_path="+new_path+ |
400 |
28 Jun 07 |
peter |
291 |
"&old="+old_rev+"&old_path="+old_path); |
1513 |
23 Sep 12 |
peter |
292 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
294 |
08 May 07 |
peter |
293 |
return true; |
294 |
08 May 07 |
peter |
294 |
} |
294 |
08 May 07 |
peter |
295 |
|
294 |
08 May 07 |
peter |
296 |
|
768 |
31 Jan 09 |
peter |
297 |
bool Trac::log(const std::string::const_iterator& first, |
1513 |
23 Sep 12 |
peter |
298 |
std::string::const_iterator& iter, |
317 |
17 May 07 |
peter |
299 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
300 |
const std::string::const_iterator& last_trunc) |
288 |
07 May 07 |
peter |
301 |
{ |
768 |
31 Jan 09 |
peter |
302 |
if (log1(first, iter, last, last_trunc)) |
293 |
08 May 07 |
peter |
303 |
return true; |
768 |
31 Jan 09 |
peter |
304 |
if (log2(iter, last, last_trunc)) |
293 |
08 May 07 |
peter |
305 |
return true; |
768 |
31 Jan 09 |
peter |
306 |
if (log3(iter, last, last_trunc)) |
293 |
08 May 07 |
peter |
307 |
return true; |
293 |
08 May 07 |
peter |
308 |
return false; |
293 |
08 May 07 |
peter |
309 |
} |
293 |
08 May 07 |
peter |
310 |
|
293 |
08 May 07 |
peter |
311 |
|
768 |
31 Jan 09 |
peter |
312 |
bool Trac::log1(const std::string::const_iterator& first, |
1513 |
23 Sep 12 |
peter |
313 |
std::string::const_iterator& iter, |
317 |
17 May 07 |
peter |
314 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
315 |
const std::string::const_iterator& last_trunc) |
293 |
08 May 07 |
peter |
316 |
{ |
768 |
31 Jan 09 |
peter |
317 |
if (iter==last) |
288 |
07 May 07 |
peter |
318 |
return false; |
288 |
07 May 07 |
peter |
319 |
|
768 |
31 Jan 09 |
peter |
320 |
const std::string::const_iterator iter_orig(iter); |
768 |
31 Jan 09 |
peter |
321 |
if (*iter != 'r') |
293 |
08 May 07 |
peter |
322 |
return false; |
768 |
31 Jan 09 |
peter |
323 |
if (iter!=first && isalnum(*(iter-1))) |
768 |
31 Jan 09 |
peter |
324 |
return false; |
768 |
31 Jan 09 |
peter |
325 |
++iter; |
289 |
08 May 07 |
peter |
326 |
|
768 |
31 Jan 09 |
peter |
327 |
std::string stop_rev = match(iter, last, Digit()); |
768 |
31 Jan 09 |
peter |
328 |
if (stop_rev.empty() || iter == last || *iter != ':') { |
768 |
31 Jan 09 |
peter |
329 |
iter = iter_orig; |
293 |
08 May 07 |
peter |
330 |
return false; |
293 |
08 May 07 |
peter |
331 |
} |
768 |
31 Jan 09 |
peter |
332 |
++iter; |
768 |
31 Jan 09 |
peter |
333 |
std::string rev = match(iter, last, Digit()); |
768 |
31 Jan 09 |
peter |
334 |
if (rev.empty() || (iter!=last && std::isalnum(*iter) ) ){ |
768 |
31 Jan 09 |
peter |
335 |
iter = iter_orig; |
293 |
08 May 07 |
peter |
336 |
return false; |
293 |
08 May 07 |
peter |
337 |
} |
293 |
08 May 07 |
peter |
338 |
std::string href(Configuration::instance().trac_root()+"log/?rev="+ |
400 |
28 Jun 07 |
peter |
339 |
rev+"&stop_rev="+stop_rev); |
1513 |
23 Sep 12 |
peter |
340 |
hs_.stream() << anchor(href, anchor_text(iter_orig,iter, last_trunc)); |
293 |
08 May 07 |
peter |
341 |
return true; |
293 |
08 May 07 |
peter |
342 |
} |
293 |
08 May 07 |
peter |
343 |
|
293 |
08 May 07 |
peter |
344 |
|
1513 |
23 Sep 12 |
peter |
345 |
bool Trac::log2(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
346 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
347 |
const std::string::const_iterator& last_trunc) |
293 |
08 May 07 |
peter |
348 |
{ |
293 |
08 May 07 |
peter |
349 |
if (first==last) |
293 |
08 May 07 |
peter |
350 |
return false; |
293 |
08 May 07 |
peter |
351 |
|
293 |
08 May 07 |
peter |
352 |
const std::string::const_iterator first_orig(first); |
293 |
08 May 07 |
peter |
353 |
if (*first != '[') |
293 |
08 May 07 |
peter |
354 |
return false; |
293 |
08 May 07 |
peter |
355 |
++first; |
293 |
08 May 07 |
peter |
356 |
|
308 |
12 May 07 |
peter |
357 |
std::string stop_rev = match(first, last, AlNum()); |
293 |
08 May 07 |
peter |
358 |
if (stop_rev.empty() || first == last || *first != ':') { |
293 |
08 May 07 |
peter |
359 |
first = first_orig; |
293 |
08 May 07 |
peter |
360 |
return false; |
293 |
08 May 07 |
peter |
361 |
} |
293 |
08 May 07 |
peter |
362 |
++first; |
308 |
12 May 07 |
peter |
363 |
std::string rev = match(first, last, AlNum()); |
293 |
08 May 07 |
peter |
364 |
if (rev.empty() || first == last || *first != ']') { |
293 |
08 May 07 |
peter |
365 |
first = first_orig; |
293 |
08 May 07 |
peter |
366 |
return false; |
293 |
08 May 07 |
peter |
367 |
} |
309 |
12 May 07 |
peter |
368 |
++first; // eating ']' |
293 |
08 May 07 |
peter |
369 |
std::string href(Configuration::instance().trac_root()+"log/?rev="+ |
400 |
28 Jun 07 |
peter |
370 |
rev+"&stop_rev="+stop_rev); |
1513 |
23 Sep 12 |
peter |
371 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
293 |
08 May 07 |
peter |
372 |
return true; |
293 |
08 May 07 |
peter |
373 |
} |
293 |
08 May 07 |
peter |
374 |
|
293 |
08 May 07 |
peter |
375 |
|
1513 |
23 Sep 12 |
peter |
376 |
bool Trac::log3(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
377 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
378 |
const std::string::const_iterator& last_trunc) |
293 |
08 May 07 |
peter |
379 |
{ |
293 |
08 May 07 |
peter |
380 |
if (first==last) |
293 |
08 May 07 |
peter |
381 |
return false; |
293 |
08 May 07 |
peter |
382 |
|
293 |
08 May 07 |
peter |
383 |
const std::string::const_iterator first_orig(first); |
293 |
08 May 07 |
peter |
384 |
|
1513 |
23 Sep 12 |
peter |
385 |
const std::string log_str("log:"); |
289 |
08 May 07 |
peter |
386 |
if (!match_begin(first, last, log_str)) { |
289 |
08 May 07 |
peter |
387 |
first = first_orig; |
288 |
07 May 07 |
peter |
388 |
return false; |
289 |
08 May 07 |
peter |
389 |
} |
289 |
08 May 07 |
peter |
390 |
first += log_str.size(); |
289 |
08 May 07 |
peter |
391 |
std::string node = match(first, last, not2Char('#', '@')); |
288 |
07 May 07 |
peter |
392 |
++first; |
308 |
12 May 07 |
peter |
393 |
std::string stop_rev = match(first, last, AlNum()); |
289 |
08 May 07 |
peter |
394 |
if (stop_rev.empty() || first == last || *first != ':') { |
289 |
08 May 07 |
peter |
395 |
first = first_orig; |
288 |
07 May 07 |
peter |
396 |
return false; |
289 |
08 May 07 |
peter |
397 |
} |
289 |
08 May 07 |
peter |
398 |
++first; |
308 |
12 May 07 |
peter |
399 |
std::string rev = match(first, last, AlNum()); |
291 |
08 May 07 |
peter |
400 |
if (rev.empty() ) { |
291 |
08 May 07 |
peter |
401 |
first = first_orig; |
291 |
08 May 07 |
peter |
402 |
return false; |
291 |
08 May 07 |
peter |
403 |
} |
293 |
08 May 07 |
peter |
404 |
std::string href; |
293 |
08 May 07 |
peter |
405 |
if (!node.empty() && node[0]=='/') |
293 |
08 May 07 |
peter |
406 |
href = std::string(Configuration::instance().trac_root()+"log"+node+ |
400 |
28 Jun 07 |
peter |
407 |
"?rev="+rev+"&stop_rev="+stop_rev); |
293 |
08 May 07 |
peter |
408 |
else |
293 |
08 May 07 |
peter |
409 |
href = std::string(Configuration::instance().trac_root()+"log/"+node+ |
400 |
28 Jun 07 |
peter |
410 |
"?rev="+rev+"&stop_rev="+stop_rev); |
1513 |
23 Sep 12 |
peter |
411 |
|
1513 |
23 Sep 12 |
peter |
412 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
288 |
07 May 07 |
peter |
413 |
return true; |
288 |
07 May 07 |
peter |
414 |
} |
288 |
07 May 07 |
peter |
415 |
|
308 |
12 May 07 |
peter |
416 |
|
1513 |
23 Sep 12 |
peter |
417 |
bool Trac::milestone(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
418 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
419 |
const std::string::const_iterator& last_trunc) |
308 |
12 May 07 |
peter |
420 |
{ |
308 |
12 May 07 |
peter |
421 |
if (first==last) |
308 |
12 May 07 |
peter |
422 |
return false; |
308 |
12 May 07 |
peter |
423 |
|
308 |
12 May 07 |
peter |
424 |
const std::string::const_iterator first_orig(first); |
308 |
12 May 07 |
peter |
425 |
|
309 |
12 May 07 |
peter |
426 |
if (match(first, last, std::string("milestone:")).empty()){ |
308 |
12 May 07 |
peter |
427 |
first = first_orig; |
308 |
12 May 07 |
peter |
428 |
return false; |
308 |
12 May 07 |
peter |
429 |
} |
308 |
12 May 07 |
peter |
430 |
|
308 |
12 May 07 |
peter |
431 |
const std::string::const_iterator milestone_begin(first); |
308 |
12 May 07 |
peter |
432 |
|
308 |
12 May 07 |
peter |
// find the last alphanumerical char before next space (or last) |
308 |
12 May 07 |
peter |
434 |
for (std::string::const_iterator i(first); i!=last && *i!=' '; ++i) |
1513 |
23 Sep 12 |
peter |
435 |
if (isalnum(*i)) |
308 |
12 May 07 |
peter |
436 |
first = i+1; |
308 |
12 May 07 |
peter |
437 |
|
308 |
12 May 07 |
peter |
438 |
std::string milestone(milestone_begin, first); |
308 |
12 May 07 |
peter |
439 |
if (milestone.empty()){ |
308 |
12 May 07 |
peter |
440 |
first = first_orig; |
308 |
12 May 07 |
peter |
441 |
return false; |
308 |
12 May 07 |
peter |
442 |
} |
308 |
12 May 07 |
peter |
443 |
|
308 |
12 May 07 |
peter |
444 |
const Configuration& conf = Configuration::instance(); |
317 |
17 May 07 |
peter |
445 |
std::string href(conf.trac_root()+"milestone/"+milestone); |
1513 |
23 Sep 12 |
peter |
446 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
308 |
12 May 07 |
peter |
447 |
return true; |
308 |
12 May 07 |
peter |
448 |
} |
308 |
12 May 07 |
peter |
449 |
|
308 |
12 May 07 |
peter |
450 |
|
317 |
17 May 07 |
peter |
451 |
void Trac::print(std::string str, size_t width) |
308 |
12 May 07 |
peter |
452 |
{ |
308 |
12 May 07 |
peter |
453 |
std::string::const_iterator first(str.begin()); |
317 |
17 May 07 |
peter |
454 |
std::string::const_iterator last_trunc(str.end()); |
317 |
17 May 07 |
peter |
455 |
if (width<=str.size()) // truncate |
317 |
17 May 07 |
peter |
456 |
last_trunc = first+width; |
317 |
17 May 07 |
peter |
457 |
while (first<last_trunc) { |
768 |
31 Jan 09 |
peter |
458 |
if (log(str.begin(), first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
459 |
continue; |
317 |
17 May 07 |
peter |
460 |
if (comment(first, str.end(), last_trunc)) |
309 |
12 May 07 |
peter |
461 |
continue; |
317 |
17 May 07 |
peter |
462 |
if (ticket(first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
463 |
continue; |
768 |
31 Jan 09 |
peter |
464 |
if (changeset(str.begin(), first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
465 |
continue; |
317 |
17 May 07 |
peter |
466 |
if (diff(first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
467 |
continue; |
317 |
17 May 07 |
peter |
468 |
if (milestone(first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
469 |
continue; |
317 |
17 May 07 |
peter |
470 |
if (source(first, str.end(), last_trunc)) |
308 |
12 May 07 |
peter |
471 |
continue; |
308 |
12 May 07 |
peter |
472 |
hs_ << *first; |
308 |
12 May 07 |
peter |
473 |
++first; |
308 |
12 May 07 |
peter |
474 |
} |
317 |
17 May 07 |
peter |
475 |
if (last_trunc!=str.end()) |
317 |
17 May 07 |
peter |
476 |
hs_ << "..."; |
308 |
12 May 07 |
peter |
477 |
} |
308 |
12 May 07 |
peter |
478 |
|
308 |
12 May 07 |
peter |
479 |
|
1513 |
23 Sep 12 |
peter |
480 |
bool Trac::source(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
481 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
482 |
const std::string::const_iterator& last_trunc) |
308 |
12 May 07 |
peter |
483 |
{ |
308 |
12 May 07 |
peter |
484 |
if (first==last) |
308 |
12 May 07 |
peter |
485 |
return false; |
308 |
12 May 07 |
peter |
486 |
|
308 |
12 May 07 |
peter |
487 |
const std::string::const_iterator first_orig(first); |
308 |
12 May 07 |
peter |
488 |
|
309 |
12 May 07 |
peter |
489 |
if (match(first, last, std::string("source:")).empty()){ |
308 |
12 May 07 |
peter |
490 |
first = first_orig; |
308 |
12 May 07 |
peter |
491 |
return false; |
308 |
12 May 07 |
peter |
492 |
} |
308 |
12 May 07 |
peter |
493 |
|
308 |
12 May 07 |
peter |
494 |
std::string node; |
308 |
12 May 07 |
peter |
495 |
std::string rev; |
308 |
12 May 07 |
peter |
496 |
std::string line; |
308 |
12 May 07 |
peter |
497 |
const std::string::const_iterator node_begin(first); |
308 |
12 May 07 |
peter |
498 |
|
308 |
12 May 07 |
peter |
499 |
node = match(first, last, not2Char('@', ' ')); |
308 |
12 May 07 |
peter |
500 |
if (!node.empty() && node[0]=='/') |
1513 |
23 Sep 12 |
peter |
501 |
node = node.substr(1, node.size()-1); |
1513 |
23 Sep 12 |
peter |
502 |
|
308 |
12 May 07 |
peter |
503 |
if (*first == '@'){ |
308 |
12 May 07 |
peter |
504 |
++first; |
308 |
12 May 07 |
peter |
505 |
rev = match(first, last, AlNum()); |
308 |
12 May 07 |
peter |
506 |
if (*first == '#') { |
308 |
12 May 07 |
peter |
507 |
++first; |
308 |
12 May 07 |
peter |
508 |
line = match(first, last, notChar(' ')); |
308 |
12 May 07 |
peter |
509 |
} |
308 |
12 May 07 |
peter |
510 |
} |
308 |
12 May 07 |
peter |
511 |
|
308 |
12 May 07 |
peter |
512 |
const Configuration& conf = Configuration::instance(); |
308 |
12 May 07 |
peter |
513 |
std::string href(conf.trac_root()+"browser/"+node); |
308 |
12 May 07 |
peter |
514 |
if (!rev.empty()) { |
308 |
12 May 07 |
peter |
515 |
href += "?rev="+rev; |
308 |
12 May 07 |
peter |
516 |
if (!line.empty()) |
308 |
12 May 07 |
peter |
517 |
href += "#"+line; |
308 |
12 May 07 |
peter |
518 |
} |
1513 |
23 Sep 12 |
peter |
519 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
308 |
12 May 07 |
peter |
520 |
return true; |
308 |
12 May 07 |
peter |
521 |
} |
308 |
12 May 07 |
peter |
522 |
|
308 |
12 May 07 |
peter |
523 |
|
1513 |
23 Sep 12 |
peter |
524 |
bool Trac::ticket(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
525 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
526 |
const std::string::const_iterator& last_trunc) |
308 |
12 May 07 |
peter |
527 |
{ |
317 |
17 May 07 |
peter |
528 |
if (ticket1(first, last, last_trunc)) |
308 |
12 May 07 |
peter |
529 |
return true; |
317 |
17 May 07 |
peter |
530 |
if (ticket2(first, last, last_trunc)) |
308 |
12 May 07 |
peter |
531 |
return true; |
308 |
12 May 07 |
peter |
532 |
return false; |
308 |
12 May 07 |
peter |
533 |
} |
308 |
12 May 07 |
peter |
534 |
|
308 |
12 May 07 |
peter |
535 |
|
1513 |
23 Sep 12 |
peter |
536 |
bool Trac::ticket1(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
537 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
538 |
const std::string::const_iterator& last_trunc) |
308 |
12 May 07 |
peter |
539 |
{ |
308 |
12 May 07 |
peter |
540 |
if (first==last) |
308 |
12 May 07 |
peter |
541 |
return false; |
308 |
12 May 07 |
peter |
542 |
|
308 |
12 May 07 |
peter |
543 |
const std::string::const_iterator first_orig(first); |
308 |
12 May 07 |
peter |
544 |
if (*first != '#') |
308 |
12 May 07 |
peter |
545 |
return false; |
308 |
12 May 07 |
peter |
546 |
++first; |
308 |
12 May 07 |
peter |
547 |
std::string ticket = match(first, last, Digit()); |
308 |
12 May 07 |
peter |
548 |
|
308 |
12 May 07 |
peter |
549 |
if (ticket.empty()) { |
308 |
12 May 07 |
peter |
550 |
first = first_orig; |
308 |
12 May 07 |
peter |
551 |
return false; |
308 |
12 May 07 |
peter |
552 |
} |
308 |
12 May 07 |
peter |
553 |
|
308 |
12 May 07 |
peter |
554 |
const Configuration& conf = Configuration::instance(); |
308 |
12 May 07 |
peter |
555 |
hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket, |
1513 |
23 Sep 12 |
peter |
556 |
anchor_text(first_orig,first, last_trunc)); |
308 |
12 May 07 |
peter |
557 |
return true; |
308 |
12 May 07 |
peter |
558 |
} |
308 |
12 May 07 |
peter |
559 |
|
308 |
12 May 07 |
peter |
560 |
|
1513 |
23 Sep 12 |
peter |
561 |
bool Trac::ticket2(std::string::const_iterator& first, |
317 |
17 May 07 |
peter |
562 |
const std::string::const_iterator& last, |
317 |
17 May 07 |
peter |
563 |
const std::string::const_iterator& last_trunc) |
308 |
12 May 07 |
peter |
564 |
{ |
308 |
12 May 07 |
peter |
565 |
if (first==last) |
308 |
12 May 07 |
peter |
566 |
return false; |
308 |
12 May 07 |
peter |
567 |
|
308 |
12 May 07 |
peter |
568 |
const std::string::const_iterator first_orig(first); |
308 |
12 May 07 |
peter |
569 |
|
309 |
12 May 07 |
peter |
570 |
if (match(first, last, std::string("ticket:")).empty()){ |
1513 |
23 Sep 12 |
peter |
571 |
first = first_orig; |
308 |
12 May 07 |
peter |
572 |
return false; |
308 |
12 May 07 |
peter |
573 |
} |
308 |
12 May 07 |
peter |
574 |
std::string ticket = match(first, last, Digit()); |
308 |
12 May 07 |
peter |
575 |
|
308 |
12 May 07 |
peter |
576 |
const Configuration& conf = Configuration::instance(); |
317 |
17 May 07 |
peter |
577 |
std::string href(conf.trac_root()+"ticket/"+ticket); |
1513 |
23 Sep 12 |
peter |
578 |
hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); |
308 |
12 May 07 |
peter |
579 |
return true; |
308 |
12 May 07 |
peter |
580 |
} |
308 |
12 May 07 |
peter |
581 |
|
308 |
12 May 07 |
peter |
582 |
|
286 |
07 May 07 |
peter |
583 |
}} // end of namespace svndigest and namespace theplu |