lib/File.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, 2009 Jari Häkkinen, Peter Johansson
1635 30 Mar 23 peter 5   Copyright (C) 2010, 2012, 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 "File.h"
303 11 May 07 peter 26
303 11 May 07 peter 27 #include "Alias.h"
963 09 Dec 09 peter 28 #include "Colors.h"
446 16 Aug 07 peter 29 #include "Configuration.h"
380 21 Jun 07 jari 30 #include "Date.h"
181 03 Sep 06 peter 31 #include "html_utility.h"
380 21 Jun 07 jari 32 #include "HtmlStream.h"
1234 23 Oct 10 peter 33 #include "NodeVisitor.h"
14 30 Dec 05 peter 34 #include "Stats.h"
380 21 Jun 07 jari 35 #include "SVNblame.h"
234 09 Apr 07 peter 36 #include "SVNlog.h"
1234 23 Oct 10 peter 37 #include "TinyStats.h"
1321 28 Nov 10 peter 38 #include "utility.h"
4 29 Dec 05 peter 39
1675 26 Aug 23 peter 40 #include <yat/utility/utility.h>
1675 26 Aug 23 peter 41
579 18 Mar 08 peter 42 #include <algorithm>
206 10 Sep 06 jari 43 #include <cassert>
462 21 Aug 07 jari 44 #include <cstdio>
225 11 Mar 07 peter 45 #include <ctime>
4 29 Dec 05 peter 46 #include <fstream>
4 29 Dec 05 peter 47 #include <iostream>
226 11 Mar 07 peter 48 #include <map>
622 23 Apr 08 peter 49 #include <stdexcept>
4 29 Dec 05 peter 50 #include <string>
864 20 Nov 09 jari 51 #include <sstream>
424 29 Jun 07 peter 52 #include <sys/stat.h>
4 29 Dec 05 peter 53
4 29 Dec 05 peter 54 namespace theplu{
149 12 Aug 06 jari 55 namespace svndigest{
4 29 Dec 05 peter 56
176 02 Sep 06 peter 57
1478 29 May 12 peter 58   File::File(const unsigned int level, const std::string& path,
1478 29 May 12 peter 59              const std::string& output)
1137 18 Jul 10 peter 60     : Node(level,path,output)
343 19 May 07 peter 61   {
343 19 May 07 peter 62     output_dir_=output;
343 19 May 07 peter 63     if (!output_dir_.empty())
356 25 May 07 peter 64       output_dir_+='/';
343 19 May 07 peter 65   }
307 12 May 07 peter 66
307 12 May 07 peter 67
1293 14 Nov 10 peter 68   std::string File::cache_name(void) const
1293 14 Nov 10 peter 69   {
1675 26 Aug 23 peter 70     std::string dir =
1675 26 Aug 23 peter 71       concatenate_path(yat::utility::dirname(path()), ".svndigest/");
1293 14 Nov 10 peter 72     return dir + name() + ".svndigest-cache";
1293 14 Nov 10 peter 73   }
1293 14 Nov 10 peter 74
1293 14 Nov 10 peter 75
175 02 Sep 06 peter 76   std::string File::href(void) const
1478 29 May 12 peter 77   {
1478 29 May 12 peter 78     return name()+".html";
100 19 Jun 06 peter 79   }
100 19 Jun 06 peter 80
100 19 Jun 06 peter 81
834 07 Nov 09 peter 82   svn_revnum_t File::last_changed_rev(void) const
834 07 Nov 09 peter 83   {
834 07 Nov 09 peter 84     return svn_info().last_changed_rev();
834 07 Nov 09 peter 85   }
834 07 Nov 09 peter 86
834 07 Nov 09 peter 87
757 27 Jan 09 peter 88   void File::log_core(SVNlog&) const
447 16 Aug 07 peter 89   {
447 16 Aug 07 peter 90   }
447 16 Aug 07 peter 91
447 16 Aug 07 peter 92
343 19 May 07 peter 93   std::string File::node_type(void) const
182 03 Sep 06 peter 94   {
182 03 Sep 06 peter 95     return std::string("file");
182 03 Sep 06 peter 96   }
182 03 Sep 06 peter 97
182 03 Sep 06 peter 98
1478 29 May 12 peter 99   const StatsCollection& File::parse(bool verbose, bool ignore,
1478 29 May 12 peter 100                                      svn_revnum_t ignore_rev)
185 06 Sep 06 jari 101   {
60 16 Jan 06 peter 102     if (verbose)
1478 29 May 12 peter 103       std::cout << "Parsing '" << path_ << "'" << std::endl;
185 06 Sep 06 jari 104     stats_.reset();
1478 29 May 12 peter 105     stats_.ignore_rev(ignore_rev);
1293 14 Nov 10 peter 106     std::string cache_file = cache_name();
1675 26 Aug 23 peter 107     std::string cache_dir = yat::utility::dirname(cache_file);
638 31 May 08 peter 108     if (!ignore && node_exist(cache_file)){
482 13 Oct 07 peter 109       std::ifstream is(cache_file.c_str());
664 13 Jun 08 peter 110       if (stats_.load_cache(is)) {
664 13 Jun 08 peter 111         is.close();
482 13 Oct 07 peter 112         return stats_;
482 13 Oct 07 peter 113       }
538 27 Dec 07 peter 114       is.close();
482 13 Oct 07 peter 115     }
1478 29 May 12 peter 116     else
663 13 Jun 08 peter 117       stats_.parse(path_);
482 13 Oct 07 peter 118     if (!node_exist(cache_dir))
1675 26 Aug 23 peter 119       yat::utility::mkdir(cache_dir);
712 27 Nov 08 peter 120     std::string tmp_cache_file(cache_file+"~");
712 27 Nov 08 peter 121     std::ofstream os(tmp_cache_file.c_str());
1234 23 Oct 10 peter 122     assert(os);
482 13 Oct 07 peter 123     stats_.print(os);
538 27 Dec 07 peter 124     os.close();
1675 26 Aug 23 peter 125     yat::utility::rename(tmp_cache_file, cache_file);
129 02 Aug 06 jari 126     return stats_;
185 06 Sep 06 jari 127   }
4 29 Dec 05 peter 128
10 30 Dec 05 jari 129
1538 07 Oct 12 peter 130   svn_revnum_t File::revision_min(void) const
1538 07 Oct 12 peter 131   {
1538 07 Oct 12 peter 132     return svn_info().rev();
1538 07 Oct 12 peter 133   }
1538 07 Oct 12 peter 134
1538 07 Oct 12 peter 135
1234 23 Oct 10 peter 136   void File::traverse(NodeVisitor& visitor)
1234 23 Oct 10 peter 137   {
1234 23 Oct 10 peter 138     visitor.visit(*this);
1234 23 Oct 10 peter 139   }
1234 23 Oct 10 peter 140
149 12 Aug 06 jari 141 }} // end of namespace svndigest and namespace theplu