Changeset 1290 for trunk/lib/File.cc


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 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/File.cc

    r1288 r1290  
    2727#include "Configuration.h"
    2828#include "Date.h"
    29 #include "Graph.h"
    3029#include "html_utility.h"
    3130#include "HtmlStream.h"
     
    6261
    6362
    64   std::string File::blame_output_file_name(void) const
    65   {
    66     return "blame_output/" + local_path() + ".html";
    67   }
    68 
    69 
    7063  std::string File::href(void) const
    7164  {
     
    8881  {
    8982    return std::string("file");
    90   }
    91 
    92 
    93   std::string File::output_path(void) const
    94   {
    95     return output_dir()+name()+".html";
    9683  }
    9784
     
    126113
    127114
    128   void File::print_blame(std::ofstream& os) const
    129   {
    130     os << "<br /><h3>" << local_path() << "</h3>";
    131     os << "<div class=\"blame_legend\">\n";
    132     os << "<dl>\n";
    133     os << "<dt class=\"code\"></dt><dd>Code</dd>\n";
    134     os << "<dt class=\"comment\"></dt><dd>Comments</dd>\n";
    135     os << "<dt class=\"other\"></dt><dd>Other</dd>\n";
    136     os << "</dl>\n</div>\n";
    137     os << "<table class=\"blame\">\n";
    138     os << "<thead>\n";
    139     os << "<tr>\n";
    140     os << "<th class=\"rev\">Rev</th>\n";
    141     os << "<th class=\"date\">Date</th>\n";
    142     os << "<th class=\"author\">Author</th>\n";
    143     os << "<th class=\"line\">Line</th>\n";
    144     os << "<th></th>\n";
    145     os << "</tr>\n</thead>\n";
    146     os << "<tbody>\n";
    147     HtmlStream hs(os);
    148     SVNblame blame(path_);
    149     LineTypeParser parser(path_);
    150     while (blame.valid()) {
    151       parser.parse(blame.line());
    152       blame.next_line();
    153     }
    154     blame.reset();
    155 
    156     std::vector<LineTypeParser::line_type>::const_iterator
    157       line_type(parser.type().begin());
    158     int last=0;
    159     int first=0;
    160     bool using_dates=true;
    161     if (!Graph::date_xticks()) {
    162       using_dates=false;
    163       first = Graph::rev_min();
    164       last = Graph::rev_max();
    165     }
    166     else {
    167       first = Graph::xticks()[Graph::rev_min()];
    168       assert(Graph::rev_max()<Graph::xticks().size());
    169       last = Graph::xticks()[Graph::rev_max()];
    170     }
    171     assert(last>first);
    172     // color is calculated linearly on time, c = kt + m
    173     // brightest color (for oldest rev in log) is set to 192.
    174     double k = 192.0/(first-last);
    175     double m = -last*k;
    176     while (blame.valid()) {
    177       std::string color;
    178       Date date(blame.date());
    179       if (using_dates)
    180         color = hex(static_cast<int>(k*date.seconds()+m),2);
    181       else
    182         color = hex(static_cast<int>(k*blame.revision()+m),2);
    183       os << "<tr>\n<td class=\"rev\">";
    184       std::stringstream color_ss;
    185       color_ss << "#" << color << color << color;
    186       os << "<font color=\"" << color_ss.str() << "\">"
    187          << trac_revision(blame.revision(), color_ss.str())
    188          << "</font></td>\n<td class=\"date\"><font color=\"#" << color
    189          << color << color << "\">" ;
    190       hs << date("%d %b %y");
    191       os << "</font></td>\n<td class=\"author\">";
    192       const std::string& author_color =
    193         Colors::instance().color_str(blame.author());
    194       assert(!author_color.empty());
    195       os << "<font color=\"#" << author_color << "\">";
    196       hs << blame.author();
    197       os << "</td>\n<td class=\"";
    198       assert(line_type!=parser.type().end());
    199       if (*line_type==LineTypeParser::other)
    200         os << "line-other";
    201       else if (*line_type==LineTypeParser::comment ||
    202                *line_type==LineTypeParser::copyright)       
    203         os << "line-comment";
    204       else if (*line_type==LineTypeParser::code)
    205         os << "line-code";
    206       else {
    207         std::string msg="File::print_blame(): unexpected line type found";
    208         throw std::runtime_error(msg);
    209       }
    210       os << "\">" << blame.line_no()+1
    211          << "</td>\n<td>";
    212       hs << blame.line();
    213       os << "</td>\n</tr>\n";
    214       blame.next_line();
    215       ++line_type;
    216     }
    217     os << "</tbody>\n";
    218     os << "</table>\n";
    219   }
    220 
    221 
    222   void File::print_core(const bool verbose) const
    223   {
    224     if (!Configuration::instance().output_blame_information())
    225       return;
    226     mkdir_p(directory_name(blame_output_file_name()));
    227     std::ofstream os(blame_output_file_name().c_str());
    228     assert(os.good());
    229     print_html_start(os, "svndigest", level_+1);
    230     print_blame(os);
    231     print_footer(os);
    232     os.close();
    233   }
    234 
    235 
    236   void File::print_core(const std::string& stats_type,
    237                         const std::string& user, const std::string& line_type,
    238                         const SVNlog& log) const
    239   {
    240     std::string lpath = local_path();
    241     if (lpath.empty())
    242       lpath = "index";
    243     std::string outpath = stats_type+"/"+user+"/"+line_type+"/"+lpath;
    244     std::string imagefile = stats_type+"/"+"images/"+line_type+"/"+lpath;
    245     std::string html_name(outpath + ".html");
    246     mkdir_p(directory_name(html_name));
    247     mkdir_p(directory_name(imagefile));
    248     std::ofstream os(html_name.c_str());
    249     assert(os);
    250     print_header(os, name(), level_+3, user, line_type, lpath+".html",
    251                  stats_type);
    252     path_anchor(os);
    253 
    254     std::stringstream ss;
    255     for (size_t i=0; i<level_; ++i)
    256       ss << "../";
    257     ss << "../../../";
    258     if (user=="all")
    259       ss << stats_[stats_type].plot(imagefile,line_type);
    260     else
    261       ss << imagefile;
    262     os << "<p class=\"plot\">\n";
    263     os << image(ss.str());
    264     os << "</p>\n";
    265 
    266     print_author_summary(os, stats_[stats_type], line_type, log);
    267     os << "\n";
    268     if (Configuration::instance().output_blame_information())
    269       os << "<h3>"
    270          << anchor(blame_output_file_name(), "Blame Information", level_+3)
    271          << "</h3>\n";
    272 
    273     print_footer(os);
    274     os.close();
    275   }
    276 
    277 
    278115  void File::traverse(NodeVisitor& visitor)
    279116  {
Note: See TracChangeset for help on using the changeset viewer.