source: branches/0.8-stable/lib/SVN.h @ 1199

Last change on this file since 1199 was 978, checked in by Peter Johansson, 11 years ago

refs #429. Convert copyright statements to UTF-8

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1#ifndef _theplu_svndigest_svn_
2#define _theplu_svndigest_svn_
3
4// $Id: SVN.h 978 2009-12-12 20:09:41Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen
8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2009 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  { inline SVNException(const std::string& msg) : runtime_error(msg) {} };
53
54  /**
55     \brief The SVN class is a front end to the subversion API.
56
57     SVN provides one single global access point to the underlying
58     subversion API and makes sure that there is only one point of
59     access for the binary.
60
61     The singleton SVN object should be initialized with
62     SVN::instancs(const std::string& path), rather than
63     SVN::instance(void), before using any other subversion related
64     classes or calls. Best practice is to initilize the singleton
65     object early in the main program. The logic behind this
66     requirement is that all subverison related classes and calls
67     expect that repository and WC access is properly set up at
68     initialization. However, most functionality is available
69     irrespectively which instance call is made.
70
71     \see Design Patterns (the singleton pattern). Subversion API
72     documents, SVN::instancs(void), SVN::instancs(const
73     std::string&).
74  */
75  class SVN {
76  public:
77
78    enum vc_status {
79      unversioned=0,
80      uptodate,
81      unresolved
82    };
83
84    /**
85       \brief Call the underlying svn_client_blame3 for \a path with
86       \a receiver and \a baton.
87
88       This function is called from SVNblame to do 'svn blame' on an
89       item. The \a receiver and \a baton is defined in SVNblame and
90       the \a receiver is called by the underlying subversion API for
91       every line in \a path provided it the item is under subversion
92       control. The \a baton is used to communicate anonymous
93       information through the API to the \a receiver. If \a path is a
94       binary object an error is returned, all other errors will
95       generate an SVNException.
96
97       \a path can be either a URL or an WC target.
98
99       \return SVN_NO_ERROR or SVN_ERR_CLIENT_IS_BINARY_FILE, the
100       latter can be used to trigger on binary files. Note that errors
101       return from underlying subversion API must be cleared by the
102       receiver.
103
104       \see Subversion API (svn_error_clear).
105    */
106    svn_error_t * client_blame(const std::string& path,
107                               svn_client_blame_receiver_t receiver,
108                               void *baton);
109
110    /**
111       \brief Same as function above with the extension that revision
112       \a rev can be set.
113     */
114    svn_error_t * client_blame(const std::string& path,
115                               svn_client_blame_receiver_t receiver,
116                               void *baton, svn_revnum_t rev);
117
118    /**
119       \brief Call the underlying svn_client_info for \a path with \a
120       receiver and \a baton.
121
122       This function is called from SVNinfo to do 'svn info' on an
123       item. The \a receiver and \a baton is defined in SVNinfo and
124       the \a receiver is called by the underlying subversion API if
125       \a path is under subversion control. The \a baton is used to
126       communicate anonymous information through the API to the \a
127       receiver.
128
129       \a path can be either a URL or an WC target.
130
131       \see Subversion API documentation, SVNinfo
132    */
133    void client_info(const std::string& path, svn_info_receiver_t receiver,
134                     void *baton);
135
136    /**
137       \a path can be either a URL or an WC target.
138
139       \todo doc
140    */
141    void client_log(const std::string& path, svn_log_message_receiver_t receiver,
142                    void *baton);
143
144    /**
145       \brief Get the subversion properties for \a path.
146
147       The retrieved properties are stored in \a properties. To check
148       whether \a is a binary item use SVNproperty::binary(void).
149
150       \a path can be either a URL or an WC target.
151    */
152    void client_proplist(const std::string& path,
153                         std::map<std::string, std::string>& properties);
154
155    /**
156       \brief Get an instance of SVN.
157
158       The singleton SVN object should be initialized with
159       SVN::instancs(const std::string&) before usage of this
160       function. Best practice is to initilize the singleton object
161       early in the main program. The logic behind this requirement is
162       that subverison related classes and calls may expect that
163       repository and WC access is properly set up at initialization.
164
165       \throw An SVNException if the singleton SVN onject is not
166       already initilized.
167
168       \see SVN::instancs(const std::string&)
169    */
170    static SVN* instance(void);
171
172    /**
173       \brief Get an instance of SVN setup against repository pointed
174       to by \a path.
175
176       The singleton SVN object should be initialized with this
177       instance call before any subversion related classes or calls
178       are made. Best practice is to initilize the singleton object
179       early in the main program. The logic behind this requirement is
180       that subverison related classes and calls may expect that
181       repository and WC access is properly set up at initialization.
182
183       \throw Throws an SVNException if initialization fails in the
184       underlying subversion API calls, or if \a path is a URL.
185    */
186    static SVN* instance(const std::string& path);
187
188    /**
189       \brief Set up a repository access session.
190
191       \throws SVNException if session setup fails, or if a session is
192       already set up (i.e., repository cannot be changed during
193       program lifetime).
194    */
195    //    void setup_ra_session(const std::string& path);
196
197    ///
198    /// @brief Check if entry \a path is under version control
199    ///
200    /// @return True if \a path is under version control, false
201    /// otherwise.
202    ///
203    vc_status version_controlled(const std::string& path);
204
205  private:
206    /**
207       \brief Constructor
208
209       The only way to create an object of SVN type is by calling
210       SVN::instance(const std::string&). \a path must be a WC path,
211       i.e., not a URL.
212    */
213    SVN(const std::string& path);
214
215    ///
216    /// @brief Copy Constructor, not implemented.
217    ///
218    SVN(const SVN&);
219    SVN& operator=(const SVN&);
220
221    ///
222    /// @brief The destructor.
223    ///
224    virtual ~SVN(void);
225
226    /**
227       @brief Free resources when svn API calls fail.
228
229       This function will write an error message to stdout, free \a
230       err and \a pool resources. If \a err or \a pool are a NULL
231       pointers the function will do nothing with these resources. If
232       \a mute is true, no error message is written.
233
234       cleanup will throw a SVNException if \a message has
235       length>0. The default bahaviour is to free resources and return
236       normally.
237
238       @see SVNException
239    */
240    void cleanup(svn_error_t *err, apr_pool_t *pool,
241                 std::string message=std::string(), bool mute=false);
242
243    /**
244       @brief Free resources when failing to reach end of
245       constructor.
246
247       cleanup_failed_init will free all resource acquired in the
248       constructor and throw an SVNException with \a message as the
249       message.
250
251       @see SVNException
252    */
253    void cleanup_failed_init(svn_error_t *err, const std::string& message,
254                             bool mute=false);
255
256    static SVN* instance_;
257
258    // Subversion API stuff
259
260    /**
261       the url is fech with svn info. The ursl is stored in a
262       url_receiver_baton. The struct is filled in the url_receiver
263       function.
264    */
265    struct root_url_receiver_baton {
266      std::string path;
267    };
268
269    /**
270       url_receiver is the function passed to the underlying
271       subversion API call svn_client_info. This function is called by
272       the subversion API for every item matched by the conditions of
273       the API call.
274
275       \see Subversion API documentation
276    */
277    static svn_error_t*
278    root_url_receiver(void *baton, const char *path, const svn_info_t *info,
279                      apr_pool_t *pool);
280
281    svn_error_t* client_blame_call(const std::string& path,
282                                   svn_client_blame_receiver_t receiver,
283                                   void *baton, svn_opt_revision_t& head);
284
285    svn_wc_adm_access_t* adm_access_;
286    apr_allocator_t* allocator_;
287    svn_client_ctx_t* context_;
288    apr_pool_t* pool_;
289    svn_ra_session_t* ra_session_;
290  };
291
292}} // end of namespace svndigest and namespace theplu
293
294#endif
Note: See TracBrowser for help on using the repository browser.