source: trunk/lib/CommitStat.cc @ 74

Last change on this file since 74 was 73, checked in by Jari Häkkinen, 16 years ago

Divided Gnuplot class into a basic gnuplot communication class
and a front end class specialized for svnstat.
Added option to plot stats against time or revision.
Removed gnuplot usage of temporary files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1// $Id: CommitStat.cc 73 2006-03-04 18:10:07Z jari $
2
3#include "CommitStat.h"
4
5#include <algorithm>
6#include <cassert>
7#include <fstream>
8#include <iostream>
9#include <sstream>
10#include <string>
11
12namespace theplu{
13namespace svnstat{
14
15  int CommitStat::log(const std::string& path) const
16  {
17    std::string system_call = "svn log -q -r HEAD:1 " + path + 
18      " > svnstat.log.tmp";
19    int system_return = system(system_call.c_str());
20    if (system_return)
21      std::cerr << "Error: svn log " << path << std::endl;     
22    return system_return;
23  }
24
25
26  int CommitStat::parse(const std::string& path)
27  {
28    reset();
29    int system_return = log(path);
30   
31    std::ifstream is("svnstat.log.tmp");
32    std::string line;
33    typedef std::vector<std::string>::iterator DateIter;
34    size_t rev_last_iteration=0;
35    std::string date;
36    while (getline(is,line, '\n')){
37      if (!line.size()) // skip empty line
38        continue;
39      std::stringstream ss(line);
40
41      if (ss.get() == 'r'){
42        size_t revision;
43        ss >> revision;
44        assert(revision);
45        std::string tmp;
46        ss >> tmp;
47        std::string user;
48        getline(ss,user,'|');
49        ss >> date; 
50        std::string time;
51        ss >> time;
52
53        if (revision+1 > date_.size()){
54          date_.resize(revision+1);
55          rev_last_iteration=revision+1;
56        }
57        assert(revision<=rev_last_iteration);
58        std::fill(date_.begin()+revision,
59                  date_.begin()+rev_last_iteration,
60                  date);
61        rev_last_iteration=revision;
62      }
63      std::fill(date_.begin(),
64                date_.begin()+rev_last_iteration,
65                date);
66    }
67    is.close();
68
69    assert(date_.size());
70    assert(date_[0].size());
71    return system_return;
72  }
73
74
75  void CommitStat::reset(void)
76  {
77    date_.clear();
78  }
79
80}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.