source: trunk/lib/SVN.h @ 123

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

Addresses ticket:23. Removed 'svn log' for revision-date extraction.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1// $Id: SVN.h 123 2006-07-29 22:42:54Z 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  class Directory;
41
42  ///
43  /// If something goes wrong in the use of the SVN class, a
44  /// SVNException is thrown.
45  ///
46  struct SVNException : public std::runtime_error
47  { inline SVNException(const std::string& msg) : runtime_error(msg) {} };
48
49  ///
50  /// 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  /// @see Design Patterns (the singleton pattern). Subversion API
57  /// documents.
58  ///
59  class SVN {
60  public:
61
62    enum vc_status {
63      unversioned=0,
64      uptodate,
65      unresolved
66    };
67
68    ///
69    /// @brief The destructor.
70    ///
71    ~SVN(void);
72
73    ///
74    /// @brief Get revision dates.
75    ///
76    /// Get dates for all commits to the repository. \a root can be a
77    /// repository path or a path within a working copy. In the latter
78    /// case the corresponding repository will be used to retrieve
79    /// commit dates.
80    ///
81    /// @return Revision dates in a vector where revision is
82    /// implicitly defined by vector index, i.e., element 56 in the
83    /// resulting vector implies revision 56.
84    ///
85    /// @note Currently revision 0 (repositoy creation) is not
86    /// supported.
87    ///
88    /// @throw Various error messages generated from the subversion
89    /// API.
90    ///
91    std::vector<std::string> commit_dates(const std::string& path);
92
93    ///
94    /// @brief Get an instance of SVN.
95    ///
96    /// @throw Throws an SVNException if initialization fails in the
97    /// underlying subversion API calls.
98    ///
99    /// @todo Make sure that the underlying constructor performs
100    /// proper cleanup before throwing an exception.
101    ///
102    static SVN* instance(void)
103    { if (!instance_) instance_=new SVN; return instance_; }
104
105    ///
106    /// @brief Determine the repository root URL for \a path.
107    ///
108    /// @throws SVNException if repository location cannot be
109    /// determined.
110    ///
111    /// @return The repository root URL.
112    ///
113    std::string repository(const std::string& path);
114
115    ///
116    /// @throws SVNException if session setup fails.
117    ///
118    void setup_ra_session(const std::string& path);
119
120    ///
121    /// @throws SVNException if access setup fails.
122    ///
123    void setup_wc_adm_access(const std::string& path);
124
125    ///
126    /// @brief Check if entry \a path is under version control
127    ///
128    /// @return True if \a path is under version control, false
129    /// otherwise.
130    ///
131    vc_status version_controlled(const std::string& path);
132
133  private:
134    ///
135    /// @brief Constructor
136    ///
137    /// The only way to create a object of SVN type is by calling
138    /// SVN::instance.
139    ///
140    /// @todo Make sure that proper cleanup is performed before
141    /// throwing an exception.
142    ///
143    SVN(void);
144
145    ///
146    /// @brief Copy Constructor, not implemented.
147    ///
148    SVN(const SVN&);
149
150    static SVN* instance_;
151
152    // Subversion API stuff
153
154    // Info receiver
155    struct info_receiver_baton {
156      std::string repos_root_url;
157    };
158    static svn_error_t * info_receiver(void *baton, const char *path,
159                                       const svn_info_t *info, apr_pool_t *pool);
160
161    // Log message receiver
162    struct log_receiver_baton {
163      std::vector<std::string> commit_dates;
164    };
165    static svn_error_t *
166    log_message_receiver(void *baton, apr_hash_t *changed_paths,
167                         svn_revnum_t rev, const char *author, const char *date,
168                         const char *msg, apr_pool_t *pool);
169
170    svn_wc_adm_access_t* adm_access_;
171    apr_allocator_t* allocator_;
172    svn_client_ctx_t* context_;
173    apr_pool_t* pool_;
174    svn_ra_session_t* ra_session_;
175  };
176
177}} // end of namespace svnstat and namespace theplu
178
179#endif
Note: See TracBrowser for help on using the repository browser.