source: trunk/lib/SVN.h @ 129

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

Addresses ticket:23. Changed usage of 'svn info' to API calls.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1// $Id: SVN.h 129 2006-08-02 17:56:18Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat 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  svnstat 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_svnstat_svn_
25#define _theplu_svnstat_svn_
26
27#include <stdexcept>
28#include <string>
29#include <vector>
30
31// Jari, most of these can be replaced with forward declarations.
32#include <apr_allocator.h>
33#include <svn_client.h>
34#include <svn_ra.h>
35#include <svn_wc.h>
36
37namespace theplu {
38namespace svnstat {
39
40  ///
41  /// If something goes wrong in the use of the SVN class, a
42  /// SVNException is thrown.
43  ///
44  struct SVNException : public std::runtime_error
45  { inline SVNException(const std::string& msg) : runtime_error(msg) {} };
46
47  ///
48  /// The SVN class is a front end to the subversion API.
49  ///
50  /// SVN provides one single global access point to the underlying
51  /// subversion API and makes sure that there is only one point of
52  /// access for the binary.
53  ///
54  /// @see Design Patterns (the singleton pattern). Subversion API
55  /// documents.
56  ///
57  class SVN {
58  public:
59
60    enum vc_status {
61      unversioned=0,
62      uptodate,
63      unresolved
64    };
65
66    ///
67    /// @brief The destructor.
68    ///
69    ~SVN(void);
70
71    ///
72    /// @Brief Call the underlying svn_client_info for \a path with \a
73    /// receiver and \a baton.
74    ///
75    /// This function is called from SVNinfo to do 'svn info' on an
76    /// item. The \a receiver and \a baton is defined in SVNinfo and
77    /// the \a receiver is called by the underlying subversion API if
78    /// \a path is under subversion control. The \a baton is used to
79    /// communicate anonymous information through the API to the
80    /// \a receiver.
81    ///
82    /// @see Subversion API documentation, SVNinfo
83    ///
84    inline void client_info(const std::string& path,
85                            svn_info_receiver_t receiver, void *baton)
86    {
87      if (svn_client_info(path.c_str(), NULL, NULL, receiver, baton, false,
88                          context_, pool_))
89        throw SVNException("repository: svn_client_info failed");
90    }
91
92    ///
93    /// @brief Get revision dates.
94    ///
95    /// Get dates for all commits to the repository. \a root can be a
96    /// repository path or a path within a working copy. In the latter
97    /// case the corresponding repository will be used to retrieve
98    /// commit dates.
99    ///
100    /// @return Revision dates in a vector where revision is
101    /// implicitly defined by vector index, i.e., element 56 in the
102    /// resulting vector implies revision 56.
103    ///
104    /// @note Currently revision 0 (repositoy creation) is not
105    /// supported.
106    ///
107    /// @throw Various error messages generated from the subversion
108    /// API.
109    ///
110    std::vector<std::string> commit_dates(const std::string& path);
111
112    ///
113    /// @brief Get an instance of SVN.
114    ///
115    /// @throw Throws an SVNException if initialization fails in the
116    /// underlying subversion API calls.
117    ///
118    /// @todo Make sure that the underlying constructor performs
119    /// proper cleanup before throwing an exception.
120    ///
121    static SVN* instance(void)
122    { if (!instance_) instance_=new SVN; return instance_; }
123
124    ///
125    /// @throws SVNException if session setup fails.
126    ///
127    void setup_ra_session(const std::string& path);
128
129    ///
130    /// @throws SVNException if access setup fails.
131    ///
132    void setup_wc_adm_access(const std::string& path);
133
134    ///
135    /// @brief Check if entry \a path is under version control
136    ///
137    /// @return True if \a path is under version control, false
138    /// otherwise.
139    ///
140    vc_status version_controlled(const std::string& path);
141
142
143  private:
144    ///
145    /// @brief Constructor
146    ///
147    /// The only way to create a object of SVN type is by calling
148    /// SVN::instance.
149    ///
150    /// @todo Make sure that proper cleanup is performed before
151    /// throwing an exception.
152    ///
153    SVN(void);
154
155    ///
156    /// @brief Copy Constructor, not implemented.
157    ///
158    SVN(const SVN&);
159
160    static SVN* instance_;
161
162    // Subversion API stuff
163
164    // Log message receiver
165    struct log_receiver_baton {
166      std::vector<std::string> commit_dates;
167    };
168    static svn_error_t *
169    log_message_receiver(void *baton, apr_hash_t *changed_paths,
170                         svn_revnum_t rev, const char *author, const char *date,
171                         const char *msg, apr_pool_t *pool);
172
173    svn_wc_adm_access_t* adm_access_;
174    apr_allocator_t* allocator_;
175    svn_client_ctx_t* context_;
176    apr_pool_t* pool_;
177    svn_ra_session_t* ra_session_;
178  };
179
180}} // end of namespace svnstat and namespace theplu
181
182#endif
Note: See TracBrowser for help on using the repository browser.