source: tags/0.6.8/lib/SVNblame.cc @ 848

Last change on this file since 848 was 731, checked in by Peter Johansson, 13 years ago

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: SVNblame.cc 731 2008-12-15 19:03:04Z 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 2 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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "SVNblame.h"
27#include "SVN.h"
28
29#include <string>
30
31namespace theplu {
32namespace svndigest {
33
34
35  SVNblame::SVNblame(const std::string& path)
36    : binary_(false), instance_(SVN::instance())
37  {
38    if (svn_error_t* err=
39        instance_->client_blame(path.c_str(), blame_receiver,
40                                static_cast<void*>(&blame_receiver_baton_))) {
41      // SVN_ERR_CLIENT_IS_BINARY_FILE is the only error allowed to
42      // escape the client_blame call
43      svn_error_clear(err);
44      binary_=true;
45    }
46    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
47  }
48
49
50  SVNblame::~SVNblame(void)
51  {
52    std::vector<blame_information*>::iterator i=
53      blame_receiver_baton_.blame_info.begin();
54    while (i!=blame_receiver_baton_.blame_info.end()) {
55      delete *i;
56      ++i;
57    }
58  }
59
60
61  std::string SVNblame::author(void)
62  {
63    return (*blame_info_iterator_)->author;
64  }
65
66
67  bool SVNblame::binary(void)
68  {
69    return binary_;
70  }
71
72
73  svn_error_t *
74  SVNblame::blame_receiver(void *baton, apr_int64_t line_no,
75                           svn_revnum_t revision, const char *author,
76                           const char *date, const char *line, apr_pool_t *pool)
77  {
78    blame_information *bi=new blame_information;
79    bi->line_no=line_no;
80    bi->revision=revision;
81    bi->author=author;
82    bi->date=date;
83    bi->line=line;
84    static_cast<struct blame_receiver_baton_*>(baton)->blame_info.push_back(bi);
85    return SVN_NO_ERROR;
86  }
87
88
89  std::string SVNblame::date(void)
90  {
91    return (*blame_info_iterator_)->date;
92  }
93
94
95  std::string SVNblame::line(void)
96  {
97    return (*blame_info_iterator_)->line;
98  }
99
100
101  apr_int64_t SVNblame::line_no(void)
102  {
103    return (*blame_info_iterator_)->line_no;
104  }
105
106
107  bool SVNblame::next_line(void)
108  {
109    if (valid())
110      ++blame_info_iterator_;
111    return valid();
112  }
113
114
115  svn_revnum_t SVNblame::revision(void)
116  {
117    return (*blame_info_iterator_)->revision;
118  }
119
120
121  bool SVNblame::valid(void)
122  {
123    return (blame_info_iterator_!=blame_receiver_baton_.blame_info.end());
124  }
125
126}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.