Changeset 537 for trunk/lib


Ignore:
Timestamp:
Dec 27, 2007, 7:37:39 AM (16 years ago)
Author:
Peter Johansson
Message:

Blame stats is implemented - fixes #24

Location:
trunk/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/BlameStats.cc

    r536 r537  
    2929#include "SVNblame.h"
    3030#include "SVNinfo.h"
     31#include "SVNlog.h"
    3132#include "utility.h"
    3233
     
    6263
    6364
     65  void BlameStats::fill_in(Author2Vector& a2v, svn_revnum_t rev)
     66  {
     67    assert(rev);
     68    for (std::set<std::string>::const_iterator iter(authors().begin());
     69         iter!=authors().end(); ++iter) {
     70      std::vector<u_int>& vec = a2v[*iter];
     71      vec.resize(revision()+1);
     72      assert(rev<static_cast<svn_revnum_t>(vec.size()));
     73      vec[rev]=vec[rev-1];
     74    }
     75  }
     76
     77
    6478  void BlameStats::do_parse(const std::string& path)
    6579  {
    6680    Parser parser(path);
    67     SVNblame svn_blame(path);
    68     while (svn_blame.valid()) {
    69       add(svn_blame.author(), svn_blame.revision(),
    70           parser.parse(svn_blame.line()));
    71       svn_blame.next_line();
     81    SVNlog log(path);
     82    typedef std::set<svn_revnum_t> RevSet;
     83    RevSet revs;
     84    std::copy(log.revision().begin(), log.revision().end(),
     85              std::inserter(revs, revs.begin()));
     86    for (RevSet::iterator rev_iter=revs.begin();rev_iter!=revs.end();++rev_iter){
     87      SVNblame svn_blame(path, *rev_iter);
     88      while (svn_blame.valid()) {
     89        add(svn_blame.author(), *rev_iter, parser.parse(svn_blame.line()));
     90        // I dont trust blame and log behave consistent (stop-on-copy).
     91        revs.insert(svn_blame.revision());
     92        svn_blame.next_line();
     93      }
     94    }
     95   
     96    // filling in pristine revisions
     97    RevSet::iterator rev_iter=revs.begin();
     98    for (svn_revnum_t rev = 1; rev<=revision(); ++rev){
     99      if (rev==*rev_iter)
     100        ++rev_iter;
     101      else {
     102        fill_in(code_,rev);
     103        fill_in(comments_,rev);
     104        fill_in(other_,rev);
     105      }
    72106    }
    73107  }
  • trunk/lib/BlameStats.h

    r533 r537  
    4747  private:
    4848    void do_parse(const std::string&);
     49    void fill_in(Author2Vector&, svn_revnum_t rev);
    4950
    5051  };
  • trunk/lib/ClassicStats.cc

    r536 r537  
    7171      svn_blame.next_line();
    7272    }
     73    accumulate_stats();
     74
    7375  }
    7476
  • trunk/lib/Stats.cc

    r534 r537  
    8787      std::vector<u_int>& other = other_[*iter];
    8888      accumulate(other);
    89 
    90       VectorPlus<u_int> vp;
    91       total_[*iter] = vp(vp(code, comments),other);
    92     }
    93     std::vector<u_int> init(revision()+1);
    94     code_["all"]=std::accumulate(code_.begin(), code_.end(), init,
    95                                  PairValuePlus<std::string,u_int>());
    96     comments_["all"]=std::accumulate(comments_.begin(), comments_.end(), init,
    97                                      PairValuePlus<std::string,u_int>());
    98     other_["all"]=std::accumulate(other_.begin(), other_.end(), init,
    99                                   PairValuePlus<std::string,u_int>());
    100     VectorPlus<u_int> vp;
    101     total_["all"] = vp(vp(code_["all"], comments_["all"]), other_["all"]);
     89    }
    10290  }
    10391
     
    10896    assert(user.size());
    10997    add_author(user);
    110 
    111     std::vector<u_int>& total = total_[user];
    112     if (total.size() < rev+1){
    113       total.reserve(revision() + 1);
    114       total.insert(total.end(), rev - total.size(), 0);
    115       total.push_back(n);
    116     }
    117     else
    118       total[rev]+=n;
    11998
    12099    std::vector<u_int>& code = code_[user];
     
    172151  {
    173152    return authors_;
     153  }
     154
     155
     156  void Stats::calc_all(void)
     157  {
     158    std::vector<u_int> init(revision()+1);
     159    code_["all"]=std::accumulate(code_.begin(), code_.end(), init,
     160                                 PairValuePlus<std::string,u_int>());
     161    comments_["all"]=std::accumulate(comments_.begin(), comments_.end(), init,
     162                                     PairValuePlus<std::string,u_int>());
     163    other_["all"]=std::accumulate(other_.begin(), other_.end(), init,
     164                                  PairValuePlus<std::string,u_int>());
     165    VectorPlus<u_int> vp;
     166    total_["all"] = vp(vp(code_["all"], comments_["all"]), other_["all"]);
     167  }
     168
     169
     170  void Stats::calc_total(void)
     171  {
     172    for (std::set<std::string>::const_iterator iter(authors().begin());
     173         iter!=authors().end(); ++iter) {
     174      std::vector<u_int>& code = code_[*iter];
     175      std::vector<u_int>& comments = comments_[*iter];
     176      std::vector<u_int>& other = other_[*iter];
     177
     178      VectorPlus<u_int> vp;
     179      total_[*iter] = vp(vp(code, comments),other);
     180    }
     181
    174182  }
    175183
     
    323331  {
    324332    do_parse(path);
    325     accumulate_stats();
     333    calc_total();
     334    calc_all();
    326335  }
    327336
  • trunk/lib/Stats.h

    r532 r537  
    143143    typedef Author2Vector::const_iterator A2VConstIter;
    144144
     145    void accumulate_stats(void);
    145146    void add_author(std::string);
    146147    void add_authors(std::set<std::string>::const_iterator,
     
    169170  private:
    170171    void accumulate(std::vector<u_int>& vec) const;
    171     void accumulate_stats(void);
    172172    virtual void do_parse(const std::string&)=0;
    173173   
     
    175175    // that all old cache files are obsolete.
    176176    inline std::string end_of_cache(void) const
    177     {return "END OF OK CACHE FILE VERSION 300";}
     177    {return "END OF OK CACHE FILE VERSION 4";}
    178178    inline std::string code_cache(void) const {return "CACHE CODE";}
    179179    inline std::string comments_cache(void) const {return "CACHE COMMENTS";}
     
    183183   
    184184
     185    void calc_all(void);
     186    void calc_total(void);
    185187    u_int get_back(const Author2Vector&, std::string user) const;
    186188    void load(std::istream& is, Author2Vector& m);
Note: See TracChangeset for help on using the changeset viewer.