source: trunk/lib/BlameStats.cc @ 647

Last change on this file since 647 was 647, checked in by Peter Johansson, 13 years ago

using mem_fun_ref

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: BlameStats.cc 647 2008-06-04 13:51:36Z 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 "GnuplotFE.h"
29#include "SVNblame.h"
30#include "SVNinfo.h"
31#include "SVNlog.h"
32#include "utility.h"
33
34#include <algorithm>
35#include <cassert>
36#include <cstdlib>
37#include <fstream>
38#include <functional>
39#include <iostream>
40#include <iterator>
41#include <map>
42#include <numeric>
43#include <string>
44#include <sstream>
45#include <unistd.h>
46#include <utility>
47#include <vector>
48
49
50namespace theplu{
51namespace svndigest{
52
53
54  BlameStats::BlameStats(const std::string& path)
55    : Stats(path)
56  {
57  }
58
59
60  BlameStats::BlameStats(const BlameStats& other)
61  : Stats(other)
62  {
63  }
64
65
66  void BlameStats::fill_in(Author2Vector& a2v, svn_revnum_t rev)
67  {
68    assert(rev);
69    for (std::set<std::string>::const_iterator iter(authors().begin());
70         iter!=authors().end(); ++iter) {
71      std::vector<unsigned int>& vec = a2v[*iter];
72      vec.resize(revision()+1);
73      assert(rev<static_cast<svn_revnum_t>(vec.size()));
74      vec[rev]=vec[rev-1];
75    }
76  }
77
78
79  void BlameStats::do_parse(const std::string& path)
80  {
81    LineTypeParser parser(path);
82    SVNlog log(path);
83    typedef std::set<svn_revnum_t> RevSet;
84    RevSet revs;
85    std::transform(log.commits().begin(), log.commits().end(),
86                   std::inserter(revs, revs.begin()), 
87                   std::mem_fun_ref(&Commitment::revision));
88    for (RevSet::iterator rev_iter=revs.begin();rev_iter!=revs.end();++rev_iter){
89      SVNblame svn_blame(path, *rev_iter);
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
99    RevSet::iterator rev_iter=revs.begin();
100    for (svn_revnum_t rev = 1; rev<=revision(); ++rev){
101      if (rev==*rev_iter)
102        ++rev_iter;
103      else {
104        fill_in(code_stats(),rev);
105        fill_in(comment_stats(),rev);
106        fill_in(other_stats(),rev);
107        fill_in(copyright_stats(),rev);
108      }
109    }
110  }
111
112
113}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.