source: trunk/lib/Node.cc

Last change on this file was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1// $Id: Node.cc 1515 2012-09-26 00:35:10Z peter $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010, 2011 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      property_(path), svninfo_(path)
53  {
54    if (Node::project_==std::string()) // no root directory in local path
55      Node::project_ = project;
56    else if (local_path.empty())
57      local_path_ = file_name(path);
58    else
59      local_path_ = local_path + "/" + file_name(path);
60
61    struct stat nodestat;                // C api from sys/stat.h
62    lstat(path,&nodestat);   // C api from sys/stat.h
63    link_ = S_ISLNK(nodestat.st_mode);
64  }
65
66
67  Node::~Node(void)
68  {
69    if (log_)
70      delete log_;
71  }
72
73
74  std::string Node::author(void) const
75  {
76    if (svndigest_ignore())
77      return svninfo_.last_changed_author();
78    assert(log().commits().size());
79    return log().latest_commit().author();
80  }
81
82
83  bool Node::binary(void) const
84  {
85    return property_.binary();
86  }
87
88
89  bool Node::dir(void) const
90  {
91    return false;
92  }
93
94
95  void Node::html_tablerow(std::ostream& os,
96                           const std::string& stats_type,
97                           const std::string& css_class,
98                           const std::string& user) const
99  {
100    os << "<tr class=\"" << css_class << "\">\n"
101       << "<td class=\"" << node_type() << "\">";
102    if (svndigest_ignore())
103      os << name() << " (<i>svndigest:ignore</i>)";
104    else if (binary())
105      os << name() << " (<i>binary</i>)";
106    else if (link_)
107      os << name() << " (<i>link</i>)";
108    // there is no output for nodes when user has zero contribution
109    else if (user!="all"
110             && !tiny_stats()(stats_type,user,LineTypeParser::total))
111      os << name();
112    else if (!Configuration::instance().output_file() && !dir())
113      os << name();
114    else
115      os << anchor(href(), name());
116    os << "</td>\n";
117
118    html_tabletd(os, stats_type, user, LineTypeParser::total);
119    html_tabletd(os, stats_type, user, LineTypeParser::code);
120    html_tabletd(os, stats_type, user, LineTypeParser::comment);
121    html_tabletd(os, stats_type, user, LineTypeParser::other);
122
123    os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n"
124       << "<td>" << author() << "</td>\n"
125       << "</tr>\n";
126  }
127
128
129  void Node::html_tabletd(std::ostream& os,
130                          const std::string& stats_type,
131                          const std::string& user,
132                          LineTypeParser::line_type lt) const
133  {
134    os << "<td>" << tiny_stats()(stats_type, user, lt);
135    if (user!="all" && tiny_stats()(stats_type, user, lt))
136      os << " (" << percent(tiny_stats()(stats_type, user, lt),
137                            tiny_stats()(stats_type, "all", lt)) << "%)";
138    os << "</td>\n";
139  }
140
141
142  void Node::init_tiny_stats(void)
143  {
144    tiny_stats_.init(stats_);
145  }
146
147
148  const SVNlog& Node::log(void) const
149  {
150    if (!log_) {
151      if (svndigest_ignore())
152        log_ = new SVNlog;
153      else {
154        log_ = new SVNlog(path());
155        log_core(*log_);
156      }
157    }
158    return *log_;
159  }
160
161
162  std::string Node::name(void) const
163  {
164    return file_name(path_);
165  }
166
167
168  const SVNproperty& Node::property(void) const
169  {
170    return property_;
171  }
172
173
174  const StatsCollection& Node::stats(void) const
175  {
176    return stats_;
177  }
178
179
180  StatsCollection& Node::stats(void)
181  {
182    return stats_;
183  }
184
185
186  bool Node::svncopyright_ignore(void) const
187  {
188    return property_.svncopyright_ignore() || binary() || link_;
189  }
190
191
192  bool Node::svndigest_ignore(void) const
193  {
194    return property_.svndigest_ignore() || binary() || link_;
195  }
196
197}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.