source: trunk/lib/BlameStats.cc @ 693

Last change on this file since 693 was 693, checked in by Jari Häkkinen, 15 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: BlameStats.cc 693 2008-09-11 20:42:56Z jari $
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://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "BlameStats.h"
24
25#include "Functor.h"
26#include "SVNblame.h"
27#include "SVNinfo.h"
28#include "SVNlog.h"
29#include "utility.h"
30
31#include <algorithm>
32#include <cassert>
33#include <cstdlib>
34#include <fstream>
35#include <functional>
36#include <iostream>
37#include <iterator>
38#include <map>
39#include <numeric>
40#include <string>
41#include <sstream>
42#include <unistd.h>
43#include <utility>
44#include <vector>
45
46
47namespace theplu{
48namespace svndigest{
49
50
51  BlameStats::BlameStats(const std::string& path)
52    : Stats(path)
53  {
54  }
55
56
57  BlameStats::BlameStats(const BlameStats& other)
58  : Stats(other)
59  {
60  }
61
62
63  void BlameStats::fill_in(Author2Vector& a2v, svn_revnum_t rev)
64  {
65    assert(rev);
66    for (std::set<std::string>::const_iterator iter(authors().begin());
67         iter!=authors().end(); ++iter) {
68      std::vector<unsigned int>& vec = a2v[*iter];
69      vec.resize(revision()+1);
70      assert(rev<static_cast<svn_revnum_t>(vec.size()));
71      vec[rev]=vec[rev-1];
72    }
73  }
74
75
76  void BlameStats::do_parse(const std::string& path, svn_revnum_t first_rev)
77  {
78    SVNlog log(path);
79    typedef std::set<svn_revnum_t, std::greater<svn_revnum_t> > RevSet;
80    RevSet revs;
81    std::transform(log.commits().begin(), log.commits().end(),
82                   std::inserter(revs, revs.begin()), 
83                   std::mem_fun_ref(&Commitment::revision));
84    for (RevSet::iterator rev_iter=revs.begin();
85         rev_iter!=revs.end() && *rev_iter>first_rev; ++rev_iter){
86      SVNblame svn_blame(path, *rev_iter);
87      LineTypeParser parser(path);
88      while (svn_blame.valid()) {
89        add(svn_blame.author(), *rev_iter, parser.parse(svn_blame.line()));
90        // I dont trust blame and log behave consistent (stop-on-copy).
91        revs.insert(svn_blame.revision());
92        svn_blame.next_line();
93      }
94    }
95   
96    // filling in pristine revisions
97    RevSet::iterator rev_iter=revs.begin();
98    for (svn_revnum_t rev = first_rev+1; rev<=revision(); ++rev){
99      if (rev==*rev_iter)
100        ++rev_iter;
101      else {
102        fill_in(code_stats(),rev);
103        fill_in(comment_stats(),rev);
104        fill_in(other_stats(),rev);
105        fill_in(copyright_stats(),rev);
106      }
107    }
108  }
109
110
111}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.