source: branches/0.6-stable/lib/SVNblame.cc @ 479

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

changing lev.thep.lu.se to trac.thep.lu.se

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