lib/Node.cc

Code
Comments
Other
Rev Date Author Line
7 30 Dec 05 jari 1 // $Id$
4 29 Dec 05 peter 2
84 13 Mar 06 jari 3 /*
978 12 Dec 09 peter 4   Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
1635 30 Mar 23 peter 5   Copyright (C) 2009, 2010, 2011, 2023 Peter Johansson
84 13 Mar 06 jari 6
687 04 Aug 08 peter 7   This file is part of svndigest, http://dev.thep.lu.se/svndigest
84 13 Mar 06 jari 8
149 12 Aug 06 jari 9   svndigest is free software; you can redistribute it and/or modify it
84 13 Mar 06 jari 10   under the terms of the GNU General Public License as published by
693 11 Sep 08 jari 11   the Free Software Foundation; either version 3 of the License, or
84 13 Mar 06 jari 12   (at your option) any later version.
84 13 Mar 06 jari 13
149 12 Aug 06 jari 14   svndigest is distributed in the hope that it will be useful, but
84 13 Mar 06 jari 15   WITHOUT ANY WARRANTY; without even the implied warranty of
149 12 Aug 06 jari 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84 13 Mar 06 jari 17   General Public License for more details.
84 13 Mar 06 jari 18
84 13 Mar 06 jari 19   You should have received a copy of the GNU General Public License
693 11 Sep 08 jari 20   along with svndigest. If not, see <http://www.gnu.org/licenses/>.
84 13 Mar 06 jari 21 */
84 13 Mar 06 jari 22
1619 12 Mar 23 peter 23 #include <config.h>
1619 12 Mar 23 peter 24
4 29 Dec 05 peter 25 #include "Node.h"
452 17 Aug 07 peter 26
1136 18 Jul 10 peter 27 #include "Configuration.h"
452 17 Aug 07 peter 28 #include "Date.h"
751 14 Jan 09 peter 29 #include "HtmlStream.h"
177 02 Sep 06 peter 30 #include "html_utility.h"
1234 23 Oct 10 peter 31 #include "LineTypeParser.h"
258 30 Apr 07 peter 32 #include "SVNlog.h"
185 06 Sep 06 jari 33 #include "SVNproperty.h"
4 29 Dec 05 peter 34 #include "utility.h"
4 29 Dec 05 peter 35
1675 26 Aug 23 peter 36 #include <yat/utility/utility.h>
1675 26 Aug 23 peter 37
828 26 Sep 09 peter 38 #include <algorithm>
207 11 Sep 06 peter 39 #include <cassert>
23 02 Jan 06 peter 40 #include <ctime>
4 29 Dec 05 peter 41 #include <fstream>
285 06 May 07 peter 42 #include <iostream>
4 29 Dec 05 peter 43 #include <sstream>
4 29 Dec 05 peter 44
361 10 Jun 07 peter 45 #include <dirent.h>
361 10 Jun 07 peter 46 #include <sys/stat.h>
361 10 Jun 07 peter 47
4 29 Dec 05 peter 48 namespace theplu{
149 12 Aug 06 jari 49 namespace svndigest{
4 29 Dec 05 peter 50
207 11 Sep 06 peter 51   std::string Node::project_=std::string();
207 11 Sep 06 peter 52
1450 22 Dec 11 peter 53   Node::Node(const unsigned int level, const std::string& path,
1264 02 Nov 10 peter 54              const std::string& local_path, const std::string& project)
1450 22 Dec 11 peter 55     : level_(level), path_(path), stats_(path), log_(NULL),
1356 17 May 11 peter 56       property_(path), svninfo_(path)
1450 22 Dec 11 peter 57   {
207 11 Sep 06 peter 58     if (Node::project_==std::string()) // no root directory in local path
1264 02 Nov 10 peter 59       Node::project_ = project;
207 11 Sep 06 peter 60     else if (local_path.empty())
1675 26 Aug 23 peter 61       local_path_ = yat::utility::basename(path);
207 11 Sep 06 peter 62     else
1675 26 Aug 23 peter 63       local_path_ = local_path + "/" + yat::utility::basename(path);
361 10 Jun 07 peter 64
361 10 Jun 07 peter 65     struct stat nodestat;                // C api from sys/stat.h
1186 27 Aug 10 peter 66     lstat(path,&nodestat);   // C api from sys/stat.h
361 10 Jun 07 peter 67     link_ = S_ISLNK(nodestat.st_mode);
23 02 Jan 06 peter 68   }
4 29 Dec 05 peter 69
185 06 Sep 06 jari 70
453 17 Aug 07 peter 71   Node::~Node(void)
453 17 Aug 07 peter 72   {
453 17 Aug 07 peter 73     if (log_)
453 17 Aug 07 peter 74       delete log_;
453 17 Aug 07 peter 75   }
453 17 Aug 07 peter 76
453 17 Aug 07 peter 77
452 17 Aug 07 peter 78   std::string Node::author(void) const
1449 22 Dec 11 peter 79   {
1449 22 Dec 11 peter 80     if (svndigest_ignore())
1449 22 Dec 11 peter 81       return svninfo_.last_changed_author();
642 31 May 08 peter 82     assert(log().commits().size());
759 29 Jan 09 peter 83     return log().latest_commit().author();
452 17 Aug 07 peter 84   }
452 17 Aug 07 peter 85
452 17 Aug 07 peter 86
1356 17 May 11 peter 87   bool Node::binary(void) const
1356 17 May 11 peter 88   {
1356 17 May 11 peter 89     return property_.binary();
1356 17 May 11 peter 90   }
1356 17 May 11 peter 91
1356 17 May 11 peter 92
101 22 Jun 06 peter 93   bool Node::dir(void) const
101 22 Jun 06 peter 94   {
101 22 Jun 06 peter 95     return false;
101 22 Jun 06 peter 96   }
101 22 Jun 06 peter 97
185 06 Sep 06 jari 98
1450 22 Dec 11 peter 99   void Node::html_tablerow(std::ostream& os,
532 26 Dec 07 peter 100                            const std::string& stats_type,
213 15 Sep 06 peter 101                            const std::string& css_class,
213 15 Sep 06 peter 102                            const std::string& user) const
175 02 Sep 06 peter 103   {
175 02 Sep 06 peter 104     os << "<tr class=\"" << css_class << "\">\n"
182 03 Sep 06 peter 105        << "<td class=\"" << node_type() << "\">";
185 06 Sep 06 jari 106     if (svndigest_ignore())
185 06 Sep 06 jari 107       os << name() << " (<i>svndigest:ignore</i>)";
185 06 Sep 06 jari 108     else if (binary())
176 02 Sep 06 peter 109       os << name() << " (<i>binary</i>)";
361 10 Jun 07 peter 110     else if (link_)
361 10 Jun 07 peter 111       os << name() << " (<i>link</i>)";
234 09 Apr 07 peter 112     // there is no output for nodes when user has zero contribution
1450 22 Dec 11 peter 113     else if (user!="all"
1290 12 Nov 10 peter 114              && !tiny_stats()(stats_type,user,LineTypeParser::total))
234 09 Apr 07 peter 115       os << name();
1290 12 Nov 10 peter 116     else if (!Configuration::instance().output_file() && !dir())
1136 18 Jul 10 peter 117       os << name();
176 02 Sep 06 peter 118     else
1450 22 Dec 11 peter 119       os << anchor(href(), name());
1450 22 Dec 11 peter 120     os << "</td>\n";
313 17 May 07 peter 121
1234 23 Oct 10 peter 122     html_tabletd(os, stats_type, user, LineTypeParser::total);
1234 23 Oct 10 peter 123     html_tabletd(os, stats_type, user, LineTypeParser::code);
1234 23 Oct 10 peter 124     html_tabletd(os, stats_type, user, LineTypeParser::comment);
1234 23 Oct 10 peter 125     html_tabletd(os, stats_type, user, LineTypeParser::other);
1450 22 Dec 11 peter 126
452 17 Aug 07 peter 127     os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n"
112 29 Jun 06 peter 128        << "<td>" << author() << "</td>\n"
112 29 Jun 06 peter 129        << "</tr>\n";
101 22 Jun 06 peter 130   }
101 22 Jun 06 peter 131
185 06 Sep 06 jari 132
1450 22 Dec 11 peter 133   void Node::html_tabletd(std::ostream& os,
1450 22 Dec 11 peter 134                           const std::string& stats_type,
1450 22 Dec 11 peter 135                           const std::string& user,
1234 23 Oct 10 peter 136                           LineTypeParser::line_type lt) const
1234 23 Oct 10 peter 137   {
1450 22 Dec 11 peter 138     os << "<td>" << tiny_stats()(stats_type, user, lt);
1450 22 Dec 11 peter 139     if (user!="all" && tiny_stats()(stats_type, user, lt))
1450 22 Dec 11 peter 140       os << " (" << percent(tiny_stats()(stats_type, user, lt),
1450 22 Dec 11 peter 141                             tiny_stats()(stats_type, "all", lt)) << "%)";
1234 23 Oct 10 peter 142     os << "</td>\n";
1234 23 Oct 10 peter 143   }
1234 23 Oct 10 peter 144
1450 22 Dec 11 peter 145
1234 23 Oct 10 peter 146   void Node::init_tiny_stats(void)
1234 23 Oct 10 peter 147   {
1234 23 Oct 10 peter 148     tiny_stats_.init(stats_);
1234 23 Oct 10 peter 149   }
1234 23 Oct 10 peter 150
1234 23 Oct 10 peter 151
453 17 Aug 07 peter 152   const SVNlog& Node::log(void) const
452 17 Aug 07 peter 153   {
727 11 Dec 08 jari 154     if (!log_) {
1449 22 Dec 11 peter 155       if (svndigest_ignore())
453 17 Aug 07 peter 156         log_ = new SVNlog;
757 27 Jan 09 peter 157       else {
757 27 Jan 09 peter 158         log_ = new SVNlog(path());
757 27 Jan 09 peter 159         log_core(*log_);
757 27 Jan 09 peter 160       }
727 11 Dec 08 jari 161     }
453 17 Aug 07 peter 162     return *log_;
452 17 Aug 07 peter 163   }
452 17 Aug 07 peter 164
452 17 Aug 07 peter 165
1450 22 Dec 11 peter 166   std::string Node::name(void) const
1450 22 Dec 11 peter 167   {
1675 26 Aug 23 peter 168     return yat::utility::basename(path_);
482 13 Oct 07 peter 169   }
482 13 Oct 07 peter 170
482 13 Oct 07 peter 171
1450 22 Dec 11 peter 172   const SVNproperty& Node::property(void) const
1450 22 Dec 11 peter 173   {
1450 22 Dec 11 peter 174     return property_;
1450 22 Dec 11 peter 175   }
1450 22 Dec 11 peter 176
1450 22 Dec 11 peter 177
1234 23 Oct 10 peter 178   const StatsCollection& Node::stats(void) const
1234 23 Oct 10 peter 179   {
1234 23 Oct 10 peter 180     return stats_;
1234 23 Oct 10 peter 181   }
1234 23 Oct 10 peter 182
1234 23 Oct 10 peter 183
1234 23 Oct 10 peter 184   StatsCollection& Node::stats(void)
1234 23 Oct 10 peter 185   {
1234 23 Oct 10 peter 186     return stats_;
1234 23 Oct 10 peter 187   }
1234 23 Oct 10 peter 188
1234 23 Oct 10 peter 189
1137 18 Jul 10 peter 190   bool Node::svncopyright_ignore(void) const
1137 18 Jul 10 peter 191   {
1449 22 Dec 11 peter 192     return property_.svncopyright_ignore() || binary() || link_;
1137 18 Jul 10 peter 193   }
1137 18 Jul 10 peter 194
1356 17 May 11 peter 195
1356 17 May 11 peter 196   bool Node::svndigest_ignore(void) const
1356 17 May 11 peter 197   {
1449 22 Dec 11 peter 198     return property_.svndigest_ignore() || binary() || link_;
1356 17 May 11 peter 199   }
1356 17 May 11 peter 200
149 12 Aug 06 jari 201 }} // end of namespace svndigest and namespace theplu