1 | #ifndef _theplu_svndigest_file_ |
---|
2 | #define _theplu_svndigest_file_ |
---|
3 | |
---|
4 | // $Id: File.h 1238 2010-10-23 22:05:25Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2009 Peter Johansson |
---|
9 | |
---|
10 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
11 | |
---|
12 | svndigest is free software; you can redistribute it and/or modify it |
---|
13 | under the terms of the GNU General Public License as published by |
---|
14 | the Free Software Foundation; either version 3 of the License, or |
---|
15 | (at your option) any later version. |
---|
16 | |
---|
17 | svndigest is distributed in the hope that it will be useful, but |
---|
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "Node.h" |
---|
27 | |
---|
28 | #include <map> |
---|
29 | #include <string> |
---|
30 | |
---|
31 | namespace theplu{ |
---|
32 | namespace svndigest{ |
---|
33 | |
---|
34 | class NodeVisitor; |
---|
35 | |
---|
36 | class File : public Node |
---|
37 | { |
---|
38 | public: |
---|
39 | /// |
---|
40 | /// @brief Default Constructor |
---|
41 | /// |
---|
42 | File(const unsigned int level, const std::string& path, |
---|
43 | const std::string& output=""); |
---|
44 | |
---|
45 | /** |
---|
46 | For example 'File.h.html' |
---|
47 | |
---|
48 | @return href to this file |
---|
49 | */ |
---|
50 | std::string href(void) const; |
---|
51 | |
---|
52 | /** |
---|
53 | \brief Get the revision number of the latest commit. |
---|
54 | */ |
---|
55 | svn_revnum_t last_changed_rev(void) const; |
---|
56 | |
---|
57 | /** |
---|
58 | @return The explicit string "file", nothing else. |
---|
59 | */ |
---|
60 | std::string node_type(void) const; |
---|
61 | |
---|
62 | /** |
---|
63 | @return output path for example 'lib/File.h.html' for this file |
---|
64 | */ |
---|
65 | std::string output_path(void) const; |
---|
66 | |
---|
67 | /// |
---|
68 | /// @brief Parsing out information from svn repository |
---|
69 | /// |
---|
70 | /// @return Stats object of the file |
---|
71 | /// |
---|
72 | const StatsCollection& parse(bool verbose, bool ignore); |
---|
73 | |
---|
74 | /** |
---|
75 | @throw std::runtime_error when a file error is encountered |
---|
76 | updating the copyrights. |
---|
77 | */ |
---|
78 | void print_copyright(std::map<std::string, Alias>&, bool verbose, |
---|
79 | const std::map<int, svn_revnum_t>&) const; |
---|
80 | |
---|
81 | /** |
---|
82 | Let the visitor perform its mission via visitor(*this) |
---|
83 | */ |
---|
84 | void traverse(NodeVisitor& visitor); |
---|
85 | |
---|
86 | private: |
---|
87 | std::string blame_output_file_name(void) const; |
---|
88 | |
---|
89 | /** |
---|
90 | do nothing |
---|
91 | */ |
---|
92 | void log_core(SVNlog&) const; |
---|
93 | |
---|
94 | /// |
---|
95 | /// @brief Copy Constructor, not implemented |
---|
96 | /// |
---|
97 | File(const File&); |
---|
98 | |
---|
99 | /// |
---|
100 | /// @brief Parsing svn blame output |
---|
101 | /// |
---|
102 | /// @return true if parsing is succesful |
---|
103 | /// |
---|
104 | bool blame(void) const; |
---|
105 | |
---|
106 | /** |
---|
107 | \return copyright block |
---|
108 | */ |
---|
109 | std::string copyright_block(const std::map<int, std::set<Alias> >& map, |
---|
110 | const std::string& prefix) const; |
---|
111 | |
---|
112 | /** |
---|
113 | Create a map from year to set of authors. |
---|
114 | */ |
---|
115 | std::map<int, std::set<Alias> > |
---|
116 | copyright_map(std::map<std::string, Alias>& alias, |
---|
117 | const std::map<int, svn_revnum_t>&) const; |
---|
118 | |
---|
119 | /** |
---|
120 | Create a map from year to set of authors. |
---|
121 | |
---|
122 | \return true if Copyright block is found |
---|
123 | */ |
---|
124 | bool detect_copyright(std::string& block, size_t& start_at_line, |
---|
125 | size_t& end_at_line, std::string& prefix) const; |
---|
126 | |
---|
127 | /** |
---|
128 | @brief Print blame output |
---|
129 | */ |
---|
130 | void print_blame(std::ofstream& os) const; |
---|
131 | |
---|
132 | void print_core(bool verbose=false) const; |
---|
133 | |
---|
134 | /// |
---|
135 | /// print page for specific user (or all) and specific line_style |
---|
136 | /// (or total). |
---|
137 | /// |
---|
138 | void print_core(const std::string& stats_type, const std::string& user, |
---|
139 | const std::string& line_type, const SVNlog&) const; |
---|
140 | |
---|
141 | /** |
---|
142 | Doing the actual print of copyright statement |
---|
143 | |
---|
144 | \param block new copyright block |
---|
145 | \param start_at_line line number of first line in old block |
---|
146 | \param end_at_line line number of first line after old block |
---|
147 | */ |
---|
148 | void update_copyright(const std::string& block, |
---|
149 | size_t start_at_line, size_t end_at_line) const; |
---|
150 | }; |
---|
151 | |
---|
152 | }} // end of namespace svndigest and namespace theplu |
---|
153 | |
---|
154 | #endif |
---|
155 | |
---|
156 | |
---|