source: trunk/lib/File.cc @ 16

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

merged Node::info() and Node::subversion_controlled()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: File.cc 16 2005-12-30 17:30:51Z 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  const Stats& File::parse(void)
25  {
26    stats_.reset();
27    if (binary_){
28      stats_.add(author_,revision_);
29      return stats_;
30    }
31
32    // Calling svn blame
33    if (!blame())
34      return stats_;
35
36    // Check if file is binary
37    std::ifstream is("svnstat.tmp");
38    std::string line;
39    getline(is,line,' ');
40    if (line==std::string("Skipping")){
41      getline(is,line,' ');
42      if (line==std::string("binary")){
43  is.close();
44  binary_ = true;
45  return parse();
46      }
47    }
48    is.close();
49
50    is.open("svnstat.tmp");
51    while (getline(is,line, '\n')){
52      if (!line.size()) // skip empty line
53  continue;
54      std::stringstream ss(line);
55      u_int revision;
56      std::string user;
57      ss >> revision;
58      ss >> user;
59      stats_.add(user, revision);
60    }
61    is.close();
62    return stats_;
63  }
64
65  void File::print(void) {
66    // Jari, temporary using this to print directory tree
67    std::cout << "File '" << path_ << "'" << std::endl;
68  }
69
70}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.