1 | // $Id: BlameStats.cc 657 2008-06-10 00:27:40Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005 Peter Johansson |
---|
5 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
6 | |
---|
7 | This file is part of svndigest, http://trac.thep.lu.se/svndigest |
---|
8 | |
---|
9 | svndigest is free software; you can redistribute it and/or modify it |
---|
10 | under the terms of the GNU General Public License as published by |
---|
11 | the Free Software Foundation; either version 2 of the License, or |
---|
12 | (at your option) any later version. |
---|
13 | |
---|
14 | svndigest is distributed in the hope that it will be useful, but |
---|
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
22 | 02111-1307, USA. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "BlameStats.h" |
---|
26 | |
---|
27 | #include "Functor.h" |
---|
28 | #include "SVNblame.h" |
---|
29 | #include "SVNinfo.h" |
---|
30 | #include "SVNlog.h" |
---|
31 | #include "utility.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::fill_in(Author2Vector& a2v, svn_revnum_t rev) |
---|
66 | { |
---|
67 | assert(rev); |
---|
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) |
---|
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::iterator rev_iter=revs.begin();rev_iter!=revs.end();++rev_iter){ |
---|
87 | SVNblame svn_blame(path, *rev_iter); |
---|
88 | LineTypeParser parser(path); |
---|
89 | while (svn_blame.valid()) { |
---|
90 | add(svn_blame.author(), *rev_iter, parser.parse(svn_blame.line())); |
---|
91 | // I dont trust blame and log behave consistent (stop-on-copy). |
---|
92 | revs.insert(svn_blame.revision()); |
---|
93 | svn_blame.next_line(); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | // filling in pristine revisions |
---|
98 | RevSet::iterator rev_iter=revs.begin(); |
---|
99 | for (svn_revnum_t rev = 1; rev<=revision(); ++rev){ |
---|
100 | if (rev==*rev_iter) |
---|
101 | ++rev_iter; |
---|
102 | else { |
---|
103 | fill_in(code_stats(),rev); |
---|
104 | fill_in(comment_stats(),rev); |
---|
105 | fill_in(other_stats(),rev); |
---|
106 | fill_in(copyright_stats(),rev); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | }} // end of namespace svndigest and namespace theplu |
---|