source: trunk/lib/CommitStat.cc @ 64

Last change on this file since 64 was 64, checked in by Peter Johansson, 16 years ago

fixed problem with parsing with user names with white spaces, e.g. (no author)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1
2//$Id: CommitStat.cc 64 2006-01-20 09:02:37Z peter $
3
4#include "CommitStat.h"
5
6#include <algorithm>
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    return system_return;
70  }
71
72
73  void CommitStat::reset(void)
74  {
75    date_.clear();
76  }
77
78}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.