7 |
30 Dec 05 |
jari |
// $Id$ |
4 |
29 Dec 05 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2005, 2006, 2007, 2008, 2009 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2012, 2023 Peter Johansson |
84 |
13 Mar 06 |
jari |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
8 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
13 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
18 |
|
84 |
13 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
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 |
|
579 |
18 Mar 08 |
peter |
40 |
#include <algorithm> |
206 |
10 Sep 06 |
jari |
41 |
#include <cassert> |
462 |
21 Aug 07 |
jari |
42 |
#include <cstdio> |
225 |
11 Mar 07 |
peter |
43 |
#include <ctime> |
4 |
29 Dec 05 |
peter |
44 |
#include <fstream> |
4 |
29 Dec 05 |
peter |
45 |
#include <iostream> |
226 |
11 Mar 07 |
peter |
46 |
#include <map> |
622 |
23 Apr 08 |
peter |
47 |
#include <stdexcept> |
4 |
29 Dec 05 |
peter |
48 |
#include <string> |
864 |
20 Nov 09 |
jari |
49 |
#include <sstream> |
424 |
29 Jun 07 |
peter |
50 |
#include <sys/stat.h> |
4 |
29 Dec 05 |
peter |
51 |
|
4 |
29 Dec 05 |
peter |
52 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
53 |
namespace svndigest{ |
4 |
29 Dec 05 |
peter |
54 |
|
176 |
02 Sep 06 |
peter |
55 |
|
1478 |
29 May 12 |
peter |
56 |
File::File(const unsigned int level, const std::string& path, |
1478 |
29 May 12 |
peter |
57 |
const std::string& output) |
1137 |
18 Jul 10 |
peter |
58 |
: Node(level,path,output) |
343 |
19 May 07 |
peter |
59 |
{ |
343 |
19 May 07 |
peter |
60 |
output_dir_=output; |
343 |
19 May 07 |
peter |
61 |
if (!output_dir_.empty()) |
356 |
25 May 07 |
peter |
62 |
output_dir_+='/'; |
343 |
19 May 07 |
peter |
63 |
} |
307 |
12 May 07 |
peter |
64 |
|
307 |
12 May 07 |
peter |
65 |
|
1293 |
14 Nov 10 |
peter |
66 |
std::string File::cache_name(void) const |
1293 |
14 Nov 10 |
peter |
67 |
{ |
1293 |
14 Nov 10 |
peter |
68 |
std::string dir = concatenate_path(directory_name(path()), ".svndigest/"); |
1293 |
14 Nov 10 |
peter |
69 |
return dir + name() + ".svndigest-cache"; |
1293 |
14 Nov 10 |
peter |
70 |
} |
1293 |
14 Nov 10 |
peter |
71 |
|
1293 |
14 Nov 10 |
peter |
72 |
|
175 |
02 Sep 06 |
peter |
73 |
std::string File::href(void) const |
1478 |
29 May 12 |
peter |
74 |
{ |
1478 |
29 May 12 |
peter |
75 |
return name()+".html"; |
100 |
19 Jun 06 |
peter |
76 |
} |
100 |
19 Jun 06 |
peter |
77 |
|
100 |
19 Jun 06 |
peter |
78 |
|
834 |
07 Nov 09 |
peter |
79 |
svn_revnum_t File::last_changed_rev(void) const |
834 |
07 Nov 09 |
peter |
80 |
{ |
834 |
07 Nov 09 |
peter |
81 |
return svn_info().last_changed_rev(); |
834 |
07 Nov 09 |
peter |
82 |
} |
834 |
07 Nov 09 |
peter |
83 |
|
834 |
07 Nov 09 |
peter |
84 |
|
757 |
27 Jan 09 |
peter |
85 |
void File::log_core(SVNlog&) const |
447 |
16 Aug 07 |
peter |
86 |
{ |
447 |
16 Aug 07 |
peter |
87 |
} |
447 |
16 Aug 07 |
peter |
88 |
|
447 |
16 Aug 07 |
peter |
89 |
|
343 |
19 May 07 |
peter |
90 |
std::string File::node_type(void) const |
182 |
03 Sep 06 |
peter |
91 |
{ |
182 |
03 Sep 06 |
peter |
92 |
return std::string("file"); |
182 |
03 Sep 06 |
peter |
93 |
} |
182 |
03 Sep 06 |
peter |
94 |
|
182 |
03 Sep 06 |
peter |
95 |
|
1478 |
29 May 12 |
peter |
96 |
const StatsCollection& File::parse(bool verbose, bool ignore, |
1478 |
29 May 12 |
peter |
97 |
svn_revnum_t ignore_rev) |
185 |
06 Sep 06 |
jari |
98 |
{ |
60 |
16 Jan 06 |
peter |
99 |
if (verbose) |
1478 |
29 May 12 |
peter |
100 |
std::cout << "Parsing '" << path_ << "'" << std::endl; |
185 |
06 Sep 06 |
jari |
101 |
stats_.reset(); |
1478 |
29 May 12 |
peter |
102 |
stats_.ignore_rev(ignore_rev); |
1293 |
14 Nov 10 |
peter |
103 |
std::string cache_file = cache_name(); |
1293 |
14 Nov 10 |
peter |
104 |
std::string cache_dir = directory_name(cache_file); |
638 |
31 May 08 |
peter |
105 |
if (!ignore && node_exist(cache_file)){ |
482 |
13 Oct 07 |
peter |
106 |
std::ifstream is(cache_file.c_str()); |
664 |
13 Jun 08 |
peter |
107 |
if (stats_.load_cache(is)) { |
664 |
13 Jun 08 |
peter |
108 |
is.close(); |
482 |
13 Oct 07 |
peter |
109 |
return stats_; |
482 |
13 Oct 07 |
peter |
110 |
} |
538 |
27 Dec 07 |
peter |
111 |
is.close(); |
482 |
13 Oct 07 |
peter |
112 |
} |
1478 |
29 May 12 |
peter |
113 |
else |
663 |
13 Jun 08 |
peter |
114 |
stats_.parse(path_); |
482 |
13 Oct 07 |
peter |
115 |
if (!node_exist(cache_dir)) |
482 |
13 Oct 07 |
peter |
116 |
mkdir(cache_dir); |
712 |
27 Nov 08 |
peter |
117 |
std::string tmp_cache_file(cache_file+"~"); |
712 |
27 Nov 08 |
peter |
118 |
std::ofstream os(tmp_cache_file.c_str()); |
1234 |
23 Oct 10 |
peter |
119 |
assert(os); |
482 |
13 Oct 07 |
peter |
120 |
stats_.print(os); |
538 |
27 Dec 07 |
peter |
121 |
os.close(); |
1186 |
27 Aug 10 |
peter |
122 |
rename(tmp_cache_file, cache_file); |
129 |
02 Aug 06 |
jari |
123 |
return stats_; |
185 |
06 Sep 06 |
jari |
124 |
} |
4 |
29 Dec 05 |
peter |
125 |
|
10 |
30 Dec 05 |
jari |
126 |
|
1538 |
07 Oct 12 |
peter |
127 |
svn_revnum_t File::revision_min(void) const |
1538 |
07 Oct 12 |
peter |
128 |
{ |
1538 |
07 Oct 12 |
peter |
129 |
return svn_info().rev(); |
1538 |
07 Oct 12 |
peter |
130 |
} |
1538 |
07 Oct 12 |
peter |
131 |
|
1538 |
07 Oct 12 |
peter |
132 |
|
1234 |
23 Oct 10 |
peter |
133 |
void File::traverse(NodeVisitor& visitor) |
1234 |
23 Oct 10 |
peter |
134 |
{ |
1234 |
23 Oct 10 |
peter |
135 |
visitor.visit(*this); |
1234 |
23 Oct 10 |
peter |
136 |
} |
1234 |
23 Oct 10 |
peter |
137 |
|
149 |
12 Aug 06 |
jari |
138 |
}} // end of namespace svndigest and namespace theplu |