source: trunk/lib/BlameStats.cc

Last change on this file was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: BlameStats.cc 1515 2012-09-26 00:35:10Z 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, 2011, 2012 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 "SVNblame.h"
27#include "SVNinfo.h"
28#include "SVNlog.h"
29#include "Vector.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::do_parse(const std::string& path, svn_revnum_t first_rev)
64  {
65    first_rev = std::max(first_rev, ignore_rev()+1);
66    // FIXME: using log from File object
67    SVNlog log(path);
68    typedef std::set<svn_revnum_t> RevSet;
69    RevSet revs;
70    std::transform(log.commits().begin(), log.commits().end(),
71                   std::inserter(revs, revs.begin()),
72                   std::mem_fun_ref(&Commitment::revision));
73    // we use a ParseVector here to be able to detect when people are
74    // absent in a revision.
75    std::vector<std::map<std::string, SparseVector> > data(4);
76    for (RevSet::reverse_iterator rev_iter=revs.rbegin();
77         rev_iter!=revs.rend() && *rev_iter>=first_rev; ++rev_iter){
78      SVNblame svn_blame(path, *rev_iter);
79      LineTypeParser parser(path);
80      while (svn_blame.valid()) {
81        int lt = parser.parse(svn_blame.line());
82        assert(static_cast<size_t>(lt)<data.size());
83        SparseVector& vec = data[lt][svn_blame.author()];
84        if (svn_blame.revision()>ignore_rev()) {
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        }
90        svn_blame.next_line();
91      }
92    }
93
94    // for count=zero we have not created an entry in SumVector and
95    // value will be "value for previous rev". Therefore we need to
96    // set the value to zero explicitely.
97    if (stats_.size()<data.size())
98      stats_.resize(data.size());
99    for (size_t lt =0; lt<data.size(); ++lt) {
100      // just to avoid long long lines
101      typedef std::map<std::string,SparseVector>::const_iterator const_iterator;
102      for (const_iterator av = data[lt].begin(); av!=data[lt].end(); ++av) {
103        for (RevSet::const_reverse_iterator rev_iter=revs.rbegin();
104             rev_iter!=revs.rend() && *rev_iter >= first_rev; ++rev_iter) {
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
Note: See TracBrowser for help on using the repository browser.