Ignore:
Timestamp:
Nov 12, 2010, 5:01:35 AM (11 years ago)
Author:
Peter Johansson
Message:

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/FilePrinter.cc

    r1289 r1290  
    2020  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
    2121*/
     22
     23#include "FilePrinter.h"
    2224
    2325#include "File.h"
     
    3234#include "NodeVisitor.h"
    3335#include "Stats.h"
     36#include "StatsPlotter.h"
    3437#include "SVNblame.h"
    3538#include "SVNlog.h"
     
    5154namespace svndigest{
    5255
    53 
    54   File::File(const unsigned int level, const std::string& path,
    55              const std::string& output)
    56     : Node(level,path,output)
    57   {
    58     output_dir_=output;
    59     if (!output_dir_.empty())
    60       output_dir_+='/';
    61   }
    62 
    63 
    64   std::string File::blame_output_file_name(void) const
    65   {
    66     return "blame_output/" + local_path() + ".html";
    67   }
    68 
    69 
    70   std::string File::href(void) const
    71   {
    72     return name()+".html";
    73   }
    74 
    75 
    76   svn_revnum_t File::last_changed_rev(void) const
    77   {
    78     return svn_info().last_changed_rev();
    79   }
    80 
    81 
    82   void File::log_core(SVNlog&) const
    83   {
    84   }
    85 
    86 
    87   std::string File::node_type(void) const
    88   {
    89     return std::string("file");
    90   }
    91 
    92 
    93   std::string File::output_path(void) const
    94   {
    95     return output_dir()+name()+".html";
    96   }
    97 
    98 
    99   const StatsCollection& File::parse(bool verbose, bool ignore)
    100   {
    101     if (verbose)
    102       std::cout << "Parsing '" << path_ << "'" << std::endl;
    103     stats_.reset();
    104     std::string cache_dir = directory_name(path()) + std::string(".svndigest/");
    105     std::string cache_file = cache_dir + name()+std::string(".svndigest-cache");
    106     if (!ignore && node_exist(cache_file)){
    107       std::ifstream is(cache_file.c_str());
    108       if (stats_.load_cache(is)) {
    109         is.close();
    110         return stats_;
    111       }
    112       is.close();
    113     }
    114     else
    115       stats_.parse(path_);
    116     if (!node_exist(cache_dir))
    117       mkdir(cache_dir);
    118     std::string tmp_cache_file(cache_file+"~");
    119     std::ofstream os(tmp_cache_file.c_str());
    120     assert(os);
    121     stats_.print(os);
    122     os.close();
    123     rename(tmp_cache_file, cache_file);
    124     return stats_;
    125   }
    126 
    127 
    128   void File::print_blame(std::ofstream& os) const
    129   {
    130     os << "<br /><h3>" << local_path() << "</h3>";
     56  FilePrinter::FilePrinter(const File& file)
     57    : NodePrinter(), file_(file)
     58  {
     59  }
     60
     61
     62  std::string FilePrinter::blame_output_file_name(void) const
     63  {
     64    return "blame_output/" + node().local_path() + ".html";
     65  }
     66
     67
     68  const Node& FilePrinter::node(void) const
     69  {
     70    return file_;
     71  }
     72
     73
     74  std::string FilePrinter::output_path(void) const
     75  {
     76    return output_dir()+node().name()+".html";
     77  }
     78
     79
     80  void FilePrinter::print_blame(std::ofstream& os) const
     81  {
     82    os << "<br /><h3>" << node().local_path() << "</h3>";
    13183    os << "<div class=\"blame_legend\">\n";
    13284    os << "<dl>\n";
     
    14698    os << "<tbody>\n";
    14799    HtmlStream hs(os);
    148     SVNblame blame(path_);
    149     LineTypeParser parser(path_);
     100    SVNblame blame(node().path_);
     101    LineTypeParser parser(node().path_);
    150102    while (blame.valid()) {
    151103      parser.parse(blame.line());
     
    205157        os << "line-code";
    206158      else {
    207         std::string msg="File::print_blame(): unexpected line type found";
     159        std::string msg="FilePrinter::print_blame(): unexpected line type found";
    208160        throw std::runtime_error(msg);
    209161      }
     
    220172
    221173
    222   void File::print_core(const bool verbose) const
     174  void FilePrinter::print_core(const bool verbose) const
    223175  {
    224176    if (!Configuration::instance().output_blame_information())
     
    227179    std::ofstream os(blame_output_file_name().c_str());
    228180    assert(os.good());
    229     print_html_start(os, "svndigest", level_+1);
     181    print_html_start(os, "svndigest", file_.level_+1);
    230182    print_blame(os);
    231183    print_footer(os);
     
    234186
    235187
    236   void File::print_core(const std::string& stats_type,
     188  void FilePrinter::print_core(const std::string& stats_type,
    237189                        const std::string& user, const std::string& line_type,
    238190                        const SVNlog& log) const
    239191  {
    240     std::string lpath = local_path();
     192    std::string lpath = node().local_path();
    241193    if (lpath.empty())
    242194      lpath = "index";
     
    248200    std::ofstream os(html_name.c_str());
    249201    assert(os);
    250     print_header(os, name(), level_+3, user, line_type, lpath+".html",
     202    print_header(os, node().name(), file_.level_+3, user, line_type, lpath+".html",
    251203                 stats_type);
    252204    path_anchor(os);
    253205
    254206    std::stringstream ss;
    255     for (size_t i=0; i<level_; ++i)
     207    for (size_t i=0; i<file_.level_; ++i)
    256208      ss << "../";
    257209    ss << "../../../";
    258210    if (user=="all")
    259       ss << stats_[stats_type].plot(imagefile,line_type);
     211      ss << StatsPlotter(file_.stats_[stats_type]).plot(imagefile,line_type);
    260212    else
    261213      ss << imagefile;
     
    264216    os << "</p>\n";
    265217
    266     print_author_summary(os, stats_[stats_type], line_type, log);
     218    print_author_summary(os, file_.stats_[stats_type], line_type, log);
    267219    os << "\n";
    268220    if (Configuration::instance().output_blame_information())
    269221      os << "<h3>"
    270          << anchor(blame_output_file_name(), "Blame Information", level_+3)
     222         << anchor(blame_output_file_name(), "Blame Information", file_.level_+3)
    271223         << "</h3>\n";
    272224
     
    276228
    277229
    278   void File::traverse(NodeVisitor& visitor)
    279   {
    280     visitor.visit(*this);
    281   }
    282 
    283230}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.