532 |
26 Dec 07 |
peter |
// $Id$ |
532 |
26 Dec 07 |
peter |
2 |
|
532 |
26 Dec 07 |
peter |
3 |
/* |
532 |
26 Dec 07 |
peter |
Copyright (C) 2007 Peter Johansson |
978 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2010, 2012, 2023 Peter Johansson |
532 |
26 Dec 07 |
peter |
7 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
532 |
26 Dec 07 |
peter |
9 |
|
532 |
26 Dec 07 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
532 |
26 Dec 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 |
532 |
26 Dec 07 |
peter |
(at your option) any later version. |
532 |
26 Dec 07 |
peter |
14 |
|
532 |
26 Dec 07 |
peter |
svndigest is distributed in the hope that it will be useful, but |
532 |
26 Dec 07 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
532 |
26 Dec 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
532 |
26 Dec 07 |
peter |
General Public License for more details. |
532 |
26 Dec 07 |
peter |
19 |
|
532 |
26 Dec 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/>. |
532 |
26 Dec 07 |
peter |
22 |
*/ |
532 |
26 Dec 07 |
peter |
23 |
|
1619 |
12 Mar 23 |
peter |
24 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
25 |
|
532 |
26 Dec 07 |
peter |
26 |
#include "StatsCollection.h" |
532 |
26 Dec 07 |
peter |
27 |
|
543 |
04 Jan 08 |
peter |
28 |
#include "AddStats.h" |
533 |
26 Dec 07 |
peter |
29 |
#include "BlameStats.h" |
532 |
26 Dec 07 |
peter |
30 |
#include "ClassicStats.h" |
532 |
26 Dec 07 |
peter |
31 |
#include "Stats.h" |
532 |
26 Dec 07 |
peter |
32 |
|
532 |
26 Dec 07 |
peter |
33 |
#include <cassert> |
532 |
26 Dec 07 |
peter |
34 |
#include <map> |
532 |
26 Dec 07 |
peter |
35 |
#include <stdexcept> |
532 |
26 Dec 07 |
peter |
36 |
#include <string> |
532 |
26 Dec 07 |
peter |
37 |
|
532 |
26 Dec 07 |
peter |
38 |
#include <iostream> |
532 |
26 Dec 07 |
peter |
39 |
|
532 |
26 Dec 07 |
peter |
40 |
namespace theplu{ |
532 |
26 Dec 07 |
peter |
41 |
namespace svndigest{ |
532 |
26 Dec 07 |
peter |
42 |
|
532 |
26 Dec 07 |
peter |
43 |
|
532 |
26 Dec 07 |
peter |
44 |
StatsCollection::StatsCollection(const std::string& path) |
532 |
26 Dec 07 |
peter |
45 |
: path_(path) |
532 |
26 Dec 07 |
peter |
46 |
{ |
532 |
26 Dec 07 |
peter |
47 |
stats_["classic"] = new ClassicStats(path); |
533 |
26 Dec 07 |
peter |
48 |
stats_["blame"] = new BlameStats(path); |
543 |
04 Jan 08 |
peter |
49 |
stats_["add"] = new AddStats(path); |
532 |
26 Dec 07 |
peter |
50 |
} |
532 |
26 Dec 07 |
peter |
51 |
|
532 |
26 Dec 07 |
peter |
52 |
|
532 |
26 Dec 07 |
peter |
53 |
StatsCollection::~StatsCollection(void) |
532 |
26 Dec 07 |
peter |
54 |
{ |
1081 |
08 Jun 10 |
peter |
55 |
for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
532 |
26 Dec 07 |
peter |
56 |
assert(i->second); |
532 |
26 Dec 07 |
peter |
57 |
delete i->second; |
1081 |
08 Jun 10 |
peter |
58 |
i->second = NULL; |
532 |
26 Dec 07 |
peter |
59 |
} |
532 |
26 Dec 07 |
peter |
60 |
} |
532 |
26 Dec 07 |
peter |
61 |
|
532 |
26 Dec 07 |
peter |
62 |
|
532 |
26 Dec 07 |
peter |
63 |
bool StatsCollection::load_cache(std::istream& is) |
532 |
26 Dec 07 |
peter |
64 |
{ |
532 |
26 Dec 07 |
peter |
65 |
bool result = true; |
532 |
26 Dec 07 |
peter |
66 |
for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
1124 |
07 Jul 10 |
peter |
67 |
bool latest_ver=true; |
1124 |
07 Jul 10 |
peter |
68 |
svn_revnum_t cache_rev = i->second->load_cache(is, latest_ver); |
1124 |
07 Jul 10 |
peter |
69 |
result &= latest_ver; |
702 |
23 Nov 08 |
peter |
70 |
if (cache_rev < i->second->last_changed_rev()) { |
532 |
26 Dec 07 |
peter |
71 |
result = false; |
664 |
13 Jun 08 |
peter |
// reset if load cache failed |
664 |
13 Jun 08 |
peter |
73 |
if (!cache_rev) |
664 |
13 Jun 08 |
peter |
74 |
i->second->reset(); |
703 |
24 Nov 08 |
peter |
75 |
i->second->parse(path_, cache_rev+1); |
532 |
26 Dec 07 |
peter |
76 |
} |
532 |
26 Dec 07 |
peter |
77 |
} |
532 |
26 Dec 07 |
peter |
78 |
return result; |
532 |
26 Dec 07 |
peter |
79 |
} |
532 |
26 Dec 07 |
peter |
80 |
|
532 |
26 Dec 07 |
peter |
81 |
|
532 |
26 Dec 07 |
peter |
82 |
const std::map<std::string, Stats*>& StatsCollection::stats(void) const |
532 |
26 Dec 07 |
peter |
83 |
{ |
532 |
26 Dec 07 |
peter |
84 |
return stats_; |
532 |
26 Dec 07 |
peter |
85 |
} |
532 |
26 Dec 07 |
peter |
86 |
|
532 |
26 Dec 07 |
peter |
87 |
|
538 |
27 Dec 07 |
peter |
88 |
void StatsCollection::parse(const std::string& path) |
532 |
26 Dec 07 |
peter |
89 |
{ |
532 |
26 Dec 07 |
peter |
90 |
for (map::iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
532 |
26 Dec 07 |
peter |
91 |
i->second->parse(path); |
532 |
26 Dec 07 |
peter |
92 |
} |
532 |
26 Dec 07 |
peter |
93 |
} |
532 |
26 Dec 07 |
peter |
94 |
|
532 |
26 Dec 07 |
peter |
95 |
|
532 |
26 Dec 07 |
peter |
96 |
void StatsCollection::print(std::ostream& os) |
532 |
26 Dec 07 |
peter |
97 |
{ |
532 |
26 Dec 07 |
peter |
98 |
for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
532 |
26 Dec 07 |
peter |
99 |
i->second->print(os); |
532 |
26 Dec 07 |
peter |
100 |
} |
532 |
26 Dec 07 |
peter |
101 |
} |
532 |
26 Dec 07 |
peter |
102 |
|
532 |
26 Dec 07 |
peter |
103 |
|
532 |
26 Dec 07 |
peter |
104 |
void StatsCollection::reset(void) |
532 |
26 Dec 07 |
peter |
105 |
{ |
532 |
26 Dec 07 |
peter |
106 |
for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
532 |
26 Dec 07 |
peter |
107 |
i->second->reset(); |
532 |
26 Dec 07 |
peter |
108 |
} |
532 |
26 Dec 07 |
peter |
109 |
} |
532 |
26 Dec 07 |
peter |
110 |
|
532 |
26 Dec 07 |
peter |
111 |
|
1478 |
29 May 12 |
peter |
112 |
void StatsCollection::ignore_rev(svn_revnum_t rev) |
1478 |
29 May 12 |
peter |
113 |
{ |
1478 |
29 May 12 |
peter |
114 |
for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
1478 |
29 May 12 |
peter |
115 |
i->second->ignore_rev(rev); |
1478 |
29 May 12 |
peter |
116 |
} |
1478 |
29 May 12 |
peter |
117 |
} |
1478 |
29 May 12 |
peter |
118 |
|
1478 |
29 May 12 |
peter |
119 |
|
532 |
26 Dec 07 |
peter |
120 |
const StatsCollection& StatsCollection::operator+=(const StatsCollection& rhs) |
532 |
26 Dec 07 |
peter |
121 |
{ |
532 |
26 Dec 07 |
peter |
122 |
assert(stats_.size()==rhs.stats_.size()); |
532 |
26 Dec 07 |
peter |
123 |
for (map::const_iterator i(stats_.begin()); i!=stats_.end(); ++i) { |
532 |
26 Dec 07 |
peter |
124 |
*(i->second) += rhs[i->first]; |
532 |
26 Dec 07 |
peter |
125 |
} |
532 |
26 Dec 07 |
peter |
126 |
return *this; |
532 |
26 Dec 07 |
peter |
127 |
} |
532 |
26 Dec 07 |
peter |
128 |
|
532 |
26 Dec 07 |
peter |
129 |
|
532 |
26 Dec 07 |
peter |
130 |
const Stats& StatsCollection::operator[](const std::string& key) const |
532 |
26 Dec 07 |
peter |
131 |
{ |
532 |
26 Dec 07 |
peter |
132 |
map::const_iterator iter = stats_.find(key); |
532 |
26 Dec 07 |
peter |
133 |
if (iter==stats_.end()) |
1478 |
29 May 12 |
peter |
134 |
throw std::runtime_error(key + |
532 |
26 Dec 07 |
peter |
135 |
std::string(" not found in StatsCollection")); |
532 |
26 Dec 07 |
peter |
136 |
return *(iter->second); |
532 |
26 Dec 07 |
peter |
137 |
} |
532 |
26 Dec 07 |
peter |
138 |
|
532 |
26 Dec 07 |
peter |
139 |
|
532 |
26 Dec 07 |
peter |
140 |
Stats& StatsCollection::operator[](const std::string& key) |
532 |
26 Dec 07 |
peter |
141 |
{ |
532 |
26 Dec 07 |
peter |
142 |
assert(stats_.find(key)!=stats_.end()); |
532 |
26 Dec 07 |
peter |
143 |
return *(stats_[key]); |
532 |
26 Dec 07 |
peter |
144 |
} |
532 |
26 Dec 07 |
peter |
145 |
|
532 |
26 Dec 07 |
peter |
146 |
|
532 |
26 Dec 07 |
peter |
147 |
}} // end of namespace svndigest and namespace theplu |