source: trunk/lib/SVNblame.h @ 693

Last change on this file since 693 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1#ifndef _theplu_svndigest_svnblame_
2#define _theplu_svndigest_svnblame_
3
4// $Id: SVNblame.h 693 2008-09-11 20:42:56Z jari $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen
8  Copyright (C) 2007 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       Returns true if item is binary false otherwise
81
82       Binary files are invalid for 'svn blame'.
83    */
84    bool binary(void);
85
86    /**
87       @brief Retrieve the blame date for the current line.
88
89       If current line is outside blame entries the behaviour is
90       undefined.
91
92       @return The date.
93    */
94    std::string date(void);
95
96    /**
97       @brief Retrieve the content of the current line.
98
99       If current line is outside blame entries the behaviour is
100       undefined.
101
102       @return The line content.
103    */
104    std::string line(void);
105
106    /**
107       @brief Retrieve the line number of the current line.
108
109       If current line is outside blame entries the behaviour is
110       undefined.
111
112       @return The line number.
113    */
114    apr_int64_t line_no(void);
115
116    /**
117       @brief Skip to the next line.
118
119       @return False if no more blame information is available, true
120       otherwise.
121    */
122    bool next_line(void);
123
124    /**
125       @brief Retrieve the blame revision of the current line.
126
127       If current line is outside blame entries the behaviour is
128       undefined.
129
130       @return The blame revision.
131    */
132    svn_revnum_t revision(void);
133
134    /**
135       \brief resets iterator to first line
136     */
137    void reset(void);
138
139    /**
140       @brief Check if more blame information is available.
141
142       @return True if valid information exists, false otherwise.
143    */
144    bool valid(void);
145
146  private:
147
148    /**
149       @brief Copy Constructor, not implemented.
150    */
151    SVNblame(const SVNblame&);
152
153    /**
154       @brief Information return by subversion (blame) API
155
156       @see Subversion API for blame usage.
157    */
158    struct blame_information {
159      apr_int64_t line_no;
160      svn_revnum_t revision;
161      std::string author;
162      std::string date;
163      std::string line;
164    };
165
166    // binary_ is true if item in any revision has been binary.
167    bool binary_;
168    // blame_info_iterator_ is used in statistics analysis to traverse
169    // blame_receiver_baton.blame_info vector through calls to next().
170    std::vector<blame_information*>::iterator blame_info_iterator_;
171    SVN* instance_;
172
173    struct blame_receiver_baton_ {
174      std::vector<blame_information*> blame_info;
175    } blame_receiver_baton_ ;
176
177    static svn_error_t *
178    blame_receiver(void *baton, apr_int64_t line_no, svn_revnum_t revision,
179                   const char *author, const char *date, const char *line,
180                   apr_pool_t *pool);
181  };
182
183}} // end of namespace svndigest and namespace theplu
184
185#endif
Note: See TracBrowser for help on using the repository browser.