source: trunk/lib/SVN.h @ 163

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

Changed svnstat to svndigest.

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