source: trunk/lib/SVN.h @ 1513

Last change on this file since 1513 was 1513, checked in by Peter Johansson, 9 years ago

remove trailing whitespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1#ifndef _theplu_svndigest_svn_
2#define _theplu_svndigest_svn_
3
4// $Id: SVN.h 1513 2012-09-23 04:09:08Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen
8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2009, 2010 Peter Johansson
10
11  This file is part of svndigest, http://dev.thep.lu.se/svndigest
12
13  svndigest is free software; you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 3 of the License, or
16  (at your option) any later version.
17
18  svndigest is distributed in the hope that it will be useful, but
19  WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27// Turning off warnings from using deprecated function, i.e., we are
28// using subversion 1.4
29#ifndef SVN_DEPRECATED
30#define SVN_DEPRECATED
31#endif
32
33
34#include <map>
35#include <stdexcept>
36#include <string>
37#include <vector>
38
39#include <subversion-1/svn_client.h>
40#include <subversion-1/svn_types.h>
41
42namespace theplu {
43namespace svndigest {
44
45  struct log_receiver_baton;
46
47  ///
48  /// If something goes wrong in the use of the different SVN classes,
49  /// an SVNException is thrown.
50  ///
51  struct SVNException : public std::runtime_error
52  {
53    SVNException(const std::string& msg, svn_error_t* error=NULL);
54
55    /**
56       Copy constructor
57     */
58    SVNException(const SVNException& other);
59
60    /**
61       Destructor
62     */
63    virtual ~SVNException(void) throw();
64
65    /**
66       override base implementation
67     */
68    const char* what(void) const throw();
69
70    /**
71       access svn_error_t
72     */
73    const svn_error_t* error(void) const;
74  private:
75    svn_error_t* error_;
76    std::string msg_;
77    int* ref_count_;
78
79    // assignment not allowed
80    SVNException& operator=(const SVNException&);
81  };
82
83  /**
84     \brief The SVN class is a front end to the subversion API.
85
86     SVN provides one single global access point to the underlying
87     subversion API and makes sure that there is only one point of
88     access for the binary.
89
90     The singleton SVN object should be initialized with
91     SVN::instancs(const std::string& path), rather than
92     SVN::instance(void), before using any other subversion related
93     classes or calls. Best practice is to initilize the singleton
94     object early in the main program. The logic behind this
95     requirement is that all subverison related classes and calls
96     expect that repository and WC access is properly set up at
97     initialization. However, most functionality is available
98     irrespectively which instance call is made.
99
100     \see Design Patterns (the singleton pattern). Subversion API
101     documents, SVN::instancs(void), SVN::instancs(const
102     std::string&).
103  */
104  class SVN {
105  public:
106
107    enum vc_status {
108      unversioned=0,
109      uptodate,
110      unresolved
111    };
112
113    /**
114       \brief Call the underlying svn_client_blame3 for \a path with
115       \a receiver and \a baton.
116
117       This function is called from SVNblame to do 'svn blame' on an
118       item. The \a receiver and \a baton is defined in SVNblame and
119       the \a receiver is called by the underlying subversion API for
120       every line in \a path provided it the item is under subversion
121       control. The \a baton is used to communicate anonymous
122       information through the API to the \a receiver. If \a path is a
123       binary object an error is returned, all other errors will
124       generate an SVNException.
125
126       \a path can be either a URL or an WC target.
127    */
128    void client_blame(const std::string& path,
129                      svn_client_blame_receiver_t receiver,
130                      void *baton);
131
132    /**
133       \brief Same as function above with the extension that revision
134       \a rev can be set.
135     */
136    void client_blame(const std::string& path,
137                      svn_client_blame_receiver_t receiver,
138                      void *baton, svn_revnum_t rev);
139
140    /**
141       \brief Call the underlying svn_client_info for \a path with \a
142       receiver and \a baton.
143
144       This function is called from SVNinfo to do 'svn info' on an
145       item. The \a receiver and \a baton is defined in SVNinfo and
146       the \a receiver is called by the underlying subversion API if
147       \a path is under subversion control. The \a baton is used to
148       communicate anonymous information through the API to the \a
149       receiver.
150
151       \a path can be either a URL or an WC target.
152
153       \see Subversion API documentation, SVNinfo
154    */
155    void client_info(const std::string& path, svn_info_receiver_t receiver,
156                     void *baton);
157
158    /**
159       \a path can be either a URL or an WC target.
160
161       \todo doc
162    */
163    void client_log(const std::string& path, svn_log_message_receiver_t receiver,
164                    void *baton);
165
166    /**
167       \brief Get the subversion properties for \a path.
168
169       The retrieved properties are stored in \a properties. To check
170       whether \a is a binary item use SVNproperty::binary(void).
171
172       \a path can be either a URL or an WC target.
173    */
174    void client_proplist(const std::string& path,
175                         std::map<std::string, std::string>& properties);
176
177    /**
178       \brief Get an instance of SVN.
179
180       The singleton SVN object should be initialized with
181       SVN::instancs(const std::string&) before usage of this
182       function. Best practice is to initilize the singleton object
183       early in the main program. The logic behind this requirement is
184       that subverison related classes and calls may expect that
185       repository and WC access is properly set up at initialization.
186
187       \throw An SVNException if the singleton SVN onject is not
188       already initilized.
189
190       \see SVN::instancs(const std::string&)
191    */
192    static SVN* instance(void);
193
194    /**
195       \brief Get an instance of SVN setup against repository pointed
196       to by \a path.
197
198       The singleton SVN object should be initialized with this
199       instance call before any subversion related classes or calls
200       are made. Best practice is to initilize the singleton object
201       early in the main program. The logic behind this requirement is
202       that subverison related classes and calls may expect that
203       repository and WC access is properly set up at initialization.
204
205       \throw Throws an SVNException if initialization fails in the
206       underlying subversion API calls, or if \a path is a URL.
207    */
208    static SVN* instance(const std::string& path);
209
210    /**
211       \brief Set up a repository access session.
212
213       \throws SVNException if session setup fails, or if a session is
214       already set up (i.e., repository cannot be changed during
215       program lifetime).
216    */
217    //    void setup_ra_session(const std::string& path);
218
219    ///
220    /// @brief Check if entry \a path is under version control
221    ///
222    /// @return True if \a path is under version control, false
223    /// otherwise.
224    ///
225    vc_status version_controlled(const std::string& path);
226
227  private:
228    /**
229       \brief Constructor
230
231       The only way to create an object of SVN type is by calling
232       SVN::instance(const std::string&). \a path must be a WC path,
233       i.e., not a URL.
234    */
235    SVN(const std::string& path);
236
237    ///
238    /// @brief Copy Constructor, not implemented.
239    ///
240    SVN(const SVN&);
241    SVN& operator=(const SVN&);
242
243    ///
244    /// @brief The destructor.
245    ///
246    virtual ~SVN(void);
247
248    /**
249       @brief Free resources when svn API calls fail.
250
251       This function will free \a pool resources and throw an
252       exception holding the \a message. If mute is false, the thrown
253       exception also contains \a err.
254
255       \throw cleanup will throw a SVNException
256
257       @see SVNException
258    */
259    void cleanup(svn_error_t *err, apr_pool_t *pool,
260                 std::string message=std::string(), bool mute=false);
261
262    /**
263       @brief Free resources when failing to reach end of
264       constructor.
265
266       cleanup_failed_init will free all resource acquired in the
267       constructor and throw an SVNException with \a message as the
268       message.
269
270       @see SVNException
271    */
272    void cleanup_failed_init(svn_error_t *err, const std::string& message);
273
274    static SVN* instance_;
275
276    // Subversion API stuff
277
278    /**
279       the url is fech with svn info. The ursl is stored in a
280       url_receiver_baton. The struct is filled in the url_receiver
281       function.
282    */
283    struct root_url_receiver_baton {
284      std::string path;
285    };
286
287    /**
288       url_receiver is the function passed to the underlying
289       subversion API call svn_client_info. This function is called by
290       the subversion API for every item matched by the conditions of
291       the API call.
292
293       \see Subversion API documentation
294    */
295    static svn_error_t*
296    root_url_receiver(void *baton, const char *path,
297                      const svn_info_t *info, apr_pool_t *pool);
298
299    void client_blame_call(const std::string& path,
300                           svn_client_blame_receiver_t receiver,
301                           void *baton, svn_opt_revision_t& head);
302
303    svn_wc_adm_access_t* adm_access_;
304    apr_allocator_t* allocator_;
305    svn_client_ctx_t* context_;
306    apr_pool_t* pool_;
307    svn_ra_session_t* ra_session_;
308  };
309
310}} // end of namespace svndigest and namespace theplu
311
312#endif
Note: See TracBrowser for help on using the repository browser.