1 | #ifndef _theplu_svndigest_svnblame_ |
---|
2 | #define _theplu_svndigest_svnblame_ |
---|
3 | |
---|
4 | // $Id: SVNblame.h 501 2007-10-19 19:14:45Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006 Jari Häkkinen |
---|
8 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
9 | |
---|
10 | This file is part of svndigest, http://trac.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include <string> |
---|
29 | #include <vector> |
---|
30 | |
---|
31 | #include <subversion-1/svn_client.h> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace svndigest { |
---|
35 | |
---|
36 | class SVN; |
---|
37 | |
---|
38 | /** |
---|
39 | The SVNblame class is a utility class for taking care of 'svn |
---|
40 | blame' information. An 'svn blame' is performed on an item, the |
---|
41 | blame information for each line is traversed with |
---|
42 | SVNblame.next_line() and SVNblame.valid() calls giving access to |
---|
43 | the blame information. |
---|
44 | */ |
---|
45 | class SVNblame { |
---|
46 | public: |
---|
47 | |
---|
48 | /** |
---|
49 | @brief The contructor. |
---|
50 | |
---|
51 | The constructor performs an 'svn blame' on \a path and |
---|
52 | initializes the SVNblame object for statistics traversal using |
---|
53 | SVNblame::next_line() and SVNblame::valid(). |
---|
54 | */ |
---|
55 | explicit SVNblame(const std::string& path); |
---|
56 | |
---|
57 | /** |
---|
58 | @brief The contructor. |
---|
59 | |
---|
60 | The constructor performs an 'svn blame -r rev' on \a path and |
---|
61 | initializes the SVNblame object for statistics traversal using |
---|
62 | SVNblame::next_line() and SVNblame::valid(). |
---|
63 | */ |
---|
64 | SVNblame(const std::string& path, svn_revnum_t rev); |
---|
65 | |
---|
66 | /** |
---|
67 | @brief The destructor. |
---|
68 | */ |
---|
69 | ~SVNblame(void); |
---|
70 | |
---|
71 | /** |
---|
72 | @brief Retrieve the author for the current line. |
---|
73 | |
---|
74 | If current line is outside blame entries the behaviour is |
---|
75 | undefined. |
---|
76 | |
---|
77 | @return The author. |
---|
78 | */ |
---|
79 | std::string author(void); |
---|
80 | |
---|
81 | /** |
---|
82 | Returns true if item is binary false otherwise |
---|
83 | |
---|
84 | Binary files are invalid for 'svn blame'. |
---|
85 | */ |
---|
86 | bool binary(void); |
---|
87 | |
---|
88 | /** |
---|
89 | @brief Retrieve the blame date for the current line. |
---|
90 | |
---|
91 | If current line is outside blame entries the behaviour is |
---|
92 | undefined. |
---|
93 | |
---|
94 | @return The date. |
---|
95 | */ |
---|
96 | std::string date(void); |
---|
97 | |
---|
98 | /** |
---|
99 | @brief Retrieve the content of the current line. |
---|
100 | |
---|
101 | If current line is outside blame entries the behaviour is |
---|
102 | undefined. |
---|
103 | |
---|
104 | @return The line content. |
---|
105 | */ |
---|
106 | std::string line(void); |
---|
107 | |
---|
108 | /** |
---|
109 | @brief Retrieve the line number of the current line. |
---|
110 | |
---|
111 | If current line is outside blame entries the behaviour is |
---|
112 | undefined. |
---|
113 | |
---|
114 | @return The line number. |
---|
115 | */ |
---|
116 | apr_int64_t line_no(void); |
---|
117 | |
---|
118 | /** |
---|
119 | @brief Skip to the next line. |
---|
120 | |
---|
121 | @return False if no more blame information is available, true |
---|
122 | otherwise. |
---|
123 | */ |
---|
124 | bool next_line(void); |
---|
125 | |
---|
126 | /** |
---|
127 | @brief Retrieve the blame revision of the current line. |
---|
128 | |
---|
129 | If current line is outside blame entries the behaviour is |
---|
130 | undefined. |
---|
131 | |
---|
132 | @return The blame revision. |
---|
133 | */ |
---|
134 | svn_revnum_t revision(void); |
---|
135 | |
---|
136 | /** |
---|
137 | @brief Check if more blame information is available. |
---|
138 | |
---|
139 | @return True if valid information exists, false otherwise. |
---|
140 | */ |
---|
141 | bool valid(void); |
---|
142 | |
---|
143 | private: |
---|
144 | |
---|
145 | /** |
---|
146 | @brief Copy Constructor, not implemented. |
---|
147 | */ |
---|
148 | SVNblame(const SVNblame&); |
---|
149 | |
---|
150 | /** |
---|
151 | @brief Information return by subversion (blame) API |
---|
152 | |
---|
153 | @see Subversion API for blame usage. |
---|
154 | */ |
---|
155 | struct blame_information { |
---|
156 | apr_int64_t line_no; |
---|
157 | svn_revnum_t revision; |
---|
158 | std::string author; |
---|
159 | std::string date; |
---|
160 | std::string line; |
---|
161 | }; |
---|
162 | |
---|
163 | // binary_ is true if item in any revision has been binary. |
---|
164 | bool binary_; |
---|
165 | // blame_info_iterator_ is used in statistics analysis to traverse |
---|
166 | // blame_receiver_baton.blame_info vector through calls to next(). |
---|
167 | std::vector<blame_information*>::iterator blame_info_iterator_; |
---|
168 | SVN* instance_; |
---|
169 | |
---|
170 | struct blame_receiver_baton_ { |
---|
171 | std::vector<blame_information*> blame_info; |
---|
172 | } blame_receiver_baton_ ; |
---|
173 | |
---|
174 | static svn_error_t * |
---|
175 | blame_receiver(void *baton, apr_int64_t line_no, svn_revnum_t revision, |
---|
176 | const char *author, const char *date, const char *line, |
---|
177 | apr_pool_t *pool); |
---|
178 | }; |
---|
179 | |
---|
180 | }} // end of namespace svndigest and namespace theplu |
---|
181 | |
---|
182 | #endif |
---|