source: trunk/lib/CommitStat.cc @ 84

Last change on this file since 84 was 84, checked in by Jari Häkkinen, 15 years ago

Added copyright statement. Bumped version number to pre0.3. Cleaned up code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1// $Id: CommitStat.cc 84 2006-03-13 22:04:34Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "CommitStat.h"
25
26#include <algorithm>
27#include <cassert>
28#include <fstream>
29#include <iostream>
30#include <sstream>
31#include <string>
32
33namespace theplu{
34namespace svnstat{
35
36  int CommitStat::log(const std::string& path) const
37  {
38    std::string system_call = "svn log -q -r HEAD:1 " + path + 
39      " > svnstat.log.tmp";
40    int system_return = system(system_call.c_str());
41    if (system_return)
42      std::cerr << "Error: svn log " << path << std::endl;     
43    return system_return;
44  }
45
46
47  int CommitStat::parse(const std::string& path)
48  {
49    reset();
50    int system_return = log(path);
51   
52    std::ifstream is("svnstat.log.tmp");
53    std::string line;
54    typedef std::vector<std::string>::iterator DateIter;
55    size_t rev_last_iteration=0;
56    std::string date;
57    while (getline(is,line, '\n')){
58      if (!line.size()) // skip empty line
59        continue;
60      std::stringstream ss(line);
61
62      if (ss.get() == 'r'){
63        size_t revision;
64        ss >> revision;
65        assert(revision);
66        std::string tmp;
67        ss >> tmp;
68        std::string user;
69        getline(ss,user,'|');
70        ss >> date; 
71        std::string time;
72        ss >> time;
73
74        if (revision+1 > date_.size()){
75          date_.resize(revision+1);
76          rev_last_iteration=revision+1;
77        }
78        assert(revision<=rev_last_iteration);
79        std::fill(date_.begin()+revision,
80                  date_.begin()+rev_last_iteration,
81                  date);
82        rev_last_iteration=revision;
83      }
84      std::fill(date_.begin(),
85                date_.begin()+rev_last_iteration,
86                date);
87    }
88    is.close();
89
90    assert(date_.size());
91    assert(date_[0].size());
92    return system_return;
93  }
94
95
96  void CommitStat::reset(void)
97  {
98    date_.clear();
99  }
100
101}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.