source: trunk/lib/File.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: 2.7 KB
Line 
1// $Id: File.cc 1290 2010-11-12 04:01:35Z peter $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
5  Copyright (C) 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 "File.h"
24
25#include "Alias.h"
26#include "Colors.h"
27#include "Configuration.h"
28#include "Date.h"
29#include "html_utility.h"
30#include "HtmlStream.h"
31#include "NodeVisitor.h"
32#include "Stats.h"
33#include "SVNblame.h"
34#include "SVNlog.h"
35#include "TinyStats.h"
36
37#include <algorithm>
38#include <cassert>
39#include <cstdio>
40#include <ctime>
41#include <fstream>
42#include <iostream>
43#include <map>
44#include <stdexcept>
45#include <string>
46#include <sstream>
47#include <sys/stat.h>
48
49namespace theplu{
50namespace svndigest{
51
52
53  File::File(const unsigned int level, const std::string& path, 
54             const std::string& output) 
55    : Node(level,path,output)
56  {
57    output_dir_=output;
58    if (!output_dir_.empty())
59      output_dir_+='/';
60  }
61
62
63  std::string File::href(void) const
64  { 
65    return name()+".html"; 
66  }
67
68
69  svn_revnum_t File::last_changed_rev(void) const
70  {
71    return svn_info().last_changed_rev();
72  }
73
74
75  void File::log_core(SVNlog&) const
76  {
77  }
78
79
80  std::string File::node_type(void) const
81  {
82    return std::string("file");
83  }
84
85
86  const StatsCollection& File::parse(bool verbose, bool ignore)
87  {
88    if (verbose)
89      std::cout << "Parsing '" << path_ << "'" << std::endl; 
90    stats_.reset();
91    std::string cache_dir = directory_name(path()) + std::string(".svndigest/"); 
92    std::string cache_file = cache_dir + name()+std::string(".svndigest-cache");
93    if (!ignore && node_exist(cache_file)){
94      std::ifstream is(cache_file.c_str());
95      if (stats_.load_cache(is)) {
96        is.close();
97        return stats_;
98      }
99      is.close();
100    }
101    else 
102      stats_.parse(path_);
103    if (!node_exist(cache_dir))
104      mkdir(cache_dir);
105    std::string tmp_cache_file(cache_file+"~");
106    std::ofstream os(tmp_cache_file.c_str());
107    assert(os);
108    stats_.print(os);
109    os.close();
110    rename(tmp_cache_file, cache_file);
111    return stats_;
112  }
113
114
115  void File::traverse(NodeVisitor& visitor)
116  {
117    visitor.visit(*this);
118  }
119
120}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.