7 |
30 Dec 05 |
jari |
// $Id$ |
4 |
29 Dec 05 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2010, 2011, 2012, 2023 Peter Johansson |
84 |
13 Mar 06 |
jari |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
8 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
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 |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
13 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
18 |
|
84 |
13 Mar 06 |
jari |
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/>. |
84 |
13 Mar 06 |
jari |
21 |
*/ |
84 |
13 Mar 06 |
jari |
22 |
|
1619 |
12 Mar 23 |
peter |
23 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
24 |
|
1290 |
12 Nov 10 |
peter |
25 |
#include "NodePrinter.h" |
452 |
17 Aug 07 |
peter |
26 |
|
1136 |
18 Jul 10 |
peter |
27 |
#include "Configuration.h" |
452 |
17 Aug 07 |
peter |
28 |
#include "Date.h" |
751 |
14 Jan 09 |
peter |
29 |
#include "HtmlStream.h" |
177 |
02 Sep 06 |
peter |
30 |
#include "html_utility.h" |
1234 |
23 Oct 10 |
peter |
31 |
#include "LineTypeParser.h" |
1290 |
12 Nov 10 |
peter |
32 |
#include "Node.h" |
258 |
30 Apr 07 |
peter |
33 |
#include "SVNlog.h" |
4 |
29 Dec 05 |
peter |
34 |
#include "utility.h" |
4 |
29 Dec 05 |
peter |
35 |
|
828 |
26 Sep 09 |
peter |
36 |
#include <algorithm> |
23 |
02 Jan 06 |
peter |
37 |
#include <ctime> |
4 |
29 Dec 05 |
peter |
38 |
#include <fstream> |
285 |
06 May 07 |
peter |
39 |
#include <iostream> |
4 |
29 Dec 05 |
peter |
40 |
#include <sstream> |
4 |
29 Dec 05 |
peter |
41 |
|
361 |
10 Jun 07 |
peter |
42 |
#include <dirent.h> |
361 |
10 Jun 07 |
peter |
43 |
#include <sys/stat.h> |
361 |
10 Jun 07 |
peter |
44 |
|
4 |
29 Dec 05 |
peter |
45 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
46 |
namespace svndigest{ |
4 |
29 Dec 05 |
peter |
47 |
|
1513 |
23 Sep 12 |
peter |
48 |
NodePrinter::NodePrinter(void) |
453 |
17 Aug 07 |
peter |
49 |
{ |
453 |
17 Aug 07 |
peter |
50 |
} |
453 |
17 Aug 07 |
peter |
51 |
|
1290 |
12 Nov 10 |
peter |
52 |
NodePrinter::~NodePrinter(void) |
101 |
22 Jun 06 |
peter |
53 |
{ |
101 |
22 Jun 06 |
peter |
54 |
} |
101 |
22 Jun 06 |
peter |
55 |
|
185 |
06 Sep 06 |
jari |
56 |
|
1290 |
12 Nov 10 |
peter |
57 |
std::string NodePrinter::output_dir(void) const |
175 |
02 Sep 06 |
peter |
58 |
{ |
1290 |
12 Nov 10 |
peter |
59 |
return node().output_dir_; |
101 |
22 Jun 06 |
peter |
60 |
} |
101 |
22 Jun 06 |
peter |
61 |
|
185 |
06 Sep 06 |
jari |
62 |
|
1537 |
07 Oct 12 |
peter |
63 |
svn_revnum_t NodePrinter::output_revision(void) const |
1537 |
07 Oct 12 |
peter |
64 |
{ |
1537 |
07 Oct 12 |
peter |
65 |
std::ifstream is(out_name("classic", "all", "total").c_str()); |
1537 |
07 Oct 12 |
peter |
66 |
if (!is.good()) |
1537 |
07 Oct 12 |
peter |
67 |
return 0; |
1537 |
07 Oct 12 |
peter |
68 |
std::string line; |
1537 |
07 Oct 12 |
peter |
// search first three lines for 'revision: ' |
1537 |
07 Oct 12 |
peter |
70 |
std::string str("revision: "); |
1537 |
07 Oct 12 |
peter |
71 |
for (size_t i=0; i<3; ++i) { |
1537 |
07 Oct 12 |
peter |
72 |
getline(is, line); |
1537 |
07 Oct 12 |
peter |
73 |
size_t pos = line.find(str); |
1537 |
07 Oct 12 |
peter |
74 |
if (pos==std::string::npos) |
1537 |
07 Oct 12 |
peter |
75 |
continue; |
1537 |
07 Oct 12 |
peter |
76 |
std::istringstream ss(line.substr(pos+str.size())); |
1537 |
07 Oct 12 |
peter |
77 |
svn_revnum_t result = 0; |
1537 |
07 Oct 12 |
peter |
78 |
ss >> result; |
1537 |
07 Oct 12 |
peter |
79 |
return result; |
1537 |
07 Oct 12 |
peter |
80 |
} |
1537 |
07 Oct 12 |
peter |
81 |
is.close(); |
1537 |
07 Oct 12 |
peter |
82 |
return 0; |
1537 |
07 Oct 12 |
peter |
83 |
} |
1537 |
07 Oct 12 |
peter |
84 |
|
1537 |
07 Oct 12 |
peter |
85 |
|
1290 |
12 Nov 10 |
peter |
86 |
void NodePrinter::path_anchor(std::ostream& os) const |
1234 |
23 Oct 10 |
peter |
87 |
{ |
306 |
12 May 07 |
peter |
88 |
os << "<h2 class=\"path\">\n"; |
306 |
12 May 07 |
peter |
89 |
std::vector<std::string> words; |
1290 |
12 Nov 10 |
peter |
90 |
words.reserve(node().level_+1); |
306 |
12 May 07 |
peter |
91 |
std::string word; |
306 |
12 May 07 |
peter |
92 |
words.push_back(Node::project_); |
1290 |
12 Nov 10 |
peter |
93 |
std::stringstream ss(node().local_path()); |
306 |
12 May 07 |
peter |
94 |
while(getline(ss,word,'/')) |
306 |
12 May 07 |
peter |
95 |
if (!word.empty()) // ignore double slash in path |
306 |
12 May 07 |
peter |
96 |
words.push_back(word); |
306 |
12 May 07 |
peter |
97 |
if (words.size()==1) |
306 |
12 May 07 |
peter |
98 |
os << anchor("index.html", Node::project_,0, "View " + Node::project_); |
306 |
12 May 07 |
peter |
99 |
else { |
306 |
12 May 07 |
peter |
100 |
for (size_t i=0; i<words.size()-1; ++i){ |
1290 |
12 Nov 10 |
peter |
101 |
os << anchor("index.html", words[i], node().level_-i, "View " + words[i]); |
463 |
21 Aug 07 |
jari |
102 |
os << "<span class=\"sep\">/</span>"; |
306 |
12 May 07 |
peter |
103 |
} |
1513 |
23 Sep 12 |
peter |
104 |
os << anchor(node().href(), words.back(), node().level_+2-words.size(), |
1513 |
23 Sep 12 |
peter |
105 |
"View " + words.back()); |
306 |
12 May 07 |
peter |
106 |
} |
306 |
12 May 07 |
peter |
107 |
os << "\n</h2>\n"; |
306 |
12 May 07 |
peter |
108 |
} |
306 |
12 May 07 |
peter |
109 |
|
306 |
12 May 07 |
peter |
110 |
|
1537 |
07 Oct 12 |
peter |
111 |
void NodePrinter::print(const bool verbose, bool update) const |
258 |
30 Apr 07 |
peter |
112 |
{ |
1449 |
22 Dec 11 |
peter |
113 |
if (node().svndigest_ignore()) |
258 |
30 Apr 07 |
peter |
114 |
return; |
1290 |
12 Nov 10 |
peter |
115 |
if (!Configuration::instance().output_file() && !node().dir()) |
1136 |
18 Jul 10 |
peter |
116 |
return; |
1537 |
07 Oct 12 |
peter |
117 |
if (update && output_revision() >= node().last_changed_rev()) |
1538 |
07 Oct 12 |
peter |
118 |
return; |
258 |
30 Apr 07 |
peter |
119 |
if (verbose) |
1290 |
12 Nov 10 |
peter |
120 |
std::cout << "Printing output for '" << node().path_ << "'" << std::endl; |
1290 |
12 Nov 10 |
peter |
121 |
const SVNlog& log = node().log(); |
532 |
26 Dec 07 |
peter |
122 |
typedef std::map<std::string, Stats*>::const_iterator iter; |
258 |
30 Apr 07 |
peter |
123 |
|
1290 |
12 Nov 10 |
peter |
124 |
const iter end(node().stats_.stats().end()); |
1290 |
12 Nov 10 |
peter |
125 |
for (iter i=node().stats_.stats().begin();i!=end; ++i){ |
532 |
26 Dec 07 |
peter |
126 |
print_core(i->first, "all", "total", log); |
532 |
26 Dec 07 |
peter |
127 |
print_core(i->first, "all", "code", log); |
532 |
26 Dec 07 |
peter |
128 |
print_core(i->first, "all", "comments", log); |
532 |
26 Dec 07 |
peter |
129 |
print_core(i->first, "all", "empty", log); |
532 |
26 Dec 07 |
peter |
130 |
for (std::set<std::string>::const_iterator j=i->second->authors().begin(); |
532 |
26 Dec 07 |
peter |
131 |
j!=i->second->authors().end(); ++j) { |
532 |
26 Dec 07 |
peter |
132 |
print_core(i->first, *j, "total", log); |
532 |
26 Dec 07 |
peter |
133 |
print_core(i->first, *j, "code", log); |
532 |
26 Dec 07 |
peter |
134 |
print_core(i->first, *j, "comments", log); |
532 |
26 Dec 07 |
peter |
135 |
print_core(i->first, *j, "empty", log); |
532 |
26 Dec 07 |
peter |
136 |
} |
258 |
30 Apr 07 |
peter |
137 |
} |
1234 |
23 Oct 10 |
peter |
138 |
print_core(verbose); |
258 |
30 Apr 07 |
peter |
139 |
} |
258 |
30 Apr 07 |
peter |
140 |
|
258 |
30 Apr 07 |
peter |
141 |
|
1513 |
23 Sep 12 |
peter |
142 |
void NodePrinter::print_author_summary(std::ostream& os, |
532 |
26 Dec 07 |
peter |
143 |
const Stats& stats, |
532 |
26 Dec 07 |
peter |
144 |
const std::string& line_type, |
258 |
30 Apr 07 |
peter |
145 |
const SVNlog& log) const |
1513 |
23 Sep 12 |
peter |
146 |
{ |
751 |
14 Jan 09 |
peter |
147 |
HtmlStream hs(os); |
345 |
19 May 07 |
peter |
148 |
os << "<h3>Author Summary</h3>"; |
234 |
09 Apr 07 |
peter |
149 |
os << "<table class=\"listings\">\n"; |
378 |
20 Jun 07 |
jari |
150 |
os << "<thead>\n"; |
234 |
09 Apr 07 |
peter |
151 |
os << "<tr>\n"; |
234 |
09 Apr 07 |
peter |
152 |
os << "<th>Author</th>\n"; |
234 |
09 Apr 07 |
peter |
153 |
os << "<th>Lines</th>\n"; |
234 |
09 Apr 07 |
peter |
154 |
os << "<th>Code</th>\n"; |
234 |
09 Apr 07 |
peter |
155 |
os << "<th>Comments</th>\n"; |
251 |
28 Apr 07 |
peter |
156 |
os << "<th>Other</th>\n"; |
251 |
28 Apr 07 |
peter |
157 |
os << "<th>Revision</th>\n"; |
251 |
28 Apr 07 |
peter |
158 |
os << "<th>Date</th>\n"; |
234 |
09 Apr 07 |
peter |
159 |
os << "</tr>\n</thead>\n"; |
378 |
20 Jun 07 |
jari |
160 |
os << "<tbody>\n"; |
234 |
09 Apr 07 |
peter |
161 |
|
259 |
30 Apr 07 |
peter |
162 |
std::string color("light"); |
1290 |
12 Nov 10 |
peter |
163 |
if (!node().dir()) { |
259 |
30 Apr 07 |
peter |
164 |
os << "<tr class=\"" << color << "\">\n"; |
370 |
14 Jun 07 |
peter |
165 |
os << "<td class=\"directory\" colspan=\"7\">"; |
235 |
21 Apr 07 |
peter |
166 |
os << anchor("index.html", "../"); |
259 |
30 Apr 07 |
peter |
167 |
os << "</td>\n</tr>\n"; |
259 |
30 Apr 07 |
peter |
168 |
} |
259 |
30 Apr 07 |
peter |
169 |
|
234 |
09 Apr 07 |
peter |
// print authors |
751 |
14 Jan 09 |
peter |
171 |
const std::string timefmt("%Y-%m-%d %H:%M"); |
532 |
26 Dec 07 |
peter |
172 |
for (std::set<std::string>::const_iterator i=stats.authors().begin(); |
532 |
26 Dec 07 |
peter |
173 |
i!=stats.authors().end(); ++i){ |
259 |
30 Apr 07 |
peter |
174 |
if (color=="dark") |
259 |
30 Apr 07 |
peter |
175 |
color="light"; |
259 |
30 Apr 07 |
peter |
176 |
else |
259 |
30 Apr 07 |
peter |
177 |
color="dark"; |
1513 |
23 Sep 12 |
peter |
178 |
os << "<tr class=\"" << color << "\"><td>"; |
356 |
25 May 07 |
peter |
179 |
os << anchor(*i+"/"+line_type+"/"+output_path() |
1513 |
23 Sep 12 |
peter |
180 |
,*i, node().level_+2, "View statistics for "+*i); |
532 |
26 Dec 07 |
peter |
181 |
os << "</td><td>" << stats.lines(*i) |
532 |
26 Dec 07 |
peter |
182 |
<< "</td><td>" << stats.code(*i) |
532 |
26 Dec 07 |
peter |
183 |
<< "</td><td>" << stats.comments(*i) |
532 |
26 Dec 07 |
peter |
184 |
<< "</td><td>" << stats.empty(*i); |
282 |
06 May 07 |
peter |
185 |
if (log.exist(*i)) { |
713 |
28 Nov 08 |
peter |
186 |
const Commitment& lc(log.latest_commit(*i)); |
1513 |
23 Sep 12 |
peter |
187 |
os << "</td>" << "<td>" << trac_revision(lc.revision()) |
751 |
14 Jan 09 |
peter |
188 |
<< "</td>" << "<td>"; |
751 |
14 Jan 09 |
peter |
189 |
hs << Date(lc.date())(timefmt); |
282 |
06 May 07 |
peter |
190 |
} |
282 |
06 May 07 |
peter |
191 |
else { |
282 |
06 May 07 |
peter |
192 |
os << "</td>" << "<td>N/A" |
282 |
06 May 07 |
peter |
193 |
<< "</td>" << "<td>N/A"; |
282 |
06 May 07 |
peter |
194 |
} |
282 |
06 May 07 |
peter |
195 |
os << "</td></tr>\n"; |
234 |
09 Apr 07 |
peter |
196 |
} |
234 |
09 Apr 07 |
peter |
197 |
|
234 |
09 Apr 07 |
peter |
198 |
os << "<tr class=\"" << color << "\">\n"; |
1513 |
23 Sep 12 |
peter |
199 |
os << "<td>"; |
1290 |
12 Nov 10 |
peter |
200 |
if (node().dir()) |
1290 |
12 Nov 10 |
peter |
201 |
if (node().local_path().empty()) |
316 |
17 May 07 |
peter |
202 |
os << anchor("all/"+line_type+"/index.html" |
1513 |
23 Sep 12 |
peter |
203 |
,"Total", node().level_+2, "View statistics for all"); |
316 |
17 May 07 |
peter |
204 |
else |
1290 |
12 Nov 10 |
peter |
205 |
os << anchor("all/"+line_type+"/"+node().local_path()+"/index.html" |
1513 |
23 Sep 12 |
peter |
206 |
,"Total", node().level_+2, "View statistics for all"); |
235 |
21 Apr 07 |
peter |
207 |
else |
1290 |
12 Nov 10 |
peter |
208 |
os << anchor("all/"+line_type+"/"+node().local_path()+".html" |
1513 |
23 Sep 12 |
peter |
209 |
,"Total", node().level_+2, "View statistics for all"); |
235 |
21 Apr 07 |
peter |
210 |
os << "</td>\n"; |
532 |
26 Dec 07 |
peter |
211 |
os << "<td>" << stats.lines() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
212 |
os << "<td>" << stats.code() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
213 |
os << "<td>" << stats.comments() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
214 |
os << "<td>" << stats.empty() << "</td>\n"; |
713 |
28 Nov 08 |
peter |
215 |
const Commitment& lc(log.latest_commit()); |
274 |
02 May 07 |
peter |
216 |
os << "<td>" << trac_revision(lc.revision()) << "</td>\n"; |
751 |
14 Jan 09 |
peter |
217 |
os << "<td>"; |
751 |
14 Jan 09 |
peter |
218 |
hs << Date(lc.date())(timefmt); |
751 |
14 Jan 09 |
peter |
219 |
os << "</td>\n"; |
234 |
09 Apr 07 |
peter |
220 |
os << "</tr>\n"; |
378 |
20 Jun 07 |
jari |
221 |
os << "</tbody>\n"; |
234 |
09 Apr 07 |
peter |
222 |
os << "</table>\n"; |
234 |
09 Apr 07 |
peter |
223 |
} |
234 |
09 Apr 07 |
peter |
224 |
|
1513 |
23 Sep 12 |
peter |
225 |
|
149 |
12 Aug 06 |
jari |
226 |
}} // end of namespace svndigest and namespace theplu |