source: trunk/lib/File.cc @ 29

Last change on this file since 29 was 29, checked in by Peter Johansson, 17 years ago

modified output file names

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: File.cc 29 2006-01-09 09:35:50Z peter $
2
3#include "File.h"
4#include "Node.h"
5#include "Stats.h"
6
7#include <fstream>
8#include <iostream>
9#include <sstream>
10#include <string>
11
12namespace theplu{
13namespace svnstat{
14
15  bool File::blame() const
16  {
17    std::string system_call = "svn blame " + path_ + " > svnstat.tmp";
18    int system_return = system(system_call.c_str());
19    if (system_return)
20      std::cerr << "Error: svn blame " << path_ << std::endl;     
21    return !system_return;
22  }
23
24  void File::info(void) 
25  {
26    std::string system_call = "svn info " + path_ + " > svnstat.tmp";
27    int system_return = system(system_call.c_str());
28    if (system_return){
29      // Jari, throw exception.
30      std::cerr << "svnstat: svn info " << path_ << std::endl;     
31      exit(-1);
32    }
33    std::ifstream is("svnstat.tmp");
34    std::string line;
35    while (getline(is,line)){
36      std::stringstream ss(line);
37      std::string tag;
38      getline(ss,tag,':');
39      if (tag == std::string("Last Changed Author"))
40        ss >> author_;
41      else if (tag == std::string("Last Changed Rev"))
42        ss >> revision_;
43    }
44  }
45
46
47  const Stats& File::parse(void)
48  {
49    stats_.reset();
50    info();
51
52    if (binary_){
53      stats_.add(author_,revision_);
54      return stats_;
55    }
56
57    // Calling svn blame
58    if (!blame())
59      return stats_;
60
61    // Check if file is binary
62    std::ifstream is("svnstat.tmp");
63    std::string line;
64    getline(is,line,' ');
65    if (line==std::string("Skipping")){
66      getline(is,line,' ');
67      if (line==std::string("binary")){
68        is.close();
69        binary_ = true;
70        return parse();
71      }
72    }
73    is.close();
74
75    is.open("svnstat.tmp");
76    while (getline(is,line, '\n')){
77      if (!line.size()) // skip empty line
78        continue;
79      std::stringstream ss(line);
80      u_int revision;
81      std::string user;
82      ss >> revision;
83      ss >> user;
84      stats_.add(user, revision);
85    }
86    is.close();
87    return stats_;
88  }
89
90  void File::print(const std::string& path) const 
91  {
92    std::string output(path + output_name_ + ".html");
93    std::ofstream os(output.c_str());
94    print_header(os);
95    os << std::endl;
96    stats_.print(os);
97    os << std::endl;
98    print_footer(os);
99    os.close(); 
100
101  }
102
103}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.