source: trunk/lib/AddStats.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.1 KB
Line 
1// $Id: AddStats.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 "AddStats.h"
25
26#include "SVNblame.h"
27#include "SVNlog.h"
28
29#include <algorithm>
30#include <cassert>
31#include <cstdlib>
32#include <functional>
33#include <map>
34#include <string>
35#include <vector>
36
37namespace theplu{
38namespace svndigest{
39
40
41  AddStats::AddStats(const std::string& path)
42    : Stats(path)
43  {
44  }
45
46
47  AddStats::AddStats(const AddStats& other)
48  : Stats(other)
49  {
50  }
51
52
53  void AddStats::do_parse(const std::string& path, svn_revnum_t first_rev)
54  {
55    first_rev = std::max(first_rev, ignore_rev()+1);
56    // FIXME: why not using the log from File object
57    SVNlog log(path);
58    typedef std::set<svn_revnum_t, std::greater<svn_revnum_t> > RevSet;
59    RevSet revs;
60    std::vector<std::map<std::string, SparseVector> > data;
61    std::transform(log.commits().begin(), log.commits().end(),
62                   std::inserter(revs, revs.begin()),
63                   std::mem_fun_ref(&Commitment::revision));
64    for (RevSet::iterator rev_iter=revs.begin();
65         rev_iter!=revs.end() && *rev_iter>=first_rev; ++rev_iter){
66      SVNblame svn_blame(path, *rev_iter);
67      LineTypeParser parser(path);
68      std::vector<size_t> add_vec(4,0);
69      std::string author="";
70      while (svn_blame.valid()) {
71        LineTypeParser::line_type lt = parser.parse(svn_blame.line());
72        if (*rev_iter==svn_blame.revision()) {
73          author = svn_blame.author();
74          assert(static_cast<size_t>(lt)<add_vec.size());
75          ++add_vec[lt];
76        }
77        // I dont trust blame and log behave consistently (stop-on-copy).
78        revs.insert(svn_blame.revision());
79        svn_blame.next_line();
80      }
81      if (author.empty()) { // don't add 0 to author ""
82        assert(add_vec[0]==0);
83        assert(add_vec[1]==0);
84        assert(add_vec[2]==0);
85        assert(add_vec[3]==0);
86        continue;
87      }
88      if (data.size()<add_vec.size())
89        data.resize(add_vec.size());
90      for (size_t lt=0; lt<add_vec.size(); ++lt) {
91        assert(author.size());
92        SparseVector& vec=data[lt][author];
93        // add add_vec[lt] to current value
94        vec.set(*rev_iter, vec[*rev_iter] + add_vec[lt]);
95        assert(static_cast<size_t>(data[lt][author][*rev_iter])>=add_vec[lt]);
96      }
97    }
98    // add parsed data to member
99    add(data);
100  }
101
102
103  unsigned int AddStats::max_element(const SumVector& v) const
104  {
105    if (v.size()==0)
106      return 0;
107    return v.back();
108  }
109
110
111}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.