Changeset 1376
- Timestamp:
- Jun 14, 2011, 2:02:11 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/CopyrightStats.cc
r1362 r1376 25 25 #include "SVNinfo.h" 26 26 #include "SVNlog.h" 27 #include "utility.h" 28 29 #include <yat/utility/utility.h> 27 30 28 31 #include <subversion-1/svn_types.h> 29 32 30 33 #include <cassert> 34 #include <fstream> 31 35 #include <iostream> 32 36 … … 35 39 36 40 CopyrightStats::CopyrightStats(const std::string& path, bool ignore_cache, 37 std::map<std::string, Alias>& author2alias,38 41 const std::map<int, svn_revnum_t>& year2rev) 39 : author2alias_(author2alias), path_(path) 40 { 42 : path_(path) 43 { 44 cache_file_ = concatenate_path(concatenate_path(directory_name(path), 45 ".svndigest"), 46 file_name(path)+".svncopyright-cache"); 41 47 init(ignore_cache, year2rev); 42 48 } … … 48 54 svn_revnum_t cache_rev = 0; 49 55 if (!ignore_cache) 50 cache_rev = load_cache( "");56 cache_rev = load_cache(); 51 57 SVNinfo info(path_); 52 58 if (cache_rev >= info.last_changed_rev()) … … 58 64 59 65 parse(cache_rev+1, year2rev); 60 write_cache(""); 61 } 62 63 64 svn_revnum_t CopyrightStats::load_cache(const std::string& filename) 65 { 66 // FIXME 66 write_cache(); 67 } 68 69 70 svn_revnum_t CopyrightStats::load_cache(void) 71 { 72 std::ifstream is(cache_file_.c_str()); 73 assert(is.good()); 74 75 std::string line; 76 getline(is, line); 77 if (line!="SVNCOPYRIGHT CACHE VERSION 1") 78 return 0; 79 getline(is, line); 80 if (line!=config_) { 81 std::cout << "cache file is for different configuration.\n" 82 << "config code: '" << config_ << "'\n" 83 << "config code in cache file: '" << line << "'\n" 84 << "retrieving statistics from repository.\n"; 85 return 0; 86 } 87 88 svn_revnum_t rev = 0; 89 try { 90 getline(is, line); 91 size_t nof_years = yat::utility::convert<size_t>(line); 92 for (size_t i=0; i<nof_years; ++i) { 93 getline(is, line); 94 int year = yat::utility::convert<size_t>(line); 95 std::set<std::string>& users = year2user_[year]; 96 getline(is, line); 97 size_t nof_users = yat::utility::convert<size_t>(line); 98 for (size_t i=0; i<nof_users; ++i) { 99 getline(is, line); 100 users.insert(line); 101 } 102 } 103 getline(is, line); 104 rev = yat::utility::convert<svn_revnum_t>(line); 105 getline(is, line); 106 if (line!="SVNCOPYRIGHT CACHE") 107 return 0; 108 return rev; 109 } 110 catch (yat::utility::runtime_error e) { 111 return 0; 112 } 67 113 return 0; 68 114 } 69 115 70 116 71 const std::map<int, std::set< Alias> >CopyrightStats::map(void) const72 { 73 return year2 alias_;117 const std::map<int, std::set<std::string> >& CopyrightStats::map(void) const 118 { 119 return year2user_; 74 120 } 75 121 … … 97 143 98 144 const std::string& name = commit->author(); 99 // find username in map of aliases100 std::map<std::string, Alias>::iterator alias =101 author2alias_.lower_bound(name);102 103 // if alias not found for author104 if (alias == author2alias_.end() || alias->first!=name) {105 std::cerr << "svncopyright: warning: no copyright alias found for `"106 << name << "'\n";107 // insert alias to avoid multiple warnings.108 Alias a(name, author2alias_.size());109 // FIXME use insert with hint110 author2alias_[name] = a;111 alias = author2alias_.find(name);112 }113 assert(alias!=author2alias_.end());114 115 145 // skip if alias already has copyright for this year. 116 std::map<int, std::set< Alias> >::const_iterator year_aliases =117 year2 alias_.find(yearrev->first);118 if (year_ aliases!=year2alias_.end()119 && year_ aliases->second.count(alias->second))146 std::map<int, std::set<std::string> >::const_iterator year_users = 147 year2user_.find(yearrev->first); 148 if (year_users!=year2user_.end() 149 && year_users->second.count(name)) 120 150 continue; 121 151 … … 128 158 if ((lt==LineTypeParser::code || lt==LineTypeParser::comment) && 129 159 svn_blame.revision()==commit->revision()) { 130 year2 alias_[yearrev->first].insert(alias->second);160 year2user_[yearrev->first].insert(name); 131 161 break; 132 162 } … … 139 169 void CopyrightStats::reset(void) 140 170 { 141 year2alias_.clear(); 142 } 143 144 145 void CopyrightStats::write_cache(const std::string& filename) 146 { 147 // FIXME 171 year2user_.clear(); 172 } 173 174 175 void CopyrightStats::write_cache(void) 176 { 177 mkdir_p(directory_name(cache_file_)); 178 std::ofstream os(cache_file_.c_str()); 179 assert(os.good()); 180 181 os << "SVNCOPYRIGHT CACHE VERSION 1\n"; 182 os << config_ << "\n"; 183 os << year2user_.size() << "\n"; 184 using std::map; 185 using std::set; 186 using std::string; 187 for (map<int, set<string> >::const_iterator i=year2user_.begin(); 188 i!=year2user_.end(); ++i) { 189 os << i->first << "\n"; 190 os << i->second.size() << "\n"; 191 for (set<string>::const_iterator j=i->second.begin(); 192 j!=i->second.end(); ++j) { 193 os << *j << "\n"; 194 } 195 } 196 197 SVNinfo info(path_); 198 os << info.last_changed_rev() << "\n"; 199 os << "SVNCOPYRIGHT CACHE\n"; 200 os.close(); 148 201 } 149 202 -
trunk/lib/CopyrightStats.h
r1358 r1376 43 43 */ 44 44 CopyrightStats(const std::string& path, bool ignore_cache, 45 std::map<std::string, Alias>& author2alias,46 45 const std::map<int, svn_revnum_t>& year2rev); 47 46 48 const std::map<int, std::set< Alias> >map(void) const;47 const std::map<int, std::set<std::string> >& map(void) const; 49 48 private: 50 49 /** … … 55 54 56 55 /// return 0 if load failed; otherwise return rev cache represents 57 svn_revnum_t load_cache( const std::string& filename);56 svn_revnum_t load_cache(void); 58 57 59 58 void parse(svn_revnum_t rev, const std::map<int, svn_revnum_t>& year2rev); 60 59 void reset(void); 61 void write_cache( const std::string& filename);60 void write_cache(void); 62 61 63 std::map<std::string, Alias>& author2alias_; 62 std::string cache_file_; 63 std::string config_; 64 64 std::string path_; 65 std::map<int, std::set< Alias> > year2alias_;65 std::map<int, std::set<std::string> > year2user_; 66 66 }; 67 67 }} // end of namespace svndigest and namespace theplu -
trunk/lib/CopyrightVisitor.cc
r1358 r1376 75 75 } 76 76 return ss.str(); 77 }78 79 80 void CopyrightVisitor::create_year2alias(std::map<int, std::set<Alias> >& m,81 const File& file)82 {83 using namespace std;84 const Stats& stats = file.stats()["add"];85 86 // loop over all years87 for (std::map<int, svn_revnum_t>::const_iterator rev_iter=year2rev_.begin();88 rev_iter!=year2rev_.end(); ++rev_iter) {89 90 svn_revnum_t last_rev_this_year = rev_iter->second;91 svn_revnum_t last_rev_last_year = 0;92 if (rev_iter != year2rev_.begin()) {93 last_rev_last_year = (--rev_iter)->second;94 ++rev_iter;95 }96 // do not go beyond BASE rev of file97 last_rev_this_year = std::min(last_rev_this_year,file.last_changed_rev());98 last_rev_last_year = std::min(last_rev_last_year,file.last_changed_rev());99 // loop over authors100 for (std::set<std::string>::const_iterator a_iter=stats.authors().begin();101 a_iter!=stats.authors().end(); ++a_iter) {102 103 // check if anything has been added since last year104 if ( (stats(LineTypeParser::code, *a_iter, last_rev_this_year) >105 stats(LineTypeParser::code, *a_iter, last_rev_last_year)) ||106 (stats(LineTypeParser::comment, *a_iter, last_rev_this_year) >107 stats(LineTypeParser::comment, *a_iter, last_rev_last_year)) ) {108 109 110 // find username in map of aliases111 std::map<string,Alias>::iterator name(alias_.lower_bound(*a_iter));112 113 // if alias exist insert alias114 if (name != alias_.end() && name->first==*a_iter)115 m[rev_iter->first].insert(name->second);116 else {117 // else insert user name118 Alias a(*a_iter,alias_.size());119 m[rev_iter->first].insert(a);120 std::cerr << "svncopyright: warning: no copyright alias found for `"121 << *a_iter << "'\n";122 // insert alias to avoid multiple warnings.123 alias_.insert(name, std::make_pair(*a_iter, a));124 }125 }126 }127 }128 77 } 129 78 … … 178 127 if (verbose_) 179 128 std::cout << "Parsing '" << file.path() << "'\n"; 180 CopyrightStats stats(file.path(), ignore_cache_, alias_, year2rev_); 181 const std::map<int, std::set<Alias> >& map = stats.map(); 182 assert(!map.empty()); 183 std::string new_block = copyright_block(map, prefix); 129 CopyrightStats stats(file.path(), ignore_cache_, year2rev_); 130 const std::map<int, std::set<std::string> >& year2users = stats.map(); 131 assert(!year2users.empty()); 132 std::map<int, std::set<Alias> > year2alias; 133 translate(year2users, year2alias); 134 std::string new_block = copyright_block(year2alias, prefix); 184 135 if (old_block==new_block) 185 136 return; … … 231 182 } 232 183 184 233 185 void CopyrightVisitor::visit(File& file) 234 186 { … … 242 194 } 243 195 196 197 void CopyrightVisitor::translate(const std::set<std::string>& users, 198 std::set<Alias>& aliases) 199 { 200 for (std::set<std::string>::const_iterator user=users.begin(); 201 user!=users.end(); ++user) { 202 std::map<std::string, Alias>::const_iterator i = alias_.find(*user); 203 // if alias not found for author 204 if (i==alias_.end()) { 205 std::cerr << "svncopyright: warning: no copyright alias found for `" 206 << *user << "'\n"; 207 // insert alias to avoid multiple warnings. 208 Alias a(*user, alias_.size()); 209 alias_[*user] = a; 210 } 211 else { 212 // FIXME: perhaps use hint 213 aliases.insert(i->second); 214 } 215 } 216 } 217 218 219 void 220 CopyrightVisitor::translate(const std::map<int, std::set<std::string> >& y2u, 221 std::map<int, std::set<Alias> >& y2a) 222 { 223 using std::map; 224 using std::set; 225 using std::string; 226 for (map<int, set<string> >::const_iterator yu=y2u.begin(); 227 yu!=y2u.end();++yu) { 228 set<Alias>& alias = y2a[yu->first]; 229 translate(yu->second, alias); 230 } 231 } 232 244 233 }} // end of namespace svndigest and namespace theplu -
trunk/lib/CopyrightVisitor.h
r1239 r1376 31 31 #include <set> 32 32 #include <string> 33 #include <vector> 33 34 34 35 namespace theplu{ … … 78 79 const std::string& prefix) const; 79 80 80 /**81 Create a map from year to set of authors.82 */83 void create_year2alias(std::map<int, std::set<Alias> >&, const File& file);84 81 85 82 /** 86 Look f romcopyright block in file \a path.83 Look for copyright block in file \a path. 87 84 88 85 \param path file to look for copyright … … 113 110 void update_copyright(const std::string& path, const std::string& block, 114 111 size_t start_at_line, size_t end_at_line) const; 112 113 114 /** 115 Translating a set of users to a set of aliases using mapping in alias_ 116 */ 117 void translate(const std::set<std::string>&, std::set<Alias>&); 118 119 /** 120 Translating each year 121 */ 122 void translate(const std::map<int, std::set<std::string> >& year2user, 123 std::map<int, std::set<Alias> >& year2alias); 124 125 115 126 }; 116 127 }} // end of namespace svndigest and namespace theplu -
trunk/test/Makefile.am
r1373 r1376 58 58 59 59 # tests not yet passing are listed here 60 XFAIL_TESTS = copyright_cache_test.sh60 XFAIL_TESTS = 61 61 62 62 noinst_HEADERS = Suite.h -
trunk/test/copyright_cache_test.sh
r1364 r1376 56 56 # modify the cache file to allow us to detect that it is used 57 57 sed -i 's/peter/winston/' $cache_file 58 cat $cache_file 58 59 # create a config reflecting this name change 59 60 sed 's/peter/winston/' config > config2 … … 66 67 diff -u correct.txt copyright.txt || exit_fail 67 68 68 diff -u cache.txt $cache_file || exit_fail69 70 69 exit_success; -
trunk/yat/Makefile.am
r1152 r1376 3 3 ## $Id$ 4 4 5 # Copyright (C) 2009, 2010 Peter Johansson5 # Copyright (C) 2009, 2010, 2011 Peter Johansson 6 6 # 7 7 # This file is part of svndigest, http://dev.thep.lu.se/svndigest … … 43 43 libyat_a_SOURCES += ColumnStream.cc 44 44 libyat_a_SOURCES += CommandLine.cc 45 libyat_a_SOURCES += dummie.cc 45 46 libyat_a_SOURCES += Exception.cc 46 47 libyat_a_SOURCES += Option.cc
Note: See TracChangeset
for help on using the changeset viewer.