source: trunk/lib/Node.cc @ 1290

Last change on this file since 1290 was 1290, checked in by Peter Johansson, 11 years ago

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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1// $Id: Node.cc 1290 2010-11-12 04:01:35Z peter $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "Node.h"
24
25#include "Configuration.h"
26#include "Date.h"
27#include "HtmlStream.h"
28#include "html_utility.h"
29#include "LineTypeParser.h"
30#include "SVNlog.h"
31#include "SVNproperty.h"
32#include "utility.h"
33
34#include <algorithm>
35#include <cassert>
36#include <ctime>
37#include <fstream>
38#include <iostream>
39#include <sstream>
40
41#include <dirent.h>
42#include <sys/stat.h>
43
44namespace theplu{
45namespace svndigest{
46
47  std::string Node::project_=std::string();
48
49  Node::Node(const unsigned int level, const std::string& path, 
50             const std::string& local_path, const std::string& project)
51    : level_(level), path_(path), stats_(path), log_(NULL), 
52      svninfo_(path)
53  { 
54    SVNproperty property(path);
55    binary_=property.binary();
56    svndigest_ignore_=property.svndigest_ignore();
57    svncopyright_ignore_=property.svncopyright_ignore();
58    if (Node::project_==std::string()) // no root directory in local path
59      Node::project_ = project;
60    else if (local_path.empty())
61      local_path_ = file_name(path);
62    else
63      local_path_ = local_path + "/" + file_name(path);
64
65    struct stat nodestat;                // C api from sys/stat.h
66    lstat(path,&nodestat);   // C api from sys/stat.h
67    link_ = S_ISLNK(nodestat.st_mode);
68  }
69
70
71  Node::~Node(void)
72  {
73    if (log_)
74      delete log_;
75  }
76
77
78  std::string Node::author(void) const
79  { 
80    if (ignore())
81      return svninfo_.last_changed_author(); 
82    assert(log().commits().size());
83    return log().latest_commit().author();
84  }
85
86
87  bool Node::dir(void) const
88  {
89    return false;
90  }
91
92
93  void Node::html_tablerow(std::ostream& os, 
94                           const std::string& stats_type,
95                           const std::string& css_class,
96                           const std::string& user) const
97  {
98    os << "<tr class=\"" << css_class << "\">\n"
99       << "<td class=\"" << node_type() << "\">";
100    if (svndigest_ignore())
101      os << name() << " (<i>svndigest:ignore</i>)";
102    else if (binary())
103      os << name() << " (<i>binary</i>)";
104    else if (link_)
105      os << name() << " (<i>link</i>)";
106    // there is no output for nodes when user has zero contribution
107    else if (user!="all" 
108             && !tiny_stats()(stats_type,user,LineTypeParser::total))
109      os << name();
110    else if (!Configuration::instance().output_file() && !dir())
111      os << name();
112    else
113      os << anchor(href(), name()); 
114    os << "</td>\n"; 
115
116    html_tabletd(os, stats_type, user, LineTypeParser::total);
117    html_tabletd(os, stats_type, user, LineTypeParser::code);
118    html_tabletd(os, stats_type, user, LineTypeParser::comment);
119    html_tabletd(os, stats_type, user, LineTypeParser::other);
120   
121    os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n"
122       << "<td>" << author() << "</td>\n"
123       << "</tr>\n";
124  }
125
126
127  void Node::html_tabletd(std::ostream& os, 
128                          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_);
143  }
144
145
146  const SVNlog& Node::log(void) const
147  {
148    if (!log_) {
149      if (ignore())
150        log_ = new SVNlog;
151      else {
152        log_ = new SVNlog(path());
153        log_core(*log_);
154      }
155    }
156    return *log_;
157  }
158
159
160  std::string Node::name(void) const 
161  { 
162    std::string res = file_name(path_); 
163    return res;
164  }
165
166
167  const StatsCollection& Node::stats(void) const
168  {
169    return stats_;
170  }
171
172
173  StatsCollection& Node::stats(void)
174  {
175    return stats_;
176  }
177
178
179  bool Node::svncopyright_ignore(void) const
180  {
181    return svncopyright_ignore_;
182  }
183
184}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.