- Timestamp:
- Jun 30, 2007, 1:19:45 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/svndigest.cc
r423 r425 190 190 std::cout << "Updating copyright statements" << std::endl; 191 191 std::map<std::string, Alias> alias(config.copyright_alias()); 192 tree->print_copyright(alias );192 tree->print_copyright(alias, option->verbose()); 193 193 } 194 194 catch (const std::runtime_error& x) { -
trunk/lib/Directory.cc
r400 r425 244 244 245 245 246 void Directory::print_copyright(std::map<std::string, Alias>& alias) const { 246 void Directory::print_copyright(std::map<std::string, Alias>& alias, 247 bool verbose) const { 247 248 if (!ignore()){ 248 249 // print daughter nodes, i.e, this function is recursive 249 250 for (NodeConstIterator i = daughters_.begin(); i!=daughters_.end(); ++i) 250 (*i)->print_copyright(alias );251 (*i)->print_copyright(alias, verbose); 251 252 } 252 253 } -
trunk/lib/Directory.h
r408 r425 83 83 const Stats& parse(const bool verbose=false); 84 84 85 void print_copyright(std::map<std::string, Alias>& ) const;85 void print_copyright(std::map<std::string, Alias>&, bool verbose) const; 86 86 87 87 private: -
trunk/lib/File.cc
r424 r425 52 52 if (!output_dir_.empty()) 53 53 output_dir_+='/'; 54 } 55 56 57 std::map<int, std::set<Alias> > 58 File::copyright_map(std::map<std::string, Alias>& alias) const 59 { 60 using namespace std; 61 map<int, set<Alias> > year_authors; 62 SVNlog log(path()); 63 64 assert(log.author().size()==log.date().size()); 65 vector<string>::const_iterator author=log.author().begin(); 66 for (vector<string>::const_iterator date=log.date().begin(); 67 date!=log.date().end(); ++date, ++author) { 68 time_t sec = str2time(*date); 69 tm* timeinfo = gmtime(&sec); 70 71 // find username in map of aliases 72 std::map<string,Alias>::iterator name(alias.lower_bound(*author)); 73 74 // if alias exist insert alias 75 if (name != alias.end() && name->first==*author) 76 year_authors[timeinfo->tm_year].insert(name->second); 77 else { 78 // else insert user name 79 Alias a(*author,alias.size()); 80 year_authors[timeinfo->tm_year].insert(a); 81 std::cerr << "svndigest: warning: no copyright alias found for `" 82 << *author << "`\n"; 83 // insert alias to avoid multiple warnings. 84 alias.insert(name, std::make_pair(*author, a)); 85 } 86 } 87 return year_authors; 88 } 89 90 91 std::string 92 File::copyright_block(const std::map<int, std::set<Alias> >& year_authors, 93 const std::string& prefix) const 94 { 95 using namespace std; 96 stringstream ss; 97 for (map<int, set<Alias> >::const_iterator i(year_authors.begin()); 98 i!=year_authors.end();) { 99 ss << prefix << "Copyright (C) " 100 << 1900+i->first; 101 map<int, set<Alias> >::const_iterator j = i; 102 assert(i!=year_authors.end()); 103 while (++j!=year_authors.end() && 104 i->second == j->second){ 105 ss << ", " << 1900+(j->first); 106 } 107 // printing authors 108 std::vector<Alias> vec_alias; 109 back_insert_iterator<std::vector<Alias> > ii(vec_alias); 110 std::copy(i->second.begin(), i->second.end(), ii); 111 // sort with respect to id 112 std::sort(vec_alias.begin(), vec_alias.end(), IdCompare()); 113 for (std::vector<Alias>::iterator a=vec_alias.begin(); 114 a!=vec_alias.end(); ++a){ 115 if (a!=vec_alias.begin()) 116 ss << ","; 117 ss << " " << a->name(); 118 } 119 ss << "\n"; 120 i = j; 121 } 122 return ss.str(); 123 } 124 125 bool File::detect_copyright(std::string& block, size_t& start_at_line, 126 size_t& end_at_line, std::string& prefix) const 127 { 128 using namespace std; 129 ifstream is(path().c_str()); 130 assert(is.good()); 131 string line; 132 bool found_copyright = false; 133 bool after_copyright = false; 134 size_t line_no=0; 135 while(getline(is, line) && !after_copyright){ 136 ++line_no; 137 if (found_copyright){ 138 // check if line is end of copyright statement, i.e. contains 139 // no alphanumerical character 140 after_copyright = true; 141 for (size_t i=0; i<line.size()&&after_copyright; ++i) 142 if (isalnum(line[i])) { 143 after_copyright = false; 144 block += line + "\n"; 145 } 146 if (after_copyright) 147 end_at_line=line_no; 148 } 149 else { 150 // check whether copyright starts on this line 151 string::iterator i = search(line.begin(), line.end(), "Copyright (C)"); 152 if (i!=line.end()) { 153 start_at_line=line_no; 154 prefix = line.substr(0, distance(line.begin(), i)); 155 found_copyright = true; 156 block = line + "\n"; 157 } 158 } 159 } 160 is.close(); 161 return found_copyright; 54 162 } 55 163 … … 149 257 150 258 151 void File::print_copyright(std::map<std::string, Alias>& alias) const 259 void File::print_copyright(std::map<std::string, Alias>& alias, 260 bool verbose) const 152 261 { 153 262 if (ignore()) 154 263 return; 155 using namespace std; 156 157 SVNlog log(path()); 158 159 map<int, set<Alias> > year_authors; 160 161 assert(log.author().size()==log.date().size()); 162 vector<string>::const_iterator author=log.author().begin(); 163 for (vector<string>::const_iterator date=log.date().begin(); 164 date!=log.date().end(); ++date, ++author) { 165 time_t sec = str2time(*date); 166 tm* timeinfo = gmtime(&sec); 167 168 // find username in map of aliases 169 std::map<string,Alias>::iterator name(alias.lower_bound(*author)); 170 171 // if alias exist insert alias 172 if (name != alias.end() && name->first==*author) 173 year_authors[timeinfo->tm_year].insert(name->second); 174 else { 175 // else insert user name 176 Alias a(*author,alias.size()); 177 year_authors[timeinfo->tm_year].insert(a); 178 std::cerr << "svndigest: warning: no copyright alias found for `" 179 << *author << "`\n"; 180 // insert alias to avoid multiple warnings. 181 alias.insert(name, std::make_pair(*author, a)); 182 } 183 } 184 264 265 std::string old_block; 266 size_t start_line=0; 267 size_t end_line=0; 268 std::string prefix; 269 if (!detect_copyright(old_block, start_line, end_line, prefix)) 270 return; 271 std::map<int, std::set<Alias> > map=copyright_map(alias); 272 std::string new_block = copyright_block(map, prefix); 273 if (old_block==new_block) 274 return; 275 update_copyright(new_block, start_line, end_line); 276 } 277 278 279 void File::print_core(const bool verbose) const 280 { 281 } 282 283 284 void File::print_core(const std::string& user, const std::string& line_type, 285 const SVNlog& log) const 286 { 287 std::string outpath = user+"/"+line_type+"/"+local_path(); 288 std::string imagefile = "images/"+line_type+"/"+local_path_+".png"; 289 std::string html_name(outpath + ".html"); 290 std::ofstream os(html_name.c_str()); 291 print_header(os, name(), level_+2, user, line_type, local_path()+".html"); 292 path_anchor(os); 293 294 os << "<p class=\"plot\">\n<img src='"; 295 for (size_t i=0; i<level_; ++i) 296 os << "../"; 297 os << "../../"; 298 if (user=="all") 299 os << stats_.plot(imagefile,line_type); 300 else 301 os << imagefile; 302 os << "' alt='[plot]' />\n</p>"; 303 304 print_author_summary(os, line_type, log); 305 os << "\n"; 306 307 print_blame(os); 308 309 print_footer(os); 310 os.close(); 311 } 312 313 void File::update_copyright(const std::string& new_block, 314 size_t start_at_line, size_t end_at_line) const 315 { 185 316 // Code copied from Gnuplot -r70 186 317 char tmpname[]="/tmp/svndigestXXXXXX"; … … 194 325 std::ofstream tmp(tmpname); 195 326 327 using namespace std; 196 328 ifstream is(path().c_str()); 197 329 assert(is.good()); 198 330 string line; 199 bool found_copyright = false; 200 bool after_copyright = false; 201 string prefix; 202 while(getline(is, line)){ 203 if (after_copyright) 204 tmp << line << "\n"; 205 else if (found_copyright){ 206 // check if line is end of copyright statement, i.e. contains 207 // no alphanumerical character 208 after_copyright = true; 209 for (size_t i=0; i<line.size()&&after_copyright; ++i) 210 if (isalnum(line[i])) 211 after_copyright = false; 212 if (after_copyright) 213 tmp << line << "\n"; 214 215 } 216 else { 217 // check whether copyright starts on this line 218 string::iterator i = search(line.begin(), line.end(), "Copyright (C)"); 219 if (i==line.end()) { 220 tmp << line << "\n"; 221 } 222 else { 223 prefix = line.substr(0, distance(line.begin(), i)); 224 found_copyright = true; 225 // Printing copyright statement 226 for (map<int, set<Alias> >::const_iterator i(year_authors.begin()); 227 i!=year_authors.end();) { 228 tmp << prefix << "Copyright (C) " 229 << 1900+i->first; 230 map<int, set<Alias> >::const_iterator j = i; 231 assert(i!=year_authors.end()); 232 while (++j!=year_authors.end() && 233 i->second == j->second){ 234 tmp << ", " << 1900+(j->first); 235 } 236 // printing authors 237 std::vector<Alias> vec_alias; 238 back_insert_iterator<std::vector<Alias> > ii(vec_alias); 239 std::copy(i->second.begin(), i->second.end(), ii); 240 // sort with respect to id 241 std::sort(vec_alias.begin(), vec_alias.end(), IdCompare()); 242 for (std::vector<Alias>::iterator a=vec_alias.begin(); 243 a!=vec_alias.end(); ++a){ 244 if (a!=vec_alias.begin()) 245 tmp << ","; 246 tmp << " " << a->name(); 247 } 248 tmp << "\n"; 249 i = j; 250 } 251 } 252 } 253 } 331 // Copy lines before block 332 for (size_t i=1; i<start_at_line; ++i){ 333 assert(is.good()); 334 getline(is, line); 335 tmp << line << "\n"; 336 } 337 // Printing copyright statement 338 tmp << new_block; 339 // Ignore old block lines 340 for (size_t i=start_at_line; i<end_at_line; ++i){ 341 assert(is.good()); 342 getline(is, line); 343 } 344 // Copy lines after block 345 while(getline(is, line)) 346 tmp << line << "\n"; 347 254 348 is.close(); 255 349 tmp.close(); 256 350 close(fd); 351 // get file permission 257 352 struct stat nodestat; 258 353 stat(path().c_str(),&nodestat); … … 264 359 265 360 266 void File::print_core(const bool verbose) const267 {268 }269 270 271 void File::print_core(const std::string& user, const std::string& line_type,272 const SVNlog& log) const273 {274 std::string outpath = user+"/"+line_type+"/"+local_path();275 std::string imagefile = "images/"+line_type+"/"+local_path_+".png";276 std::string html_name(outpath + ".html");277 std::ofstream os(html_name.c_str());278 print_header(os, name(), level_+2, user, line_type, local_path()+".html");279 path_anchor(os);280 281 os << "<p class=\"plot\">\n<img src='";282 for (size_t i=0; i<level_; ++i)283 os << "../";284 os << "../../";285 if (user=="all")286 os << stats_.plot(imagefile,line_type);287 else288 os << imagefile;289 os << "' alt='[plot]' />\n</p>";290 291 print_author_summary(os, line_type, log);292 os << "\n";293 294 print_blame(os);295 296 print_footer(os);297 os.close();298 }299 300 361 }} // end of namespace svndigest and namespace theplu -
trunk/lib/File.h
r398 r425 66 66 const Stats& parse(const bool verbose=false); 67 67 68 void print_copyright(std::map<std::string, Alias>& ) const;68 void print_copyright(std::map<std::string, Alias>&, bool verbose) const; 69 69 70 70 private: 71 /// 72 /// @brief Copy Constructor, not implemented 73 /// 74 File(const File&); 71 75 72 76 /// … … 77 81 bool blame(void) const; 78 82 79 /// 80 /// @brief Copy Constructor, not implemented 81 /// 82 File(const File&); 83 /** 84 \return copyright block 85 */ 86 std::string copyright_block(const std::map<int, std::set<Alias> >& map, 87 const std::string& prefix) const; 88 89 /** 90 Create a map from year to set of authors. 91 */ 92 std::map<int, std::set<Alias> > 93 copyright_map(std::map<std::string, Alias>& alias) const; 94 95 /** 96 Create a map from year to set of authors. 97 98 \return true if Copyright block is found 99 */ 100 bool detect_copyright(std::string& block, size_t& start_at_line, 101 size_t& end_at_line, std::string& prefix) const; 83 102 84 103 /** … … 96 115 const SVNlog&) const; 97 116 117 /** 118 Doing the actual print of copyright statement 119 120 \param map containing info on who contributed which year 121 \param start_at_line line number of first line in old block 122 \param end_at_line line number of first line after old block 123 \param prefix string preceeds the 'Copyright (C)...' block 124 */ 125 void update_copyright(const std::string& block, 126 size_t start_at_line, size_t end_at_line) const; 98 127 }; 99 128 -
trunk/lib/Node.h
r380 r425 161 161 void print_author_summary(std::ostream&, std::string, const SVNlog&) const; 162 162 163 virtual void print_copyright(std::map<std::string,Alias>& 163 virtual void print_copyright(std::map<std::string,Alias>&, bool) const=0; 164 164 165 165 /**
Note: See TracChangeset
for help on using the changeset viewer.