source: trunk/lib/Node.cc

Last change on this file was 1635, checked in by Peter Johansson, 2 months ago

updating copyright statements using 0.11pre (using character-based assessment rather than line-based).

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