source: trunk/lib/SVNblame.cc @ 1218

Last change on this file since 1218 was 1218, checked in by Peter Johansson, 11 years ago

refs #371. Remove variable binary_ in SVNblame, which was not
used. SVNblame will now fail if ued on binary file (but we don't call
blame on binary files). The SVN class now takes care of svn errors and
translate them into exceptions via the cleanup function.

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