1 | //$Id$ |
---|
2 | |
---|
3 | #include "Node.h" |
---|
4 | #include "utility.h" |
---|
5 | |
---|
6 | #include <fstream> |
---|
7 | #include <iostream> |
---|
8 | #include <numeric> |
---|
9 | #include <sstream> |
---|
10 | #include <vector> |
---|
11 | |
---|
12 | namespace theplu{ |
---|
13 | namespace svnstat{ |
---|
14 | |
---|
15 | Node::Node(const std::string& path, Node* mother) |
---|
16 | : path_(path), mother_(mother) |
---|
17 | { |
---|
18 | info(); |
---|
19 | } |
---|
20 | |
---|
21 | std::vector<u_int> Node::accumulated(void) const |
---|
22 | { |
---|
23 | std::vector<u_int> sum(revision_,0); |
---|
24 | if (stats_.empty()) |
---|
25 | return sum; |
---|
26 | |
---|
27 | // sum of all users |
---|
28 | sum = std::accumulate(stats_.begin(),stats_.end(), sum, |
---|
29 | VectorPlus<std::string,u_int>()); |
---|
30 | |
---|
31 | // calculate accumulated sum |
---|
32 | std::vector<u_int> accum(sum.size()); |
---|
33 | std::partial_sum(sum.begin(),sum.end(),accum.begin()); |
---|
34 | return accum; |
---|
35 | } |
---|
36 | |
---|
37 | std::vector<u_int> Node::accumulated(const std::string& user) |
---|
38 | { |
---|
39 | std::vector<u_int> vec=stats_[user]; |
---|
40 | if (vec.empty()) |
---|
41 | return vec; |
---|
42 | std::vector<u_int> accum(vec.size()); |
---|
43 | std::partial_sum(vec.begin(),vec.end(),accum.begin()); |
---|
44 | return accum; |
---|
45 | } |
---|
46 | |
---|
47 | void Node::add(const std::string& user, const u_int& rev) |
---|
48 | { |
---|
49 | std::vector<u_int> vec = stats_[user]; |
---|
50 | if (vec.size() < rev+1){ |
---|
51 | u_int i=vec.size(); |
---|
52 | vec.resize(rev+1); |
---|
53 | for (; i<rev; i++) |
---|
54 | vec[i]=0; |
---|
55 | vec[rev]=1; |
---|
56 | } |
---|
57 | else |
---|
58 | vec[rev]++; |
---|
59 | stats_[user]=vec; |
---|
60 | |
---|
61 | if (mother_) |
---|
62 | mother_->add(user,rev); |
---|
63 | } |
---|
64 | |
---|
65 | bool Node::info() |
---|
66 | { |
---|
67 | std::string system_call = "svn info " + path_ + " > svnstat.tmp"; |
---|
68 | int system_return = system(system_call.c_str()); |
---|
69 | if (system_return){ |
---|
70 | std::cerr << "Error: svn info " << path_ << std::endl; |
---|
71 | return false; |
---|
72 | } |
---|
73 | std::ifstream is("svnstat.tmp"); |
---|
74 | std::string line; |
---|
75 | while (getline(is,line)){ |
---|
76 | std::stringstream ss(line); |
---|
77 | std::string tag; |
---|
78 | getline(ss,tag,':'); |
---|
79 | if (tag == std::string("Repository UUID")) |
---|
80 | ss >> uuid_; |
---|
81 | else if (tag == std::string("Last Changed Author")) |
---|
82 | ss >> author_; |
---|
83 | else if (tag == std::string("Last Changed Rev")) |
---|
84 | ss >> revision_; |
---|
85 | } |
---|
86 | |
---|
87 | return true; |
---|
88 | } |
---|
89 | |
---|
90 | }} // end of namespace svnstat and namespace theplu |
---|