Changeset 1234 for trunk


Ignore:
Timestamp:
Oct 23, 2010, 6:41:33 PM (11 years ago)
Author:
Peter Johansson
Message:

refs #476. Merged visitor branch into trunk. Used 'svn merge /branches/visitor' because --reintegrate did (currently) not work on our repo. Since I could not merge as suggested in subversion manual, I reverted all mergeinfo properties to avoid future confusion by svn-client. This means (I think) that there will be no connection about this commit and the visitor branch, but to svn-client this will look like a large changeset (just like a merge in the old days).

Location:
trunk
Files:
13 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/bin/svncopyright.cc

    r1119 r1234  
    6767    Directory tree(0,option.root(),"");
    6868
    69     if (option.verbose())
    70       std::cout << "Parsing directory tree" << std::endl;
    71     tree.parse(option.verbose(), option.ignore_cache());
    72     update_copyright(tree, option.verbose());
     69    update_copyright(tree, option.verbose(), option.ignore_cache());
    7370  }
    7471  catch (std::runtime_error& e) {
  • trunk/bin/svndigest.cc

    r1197 r1234  
    3434#include "lib/StatsCollection.h"
    3535#include "lib/SVN.h"
     36#include "lib/SvndigestVisitor.h"
    3637#include "lib/SVNinfo.h"
    3738#include "lib/SVNlog.h"
     
    5859                        const theplu::svndigest::Stats& stats);
    5960
    60 void write_report(const svndigestParameter& option, const std::string& repo,
    61                   const Node& tree, const StatsCollection& stats);
     61void prepare_report(const svndigestParameter& option, const std::string& repo,
     62                    const Node& tree);
    6263
    6364int main( int argc, char* argv[])
     
    113114    Directory tree(0,option.root(),"");
    114115
     116    if (option.report())
     117      prepare_report(option, repo, tree);
     118
    115119    if (option.verbose())
    116120      std::cout << "Parsing directory tree" << std::endl;
    117     const StatsCollection& stats(tree.parse(option.verbose(),
    118                                             option.ignore_cache()));
     121
     122    SvndigestVisitor visitor(option.verbose(), option.ignore_cache(),
     123                             option.report());
     124    tree.traverse(visitor);
     125    //    const StatsCollection& stats(tree.parse(option.verbose(),
     126    //                                      option.ignore_cache()));
    119127
    120128    if (option.report())
    121       write_report(option, repo, tree, stats);
    122 
    123     if (option.copyright()){
    124       update_copyright(tree, option.verbose());
    125     }
     129      print_main_page(tree.name(), tree.log(), tree.stats(), tree.url());
     130
    126131  }
    127132  catch (std::runtime_error& e) {
     
    211216}
    212217
    213 void write_report(const svndigestParameter& option, const std::string& repo,
    214                   const Node& tree, const StatsCollection& stats)
     218void prepare_report(const svndigestParameter& option, const std::string& repo,
     219                    const Node& tree)
    215220{
    216221  std::string target_path = concatenate_path(option.targetdir(),
     
    232237  chdir(tree.name());
    233238  print_css("svndigest.css");
    234   print_main_page(tree.name(), tree.log(), stats, tree.url());
    235239  // create structure StatsType/Author/LineType
     240  /*
    236241  for (std::map<std::string, Stats*>::const_iterator i(stats.stats().begin());
    237242       i!=stats.stats().end(); ++i)
    238243    create_file_struct(i->first+std::string("/"), *i->second);
    239   tree.print(option.verbose());
    240 }
     244  */
     245}
  • trunk/bin/svndigestParameter.cc

    r1220 r1234  
    5656      anchor_format_(cmd_,"anchor-format",
    5757                     "override anchor image format defined in config file"),
    58       copyright_(cmd_, "copyright", "update copyright statement [deprecated]"),
    5958      force_(cmd_, "f,force",
    6059             std::string("if sub-directory named <ROOT> exists in target dire")+
     
    109108        chdir(save_wd);
    110109      }
    111       if (copyright()) {
    112         std::cerr << "svndigest: WARNING: option `--copyright' is deprecated; "
    113                   << "use svncopyright instaed.\n";
    114       }
    115110    }
    116   }
    117 
    118 
    119   bool svndigestParameter::copyright(void) const
    120   {
    121     return copyright_.present();
    122111  }
    123112
  • trunk/bin/svndigestParameter.h

    r1121 r1234  
    5151    const yat::utility::OptionArg<std::string>& anchor_format(void) const;
    5252   
    53     bool copyright(void) const;
    5453    bool force(void) const;
    5554    const yat::utility::OptionArg<std::string>& format(void) const;
     
    6564
    6665    yat::utility::OptionArg<std::string> anchor_format_;
    67     yat::utility::OptionSwitch copyright_;
    6866    yat::utility::OptionSwitch force_;
    6967    yat::utility::OptionArg<std::string> format_;
  • trunk/lib/Directory.cc

    r1186 r1234  
    2727#include "html_utility.h"
    2828#include "Node.h"
     29#include "NodeVisitor.h"
    2930#include "SVN.h"
    3031#include "SVNlog.h"
     32#include "TinyStats.h"
    3133#include "utility.h"
    3234
     
    99101  }
    100102
     103
     104  void Directory::collect_stats(void)
     105  {
     106    stats_.reset();
     107    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
     108      if (!(*i)->ignore()) {
     109        stats_ += (*i)->stats();
     110        (*i)->stats().reset();
     111      }
     112  }
     113
     114
    101115  bool Directory::dir(void) const
    102116  {
    103117    return true;
    104118  }
     119
    105120
    106121  std::string Directory::href(void) const
     
    139154  {
    140155    stats_.reset();
    141     // Directories themselved give no contribution to statistics.
     156    assert(0 && "we are not using this function, are we?");
     157    /*
    142158    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
    143159      if (!(*i)->ignore())
    144160        stats_ += (*i)->parse(verbose, ignore);
     161    */
    145162    return stats_;
    146163  }
     
    149166  void Directory::print_core(const bool verbose) const
    150167  {
    151     mkdir("blame_output/" + local_path());
     168    //mkdir("blame_output/" + local_path());
    152169    // print daughter nodes
    153     for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
    154       (*i)->print(verbose);
     170    //for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
     171    //  (*i)->print(verbose);
    155172  }
    156173
     
    169186      outdir   += "/"+local_path();
    170187    }
    171     mkdir(outdir);
     188    mkdir_p(outdir);
    172189    if (user=="all")
    173       mkdir(imagedir);
     190      mkdir_p(imagedir);
    174191    std::string html_name = outdir+"/index.html";
    175192    std::ofstream os(html_name.c_str());
     
    278295  }
    279296
     297
     298  void Directory::traverse(NodeVisitor& visitor)
     299  {
     300    visitor.enter(*this);
     301    for (NodeIterator first=daughters_.begin(), end=daughters_.end();
     302         first!=end; ++first)
     303      (*first)->traverse(visitor);
     304    visitor.leave(*this);
     305  }
     306
     307
    280308}} // end of namespace svndigest and namespace theplu
  • trunk/lib/Directory.h

    r978 r1234  
    3333namespace svndigest{
    3434
     35  class NodeVisitor;
     36
    3537  ///
    3638  /// Class taking care of directories.
     
    3941  {
    4042  public:
    41 
    4243    ///
    4344    /// @brief Constructor
     
    5960    ///
    6061    ~Directory(void);
     62
     63    /**
     64       Collect stats from daughter nodes and reset stats in daughter
     65       nodes.
     66     */
     67    void collect_stats(void);
    6168
    6269    ///
     
    96103                         const std::map<int, svn_revnum_t>&) const;
    97104
     105    /**
     106       Calls visitor.enter(*this). If enter returns true, daughter
     107       nodes are traverses. Finally visitor visitor.leave(*this) i called.
     108     */
     109    void traverse(NodeVisitor& visitor);
     110
    98111  private:
    99112    /**
  • trunk/lib/File.cc

    r1220 r1234  
    3030#include "html_utility.h"
    3131#include "HtmlStream.h"
     32#include "NodeVisitor.h"
    3233#include "Stats.h"
    3334#include "SVNblame.h"
    3435#include "SVNlog.h"
     36#include "TinyStats.h"
    3537
    3638#include <algorithm>
     
    223225    std::string tmp_cache_file(cache_file+"~");
    224226    std::ofstream os(tmp_cache_file.c_str());
     227    assert(os);
    225228    stats_.print(os);
    226229    os.close();
     
    350353  void File::print_core(const bool verbose) const
    351354  {
     355    mkdir_p(directory_name(blame_output_file_name()));
    352356    std::ofstream os(blame_output_file_name().c_str());
    353357    assert(os.good());
     
    370374    std::string imagefile = stats_type+"/"+"images/"+line_type+"/"+lpath;
    371375    std::string html_name(outpath + ".html");
     376    mkdir_p(directory_name(html_name));
     377    mkdir_p(directory_name(imagefile));
    372378    std::ofstream os(html_name.c_str());
     379    assert(os);
    373380    print_header(os, name(), level_+3, user, line_type, lpath+".html",
    374381                 stats_type);
     
    398405  }
    399406
     407
     408  void File::traverse(NodeVisitor& visitor)
     409  {
     410    visitor.visit(*this);
     411  }
     412
     413
    400414  void File::update_copyright(const std::string& new_block,
    401415                              size_t start_at_line, size_t end_at_line) const
     
    405419                                           "#" + file_name(path()) + "#");
    406420    std::ofstream tmp(tmpname.c_str());
    407 
     421    assert(tmp);
    408422    using namespace std;
    409423    ifstream is(path().c_str());
  • trunk/lib/File.h

    r978 r1234  
    3131namespace theplu{
    3232namespace svndigest{
     33
     34  class NodeVisitor;
    3335
    3436  class File : public Node
     
    7779    void print_copyright(std::map<std::string, Alias>&, bool verbose,
    7880                         const std::map<int, svn_revnum_t>&) const;
     81
     82    /**
     83       Let the visitor perform its mission via visitor(*this)
     84     */
     85    void traverse(NodeVisitor& visitor);
    7986
    8087  private:
  • trunk/lib/Makefile.am

    r1194 r1234  
    3131
    3232noinst_HEADERS = AddStats.h Alias.h BlameStats.h ClassicStats.h \
    33   Colors.h Commitment.h Configuration.h css.h \
     33  Colors.h Commitment.h Configuration.h CopyrightVisitor.h css.h \
    3434  Date.h Directory.h File.h first_page.h Functor.h \
    3535  Graph.h \
    3636  HtmlBuf.h HtmlStream.h html_utility.h LineTypeParser.h \
    37   main_utility.h Node.h \
     37  main_utility.h Node.h NodeVisitor.h \
    3838  OptionVersion.h rmdirhier.h \
    39   Stats.h StatsCollection.h subversion_info.h SVN.h SVNblame.h  \
    40   SVNdiff.h SVNinfo.h SVNlog.h SVNproperty.h Trac.h utility.h Vector.h
     39  Stats.h StatsCollection.h subversion_info.h \
     40  SvndigestVisitor.h SVN.h SVNblame.h \
     41  SVNdiff.h SVNinfo.h SVNlog.h SVNproperty.h TinyStats.h \
     42  Trac.h utility.h Vector.h
    4143
    4244libsvndigest_a_SOURCES = AddStats.cc Alias.cc BlameStats.cc \
    4345  ClassicStats.cc Colors.cc \
    44   Commitment.cc Configuration.cc \
     46  Commitment.cc Configuration.cc CopyrightVisitor.cc \
    4547  css.cc Date.cc Directory.cc File.cc first_page.cc\
    4648  Functor.cc Graph.cc HtmlBuf.cc HtmlStream.cc \
     
    4850  OptionVersion.cc \
    4951  rmdirhier.cc Stats.cc StatsCollection.cc subversion_info.cc SVN.cc \
    50   SVNblame.cc SVNdiff.cc SVNinfo.cc SVNlog.cc SVNproperty.cc \
     52  SVNblame.cc SVNdiff.cc SvndigestVisitor.cc SVNinfo.cc \
     53  SVNlog.cc SVNproperty.cc TinyStats.cc \
    5154  Trac.cc utility.cc Vector.cc
    5255
  • trunk/lib/Node.cc

    r1220 r1234  
    2727#include "HtmlStream.h"
    2828#include "html_utility.h"
     29#include "LineTypeParser.h"
    2930#include "SVNlog.h"
    3031#include "SVNproperty.h"
     
    9596                           const std::string& user) const
    9697  {
    97     const Stats& stats = stats_[stats_type];
    9898    os << "<tr class=\"" << css_class << "\">\n"
    9999       << "<td class=\"" << node_type() << "\">";
     
    105105      os << name() << " (<i>link</i>)";
    106106    // there is no output for nodes when user has zero contribution
    107     else if (user!="all" && !stats.lines(user))
     107    else if (user!="all" && !tiny_stats_(stats_type,user,LineTypeParser::total))
    108108      os << name();
    109109    else if (!Configuration::instance().output_file() && !this->dir())
     
    112112      os << anchor(href(), name());
    113113    os << "</td>\n";
    114     if (user=="all") {
    115       os << "<td>" << stats.lines() << "</td>\n"
    116          << "<td>" << stats.code() << "</td>\n"
    117          << "<td>" << stats.comments() << "</td>\n"
    118          << "<td>" << stats.empty() << "</td>\n";
    119     }
    120     else {
    121       os << "<td>" << stats.lines(user);
    122       if (stats.lines(user))
    123         os << " (" << percent(stats.lines(user),stats.lines()) << "%)";
    124       os << "</td>\n";
    125       os << "<td>" << stats.code(user);
    126       if (stats.code(user))
    127         os << " (" << percent(stats.code(user),stats.code()) << "%)";
    128       os << "</td>\n";
    129       os << "<td>" << stats.comments(user);
    130       if (stats.comments(user))
    131         os << " (" << percent(stats.comments(user),stats.comments()) << "%)";
    132       os << "</td>\n";
    133       os << "<td>" << stats.empty(user);
    134       if (stats.empty(user))
    135         os << " (" << percent(stats.empty(user),stats.empty()) << "%)";
    136       os << "</td>\n";
    137 
    138     }
    139 
     114
     115    std::cerr << "table row: " << path() << std::endl;
     116
     117    html_tabletd(os, stats_type, user, LineTypeParser::total);
     118    html_tabletd(os, stats_type, user, LineTypeParser::code);
     119    html_tabletd(os, stats_type, user, LineTypeParser::comment);
     120    html_tabletd(os, stats_type, user, LineTypeParser::other);
     121   
    140122    os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n"
    141123       << "<td>" << author() << "</td>\n"
    142124       << "</tr>\n";
     125  }
     126
     127
     128  void Node::html_tabletd(std::ostream& os, const std::string& stats_type,
     129                          const std::string& user,
     130                          LineTypeParser::line_type lt) const
     131  {
     132    os << "<td>" << tiny_stats_(stats_type, user, lt);
     133    if (user!="all" && tiny_stats_(stats_type, user, lt))
     134      os << " (" << percent(tiny_stats_(stats_type, user, lt),
     135                            tiny_stats_(stats_type, "all", lt)) << "%)";
     136    os << "</td>\n";
     137  }
     138 
     139
     140  void Node::init_tiny_stats(void)
     141  {
     142    tiny_stats_.init(stats_);
    143143  }
    144144
     
    221221      }
    222222    }
    223       print_core(verbose);
     223    print_core(verbose);
    224224  }
    225225
     
    327327
    328328
     329  const StatsCollection& Node::stats(void) const
     330  {
     331    return stats_;
     332  }
     333
     334
     335  StatsCollection& Node::stats(void)
     336  {
     337    return stats_;
     338  }
     339
     340
    329341  bool Node::svncopyright_ignore(void) const
    330342  {
  • trunk/lib/Node.h

    r1137 r1234  
    2626
    2727#include "html_utility.h"
     28#include "LineTypeParser.h"
    2829#include "StatsCollection.h"
    2930#include "SVNinfo.h"
    3031#include "SVNlog.h"
     32#include "TinyStats.h"
    3133#include "utility.h"
    3234
     
    4042
    4143  class Alias;
     44  class NodeVisitor;
    4245
    4346  ///
     
    108111    { return binary_ || svndigest_ignore_ || link_; }
    109112
     113    /**
     114       Create the TinyStats based on the stored CollectionStats
     115     */
     116    void init_tiny_stats(void);
     117
    110118    ///
    111119    /// @brief Get the revision number of the latest commit.
     
    183191
    184192    /**
     193       \return true if svncopyright::ignore property was set
     194     */
     195    bool svncopyright_ignore(void) const;
     196
     197    /**
    185198       @brief Check if item used to create this object has been
    186199       assigned property svndigest:ignore.
     
    195208
    196209    /**
     210     */
     211    const StatsCollection& stats(void) const;
     212
     213    StatsCollection& stats(void);
     214
     215    /**
     216       Access point for a NodeVisitor to start traversing Node and its
     217       daughter nodes.
     218     */
     219    virtual void traverse(NodeVisitor& visitor)=0;
     220
     221    /**
    197222       \see SVNinfo::url(void)
    198223    */
     
    200225   
    201226  protected:
    202     /**
    203        \return true if svncopyright::ignore property was set
    204      */
    205     bool svncopyright_ignore(void) const;
    206 
    207227    ///
    208228    /// print path in html format (with anchors) to @a os
     
    217237    static std::string project_;
    218238    StatsCollection stats_;
     239    TinyStats tiny_stats_;
    219240
    220241  private:
     
    223244    ///
    224245    Node(const Node&);
     246
     247    void html_tabletd(std::ostream&, const std::string& stats_type,
     248                      const std::string& user,
     249                      LineTypeParser::line_type lt) const;
    225250
    226251    virtual void log_core(SVNlog&) const=0;
  • trunk/lib/main_utility.cc

    r1102 r1234  
    2323
    2424#include "Configuration.h"
     25#include "CopyrightVisitor.h"
    2526#include "Node.h"
    2627#include "utility.h"
     
    5859
    5960
    60   void update_copyright(const Node& tree, bool verbose)
     61  void update_copyright(Node& tree, bool verbose, bool ignore_cache)
    6162  {
    6263    if (verbose)
     
    6465    const Configuration& config = Configuration::instance();
    6566    std::map<std::string, Alias> alias(config.copyright_alias());
    66     tree.print_copyright(alias, verbose);
     67
     68    // map with last rev for every year
     69    std::map<int, svn_revnum_t> year2rev;
     70    // get log for entire project
     71    SVNlog log(SVNinfo(tree.path()).repos_root_url());
     72    typedef SVNlog::container::const_iterator LogIterator;
     73    for (LogIterator i=log.commits().begin(); i!=log.commits().end(); ++i){
     74      time_t sec = str2time(i->date());
     75      tm* timeinfo = gmtime(&sec);
     76      // ignore commits in repository not present in wc
     77      year2rev[timeinfo->tm_year] = std::min(i->revision(),
     78                                             tree.last_changed_rev());
     79    }
     80
     81    CopyrightVisitor visitor(alias, verbose, year2rev, ignore_cache);
     82    tree.traverse(visitor);
    6783  }
    6884
  • trunk/lib/main_utility.h

    r1102 r1234  
    4646     \brief update copyright statements in \a node
    4747   */
    48   void update_copyright(const Node& node, bool verbose);
     48  void update_copyright(Node& node, bool verbose, bool ignore_cache);
    4949
    5050}} // end of namespace svndigest end of namespace theplu
Note: See TracChangeset for help on using the changeset viewer.