Ignore:
Timestamp:
Jun 14, 2011, 2:02:11 AM (11 years ago)
Author:
Peter Johansson
Message:

closes #385. implementing cache for svncopyright

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/CopyrightVisitor.cc

    r1358 r1376  
    7575    }
    7676    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 years
    87     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 file
    97       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 authors
    100       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 year
    104         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 aliases
    111           std::map<string,Alias>::iterator name(alias_.lower_bound(*a_iter));
    112          
    113           // if alias exist insert alias
    114           if (name != alias_.end() && name->first==*a_iter)
    115             m[rev_iter->first].insert(name->second);
    116           else {
    117             // else insert user name
    118             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     }
    12877  }
    12978
     
    178127    if (verbose_)
    179128      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);
    184135    if (old_block==new_block)
    185136      return;
     
    231182  }
    232183
     184
    233185  void CopyrightVisitor::visit(File& file)
    234186  {
     
    242194  }
    243195
     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     
    244233}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.