Changeset 482
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Directory.cc
r452 r482 161 161 if (user=="all") 162 162 mkdir(imagedir); 163 164 163 std::string html_name = outdir+"/index.html"; 165 164 std::ofstream os(html_name.c_str()); -
trunk/lib/File.cc
r476 r482 194 194 std::cout << "Parsing " << path_ << std::endl; 195 195 stats_.reset(); 196 std::string cache_dir = directory_name(path()) + std::string(".svndigest/"); 197 std::string cache_file = cache_dir + name()+std::string(".svndigest-cache"); 198 if (node_exist(cache_file)){ 199 std::ifstream is(cache_file.c_str()); 200 if (stats_.load_cache(is)){ 201 return stats_; 202 } 203 std::cout << "failed: " << path_ << std::endl; 204 } 205 stats_.reset(); 196 206 stats_.parse(path_); 207 if (!node_exist(cache_dir)) 208 mkdir(cache_dir); 209 std::ofstream os(cache_file.c_str()); 210 stats_.print(os); 197 211 return stats_; 198 212 } -
trunk/lib/Node.cc
r463 r482 154 154 log_ = new SVNlog(log_core()); 155 155 return *log_; 156 } 157 158 159 std::string Node::name(void) const 160 { 161 std::string res = file_name(path_); 162 return res; 156 163 } 157 164 -
trunk/lib/Node.h
r453 r482 133 133 /// @return name of node (not full path) 134 134 /// 135 inline std::string name(void) const { return file_name(path_); }135 std::string name(void) const; 136 136 137 137 /** … … 139 139 exception when an empty string is returned. 140 140 141 @return output dir for example 'lib ' for this file141 @return output dir for example 'lib/' for this file 142 142 */ 143 143 std::string output_dir(void) const; -
trunk/lib/Stats.cc
r468 r482 92 92 const Parser::line_type& lt) 93 93 { 94 assert(user.size()); 94 95 authors_.insert(user); 95 96 … … 145 146 146 147 147 void Stats::load(std::istream& is) 148 { 149 is >> last_changed_rev_; 148 bool Stats::load_cache(std::istream& is) 149 { 150 svn_revnum_t rev; 151 is >> rev; 152 if (rev<last_changed_rev_){ 153 return false; // cache is not up to date 154 } 150 155 size_t a_size=0; 151 156 authors_.clear(); … … 154 159 while (authors_.size()<a_size){ 155 160 getline(is, str); 161 assert(str.size()); 156 162 authors_.insert(str); 157 163 } 164 getline(is, str); 165 if (str!=code_cache()){ 166 return false; 167 } 158 168 load(is, code_); 169 getline(is, str); 170 getline(is, str); 171 if (str!=comments_cache()){ 172 return false; 173 } 159 174 load(is, comments_); 175 getline(is, str); 176 getline(is, str); 177 if (str!=empty_cache()){ 178 return false; 179 } 160 180 load(is, empty_); 181 getline(is, str); 182 getline(is, str); 183 if (str!=total_cache()){ 184 return false; 185 } 161 186 load(is, total_); 187 getline(is,str); 188 getline(is,str); 189 return str==end_of_cache(); 162 190 } 163 191 … … 166 194 { 167 195 m.clear(); 168 while (m.size() < authors_.size() ) {196 while (m.size() < authors_.size() && is.good()) { 169 197 std::string name; 170 198 std::getline(is, name); 199 assert(name.size()); 171 200 std::vector<u_int>& vec=m[name]; 172 201 size_t revs=0; … … 319 348 void Stats::print(std::ostream& os) const 320 349 { 321 os << last_changed_rev_ << "\n"; 322 os << authors_.size() << "\n"; 350 os << last_changed_rev_ << " "; 351 os << authors_.size() << " "; 352 323 353 std::copy(authors_.begin(), authors_.end(), 324 354 std::ostream_iterator<std::string>(os, "\n")); 355 os << code_cache() << "\n"; 325 356 print(os, code_); 357 os << "\n" << comments_cache() << "\n"; 326 358 print(os, comments_); 359 os << "\n" << empty_cache() << "\n"; 327 360 print(os, empty_); 361 os << "\n" << total_cache() << "\n"; 328 362 print(os, total_); 363 os << "\n" << end_of_cache() << "\n"; 329 364 } 330 365 … … 334 369 for (MapConstIter_ i(m.begin()); i!=m.end(); ++i){ 335 370 os << i->first << "\n"; 336 os << i->second.size() << " \n";371 os << i->second.size() << " "; 337 372 std::copy(i->second.begin(), i->second.end(), 338 std::ostream_iterator<u_int>(os, " \n"));373 std::ostream_iterator<u_int>(os, " ")); 339 374 } 340 375 } -
trunk/lib/Stats.h
r468 r482 32 32 33 33 #include <map> 34 #include <istream> 34 35 #include <set> 35 36 #include <string> … … 104 105 { return accumulated(total_, user).back(); } 105 106 107 /** 108 Load object from a stream. 109 110 \return true if successful 111 */ 112 bool load_cache(std::istream&); 113 106 114 void parse(const std::string&); 107 115 … … 178 186 const Parser::line_type&); 179 187 180 181 /** 182 Load object from a stream. 183 */ 184 void load(std::istream&); 188 // Change this string if cache format is changed in such a way 189 // that all old cache files are obsolete. 190 inline std::string end_of_cache(void) const {return "END OF OK CACHE FILE";} 191 inline std::string code_cache(void) const {return "CACHE CODE";} 192 inline std::string comments_cache(void) const {return "CACHE COMMENTS";} 193 inline std::string empty_cache(void) const {return "CACHE EMPTY";} 194 inline std::string total_cache(void) const {return "CACHE TOTAL";} 195 185 196 186 197 /** -
trunk/lib/utility.cc
r465 r482 24 24 #include "utility.h" 25 25 26 #include <cerrno> 26 27 #include <cstdlib> 27 28 #include <fstream> … … 79 80 80 81 82 std::string directory_name(std::string path) 83 { 84 size_t pos = path.find_last_of("/"); 85 if (pos==path.size()-1) 86 return directory_name(path.substr(0,path.size()-2)); 87 return path.substr(0,pos+1); 88 } 89 90 81 91 std::string file_name(const std::string& full_path) 82 92 { … … 140 150 } 141 151 152 void mkdir(const std::string& dir) 153 { 154 int code = ::mkdir(dir.c_str(),0777); 155 if (code){ 156 std::stringstream ss; 157 ss << "mkdir(" << dir << "): failed with error code: errno=" << errno; 158 throw std::runtime_error(ss.str()); 159 } 160 } 161 162 163 bool node_exist(const std::string& path) 164 { 165 struct stat buf; 166 return !stat(path.c_str(),&buf); 167 } 168 142 169 143 170 int percent(int a, int b) … … 146 173 return (100*a)/b; 147 174 return 0; 148 }149 150 151 bool node_exist(const std::string& path)152 {153 struct stat buf;154 return !stat(path.c_str(),&buf);155 175 } 156 176 -
trunk/lib/utility.h
r465 r482 61 61 void copy_file(const std::string& source, const std::string& target); 62 62 63 /** 64 Parsing out the directory of path that is everything prior the 65 last '/' with the eception if \a path ends with '/' in which case 66 everything prior the second last '/' is returned. 67 68 \return directory of path. 69 */ 70 std::string directory_name(std::string path); 71 63 72 /// 64 73 /// @return everything after last '/' … … 113 122 /// mkdir'. 114 123 /// 115 inline int mkdir(const std::string& dir) { return ::mkdir(dir.c_str(),0777); }124 void mkdir(const std::string& dir); 116 125 117 126 ///
Note: See TracChangeset
for help on using the changeset viewer.