source: trunk/lib/SVNblame.cc @ 791

Last change on this file since 791 was 768, checked in by Peter Johansson, 12 years ago

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: SVNblame.cc 768 2009-01-31 21:30:37Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2008 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
29namespace theplu {
30namespace svndigest {
31
32
33  SVNblame::SVNblame(const std::string& path)
34    : binary_(false), instance_(SVN::instance())
35  {
36    if (svn_error_t* err=
37        instance_->client_blame(path.c_str(), blame_receiver,
38                                static_cast<void*>(&blame_receiver_baton_))) {
39      // SVN_ERR_CLIENT_IS_BINARY_FILE is the only error allowed to
40      // escape the client_blame call
41      svn_error_clear(err);
42      binary_=true;
43    }
44    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
45  }
46
47
48  SVNblame::SVNblame(const std::string& path, svn_revnum_t rev)
49    : binary_(false), instance_(SVN::instance())
50  {
51    if (svn_error_t* err=
52        instance_->client_blame(path.c_str(), blame_receiver,
53                                static_cast<void*>(&blame_receiver_baton_),
54                                rev)) {
55      // SVN_ERR_CLIENT_IS_BINARY_FILE is the only error allowed to
56      // escape the client_blame call
57      svn_error_clear(err);
58      binary_=true;
59    }
60    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
61  }
62
63
64  SVNblame::~SVNblame(void)
65  {
66    std::vector<blame_information*>::iterator i=
67      blame_receiver_baton_.blame_info.begin();
68    while (i!=blame_receiver_baton_.blame_info.end()) {
69      delete *i;
70      ++i;
71    }
72  }
73
74
75  std::string SVNblame::author(void)
76  {
77    return (*blame_info_iterator_)->author;
78  }
79
80
81  bool SVNblame::binary(void)
82  {
83    return binary_;
84  }
85
86
87  svn_error_t *
88  SVNblame::blame_receiver(void *baton, apr_int64_t line_no,
89                           svn_revnum_t revision, const char *author,
90                           const char *date, const char *line, apr_pool_t *pool)
91  {
92    blame_information *bi=new blame_information;
93    bi->line_no=line_no;
94    bi->revision=revision;
95    bi->author=author;
96    bi->date=date;
97    bi->line=line;
98    static_cast<struct blame_receiver_baton_*>(baton)->blame_info.push_back(bi);
99    return SVN_NO_ERROR;
100  }
101
102
103  std::string SVNblame::date(void)
104  {
105    return (*blame_info_iterator_)->date;
106  }
107
108
109  std::string SVNblame::line(void)
110  {
111    return (*blame_info_iterator_)->line;
112  }
113
114
115  apr_int64_t SVNblame::line_no(void)
116  {
117    return (*blame_info_iterator_)->line_no;
118  }
119
120
121  bool SVNblame::next_line(void)
122  {
123    if (valid())
124      ++blame_info_iterator_;
125    return valid();
126  }
127
128
129  svn_revnum_t SVNblame::revision(void)
130  {
131    return (*blame_info_iterator_)->revision;
132  }
133
134
135  void SVNblame::reset(void)
136  {
137    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
138  }
139
140
141  bool SVNblame::valid(void)
142  {
143    return (blame_info_iterator_!=blame_receiver_baton_.blame_info.end());
144  }
145
146}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.