source: trunk/lib/SVN.h @ 579

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

Merged patch release 0.6.5 to the trunk. Delta 0.6.5 - 0.6.4

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