1 | // $Id: BlameStats.cc 845 2009-11-16 22:27:19Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005 Peter Johansson |
---|
5 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2009 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 | |
---|
32 | #include <algorithm> |
---|
33 | #include <cassert> |
---|
34 | #include <cstdlib> |
---|
35 | #include <fstream> |
---|
36 | #include <functional> |
---|
37 | #include <iostream> |
---|
38 | #include <iterator> |
---|
39 | #include <map> |
---|
40 | #include <numeric> |
---|
41 | #include <string> |
---|
42 | #include <sstream> |
---|
43 | #include <unistd.h> |
---|
44 | #include <utility> |
---|
45 | #include <vector> |
---|
46 | |
---|
47 | |
---|
48 | namespace theplu{ |
---|
49 | namespace svndigest{ |
---|
50 | |
---|
51 | |
---|
52 | BlameStats::BlameStats(const std::string& path) |
---|
53 | : Stats(path) |
---|
54 | { |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | BlameStats::BlameStats(const BlameStats& other) |
---|
59 | : Stats(other) |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | void BlameStats::fill_in(Author2Vector& a2v, svn_revnum_t rev) |
---|
65 | { |
---|
66 | if (rev==0) |
---|
67 | return; |
---|
68 | for (std::set<std::string>::const_iterator iter(authors().begin()); |
---|
69 | iter!=authors().end(); ++iter) { |
---|
70 | std::vector<unsigned int>& vec = a2v[*iter]; |
---|
71 | vec.resize(revision()+1); |
---|
72 | assert(rev<static_cast<svn_revnum_t>(vec.size())); |
---|
73 | vec[rev]=vec[rev-1]; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | void BlameStats::do_parse(const std::string& path, svn_revnum_t first_rev) |
---|
79 | { |
---|
80 | SVNlog log(path); |
---|
81 | typedef std::set<svn_revnum_t> RevSet; |
---|
82 | RevSet revs; |
---|
83 | std::transform(log.commits().begin(), log.commits().end(), |
---|
84 | std::inserter(revs, revs.begin()), |
---|
85 | std::mem_fun_ref(&Commitment::revision)); |
---|
86 | for (RevSet::reverse_iterator rev_iter=revs.rbegin(); |
---|
87 | rev_iter!=revs.rend() && *rev_iter>=first_rev; ++rev_iter){ |
---|
88 | SVNblame svn_blame(path, *rev_iter); |
---|
89 | LineTypeParser parser(path); |
---|
90 | while (svn_blame.valid()) { |
---|
91 | add(svn_blame.author(), *rev_iter, parser.parse(svn_blame.line())); |
---|
92 | // I dont trust blame and log behave consistent (stop-on-copy). |
---|
93 | revs.insert(svn_blame.revision()); |
---|
94 | svn_blame.next_line(); |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | // filling in pristine revisions, i.e., revs that are larger than |
---|
99 | // first_rev and not occuring in revs. |
---|
100 | RevSet::iterator rev_iter=revs.begin(); |
---|
101 | svn_revnum_t rev = first_rev; |
---|
102 | while (rev<=revision()) { |
---|
103 | if (rev_iter!=revs.end() && rev>*rev_iter) |
---|
104 | ++rev_iter; |
---|
105 | else if (rev_iter!=revs.end() && rev==*rev_iter) { |
---|
106 | ++rev_iter; |
---|
107 | ++rev; |
---|
108 | } |
---|
109 | else { |
---|
110 | fill_in(code_stats(),rev); |
---|
111 | fill_in(comment_stats(),rev); |
---|
112 | fill_in(other_stats(),rev); |
---|
113 | fill_in(copyright_stats(),rev); |
---|
114 | ++rev; |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | }} // end of namespace svndigest and namespace theplu |
---|