source: trunk/lib/SVNblame.cc @ 492

Last change on this file since 492 was 492, checked in by Peter Johansson, 14 years ago

Merged patch release 0.6.4 to trunk. Delta 0.6.4 - 0.6.3

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