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, 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 |
|
4 |
29 Dec 05 |
peter |
25 |
#include "Node.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" |
258 |
30 Apr 07 |
peter |
32 |
#include "SVNlog.h" |
185 |
06 Sep 06 |
jari |
33 |
#include "SVNproperty.h" |
4 |
29 Dec 05 |
peter |
34 |
#include "utility.h" |
4 |
29 Dec 05 |
peter |
35 |
|
828 |
26 Sep 09 |
peter |
36 |
#include <algorithm> |
207 |
11 Sep 06 |
peter |
37 |
#include <cassert> |
23 |
02 Jan 06 |
peter |
38 |
#include <ctime> |
4 |
29 Dec 05 |
peter |
39 |
#include <fstream> |
285 |
06 May 07 |
peter |
40 |
#include <iostream> |
4 |
29 Dec 05 |
peter |
41 |
#include <sstream> |
4 |
29 Dec 05 |
peter |
42 |
|
361 |
10 Jun 07 |
peter |
43 |
#include <dirent.h> |
361 |
10 Jun 07 |
peter |
44 |
#include <sys/stat.h> |
361 |
10 Jun 07 |
peter |
45 |
|
4 |
29 Dec 05 |
peter |
46 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
47 |
namespace svndigest{ |
4 |
29 Dec 05 |
peter |
48 |
|
207 |
11 Sep 06 |
peter |
49 |
std::string Node::project_=std::string(); |
207 |
11 Sep 06 |
peter |
50 |
|
1450 |
22 Dec 11 |
peter |
51 |
Node::Node(const unsigned int level, const std::string& path, |
1264 |
02 Nov 10 |
peter |
52 |
const std::string& local_path, const std::string& project) |
1450 |
22 Dec 11 |
peter |
53 |
: level_(level), path_(path), stats_(path), log_(NULL), |
1356 |
17 May 11 |
peter |
54 |
property_(path), svninfo_(path) |
1450 |
22 Dec 11 |
peter |
55 |
{ |
207 |
11 Sep 06 |
peter |
56 |
if (Node::project_==std::string()) // no root directory in local path |
1264 |
02 Nov 10 |
peter |
57 |
Node::project_ = project; |
207 |
11 Sep 06 |
peter |
58 |
else if (local_path.empty()) |
207 |
11 Sep 06 |
peter |
59 |
local_path_ = file_name(path); |
207 |
11 Sep 06 |
peter |
60 |
else |
207 |
11 Sep 06 |
peter |
61 |
local_path_ = local_path + "/" + file_name(path); |
361 |
10 Jun 07 |
peter |
62 |
|
361 |
10 Jun 07 |
peter |
63 |
struct stat nodestat; // C api from sys/stat.h |
1186 |
27 Aug 10 |
peter |
64 |
lstat(path,&nodestat); // C api from sys/stat.h |
361 |
10 Jun 07 |
peter |
65 |
link_ = S_ISLNK(nodestat.st_mode); |
23 |
02 Jan 06 |
peter |
66 |
} |
4 |
29 Dec 05 |
peter |
67 |
|
185 |
06 Sep 06 |
jari |
68 |
|
453 |
17 Aug 07 |
peter |
69 |
Node::~Node(void) |
453 |
17 Aug 07 |
peter |
70 |
{ |
453 |
17 Aug 07 |
peter |
71 |
if (log_) |
453 |
17 Aug 07 |
peter |
72 |
delete log_; |
453 |
17 Aug 07 |
peter |
73 |
} |
453 |
17 Aug 07 |
peter |
74 |
|
453 |
17 Aug 07 |
peter |
75 |
|
452 |
17 Aug 07 |
peter |
76 |
std::string Node::author(void) const |
1449 |
22 Dec 11 |
peter |
77 |
{ |
1449 |
22 Dec 11 |
peter |
78 |
if (svndigest_ignore()) |
1449 |
22 Dec 11 |
peter |
79 |
return svninfo_.last_changed_author(); |
642 |
31 May 08 |
peter |
80 |
assert(log().commits().size()); |
759 |
29 Jan 09 |
peter |
81 |
return log().latest_commit().author(); |
452 |
17 Aug 07 |
peter |
82 |
} |
452 |
17 Aug 07 |
peter |
83 |
|
452 |
17 Aug 07 |
peter |
84 |
|
1356 |
17 May 11 |
peter |
85 |
bool Node::binary(void) const |
1356 |
17 May 11 |
peter |
86 |
{ |
1356 |
17 May 11 |
peter |
87 |
return property_.binary(); |
1356 |
17 May 11 |
peter |
88 |
} |
1356 |
17 May 11 |
peter |
89 |
|
1356 |
17 May 11 |
peter |
90 |
|
101 |
22 Jun 06 |
peter |
91 |
bool Node::dir(void) const |
101 |
22 Jun 06 |
peter |
92 |
{ |
101 |
22 Jun 06 |
peter |
93 |
return false; |
101 |
22 Jun 06 |
peter |
94 |
} |
101 |
22 Jun 06 |
peter |
95 |
|
185 |
06 Sep 06 |
jari |
96 |
|
1450 |
22 Dec 11 |
peter |
97 |
void Node::html_tablerow(std::ostream& os, |
532 |
26 Dec 07 |
peter |
98 |
const std::string& stats_type, |
213 |
15 Sep 06 |
peter |
99 |
const std::string& css_class, |
213 |
15 Sep 06 |
peter |
100 |
const std::string& user) const |
175 |
02 Sep 06 |
peter |
101 |
{ |
175 |
02 Sep 06 |
peter |
102 |
os << "<tr class=\"" << css_class << "\">\n" |
182 |
03 Sep 06 |
peter |
103 |
<< "<td class=\"" << node_type() << "\">"; |
185 |
06 Sep 06 |
jari |
104 |
if (svndigest_ignore()) |
185 |
06 Sep 06 |
jari |
105 |
os << name() << " (<i>svndigest:ignore</i>)"; |
185 |
06 Sep 06 |
jari |
106 |
else if (binary()) |
176 |
02 Sep 06 |
peter |
107 |
os << name() << " (<i>binary</i>)"; |
361 |
10 Jun 07 |
peter |
108 |
else if (link_) |
361 |
10 Jun 07 |
peter |
109 |
os << name() << " (<i>link</i>)"; |
234 |
09 Apr 07 |
peter |
// there is no output for nodes when user has zero contribution |
1450 |
22 Dec 11 |
peter |
111 |
else if (user!="all" |
1290 |
12 Nov 10 |
peter |
112 |
&& !tiny_stats()(stats_type,user,LineTypeParser::total)) |
234 |
09 Apr 07 |
peter |
113 |
os << name(); |
1290 |
12 Nov 10 |
peter |
114 |
else if (!Configuration::instance().output_file() && !dir()) |
1136 |
18 Jul 10 |
peter |
115 |
os << name(); |
176 |
02 Sep 06 |
peter |
116 |
else |
1450 |
22 Dec 11 |
peter |
117 |
os << anchor(href(), name()); |
1450 |
22 Dec 11 |
peter |
118 |
os << "</td>\n"; |
313 |
17 May 07 |
peter |
119 |
|
1234 |
23 Oct 10 |
peter |
120 |
html_tabletd(os, stats_type, user, LineTypeParser::total); |
1234 |
23 Oct 10 |
peter |
121 |
html_tabletd(os, stats_type, user, LineTypeParser::code); |
1234 |
23 Oct 10 |
peter |
122 |
html_tabletd(os, stats_type, user, LineTypeParser::comment); |
1234 |
23 Oct 10 |
peter |
123 |
html_tabletd(os, stats_type, user, LineTypeParser::other); |
1450 |
22 Dec 11 |
peter |
124 |
|
452 |
17 Aug 07 |
peter |
125 |
os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n" |
112 |
29 Jun 06 |
peter |
126 |
<< "<td>" << author() << "</td>\n" |
112 |
29 Jun 06 |
peter |
127 |
<< "</tr>\n"; |
101 |
22 Jun 06 |
peter |
128 |
} |
101 |
22 Jun 06 |
peter |
129 |
|
185 |
06 Sep 06 |
jari |
130 |
|
1450 |
22 Dec 11 |
peter |
131 |
void Node::html_tabletd(std::ostream& os, |
1450 |
22 Dec 11 |
peter |
132 |
const std::string& stats_type, |
1450 |
22 Dec 11 |
peter |
133 |
const std::string& user, |
1234 |
23 Oct 10 |
peter |
134 |
LineTypeParser::line_type lt) const |
1234 |
23 Oct 10 |
peter |
135 |
{ |
1450 |
22 Dec 11 |
peter |
136 |
os << "<td>" << tiny_stats()(stats_type, user, lt); |
1450 |
22 Dec 11 |
peter |
137 |
if (user!="all" && tiny_stats()(stats_type, user, lt)) |
1450 |
22 Dec 11 |
peter |
138 |
os << " (" << percent(tiny_stats()(stats_type, user, lt), |
1450 |
22 Dec 11 |
peter |
139 |
tiny_stats()(stats_type, "all", lt)) << "%)"; |
1234 |
23 Oct 10 |
peter |
140 |
os << "</td>\n"; |
1234 |
23 Oct 10 |
peter |
141 |
} |
1234 |
23 Oct 10 |
peter |
142 |
|
1450 |
22 Dec 11 |
peter |
143 |
|
1234 |
23 Oct 10 |
peter |
144 |
void Node::init_tiny_stats(void) |
1234 |
23 Oct 10 |
peter |
145 |
{ |
1234 |
23 Oct 10 |
peter |
146 |
tiny_stats_.init(stats_); |
1234 |
23 Oct 10 |
peter |
147 |
} |
1234 |
23 Oct 10 |
peter |
148 |
|
1234 |
23 Oct 10 |
peter |
149 |
|
453 |
17 Aug 07 |
peter |
150 |
const SVNlog& Node::log(void) const |
452 |
17 Aug 07 |
peter |
151 |
{ |
727 |
11 Dec 08 |
jari |
152 |
if (!log_) { |
1449 |
22 Dec 11 |
peter |
153 |
if (svndigest_ignore()) |
453 |
17 Aug 07 |
peter |
154 |
log_ = new SVNlog; |
757 |
27 Jan 09 |
peter |
155 |
else { |
757 |
27 Jan 09 |
peter |
156 |
log_ = new SVNlog(path()); |
757 |
27 Jan 09 |
peter |
157 |
log_core(*log_); |
757 |
27 Jan 09 |
peter |
158 |
} |
727 |
11 Dec 08 |
jari |
159 |
} |
453 |
17 Aug 07 |
peter |
160 |
return *log_; |
452 |
17 Aug 07 |
peter |
161 |
} |
452 |
17 Aug 07 |
peter |
162 |
|
452 |
17 Aug 07 |
peter |
163 |
|
1450 |
22 Dec 11 |
peter |
164 |
std::string Node::name(void) const |
1450 |
22 Dec 11 |
peter |
165 |
{ |
1450 |
22 Dec 11 |
peter |
166 |
return file_name(path_); |
482 |
13 Oct 07 |
peter |
167 |
} |
482 |
13 Oct 07 |
peter |
168 |
|
482 |
13 Oct 07 |
peter |
169 |
|
1450 |
22 Dec 11 |
peter |
170 |
const SVNproperty& Node::property(void) const |
1450 |
22 Dec 11 |
peter |
171 |
{ |
1450 |
22 Dec 11 |
peter |
172 |
return property_; |
1450 |
22 Dec 11 |
peter |
173 |
} |
1450 |
22 Dec 11 |
peter |
174 |
|
1450 |
22 Dec 11 |
peter |
175 |
|
1234 |
23 Oct 10 |
peter |
176 |
const StatsCollection& Node::stats(void) const |
1234 |
23 Oct 10 |
peter |
177 |
{ |
1234 |
23 Oct 10 |
peter |
178 |
return stats_; |
1234 |
23 Oct 10 |
peter |
179 |
} |
1234 |
23 Oct 10 |
peter |
180 |
|
1234 |
23 Oct 10 |
peter |
181 |
|
1234 |
23 Oct 10 |
peter |
182 |
StatsCollection& Node::stats(void) |
1234 |
23 Oct 10 |
peter |
183 |
{ |
1234 |
23 Oct 10 |
peter |
184 |
return stats_; |
1234 |
23 Oct 10 |
peter |
185 |
} |
1234 |
23 Oct 10 |
peter |
186 |
|
1234 |
23 Oct 10 |
peter |
187 |
|
1137 |
18 Jul 10 |
peter |
188 |
bool Node::svncopyright_ignore(void) const |
1137 |
18 Jul 10 |
peter |
189 |
{ |
1449 |
22 Dec 11 |
peter |
190 |
return property_.svncopyright_ignore() || binary() || link_; |
1137 |
18 Jul 10 |
peter |
191 |
} |
1137 |
18 Jul 10 |
peter |
192 |
|
1356 |
17 May 11 |
peter |
193 |
|
1356 |
17 May 11 |
peter |
194 |
bool Node::svndigest_ignore(void) const |
1356 |
17 May 11 |
peter |
195 |
{ |
1449 |
22 Dec 11 |
peter |
196 |
return property_.svndigest_ignore() || binary() || link_; |
1356 |
17 May 11 |
peter |
197 |
} |
1356 |
17 May 11 |
peter |
198 |
|
149 |
12 Aug 06 |
jari |
199 |
}} // end of namespace svndigest and namespace theplu |