source: trunk/lib/SVNblame.h

Last change on this file 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: 4.1 KB
Line 
1#ifndef _theplu_svndigest_svnblame_
2#define _theplu_svndigest_svnblame_
3
4// $Id: SVNblame.h 1218 2010-10-10 02:27:39Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen
8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
9
10  This file is part of svndigest, http://dev.thep.lu.se/svndigest
11
12  svndigest is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 3 of the License, or
15  (at your option) any later version.
16
17  svndigest is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <string>
27#include <vector>
28
29#include <subversion-1/svn_client.h>
30
31namespace theplu {
32namespace svndigest {
33
34  class SVN;
35
36  /**
37     The SVNblame class is a utility class for taking care of 'svn
38     blame' information. An 'svn blame' is performed on an item, the
39     blame information for each line is traversed with
40     SVNblame.next_line() and SVNblame.valid() calls giving access to
41     the blame information.
42  */
43  class SVNblame {
44  public:
45
46    /**
47       @brief The contructor.
48
49       The constructor performs an 'svn blame' on \a path and
50       initializes the SVNblame object for statistics traversal using
51       SVNblame::next_line() and SVNblame::valid().
52    */
53    explicit SVNblame(const std::string& path);
54
55    /**
56       @brief The contructor.
57
58       The constructor performs an 'svn blame -r rev' on \a path and
59       initializes the SVNblame object for statistics traversal using
60       SVNblame::next_line() and SVNblame::valid().
61    */
62    SVNblame(const std::string& path, svn_revnum_t rev);
63
64    /**
65       @brief The destructor.
66    */
67    ~SVNblame(void);
68
69    /**
70       @brief Retrieve the author for the current line.
71
72       If current line is outside blame entries the behaviour is
73       undefined.
74
75       @return The author.
76    */
77    std::string author(void);
78
79    /**
80       @brief Retrieve the blame date for the current line.
81
82       If current line is outside blame entries the behaviour is
83       undefined.
84
85       @return The date.
86    */
87    std::string date(void);
88
89    /**
90       @brief Retrieve the content of the current line.
91
92       If current line is outside blame entries the behaviour is
93       undefined.
94
95       @return The line content.
96    */
97    std::string line(void);
98
99    /**
100       @brief Retrieve the line number of the current line.
101
102       If current line is outside blame entries the behaviour is
103       undefined.
104
105       @return The line number.
106    */
107    apr_int64_t line_no(void);
108
109    /**
110       @brief Skip to the next line.
111
112       @return False if no more blame information is available, true
113       otherwise.
114    */
115    bool next_line(void);
116
117    /**
118       @brief Retrieve the blame revision of the current line.
119
120       If current line is outside blame entries the behaviour is
121       undefined.
122
123       @return The blame revision.
124    */
125    svn_revnum_t revision(void);
126
127    /**
128       \brief resets iterator to first line
129     */
130    void reset(void);
131
132    /**
133       @brief Check if more blame information is available.
134
135       @return True if valid information exists, false otherwise.
136    */
137    bool valid(void);
138
139  private:
140
141    /**
142       @brief Copy Constructor, not implemented.
143    */
144    SVNblame(const SVNblame&);
145
146    /**
147       @brief Information return by subversion (blame) API
148
149       @see Subversion API for blame usage.
150    */
151    struct blame_information {
152      apr_int64_t line_no;
153      svn_revnum_t revision;
154      std::string author;
155      std::string date;
156      std::string line;
157    };
158
159    // blame_info_iterator_ is used in statistics analysis to traverse
160    // blame_receiver_baton.blame_info vector through calls to next().
161    std::vector<blame_information*>::iterator blame_info_iterator_;
162    SVN* instance_;
163
164    struct blame_receiver_baton_ {
165      std::vector<blame_information*> blame_info;
166    } blame_receiver_baton_ ;
167
168    static svn_error_t *
169    blame_receiver(void *baton, apr_int64_t line_no, svn_revnum_t revision,
170                   const char *author, const char *date, const char *line,
171                   apr_pool_t *pool);
172  };
173
174}} // end of namespace svndigest and namespace theplu
175
176#endif
Note: See TracBrowser for help on using the repository browser.