source: branches/0.9-stable/lib/AddStats.cc @ 1276

Last change on this file since 1276 was 1276, checked in by Peter Johansson, 12 years ago

Let Graph class hold information about last point (rev_max_) rather
than defining via the size of Vector. Not resizing the Vectors means
we can avoid some copying in Stats class. But it also means we need to
handle the case of empty Vector in Stats::max_element. Made the
function Node::svn_info(void) public. In svndigest.cc set rev_min also
when not using dates as well as setting the new static variable rev_max.
closes #485

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: AddStats.cc 1276 2010-11-05 12:24:26Z 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 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#include "utility.h"
29
30#include <algorithm>
31#include <cassert>
32#include <cstdlib>
33#include <functional>
34#include <map>
35#include <string>
36#include <vector>
37
38namespace theplu{
39namespace svndigest{
40
41
42  AddStats::AddStats(const std::string& path)
43    : Stats(path)
44  {
45  }
46
47
48  AddStats::AddStats(const AddStats& other)
49  : Stats(other)
50  {
51  }
52
53
54  void AddStats::do_parse(const std::string& path, svn_revnum_t rev)
55  {
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>=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(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(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.