source: trunk/lib/File.cc

Last change on this file was 1538, checked in by Peter Johansson, 9 years ago

refs #334. implement --update also for directories. For Directories the 'revision: ' tag in html output reflects the lowest revision of the nodes (Directory and sub-nodes). Directory is not reprinted if this revision is at least last_changed_rev, in other words, there is no node by node comparison but a more easily implemented collective comparison. In case of homogenous revision (no mixtures) this is is the same thing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: File.cc 1538 2012-10-07 09:29:04Z peter $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2010, 2012 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#include "utility.h"
37
38#include <algorithm>
39#include <cassert>
40#include <cstdio>
41#include <ctime>
42#include <fstream>
43#include <iostream>
44#include <map>
45#include <stdexcept>
46#include <string>
47#include <sstream>
48#include <sys/stat.h>
49
50namespace theplu{
51namespace svndigest{
52
53
54  File::File(const unsigned int level, const std::string& path,
55             const std::string& output)
56    : Node(level,path,output)
57  {
58    output_dir_=output;
59    if (!output_dir_.empty())
60      output_dir_+='/';
61  }
62
63
64  std::string File::cache_name(void) const
65  {
66    std::string dir = concatenate_path(directory_name(path()), ".svndigest/");
67    return dir + name() + ".svndigest-cache";
68  }
69
70
71  std::string File::href(void) const
72  {
73    return name()+".html";
74  }
75
76
77  svn_revnum_t File::last_changed_rev(void) const
78  {
79    return svn_info().last_changed_rev();
80  }
81
82
83  void File::log_core(SVNlog&) const
84  {
85  }
86
87
88  std::string File::node_type(void) const
89  {
90    return std::string("file");
91  }
92
93
94  const StatsCollection& File::parse(bool verbose, bool ignore,
95                                     svn_revnum_t ignore_rev)
96  {
97    if (verbose)
98      std::cout << "Parsing '" << path_ << "'" << std::endl;
99    stats_.reset();
100    stats_.ignore_rev(ignore_rev);
101    std::string cache_file = cache_name();
102    std::string cache_dir = directory_name(cache_file);
103    if (!ignore && node_exist(cache_file)){
104      std::ifstream is(cache_file.c_str());
105      if (stats_.load_cache(is)) {
106        is.close();
107        return stats_;
108      }
109      is.close();
110    }
111    else
112      stats_.parse(path_);
113    if (!node_exist(cache_dir))
114      mkdir(cache_dir);
115    std::string tmp_cache_file(cache_file+"~");
116    std::ofstream os(tmp_cache_file.c_str());
117    assert(os);
118    stats_.print(os);
119    os.close();
120    rename(tmp_cache_file, cache_file);
121    return stats_;
122  }
123
124
125  svn_revnum_t File::revision_min(void) const
126  {
127    return svn_info().rev();
128  }
129
130
131  void File::traverse(NodeVisitor& visitor)
132  {
133    visitor.visit(*this);
134  }
135
136}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.