source: trunk/lib/File.cc @ 1293

Last change on this file since 1293 was 1293, checked in by Peter Johansson, 11 years ago

rewrite svndigest-copy-cache in C++. closes #463

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: File.cc 1293 2010-11-14 05:34:10Z 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::cache_name(void) const
64  {
65    std::string dir = concatenate_path(directory_name(path()), ".svndigest/");
66    return dir + name() + ".svndigest-cache";
67  }
68
69
70  std::string File::href(void) const
71  { 
72    return name()+".html"; 
73  }
74
75
76  svn_revnum_t File::last_changed_rev(void) const
77  {
78    return svn_info().last_changed_rev();
79  }
80
81
82  void File::log_core(SVNlog&) const
83  {
84  }
85
86
87  std::string File::node_type(void) const
88  {
89    return std::string("file");
90  }
91
92
93  const StatsCollection& File::parse(bool verbose, bool ignore)
94  {
95    if (verbose)
96      std::cout << "Parsing '" << path_ << "'" << std::endl; 
97    stats_.reset();
98    std::string cache_file = cache_name();
99    std::string cache_dir = directory_name(cache_file);
100    if (!ignore && node_exist(cache_file)){
101      std::ifstream is(cache_file.c_str());
102      if (stats_.load_cache(is)) {
103        is.close();
104        return stats_;
105      }
106      is.close();
107    }
108    else 
109      stats_.parse(path_);
110    if (!node_exist(cache_dir))
111      mkdir(cache_dir);
112    std::string tmp_cache_file(cache_file+"~");
113    std::ofstream os(tmp_cache_file.c_str());
114    assert(os);
115    stats_.print(os);
116    os.close();
117    rename(tmp_cache_file, cache_file);
118    return stats_;
119  }
120
121
122  void File::traverse(NodeVisitor& visitor)
123  {
124    visitor.visit(*this);
125  }
126
127}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.