source: trunk/lib/SVNblame.h @ 535

Last change on this file since 535 was 535, checked in by Peter Johansson, 13 years ago

add reset function in SVNblame

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1#ifndef _theplu_svndigest_svnblame_
2#define _theplu_svndigest_svnblame_
3
4// $Id: SVNblame.h 535 2007-12-27 00:27:18Z peter $
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://trac.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 2 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 this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include <string>
29#include <vector>
30
31#include <subversion-1/svn_client.h>
32
33namespace theplu {
34namespace svndigest {
35
36  class SVN;
37
38  /**
39     The SVNblame class is a utility class for taking care of 'svn
40     blame' information. An 'svn blame' is performed on an item, the
41     blame information for each line is traversed with
42     SVNblame.next_line() and SVNblame.valid() calls giving access to
43     the blame information.
44  */
45  class SVNblame {
46  public:
47
48    /**
49       @brief The contructor.
50
51       The constructor performs an 'svn blame' on \a path and
52       initializes the SVNblame object for statistics traversal using
53       SVNblame::next_line() and SVNblame::valid().
54    */
55    explicit SVNblame(const std::string& path);
56
57    /**
58       @brief The contructor.
59
60       The constructor performs an 'svn blame -r rev' on \a path and
61       initializes the SVNblame object for statistics traversal using
62       SVNblame::next_line() and SVNblame::valid().
63    */
64    SVNblame(const std::string& path, svn_revnum_t rev);
65
66    /**
67       @brief The destructor.
68    */
69    ~SVNblame(void);
70
71    /**
72       @brief Retrieve the author for the current line.
73
74       If current line is outside blame entries the behaviour is
75       undefined.
76
77       @return The author.
78    */
79    std::string author(void);
80
81    /**
82       Returns true if item is binary false otherwise
83
84       Binary files are invalid for 'svn blame'.
85    */
86    bool binary(void);
87
88    /**
89       @brief Retrieve the blame date for the current line.
90
91       If current line is outside blame entries the behaviour is
92       undefined.
93
94       @return The date.
95    */
96    std::string date(void);
97
98    /**
99       @brief Retrieve the content of the current line.
100
101       If current line is outside blame entries the behaviour is
102       undefined.
103
104       @return The line content.
105    */
106    std::string line(void);
107
108    /**
109       @brief Retrieve the line number of the current line.
110
111       If current line is outside blame entries the behaviour is
112       undefined.
113
114       @return The line number.
115    */
116    apr_int64_t line_no(void);
117
118    /**
119       @brief Skip to the next line.
120
121       @return False if no more blame information is available, true
122       otherwise.
123    */
124    bool next_line(void);
125
126    /**
127       @brief Retrieve the blame revision of the current line.
128
129       If current line is outside blame entries the behaviour is
130       undefined.
131
132       @return The blame revision.
133    */
134    svn_revnum_t revision(void);
135
136    /**
137       \brief resets iterator to first line
138     */
139    void reset(void);
140
141    /**
142       @brief Check if more blame information is available.
143
144       @return True if valid information exists, false otherwise.
145    */
146    bool valid(void);
147
148  private:
149
150    /**
151       @brief Copy Constructor, not implemented.
152    */
153    SVNblame(const SVNblame&);
154
155    /**
156       @brief Information return by subversion (blame) API
157
158       @see Subversion API for blame usage.
159    */
160    struct blame_information {
161      apr_int64_t line_no;
162      svn_revnum_t revision;
163      std::string author;
164      std::string date;
165      std::string line;
166    };
167
168    // binary_ is true if item in any revision has been binary.
169    bool binary_;
170    // blame_info_iterator_ is used in statistics analysis to traverse
171    // blame_receiver_baton.blame_info vector through calls to next().
172    std::vector<blame_information*>::iterator blame_info_iterator_;
173    SVN* instance_;
174
175    struct blame_receiver_baton_ {
176      std::vector<blame_information*> blame_info;
177    } blame_receiver_baton_ ;
178
179    static svn_error_t *
180    blame_receiver(void *baton, apr_int64_t line_no, svn_revnum_t revision,
181                   const char *author, const char *date, const char *line,
182                   apr_pool_t *pool);
183  };
184
185}} // end of namespace svndigest and namespace theplu
186
187#endif
Note: See TracBrowser for help on using the repository browser.