84 |
13 Mar 06 |
jari |
// $Id$ |
14 |
30 Dec 05 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
84 |
13 Mar 06 |
jari |
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 |
|
531 |
25 Dec 07 |
peter |
26 |
#include "BlameStats.h" |
129 |
02 Aug 06 |
jari |
27 |
|
138 |
03 Aug 06 |
jari |
28 |
#include "SVNblame.h" |
129 |
02 Aug 06 |
jari |
29 |
#include "SVNinfo.h" |
537 |
27 Dec 07 |
peter |
30 |
#include "SVNlog.h" |
1194 |
03 Oct 10 |
peter |
31 |
#include "Vector.h" |
14 |
30 Dec 05 |
peter |
32 |
|
41 |
13 Jan 06 |
peter |
33 |
#include <algorithm> |
65 |
20 Jan 06 |
peter |
34 |
#include <cassert> |
63 |
19 Jan 06 |
peter |
35 |
#include <cstdlib> |
454 |
18 Aug 07 |
peter |
36 |
#include <fstream> |
647 |
04 Jun 08 |
peter |
37 |
#include <functional> |
60 |
16 Jan 06 |
peter |
38 |
#include <iostream> |
454 |
18 Aug 07 |
peter |
39 |
#include <iterator> |
14 |
30 Dec 05 |
peter |
40 |
#include <map> |
14 |
30 Dec 05 |
peter |
41 |
#include <numeric> |
14 |
30 Dec 05 |
peter |
42 |
#include <string> |
138 |
03 Aug 06 |
jari |
43 |
#include <sstream> |
44 |
13 Jan 06 |
jari |
44 |
#include <unistd.h> |
23 |
02 Jan 06 |
peter |
45 |
#include <utility> |
14 |
30 Dec 05 |
peter |
46 |
#include <vector> |
14 |
30 Dec 05 |
peter |
47 |
|
63 |
19 Jan 06 |
peter |
48 |
|
14 |
30 Dec 05 |
peter |
49 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
50 |
namespace svndigest{ |
14 |
30 Dec 05 |
peter |
51 |
|
14 |
30 Dec 05 |
peter |
52 |
|
531 |
25 Dec 07 |
peter |
53 |
BlameStats::BlameStats(const std::string& path) |
487 |
13 Oct 07 |
peter |
54 |
: Stats(path) |
80 |
10 Mar 06 |
jari |
55 |
{ |
80 |
10 Mar 06 |
jari |
56 |
} |
80 |
10 Mar 06 |
jari |
57 |
|
529 |
25 Dec 07 |
peter |
58 |
|
531 |
25 Dec 07 |
peter |
59 |
BlameStats::BlameStats(const BlameStats& other) |
528 |
25 Dec 07 |
peter |
60 |
: Stats(other) |
528 |
25 Dec 07 |
peter |
61 |
{ |
528 |
25 Dec 07 |
peter |
62 |
} |
80 |
10 Mar 06 |
jari |
63 |
|
14 |
30 Dec 05 |
peter |
64 |
|
664 |
13 Jun 08 |
peter |
65 |
void BlameStats::do_parse(const std::string& path, svn_revnum_t first_rev) |
60 |
16 Jan 06 |
peter |
66 |
{ |
1478 |
29 May 12 |
peter |
67 |
first_rev = std::max(first_rev, ignore_rev()+1); |
1194 |
03 Oct 10 |
peter |
// FIXME: using log from File object |
537 |
27 Dec 07 |
peter |
69 |
SVNlog log(path); |
700 |
21 Nov 08 |
peter |
70 |
typedef std::set<svn_revnum_t> RevSet; |
537 |
27 Dec 07 |
peter |
71 |
RevSet revs; |
642 |
31 May 08 |
peter |
72 |
std::transform(log.commits().begin(), log.commits().end(), |
1478 |
29 May 12 |
peter |
73 |
std::inserter(revs, revs.begin()), |
1652 |
14 Jun 23 |
peter |
74 |
std::mem_fn(&Commitment::revision)); |
1194 |
03 Oct 10 |
peter |
// we use a ParseVector here to be able to detect when people are |
1194 |
03 Oct 10 |
peter |
// absent in a revision. |
1611 |
12 Feb 23 |
peter |
77 |
std::vector<std::map<std::string, SparseVector> > data(5); |
700 |
21 Nov 08 |
peter |
78 |
for (RevSet::reverse_iterator rev_iter=revs.rbegin(); |
703 |
24 Nov 08 |
peter |
79 |
rev_iter!=revs.rend() && *rev_iter>=first_rev; ++rev_iter){ |
537 |
27 Dec 07 |
peter |
80 |
SVNblame svn_blame(path, *rev_iter); |
657 |
10 Jun 08 |
peter |
81 |
LineTypeParser parser(path); |
537 |
27 Dec 07 |
peter |
82 |
while (svn_blame.valid()) { |
1194 |
03 Oct 10 |
peter |
83 |
int lt = parser.parse(svn_blame.line()); |
1611 |
12 Feb 23 |
peter |
84 |
if (lt == LineTypeParser::copyright || lt == LineTypeParser::comment) |
1611 |
12 Feb 23 |
peter |
85 |
lt = LineTypeParser::comment_or_copy; |
1418 |
25 Oct 11 |
peter |
86 |
assert(static_cast<size_t>(lt)<data.size()); |
1194 |
03 Oct 10 |
peter |
87 |
SparseVector& vec = data[lt][svn_blame.author()]; |
1478 |
29 May 12 |
peter |
88 |
if (svn_blame.revision()>ignore_rev()) { |
1478 |
29 May 12 |
peter |
89 |
vec.set(*rev_iter, vec[*rev_iter] + 1); |
1478 |
29 May 12 |
peter |
90 |
add_author(svn_blame.author()); |
1478 |
29 May 12 |
peter |
// I dont trust blame and log behave consistently (stop-on-copy). |
1478 |
29 May 12 |
peter |
92 |
revs.insert(svn_blame.revision()); |
1478 |
29 May 12 |
peter |
93 |
} |
537 |
27 Dec 07 |
peter |
94 |
svn_blame.next_line(); |
537 |
27 Dec 07 |
peter |
95 |
} |
138 |
03 Aug 06 |
jari |
96 |
} |
1194 |
03 Oct 10 |
peter |
97 |
|
1194 |
03 Oct 10 |
peter |
// for count=zero we have not created an entry in SumVector and |
1194 |
03 Oct 10 |
peter |
// value will be "value for previous rev". Therefore we need to |
1194 |
03 Oct 10 |
peter |
// set the value to zero explicitely. |
1194 |
03 Oct 10 |
peter |
101 |
if (stats_.size()<data.size()) |
1194 |
03 Oct 10 |
peter |
102 |
stats_.resize(data.size()); |
1418 |
25 Oct 11 |
peter |
103 |
for (size_t lt =0; lt<data.size(); ++lt) { |
1194 |
03 Oct 10 |
peter |
// just to avoid long long lines |
1194 |
03 Oct 10 |
peter |
105 |
typedef std::map<std::string,SparseVector>::const_iterator const_iterator; |
1194 |
03 Oct 10 |
peter |
106 |
for (const_iterator av = data[lt].begin(); av!=data[lt].end(); ++av) { |
1478 |
29 May 12 |
peter |
107 |
for (RevSet::const_reverse_iterator rev_iter=revs.rbegin(); |
1194 |
03 Oct 10 |
peter |
108 |
rev_iter!=revs.rend() && *rev_iter >= first_rev; ++rev_iter) { |
1194 |
03 Oct 10 |
peter |
109 |
stats_[lt][av->first].set(*rev_iter, data[lt][av->first][*rev_iter]); |
1194 |
03 Oct 10 |
peter |
110 |
} |
818 |
09 Aug 09 |
peter |
111 |
} |
537 |
27 Dec 07 |
peter |
112 |
} |
60 |
16 Jan 06 |
peter |
113 |
} |
60 |
16 Jan 06 |
peter |
114 |
|
149 |
12 Aug 06 |
jari |
115 |
}} // end of namespace svndigest and namespace theplu |