1 | // $Id: BlameStats.cc 1194 2010-10-03 23:39:12Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005 Peter Johansson |
---|
5 | Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2009, 2010 Peter Johansson |
---|
7 | |
---|
8 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
9 | |
---|
10 | svndigest is free software; you can redistribute it and/or modify it |
---|
11 | under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 3 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | svndigest is distributed in the hope that it will be useful, but |
---|
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "BlameStats.h" |
---|
25 | |
---|
26 | #include "Functor.h" |
---|
27 | #include "SVNblame.h" |
---|
28 | #include "SVNinfo.h" |
---|
29 | #include "SVNlog.h" |
---|
30 | #include "utility.h" |
---|
31 | #include "Vector.h" |
---|
32 | |
---|
33 | #include <algorithm> |
---|
34 | #include <cassert> |
---|
35 | #include <cstdlib> |
---|
36 | #include <fstream> |
---|
37 | #include <functional> |
---|
38 | #include <iostream> |
---|
39 | #include <iterator> |
---|
40 | #include <map> |
---|
41 | #include <numeric> |
---|
42 | #include <string> |
---|
43 | #include <sstream> |
---|
44 | #include <unistd.h> |
---|
45 | #include <utility> |
---|
46 | #include <vector> |
---|
47 | |
---|
48 | |
---|
49 | namespace theplu{ |
---|
50 | namespace svndigest{ |
---|
51 | |
---|
52 | |
---|
53 | BlameStats::BlameStats(const std::string& path) |
---|
54 | : Stats(path) |
---|
55 | { |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | BlameStats::BlameStats(const BlameStats& other) |
---|
60 | : Stats(other) |
---|
61 | { |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void BlameStats::do_parse(const std::string& path, svn_revnum_t first_rev) |
---|
66 | { |
---|
67 | // FIXME: using log from File object |
---|
68 | SVNlog log(path); |
---|
69 | typedef std::set<svn_revnum_t> RevSet; |
---|
70 | RevSet revs; |
---|
71 | std::transform(log.commits().begin(), log.commits().end(), |
---|
72 | std::inserter(revs, revs.begin()), |
---|
73 | std::mem_fun_ref(&Commitment::revision)); |
---|
74 | // we use a ParseVector here to be able to detect when people are |
---|
75 | // absent in a revision. |
---|
76 | std::vector<std::map<std::string, SparseVector> > data(4); |
---|
77 | for (RevSet::reverse_iterator rev_iter=revs.rbegin(); |
---|
78 | rev_iter!=revs.rend() && *rev_iter>=first_rev; ++rev_iter){ |
---|
79 | SVNblame svn_blame(path, *rev_iter); |
---|
80 | LineTypeParser parser(path); |
---|
81 | while (svn_blame.valid()) { |
---|
82 | int lt = parser.parse(svn_blame.line()); |
---|
83 | assert(lt<data.size()); |
---|
84 | SparseVector& vec = data[lt][svn_blame.author()]; |
---|
85 | vec.set(*rev_iter, vec[*rev_iter] + 1); |
---|
86 | add_author(svn_blame.author()); |
---|
87 | // I dont trust blame and log behave consistently (stop-on-copy). |
---|
88 | revs.insert(svn_blame.revision()); |
---|
89 | svn_blame.next_line(); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | // for count=zero we have not created an entry in SumVector and |
---|
94 | // value will be "value for previous rev". Therefore we need to |
---|
95 | // set the value to zero explicitely. |
---|
96 | if (stats_.size()<data.size()) |
---|
97 | stats_.resize(data.size()); |
---|
98 | for (int lt =0; lt<data.size(); ++lt) { |
---|
99 | // just to avoid long long lines |
---|
100 | typedef std::map<std::string,SparseVector>::const_iterator const_iterator; |
---|
101 | for (const_iterator av = data[lt].begin(); av!=data[lt].end(); ++av) { |
---|
102 | for (RevSet::const_reverse_iterator rev_iter=revs.rbegin(); |
---|
103 | rev_iter!=revs.rend() && *rev_iter >= first_rev; ++rev_iter) { |
---|
104 | // FIXME: use Vector::iterator to avoid logN checkup |
---|
105 | stats_[lt][av->first].set(*rev_iter, data[lt][av->first][*rev_iter]); |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | }} // end of namespace svndigest and namespace theplu |
---|