source: trunk/lib/SVNblame.cc @ 501

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

added function calling svn blame for specific revision. refs #24.

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