1 | // $Id: SVNblame.cc 1267 2010-11-02 03:56:19Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Jari Häkkinen |
---|
5 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2010 Peter Johansson |
---|
7 | |
---|
8 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
9 | |
---|
10 | svndigest is free software; you can redistribute it and/or modify it |
---|
11 | under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 3 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | svndigest is distributed in the hope that it will be useful, but |
---|
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "SVNblame.h" |
---|
25 | #include "SVN.h" |
---|
26 | |
---|
27 | #include <string> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace svndigest { |
---|
31 | |
---|
32 | |
---|
33 | SVNblame::SVNblame(const std::string& path) |
---|
34 | : instance_(SVN::instance()) |
---|
35 | { |
---|
36 | instance_->client_blame(path.c_str(), blame_receiver, |
---|
37 | static_cast<void*>(&blame_receiver_baton_)); |
---|
38 | blame_info_iterator_ = blame_receiver_baton_.blame_info.begin(); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | SVNblame::SVNblame(const std::string& path, svn_revnum_t rev) |
---|
43 | : instance_(SVN::instance()) |
---|
44 | { |
---|
45 | instance_->client_blame(path.c_str(), blame_receiver, |
---|
46 | static_cast<void*>(&blame_receiver_baton_), |
---|
47 | rev); |
---|
48 | blame_info_iterator_ = blame_receiver_baton_.blame_info.begin(); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | SVNblame::~SVNblame(void) |
---|
53 | { |
---|
54 | std::vector<blame_information*>::iterator i= |
---|
55 | blame_receiver_baton_.blame_info.begin(); |
---|
56 | while (i!=blame_receiver_baton_.blame_info.end()) { |
---|
57 | delete *i; |
---|
58 | ++i; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | std::string SVNblame::author(void) |
---|
64 | { |
---|
65 | return (*blame_info_iterator_)->author; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | svn_error_t * |
---|
70 | SVNblame::blame_receiver(void *baton, apr_int64_t line_no, |
---|
71 | svn_revnum_t revision, const char *author, |
---|
72 | const char *date, const char *line, apr_pool_t *pool) |
---|
73 | { |
---|
74 | blame_information *bi=new blame_information; |
---|
75 | bi->line_no=line_no; |
---|
76 | bi->revision=revision; |
---|
77 | bi->author=author; |
---|
78 | bi->date=date; |
---|
79 | bi->line=line; |
---|
80 | static_cast<struct blame_receiver_baton_*>(baton)->blame_info.push_back(bi); |
---|
81 | return SVN_NO_ERROR; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | std::string SVNblame::date(void) |
---|
86 | { |
---|
87 | return (*blame_info_iterator_)->date; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | std::string SVNblame::line(void) |
---|
92 | { |
---|
93 | return (*blame_info_iterator_)->line; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | apr_int64_t SVNblame::line_no(void) |
---|
98 | { |
---|
99 | return (*blame_info_iterator_)->line_no; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | bool SVNblame::next_line(void) |
---|
104 | { |
---|
105 | if (valid()) |
---|
106 | ++blame_info_iterator_; |
---|
107 | return valid(); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | svn_revnum_t SVNblame::revision(void) |
---|
112 | { |
---|
113 | return (*blame_info_iterator_)->revision; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | void SVNblame::reset(void) |
---|
118 | { |
---|
119 | blame_info_iterator_ = blame_receiver_baton_.blame_info.begin(); |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | bool SVNblame::valid(void) |
---|
124 | { |
---|
125 | return (blame_info_iterator_!=blame_receiver_baton_.blame_info.end()); |
---|
126 | } |
---|
127 | |
---|
128 | }} // end of namespace svndigest and namespace theplu |
---|