source: trunk/lib/SVNblame.cc @ 693

Last change on this file since 693 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

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