Changeset 112


Ignore:
Timestamp:
Jun 29, 2006, 11:30:54 AM (15 years ago)
Author:
Peter Johansson
Message:

fixes #27 and added some beauty

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svnstat.cc

    r109 r112  
    8686  }
    8787
    88   Directory tree(option->root(),"");
     88  Directory tree(0,option->root(),"");
    8989  tree.parse(option->verbose());
    9090
     
    9797    std::cerr << "svnstat: " << x.what() << std::endl;
    9898  }
     99  std::string css(file_name(option->root())+"/svnstat.css");
     100  std::ofstream os(css.c_str());
     101  print_css(os);
     102  os.close();
    99103
    100104  delete option;
  • trunk/lib/Directory.cc

    r101 r112  
    4343
    4444
    45   Directory::Directory(const std::string& path, const std::string& output)
    46     : Node(path,output)
     45  Directory::Directory(const u_int level, const std::string& path,
     46                       const std::string& output)
     47    : Node(level,path,output)
    4748  {
    4849    using namespace std;
     
    6970          lstat(fullpath.c_str(),&nodestat);   // C api from sys/stat.h
    7071          if (S_ISDIR(nodestat.st_mode))       // C api from sys/stat.h
    71             daughters_.push_back(new Directory(fullpath, output_name()+"/"));
     72            daughters_.push_back(new Directory(level_+1,fullpath,
     73                                               output_name()+"/"));
    7274          else
    73             daughters_.push_back(new File(fullpath,output_name()+"/"));
     75            daughters_.push_back(new File(level_,fullpath,output_name()+"/"));
    7476          break;
    7577        case SVN::unresolved:
     
    8890  }
    8991
     92  std::string Directory::author(void) const
     93  {
     94    std::string a;
     95    u_int max_rev=0;
     96    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); i++)
     97      if ((*i)->last_changed_rev()>max_rev){
     98        max_rev = (*i)->last_changed_rev();
     99        a = (*i)->author();
     100      }
     101    return a;
     102  }
     103
    90104  bool Directory::dir(void) const
    91105  {
     
    96110  {
    97111    return "<a href=\"" + name() + "/index.html\">" + name() + "</a>";
     112  }
     113
     114  u_int Directory::last_changed_rev(void) const
     115  {
     116    u_int max_rev=0;
     117    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); i++)
     118      if ((*i)->last_changed_rev()>max_rev)
     119        max_rev = (*i)->last_changed_rev();
     120    return max_rev;
    98121  }
    99122
     
    120143       << file_name(stats_.plot(output_name()+"/index.png", output_name()))
    121144       << "' alt='[plot]' border=0><br>\n";
    122     os << "<table>\n";
    123     os << "<tr>\n<td><strong>Node</strong></td>\n";
    124     os << "<td><strong>Count</strong></td>\n</tr>\n";
    125     os << "<tr>\n<td bgcolor=#dddddd>Total</td>\n";
    126     os << "<td align=right bgcolor=#dddddd>" << stats_.rows()
    127        << "</td>\n</tr>\n";
     145    os << "<table class=\"listings\">\n";
     146    os << "<thead>";
     147    os << "<tr>\n";
     148    os << "<th>Node</th>\n";
     149    os << "<th>Lines</th>\n";
     150    os << "<th>Code</th>\n";
     151    os << "<th>Comments</th>\n";
     152    os << "<th>Revision</th>\n";
     153    os << "<th>Author</th>\n";
     154    os << "</tr>\n</thead>\n";
     155    os << "<tbody>";
     156
     157    bool dark=false;
     158    if (level_){
     159      os << "<tr class=\"light\">\n";
     160      os << "<td colspan=\"6\"><a href=\"../index.html\">../</a></td>\n";
     161      os << "</tr>\n";
     162      dark=!dark;
     163    }
    128164
    129165    // print html links to daughter nodes
    130     bool dark=true;
    131166    for (NodeConstIterator d = daughters_.begin(); d!=daughters_.end(); d++){
    132167      if (dark)
    133         os << (*d)->html_tablerow("#eeeeee");
     168        os << (*d)->html_tablerow("dark");
    134169      else
    135         os << (*d)->html_tablerow("#dddddd");
     170        os << (*d)->html_tablerow("light");
    136171      dark = !dark;
    137172    }
     173    if (dark)
     174      os << "<tr class=\"dark\">\n";
     175    else
     176      os << "<tr class=\"light\">\n";
     177    os << "<td>Total</td>\n";
     178    os << "<td>" << stats_.rows() << "</td>\n";
     179    os << "<td>---</td>\n";
     180    os << "<td>---</td>\n";
     181    os << "<td>" << stats_.last_changed_rev() << "</td>\n";
     182    os << "<td>" << author() << "</td>\n";
     183    os << "</tr>\n";
    138184    os << "</table>\n";
    139185    os << "</p>\n";
  • trunk/lib/Directory.h

    r101 r112  
    5252    /// traversed.
    5353    ///
    54     Directory(const std::string& path, const std::string& output="");
     54    Directory(const u_int level, const std::string& path,
     55              const std::string& output="");
    5556
    5657    ///
     
    5859    ///
    5960    ~Directory(void);
     61
     62    ///
     63    /// @return author of last commitment.
     64    ///
     65    std::string author(void) const;
    6066
    6167    ///
     
    6975    std::string html_link(void) const;
    7076   
     77    ///
     78    ///
     79    ///
     80    u_int last_changed_rev(void) const;
     81
    7182    const Stats& parse(const bool verbose=false);
    7283
  • trunk/lib/File.h

    r100 r112  
    3838    /// @brief Default Constructor
    3939    ///
    40     File(const std::string& path, const std::string& output="")
    41       : Node(path,output), binary_(false), ignore_(false) {}
     40    File(const u_int level, const std::string& path,
     41         const std::string& output="")
     42      : Node(level,path,output), binary_(false), ignore_(false) {}
     43
     44    ///
     45    ///
     46    ///
     47    std::string author(void) const { return author_; }
    4248
    4349    ///
     
    4551    ///
    4652    std::string html_link(void) const;
     53
     54    ///
     55    ///
     56    ///
     57    u_int last_changed_rev(void) const { return revision_; }
    4758
    4859    ///
     
    7182    File(const File&);
    7283
    73     std::string author_;
     84    std::string author_;
    7485    bool binary_;
    7586    bool ignore_;
  • trunk/lib/Node.cc

    r102 r112  
    3434namespace svnstat{
    3535
    36   Node::Node(const std::string& path, const std::string& output="")
    37       : path_(path), stats_(path)
     36  Node::Node(const u_int level, const std::string& path,
     37             const std::string& output="")
     38    : level_(level), path_(path), stats_(path)
    3839  {
    3940    output_name_ = output+file_name(path_);
     
    4546  }
    4647
    47   std::string Node::html_tablerow(const std::string& color) const
     48  std::string Node::html_tablerow(const std::string& css_class) const
    4849  {
    4950    std::stringstream ss;
    50     ss << "<tr>\n<td bgcolor=" << color << ">" << html_link()
    51        << "</td>\n<td bgcolor=" << color << " align=right>"
    52        << stats_.rows() << "</td>\n</tr>\n";
     51    ss << "<tr class=\"" << css_class << "\">\n"
     52       << "<td" << html_link() << "</td>\n"
     53       << "<td>" << stats_.rows() << "</td>\n"
     54       << "<td>" << "---" << "</td>\n"
     55       << "<td>" << "---" << "</td>\n"
     56       << "<td>" << stats_.last_changed_rev() << "</td>\n"
     57       << "<td>" << author() << "</td>\n"
     58       << "</tr>\n";
    5359    return ss.str();
    5460  }
     
    7884       << "<title> svnstat " << name() << "</title>\n"
    7985       << "</head>\n"
    80        << "<body bgcolor=#ffffff vlink=#000000>\n";
     86       << "<link rel=\"stylesheet\" "
     87       << "href=\"";
     88    for (u_int i=0; i<level_; ++i)
     89      os << "../";
     90    os << "svnstat.css\" type=\"text/css\" />\n";
    8191  }
    8292
  • trunk/lib/Node.h

    r101 r112  
    5353    /// @brief Constructor
    5454    ///
    55     //    Node(void) : path_("JARI_trixar"), stats_("JARI_trixar") { };
    56 
    57     ///
    58     /// @brief Constructor
    59     ///
    60     Node(const std::string&, const std::string&);
     55    Node(const u_int, const std::string&, const std::string&);
    6156
    6257    ///
     
    6459    ///
    6560    virtual inline ~Node(void) {};
     61
     62    ///
     63    ///
     64    ///
     65    virtual std::string author(void) const=0;
    6666
    6767    ///
     
    7979    ///
    8080    std::string html_tablerow(const std::string&) const;
     81
     82    ///
     83    ///
     84    ///
     85    virtual u_int last_changed_rev(void) const=0;
    8186
    8287    ///
     
    98103
    99104  protected:
     105
    100106    ///
    101107    /// Function returning everything after the last '/'
     
    115121    void print_header(std::ostream&) const;
    116122
     123    u_int level_;
    117124    std::string output_name_; //without suffix
    118125    std::string path_;
  • trunk/lib/Stats.cc

    r101 r112  
    5151    std::stringstream ss;
    5252    ss << (svn_info.count("Revision") ? svn_info["Revision"] : "0");
    53     ss >> latest_revision_;
     53    ss >> revision_;
     54    ss.clear();
     55    ss << (svn_info.count("Last Changed Rev") ? svn_info["Last Changed Rev"] : "0");
     56    ss >> last_changed_rev_;
    5457  }
    5558
     
    5861  {
    5962    // sum of all users
    60     std::vector<u_int> sum(latest_revision_+1, 0);
     63    std::vector<u_int> sum(revision_+1, 0);
    6164    sum=std::accumulate(map_.begin(), map_.end(), sum,
    6265                        PairValuePlus<std::string,u_int>());
     
    7578    std::vector<u_int> vec=(map_.find(user))->second;
    7679 
    77     if (vec.size() < latest_revision_+1)
    78       vec.insert(vec.end(), latest_revision_+1-vec.size(), 0);
     80    if (vec.size() < revision_+1)
     81      vec.insert(vec.end(), revision_+1-vec.size(), 0);
    7982
    8083    std::vector<u_int> accum(vec.size());
     
    8790    std::vector<u_int>* vec = &(map_[user]);
    8891    if (vec->size() < rev+1){
    89       vec->reserve(latest_revision_ + 1);
     92      vec->reserve(revision_ + 1);
    9093      vec->insert(vec->end(), rev - vec->size(),0);
    9194      vec->push_back(1);
  • trunk/lib/Stats.h

    r101 r112  
    4747
    4848    ///
     49    ///
     50    ///
     51    inline u_int last_changed_rev(void) const { return last_changed_rev_; }
     52
     53    ///
    4954    /// @return true if file is binary
    5055    ///
     
    6065    ///
    6166    inline void reset(void) { map_.clear(); }
     67
     68    ///
     69    ///
     70    ///
     71    inline u_int revision(void) const { return revision_; }
    6272
    6373    ///
     
    93103
    94104
    95     u_int latest_revision_; // Should be the latest revision for whole project
     105    u_int revision_; // Should be the latest revision for whole project
     106    u_int last_changed_rev_; // Should be the latest revision for file
    96107
    97108    // Peter, if the vector is sparse make it a map
  • trunk/lib/utility.cc

    r100 r112  
    8080  }
    8181
    82 
     82  void print_css(std::ostream& s)
     83  {
     84    s << "body {\n";
     85    s << " background: #fff; \n";
     86    s << " color: #000; \n";
     87    s << " margin: 10px; \n";
     88    s << " padding: 0; \n";
     89    s << "} \n";
     90    s << "\n";
     91    s << "body, th, td {\n";
     92    s << " font: normal 13px verdana,arial,'Bitstream Vera Sans',"
     93      << "helvetica,sans-serif;\n";
     94    s << "}\n";
     95    s << ":link, :visited {\n";
     96    s << " text-decoration: none;\n";
     97    s << " color: #b00;\n";
     98    s << " border-bottom: 1px dotted #bbb;\n";
     99    s << "}\n";
     100    s << "\n";
     101    s << "table.listings {\n";
     102    s << " clear: both;\n";
     103    s << " border-bottom: 1px solid #d7d7d7;\n";
     104    s << " border-collapse: collapse;\n";
     105    s << " border-spacing: 0;\n";
     106    s << " margin-top: 1em;\n";
     107    s << " width: 100%;\n";
     108    s << "}\n";
     109    s << "\n";
     110    s << "table.listings th {\n";
     111    s << " text-align: left;\n";
     112    s << " padding: 0 1em .1em 0;\n";
     113    s << " font-size: 12px\n";
     114    s << "}\n";
     115    s << "table.listings thead { background: #f7f7f0 }\n";
     116    s << "table.listings thead th {\n";
     117    s << " border: 1px solid #d7d7d7;\n";
     118    s << " border-bottom-color: #999;\n";
     119    s << " font-size: 11px;\n";
     120    s << " font-wheight: bold;\n";
     121    s << " padding: 2px .5em;\n";
     122    s << " vertical-align: bottom;\n";
     123    s << "}\n";
     124    s << "\n";
     125    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
     126    s << " background-color: transparent;\n";
     127    s << "}\n";
     128    s << "\n";
     129    s << "table.listings tbody td, table.listing tbody th {\n";
     130    s << " border: 1px dotted #ddd;\n";
     131    s << " padding: .33em .5em;\n";
     132    s << " vertical-align: top;\n";
     133    s << "}\n";
     134    s << "\n";
     135    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
     136    s << " background-color: transparent;\n";
     137    s << "}\n";
     138    s << "table.listings tbody tr { border-top: 1px solid #ddd }\n";
     139    s << "table.listings tbody tr.light { background-color: #fcfcfc }\n";
     140    s << "table.listings tbody tr.dark { background-color: #f7f7f7 }\n";
     141    s << "table.listings tbody tr.hover { background: #eed }\n";
     142    s << "\n";
     143    s << "\n";
     144    s << "\n";
     145  }
    83146
    84147
  • trunk/lib/utility.h

    r100 r112  
    2626
    2727#include <algorithm>
     28#include <fstream>
    2829#include <functional>
    2930#include <map>
     
    5960  std::map<std::string, std::string> info(const std::string&);
    6061
    61 //  int log(const std::string&);
     62  ///
     63  /// @printing cascading style sheet to stream @a s.
     64  ///
     65  void print_css(std::ostream& s);
    6266
    6367  ///
Note: See TracChangeset for help on using the changeset viewer.