84 |
13 Mar 06 |
jari |
// $Id$ |
14 |
30 Dec 05 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
847 |
17 Nov 09 |
peter |
Copyright (C) 2005 Peter Johansson |
978 |
12 Dec 09 |
peter |
Copyright (C) 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 |
7 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
9 |
|
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 |
14 |
|
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 |
19 |
|
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 |
22 |
*/ |
84 |
13 Mar 06 |
jari |
23 |
|
1619 |
12 Mar 23 |
peter |
24 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
25 |
|
543 |
04 Jan 08 |
peter |
26 |
#include "AddStats.h" |
129 |
02 Aug 06 |
jari |
27 |
|
138 |
03 Aug 06 |
jari |
28 |
#include "SVNblame.h" |
537 |
27 Dec 07 |
peter |
29 |
#include "SVNlog.h" |
14 |
30 Dec 05 |
peter |
30 |
|
41 |
13 Jan 06 |
peter |
31 |
#include <algorithm> |
65 |
20 Jan 06 |
peter |
32 |
#include <cassert> |
63 |
19 Jan 06 |
peter |
33 |
#include <cstdlib> |
647 |
04 Jun 08 |
peter |
34 |
#include <functional> |
14 |
30 Dec 05 |
peter |
35 |
#include <map> |
14 |
30 Dec 05 |
peter |
36 |
#include <string> |
14 |
30 Dec 05 |
peter |
37 |
#include <vector> |
14 |
30 Dec 05 |
peter |
38 |
|
14 |
30 Dec 05 |
peter |
39 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
40 |
namespace svndigest{ |
14 |
30 Dec 05 |
peter |
41 |
|
14 |
30 Dec 05 |
peter |
42 |
|
543 |
04 Jan 08 |
peter |
43 |
AddStats::AddStats(const std::string& path) |
487 |
13 Oct 07 |
peter |
44 |
: Stats(path) |
80 |
10 Mar 06 |
jari |
45 |
{ |
80 |
10 Mar 06 |
jari |
46 |
} |
80 |
10 Mar 06 |
jari |
47 |
|
529 |
25 Dec 07 |
peter |
48 |
|
543 |
04 Jan 08 |
peter |
49 |
AddStats::AddStats(const AddStats& other) |
528 |
25 Dec 07 |
peter |
50 |
: Stats(other) |
528 |
25 Dec 07 |
peter |
51 |
{ |
528 |
25 Dec 07 |
peter |
52 |
} |
80 |
10 Mar 06 |
jari |
53 |
|
14 |
30 Dec 05 |
peter |
54 |
|
1478 |
29 May 12 |
peter |
55 |
void AddStats::do_parse(const std::string& path, svn_revnum_t first_rev) |
537 |
27 Dec 07 |
peter |
56 |
{ |
1478 |
29 May 12 |
peter |
57 |
first_rev = std::max(first_rev, ignore_rev()+1); |
1194 |
03 Oct 10 |
peter |
// FIXME: why not using the log from File object |
537 |
27 Dec 07 |
peter |
59 |
SVNlog log(path); |
664 |
13 Jun 08 |
peter |
60 |
typedef std::set<svn_revnum_t, std::greater<svn_revnum_t> > RevSet; |
537 |
27 Dec 07 |
peter |
61 |
RevSet revs; |
1194 |
03 Oct 10 |
peter |
62 |
std::vector<std::map<std::string, SparseVector> > data; |
642 |
31 May 08 |
peter |
63 |
std::transform(log.commits().begin(), log.commits().end(), |
1478 |
29 May 12 |
peter |
64 |
std::inserter(revs, revs.begin()), |
1652 |
14 Jun 23 |
peter |
65 |
std::mem_fn(&Commitment::revision)); |
664 |
13 Jun 08 |
peter |
66 |
for (RevSet::iterator rev_iter=revs.begin(); |
1478 |
29 May 12 |
peter |
67 |
rev_iter!=revs.end() && *rev_iter>=first_rev; ++rev_iter){ |
537 |
27 Dec 07 |
peter |
68 |
SVNblame svn_blame(path, *rev_iter); |
657 |
10 Jun 08 |
peter |
69 |
LineTypeParser parser(path); |
1611 |
12 Feb 23 |
peter |
70 |
std::vector<size_t> add_vec(5,0); |
1194 |
03 Oct 10 |
peter |
71 |
std::string author=""; |
537 |
27 Dec 07 |
peter |
72 |
while (svn_blame.valid()) { |
657 |
10 Jun 08 |
peter |
73 |
LineTypeParser::line_type lt = parser.parse(svn_blame.line()); |
1611 |
12 Feb 23 |
peter |
74 |
if (lt == LineTypeParser::copyright || lt == LineTypeParser::comment) |
1611 |
12 Feb 23 |
peter |
75 |
lt = LineTypeParser::comment_or_copy; |
1194 |
03 Oct 10 |
peter |
76 |
if (*rev_iter==svn_blame.revision()) { |
1194 |
03 Oct 10 |
peter |
77 |
author = svn_blame.author(); |
1418 |
25 Oct 11 |
peter |
78 |
assert(static_cast<size_t>(lt)<add_vec.size()); |
1194 |
03 Oct 10 |
peter |
79 |
++add_vec[lt]; |
1194 |
03 Oct 10 |
peter |
80 |
} |
803 |
10 Jul 09 |
peter |
// I dont trust blame and log behave consistently (stop-on-copy). |
537 |
27 Dec 07 |
peter |
82 |
revs.insert(svn_blame.revision()); |
537 |
27 Dec 07 |
peter |
83 |
svn_blame.next_line(); |
537 |
27 Dec 07 |
peter |
84 |
} |
1194 |
03 Oct 10 |
peter |
85 |
if (author.empty()) { // don't add 0 to author "" |
1194 |
03 Oct 10 |
peter |
86 |
assert(add_vec[0]==0); |
1194 |
03 Oct 10 |
peter |
87 |
assert(add_vec[1]==0); |
1194 |
03 Oct 10 |
peter |
88 |
assert(add_vec[2]==0); |
1194 |
03 Oct 10 |
peter |
89 |
assert(add_vec[3]==0); |
1194 |
03 Oct 10 |
peter |
90 |
continue; |
1194 |
03 Oct 10 |
peter |
91 |
} |
1194 |
03 Oct 10 |
peter |
92 |
if (data.size()<add_vec.size()) |
1194 |
03 Oct 10 |
peter |
93 |
data.resize(add_vec.size()); |
1194 |
03 Oct 10 |
peter |
94 |
for (size_t lt=0; lt<add_vec.size(); ++lt) { |
1194 |
03 Oct 10 |
peter |
95 |
assert(author.size()); |
1194 |
03 Oct 10 |
peter |
96 |
SparseVector& vec=data[lt][author]; |
1194 |
03 Oct 10 |
peter |
// add add_vec[lt] to current value |
1194 |
03 Oct 10 |
peter |
98 |
vec.set(*rev_iter, vec[*rev_iter] + add_vec[lt]); |
1418 |
25 Oct 11 |
peter |
99 |
assert(static_cast<size_t>(data[lt][author][*rev_iter])>=add_vec[lt]); |
1194 |
03 Oct 10 |
peter |
100 |
} |
138 |
03 Aug 06 |
jari |
101 |
} |
1194 |
03 Oct 10 |
peter |
// add parsed data to member |
1194 |
03 Oct 10 |
peter |
103 |
add(data); |
60 |
16 Jan 06 |
peter |
104 |
} |
60 |
16 Jan 06 |
peter |
105 |
|
60 |
16 Jan 06 |
peter |
106 |
|
1478 |
29 May 12 |
peter |
107 |
unsigned int AddStats::max_element(const SumVector& v) const |
1003 |
02 Jan 10 |
peter |
108 |
{ |
1280 |
06 Nov 10 |
peter |
109 |
if (v.size()==0) |
1280 |
06 Nov 10 |
peter |
110 |
return 0; |
1003 |
02 Jan 10 |
peter |
111 |
return v.back(); |
1003 |
02 Jan 10 |
peter |
112 |
} |
1003 |
02 Jan 10 |
peter |
113 |
|
1003 |
02 Jan 10 |
peter |
114 |
|
149 |
12 Aug 06 |
jari |
115 |
}} // end of namespace svndigest and namespace theplu |