source: trunk/lib/SVN.h @ 191

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

Fixes #81. Changed behaviour of the cleanup functionalities in the SVN class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1#ifndef _theplu_svndigest_svn_
2#define _theplu_svndigest_svn_
3
4// $Id: SVN.h 191 2006-09-07 11:14:45Z jari $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen
8
9  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
10
11  svndigest is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15
16  svndigest is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <map>
28#include <stdexcept>
29#include <string>
30#include <vector>
31
32#include <subversion-1/svn_client.h>
33#include <subversion-1/svn_types.h>
34
35namespace theplu {
36namespace svndigest {
37
38  ///
39  /// If something goes wrong in the use of the different SVN classes,
40  /// an SVNException is thrown.
41  ///
42  struct SVNException : public std::runtime_error
43  { inline SVNException(const std::string& msg) : runtime_error(msg) {} };
44
45  ///
46  /// The SVN class is a front end to the subversion API.
47  ///
48  /// SVN provides one single global access point to the underlying
49  /// subversion API and makes sure that there is only one point of
50  /// access for the binary.
51  ///
52  /// @see Design Patterns (the singleton pattern). Subversion API
53  /// documents.
54  ///
55  class SVN {
56  public:
57
58    enum vc_status {
59      unversioned=0,
60      uptodate,
61      unresolved
62    };
63
64    ///
65    /// @brief The destructor.
66    ///
67    ~SVN(void);
68
69    ///
70    /// @brief Call the underlying svn_client_blame3 for \a path with
71    /// \a receiver and \a baton.
72    ///
73    /// This function is called from SVNblame to do 'svn blame' on an
74    /// item. The \a receiver and \a baton is defined in SVNblame and
75    /// the \a receiver is called by the underlying subversion API for
76    /// every line in \a path provided it the item is under subversion
77    /// control. The \a baton is used to communicate anonymous
78    /// information through the API to the \a receiver. If \a path is
79    /// a binary object an error is returned, all other errors will
80    /// generate an SVNException.
81    ///
82    /// @return SVN_NO_ERROR or SVN_ERR_CLIENT_IS_BINARY_FILE, the
83    /// latter can be used to trigger on binary files. Note that
84    /// errors return from underlying subversion API must be cleared
85    /// by the receiver.
86    ///
87    /// @see Subversion API (svn_error_clear).
88    ///
89    svn_error_t * client_blame(const std::string& path,
90                               svn_client_blame_receiver_t receiver,
91                               void *baton);
92
93    ///
94    /// @brief Call the underlying svn_client_info for \a path with \a
95    /// receiver and \a baton.
96    ///
97    /// This function is called from SVNinfo to do 'svn info' on an
98    /// item. The \a receiver and \a baton is defined in SVNinfo and
99    /// the \a receiver is called by the underlying subversion API if
100    /// \a path is under subversion control. The \a baton is used to
101    /// communicate anonymous information through the API to the
102    /// \a receiver.
103    ///
104    /// @see Subversion API documentation, SVNinfo
105    ///
106    void client_info(const std::string& path, svn_info_receiver_t receiver,
107                     void *baton);
108
109    /**
110       @brief Get the properties for \a path.
111
112       The retrieved properties are stored in \a properties. To check
113       whether \a is a binary item use SVNproperty::binary(void).
114    */
115    void client_proplist(const std::string& path,
116                         std::map<std::string, std::string>& properties);
117
118    ///
119    /// @brief Get revision dates.
120    ///
121    /// Get dates for all commits to the repository. \a root can be a
122    /// repository path or a path within a working copy. In the latter
123    /// case the corresponding repository will be used to retrieve
124    /// commit dates.
125    ///
126    /// @return Revision dates in a vector where revision is
127    /// implicitly defined by vector index, i.e., element 56 in the
128    /// resulting vector implies revision 56.
129    ///
130    /// @note Currently revision 0 (repositoy creation) is not
131    /// supported.
132    ///
133    /// @throw Various error messages generated from the subversion
134    /// API.
135    ///
136    std::vector<std::string> commit_dates(const std::string& path);
137
138    ///
139    /// @brief Get an instance of SVN.
140    ///
141    /// @throw Throws an SVNException if initialization fails in the
142    /// underlying subversion API calls.
143    ///
144    static SVN* instance(void)
145    { if (!instance_) instance_=new SVN; return instance_; }
146
147    ///
148    /// @throws SVNException if session setup fails.
149    ///
150    void setup_ra_session(const std::string& path);
151
152    ///
153    /// @throws SVNException if access setup fails.
154    ///
155    void setup_wc_adm_access(const std::string& path);
156
157    ///
158    /// @brief Check if entry \a path is under version control
159    ///
160    /// @return True if \a path is under version control, false
161    /// otherwise.
162    ///
163    vc_status version_controlled(const std::string& path);
164
165
166  private:
167    ///
168    /// @brief Constructor
169    ///
170    /// The only way to create a object of SVN type is by calling
171    /// SVN::instance.
172    ///
173    SVN(void);
174
175    ///
176    /// @brief Copy Constructor, not implemented.
177    ///
178    SVN(const SVN&);
179
180    /**
181       @brief Free resources when svn API calls fail.
182
183       This function will write an error message to stdout, free \a
184       err and \a pool resources. If \a err or \a pool are a NULL
185       pointers the function will do nothing with these resources.
186
187       cleanup will throw a SVNException if \a message has
188       length>0. The default bahaviour is to free resources and return
189       normally.
190
191       @see SVNException
192    */
193    void cleanup(svn_error_t *err, apr_pool_t *pool,
194                 const std::string& message=std::string());
195
196    /**
197       @brief Free resources when failing to reach end of
198       constructor.
199
200       cleanup_failed_init will free all resource acquired in the
201       constructor and throw an SVNException with \a message as the
202       message.
203
204       @see SVNException
205    */
206    void cleanup_failed_init(svn_error_t *err, const std::string& message);
207
208    static SVN* instance_;
209
210    // Subversion API stuff
211
212    // Log message receiver
213    struct log_receiver_baton {
214      std::vector<std::string> commit_dates;
215    };
216    static svn_error_t *
217    log_message_receiver(void *baton, apr_hash_t *changed_paths,
218                         svn_revnum_t rev, const char *author, const char *date,
219                         const char *msg, apr_pool_t *pool);
220
221    svn_wc_adm_access_t* adm_access_;
222    apr_allocator_t* allocator_;
223    svn_client_ctx_t* context_;
224    apr_pool_t* pool_;
225    svn_ra_session_t* ra_session_;
226  };
227
228}} // end of namespace svndigest and namespace theplu
229
230#endif
Note: See TracBrowser for help on using the repository browser.