91 |
23 Mar 06 |
jari |
// $Id$ |
91 |
23 Mar 06 |
jari |
2 |
|
91 |
23 Mar 06 |
jari |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen |
978 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2012, 2015, 2023 Peter Johansson |
91 |
23 Mar 06 |
jari |
7 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
91 |
23 Mar 06 |
jari |
9 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
91 |
23 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
91 |
23 Mar 06 |
jari |
(at your option) any later version. |
91 |
23 Mar 06 |
jari |
14 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
91 |
23 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
91 |
23 Mar 06 |
jari |
General Public License for more details. |
91 |
23 Mar 06 |
jari |
19 |
|
91 |
23 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
91 |
23 Mar 06 |
jari |
22 |
*/ |
91 |
23 Mar 06 |
jari |
23 |
|
1619 |
12 Mar 23 |
peter |
24 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
25 |
|
91 |
23 Mar 06 |
jari |
26 |
#include "SVN.h" |
91 |
23 Mar 06 |
jari |
27 |
|
1547 |
20 Oct 12 |
peter |
28 |
#include "utility.h" |
1547 |
20 Oct 12 |
peter |
29 |
|
185 |
06 Sep 06 |
jari |
30 |
#include <map> |
91 |
23 Mar 06 |
jari |
31 |
#include <string> |
185 |
06 Sep 06 |
jari |
32 |
#include <vector> |
140 |
04 Aug 06 |
jari |
33 |
|
642 |
31 May 08 |
peter |
34 |
#include <cassert> |
225 |
11 Mar 07 |
peter |
35 |
|
140 |
04 Aug 06 |
jari |
36 |
#include <apr_allocator.h> |
91 |
23 Mar 06 |
jari |
37 |
#include <apr_hash.h> |
164 |
23 Aug 06 |
jari |
38 |
#include <subversion-1/svn_client.h> |
164 |
23 Aug 06 |
jari |
39 |
#include <subversion-1/svn_cmdline.h> |
164 |
23 Aug 06 |
jari |
40 |
#include <subversion-1/svn_path.h> |
164 |
23 Aug 06 |
jari |
41 |
#include <subversion-1/svn_pools.h> |
164 |
23 Aug 06 |
jari |
42 |
#include <subversion-1/svn_wc.h> |
185 |
06 Sep 06 |
jari |
43 |
#include <subversion-1/svn_subst.h> |
91 |
23 Mar 06 |
jari |
44 |
|
1215 |
09 Oct 10 |
peter |
45 |
#include <string> |
1215 |
09 Oct 10 |
peter |
46 |
|
1547 |
20 Oct 12 |
peter |
47 |
#include <iostream> |
91 |
23 Mar 06 |
jari |
48 |
namespace theplu { |
149 |
12 Aug 06 |
jari |
49 |
namespace svndigest { |
91 |
23 Mar 06 |
jari |
50 |
|
91 |
23 Mar 06 |
jari |
51 |
|
1215 |
09 Oct 10 |
peter |
52 |
SVNException::SVNException(const std::string& msg, svn_error_t* error) |
1373 |
10 Jun 11 |
peter |
53 |
: std::runtime_error(""), error_(error) |
1219 |
12 Oct 10 |
peter |
54 |
{ |
1219 |
12 Oct 10 |
peter |
55 |
ref_count_ = new int(1); |
1221 |
13 Oct 10 |
peter |
56 |
if (error_) { |
1221 |
13 Oct 10 |
peter |
57 |
apr_size_t bufsize=255; |
1221 |
13 Oct 10 |
peter |
58 |
char buf[255]; |
1221 |
13 Oct 10 |
peter |
59 |
msg_ = svn_err_best_message(error_, buf, bufsize); |
1221 |
13 Oct 10 |
peter |
60 |
} |
1221 |
13 Oct 10 |
peter |
61 |
if (msg.size()) { |
1610 |
11 Feb 23 |
peter |
62 |
msg_ += ". "; |
1221 |
13 Oct 10 |
peter |
63 |
msg_ += msg; |
1221 |
13 Oct 10 |
peter |
64 |
} |
1219 |
12 Oct 10 |
peter |
65 |
} |
1215 |
09 Oct 10 |
peter |
66 |
|
1219 |
12 Oct 10 |
peter |
67 |
SVNException::SVNException(const SVNException& other) |
1219 |
12 Oct 10 |
peter |
68 |
: std::runtime_error(other), error_(other.error_), msg_(other.msg_), |
1219 |
12 Oct 10 |
peter |
69 |
ref_count_(other.ref_count_) |
1219 |
12 Oct 10 |
peter |
70 |
{ |
1219 |
12 Oct 10 |
peter |
71 |
++(*ref_count_); |
1219 |
12 Oct 10 |
peter |
72 |
} |
1215 |
09 Oct 10 |
peter |
73 |
|
1215 |
09 Oct 10 |
peter |
74 |
|
1513 |
23 Sep 12 |
peter |
75 |
SVNException::~SVNException(void) throw() |
1219 |
12 Oct 10 |
peter |
76 |
{ |
1221 |
13 Oct 10 |
peter |
77 |
--(*ref_count_); |
1221 |
13 Oct 10 |
peter |
78 |
if (!(*ref_count_)) { |
1219 |
12 Oct 10 |
peter |
79 |
delete ref_count_; |
1219 |
12 Oct 10 |
peter |
80 |
ref_count_=NULL; |
1219 |
12 Oct 10 |
peter |
81 |
svn_error_clear(error_); |
1219 |
12 Oct 10 |
peter |
82 |
error_=SVN_NO_ERROR; |
1219 |
12 Oct 10 |
peter |
83 |
} |
1219 |
12 Oct 10 |
peter |
84 |
} |
1215 |
09 Oct 10 |
peter |
85 |
|
1219 |
12 Oct 10 |
peter |
86 |
|
1215 |
09 Oct 10 |
peter |
87 |
const char* SVNException::what(void) const throw() |
1215 |
09 Oct 10 |
peter |
88 |
{ |
1221 |
13 Oct 10 |
peter |
89 |
return msg_.c_str(); |
1215 |
09 Oct 10 |
peter |
90 |
} |
1215 |
09 Oct 10 |
peter |
91 |
|
1215 |
09 Oct 10 |
peter |
92 |
|
1215 |
09 Oct 10 |
peter |
93 |
const svn_error_t* SVNException::error(void) const |
1215 |
09 Oct 10 |
peter |
94 |
{ |
1215 |
09 Oct 10 |
peter |
95 |
return error_; |
1215 |
09 Oct 10 |
peter |
96 |
} |
1215 |
09 Oct 10 |
peter |
97 |
|
1215 |
09 Oct 10 |
peter |
98 |
|
91 |
23 Mar 06 |
jari |
99 |
SVN* SVN::instance_=NULL; |
91 |
23 Mar 06 |
jari |
100 |
|
91 |
23 Mar 06 |
jari |
101 |
|
318 |
18 May 07 |
jari |
102 |
SVN::SVN(const std::string& path) |
91 |
23 Mar 06 |
jari |
103 |
: adm_access_(NULL), allocator_(NULL), context_(NULL), pool_(NULL) |
91 |
23 Mar 06 |
jari |
104 |
{ |
123 |
29 Jul 06 |
jari |
105 |
svn_error_t* err=NULL; |
123 |
29 Jul 06 |
jari |
106 |
|
1579 |
23 Feb 15 |
peter |
// From http://subversion.apache.org: Applications using the |
1579 |
23 Feb 15 |
peter |
// Subversion libraries must call apr_initialize() before calling |
1579 |
23 Feb 15 |
peter |
// any Subversion functions. |
1579 |
23 Feb 15 |
peter |
110 |
apr_initialize(); |
1579 |
23 Feb 15 |
peter |
111 |
|
1579 |
23 Feb 15 |
peter |
// The subversion API documentation says that svn_cmdline_init |
1579 |
23 Feb 15 |
peter |
// will iSet up the locale for character conversion, and |
1579 |
23 Feb 15 |
peter |
// initialize APR". The documentation goes on to say that this |
1579 |
23 Feb 15 |
peter |
// function should only be called once before any other APR and |
1579 |
23 Feb 15 |
peter |
// subversion functions. This of course is in conflict with the |
1579 |
23 Feb 15 |
peter |
// apr_initialize() recommendation above. |
149 |
12 Aug 06 |
jari |
118 |
if (svn_cmdline_init("svndigest",stderr) != EXIT_SUCCESS) |
318 |
18 May 07 |
jari |
119 |
throw SVNException("SVN: svn_cmdline_init failed"); |
91 |
23 Mar 06 |
jari |
120 |
|
91 |
23 Mar 06 |
jari |
/// create top-level pool |
91 |
23 Mar 06 |
jari |
122 |
if (apr_allocator_create(&allocator_)) |
318 |
18 May 07 |
jari |
123 |
throw SVNException("SVN(_allocator_create failed"); |
91 |
23 Mar 06 |
jari |
124 |
apr_allocator_max_free_set(allocator_,SVN_ALLOCATOR_RECOMMENDED_MAX_FREE); |
91 |
23 Mar 06 |
jari |
125 |
pool_ = svn_pool_create_ex(NULL, allocator_); |
91 |
23 Mar 06 |
jari |
126 |
apr_allocator_owner_set(allocator_, pool_); |
91 |
23 Mar 06 |
jari |
127 |
|
91 |
23 Mar 06 |
jari |
// initialize the repository access library |
191 |
07 Sep 06 |
jari |
129 |
if ((err=svn_ra_initialize(pool_))) |
318 |
18 May 07 |
jari |
130 |
cleanup_failed_init(err, "SVN: svn_ra_initialize failed"); |
91 |
23 Mar 06 |
jari |
131 |
|
91 |
23 Mar 06 |
jari |
// Check that users .subversion exist. Should this really be done? |
91 |
23 Mar 06 |
jari |
// If this check is to be done, we might be forced to support a |
91 |
23 Mar 06 |
jari |
// command line option to change the location of the .subversion |
91 |
23 Mar 06 |
jari |
// stuff (compare with the svn binary). |
191 |
07 Sep 06 |
jari |
136 |
if ((err=svn_config_ensure(NULL, pool_))) |
318 |
18 May 07 |
jari |
137 |
cleanup_failed_init(err, "SVN: svn_config_ensure failed"); |
91 |
23 Mar 06 |
jari |
138 |
|
91 |
23 Mar 06 |
jari |
// create a client context object |
191 |
07 Sep 06 |
jari |
140 |
if ((err=svn_client_create_context(&context_, pool_))) |
318 |
18 May 07 |
jari |
141 |
cleanup_failed_init(err, "SVN: svn_client_create_context failed"); |
91 |
23 Mar 06 |
jari |
142 |
|
191 |
07 Sep 06 |
jari |
143 |
if ((err=svn_config_get_config(&(context_->config), NULL, pool_))) |
318 |
18 May 07 |
jari |
144 |
cleanup_failed_init(err, "SVN: svn_config_get_config failed"); |
91 |
23 Mar 06 |
jari |
145 |
|
91 |
23 Mar 06 |
jari |
// set up authentication stuff |
91 |
23 Mar 06 |
jari |
147 |
if ((err=svn_cmdline_setup_auth_baton(&(context_->auth_baton), false, NULL, |
91 |
23 Mar 06 |
jari |
148 |
NULL, NULL, false, |
191 |
07 Sep 06 |
jari |
149 |
static_cast<svn_config_t*>(apr_hash_get(context_->config, |
91 |
23 Mar 06 |
jari |
150 |
SVN_CONFIG_CATEGORY_CONFIG, |
91 |
23 Mar 06 |
jari |
151 |
APR_HASH_KEY_STRING)), |
91 |
23 Mar 06 |
jari |
152 |
context_->cancel_func, |
191 |
07 Sep 06 |
jari |
153 |
context_->cancel_baton, pool_))) |
318 |
18 May 07 |
jari |
154 |
cleanup_failed_init(err, "SVN: svn_cmdline_setup_auth_baton failed"); |
318 |
18 May 07 |
jari |
155 |
|
318 |
18 May 07 |
jari |
// Set up svn administration area access. The whole structure is |
318 |
18 May 07 |
jari |
// setup, maybe this is unnecessary? |
318 |
18 May 07 |
jari |
158 |
const char* canonical_path=svn_path_internal_style(path.c_str(), pool_); |
1547 |
20 Oct 12 |
peter |
159 |
abs_wc_root_path_ = absolute_path(canonical_path); |
579 |
18 Mar 08 |
peter |
160 |
if ((err=svn_wc_adm_open3(&adm_access_, NULL, canonical_path, |
579 |
18 Mar 08 |
peter |
161 |
false, -1, context_->cancel_func, |
579 |
18 Mar 08 |
peter |
162 |
context_->cancel_baton, pool_))){ |
579 |
18 Mar 08 |
peter |
163 |
if (err->apr_err == SVN_ERR_WC_NOT_DIRECTORY) |
1217 |
10 Oct 10 |
peter |
164 |
cleanup_failed_init(err, std::string(err->message)); |
318 |
18 May 07 |
jari |
165 |
cleanup_failed_init(err, "SVN: svn_wc_adm_open3 failed"); |
579 |
18 Mar 08 |
peter |
166 |
} |
318 |
18 May 07 |
jari |
167 |
|
318 |
18 May 07 |
jari |
// get a session to the repository |
1547 |
20 Oct 12 |
peter |
169 |
struct url_receiver_baton urb; |
1547 |
20 Oct 12 |
peter |
170 |
client_info(path, url_receiver, static_cast<void*>(&urb)); |
579 |
18 Mar 08 |
peter |
171 |
if ((err=svn_client_open_ra_session(&ra_session_, |
1547 |
20 Oct 12 |
peter |
172 |
urb.root_url.c_str(), |
579 |
18 Mar 08 |
peter |
173 |
context_, pool_))) |
318 |
18 May 07 |
jari |
174 |
cleanup_failed_init(err, "SVN: svn_client_open_ra_session failed"); |
1547 |
20 Oct 12 |
peter |
175 |
|
1547 |
20 Oct 12 |
peter |
// extract and store URL relative to root URL |
1547 |
20 Oct 12 |
peter |
177 |
relative_url_ = relative_path(urb.url, urb.root_url); |
91 |
23 Mar 06 |
jari |
178 |
} |
91 |
23 Mar 06 |
jari |
179 |
|
91 |
23 Mar 06 |
jari |
180 |
|
91 |
23 Mar 06 |
jari |
181 |
SVN::~SVN(void) |
91 |
23 Mar 06 |
jari |
182 |
{ |
140 |
04 Aug 06 |
jari |
183 |
if (adm_access_) |
140 |
04 Aug 06 |
jari |
184 |
svn_error_clear(svn_wc_adm_close(adm_access_)); |
91 |
23 Mar 06 |
jari |
185 |
svn_pool_destroy(pool_); |
579 |
18 Mar 08 |
peter |
186 |
pool_=NULL; |
91 |
23 Mar 06 |
jari |
// other apr resources acquired in svn_cmdline_init are destroyed |
91 |
23 Mar 06 |
jari |
// at program exit, ok since SVN is a singleton |
91 |
23 Mar 06 |
jari |
189 |
} |
91 |
23 Mar 06 |
jari |
190 |
|
91 |
23 Mar 06 |
jari |
191 |
|
1546 |
13 Oct 12 |
peter |
192 |
void SVN::cleanup_failed_init(svn_error_t *err, const std::string& message) |
318 |
18 May 07 |
jari |
193 |
{ |
1546 |
13 Oct 12 |
peter |
194 |
assert(message.size()); // compatible with r1213 |
1546 |
13 Oct 12 |
peter |
195 |
svn_error_clear(err); |
1546 |
13 Oct 12 |
peter |
196 |
if (pool_) { |
1546 |
13 Oct 12 |
peter |
197 |
svn_pool_destroy(pool_); |
1546 |
13 Oct 12 |
peter |
198 |
pool_=NULL; |
579 |
18 Mar 08 |
peter |
199 |
} |
1214 |
09 Oct 10 |
peter |
200 |
throw SVNException(message); |
318 |
18 May 07 |
jari |
201 |
} |
318 |
18 May 07 |
jari |
202 |
|
318 |
18 May 07 |
jari |
203 |
|
1218 |
10 Oct 10 |
peter |
204 |
void SVN::client_blame(const std::string& path, |
1218 |
10 Oct 10 |
peter |
205 |
svn_client_blame_receiver_t receiver, |
1218 |
10 Oct 10 |
peter |
206 |
void *baton, svn_revnum_t rev) |
501 |
19 Oct 07 |
peter |
207 |
{ |
501 |
19 Oct 07 |
peter |
208 |
svn_opt_revision_t head; |
501 |
19 Oct 07 |
peter |
209 |
head.kind=svn_opt_revision_number; |
501 |
19 Oct 07 |
peter |
210 |
head.value.number=rev; |
1218 |
10 Oct 10 |
peter |
211 |
client_blame_call(path, receiver, baton, head); |
501 |
19 Oct 07 |
peter |
212 |
} |
501 |
19 Oct 07 |
peter |
213 |
|
1218 |
10 Oct 10 |
peter |
214 |
void SVN::client_blame(const std::string& path, |
1218 |
10 Oct 10 |
peter |
215 |
svn_client_blame_receiver_t receiver, |
1218 |
10 Oct 10 |
peter |
216 |
void *baton) |
138 |
03 Aug 06 |
jari |
217 |
{ |
501 |
19 Oct 07 |
peter |
218 |
svn_opt_revision_t head; |
501 |
19 Oct 07 |
peter |
219 |
head.kind = ( svn_path_is_url(path.c_str()) ? |
501 |
19 Oct 07 |
peter |
220 |
svn_opt_revision_head : svn_opt_revision_base ); |
1218 |
10 Oct 10 |
peter |
221 |
client_blame_call(path, receiver, baton, head); |
501 |
19 Oct 07 |
peter |
222 |
} |
501 |
19 Oct 07 |
peter |
223 |
|
501 |
19 Oct 07 |
peter |
224 |
|
1218 |
10 Oct 10 |
peter |
225 |
void SVN::client_blame_call(const std::string& path, |
1218 |
10 Oct 10 |
peter |
226 |
svn_client_blame_receiver_t receiver, |
1218 |
10 Oct 10 |
peter |
227 |
void *baton, svn_opt_revision_t& head) |
501 |
19 Oct 07 |
peter |
228 |
{ |
138 |
03 Aug 06 |
jari |
// Setup to use all revisions |
501 |
19 Oct 07 |
peter |
230 |
svn_opt_revision_t peg, start; |
138 |
03 Aug 06 |
jari |
231 |
peg.kind=svn_opt_revision_unspecified; |
138 |
03 Aug 06 |
jari |
232 |
start.kind=svn_opt_revision_number; |
138 |
03 Aug 06 |
jari |
233 |
start.value.number=0; |
1546 |
13 Oct 12 |
peter |
234 |
AprPool subpool(pool_); |
1546 |
13 Oct 12 |
peter |
235 |
svn_error_t* err = |
1546 |
13 Oct 12 |
peter |
236 |
svn_client_blame3(path.c_str(), &peg, &start, &head, |
1546 |
13 Oct 12 |
peter |
237 |
svn_diff_file_options_create(subpool.get()), |
1546 |
13 Oct 12 |
peter |
238 |
false, receiver, baton, context_, |
1546 |
13 Oct 12 |
peter |
239 |
subpool.get()); |
1218 |
10 Oct 10 |
peter |
240 |
if (err) |
1546 |
13 Oct 12 |
peter |
241 |
throw SVNException("SVN::client_blame: svn_client_blame3 failed", err); |
138 |
03 Aug 06 |
jari |
242 |
} |
138 |
03 Aug 06 |
jari |
243 |
|
138 |
03 Aug 06 |
jari |
244 |
|
1547 |
20 Oct 12 |
peter |
245 |
void SVN::client_cat(const std::string& path, svn_revnum_t rev, |
1547 |
20 Oct 12 |
peter |
246 |
std::string& result) |
1547 |
20 Oct 12 |
peter |
247 |
{ |
1547 |
20 Oct 12 |
peter |
248 |
AprPool subpool(pool_); |
1610 |
11 Feb 23 |
peter |
249 |
AprPool scratchpool(pool_); |
1547 |
20 Oct 12 |
peter |
250 |
svn_stringbuf_t* str = svn_stringbuf_create("", subpool.get()); |
1547 |
20 Oct 12 |
peter |
251 |
assert(str); |
1547 |
20 Oct 12 |
peter |
252 |
svn_stream_t* out = svn_stream_from_stringbuf(str, subpool.get()); |
1547 |
20 Oct 12 |
peter |
253 |
assert(out); |
1547 |
20 Oct 12 |
peter |
254 |
|
1547 |
20 Oct 12 |
peter |
255 |
svn_error_t* err = NULL; |
1547 |
20 Oct 12 |
peter |
256 |
|
1610 |
11 Feb 23 |
peter |
257 |
svn_opt_revision_t peg; |
1610 |
11 Feb 23 |
peter |
258 |
peg.kind = svn_opt_revision_unspecified; |
1610 |
11 Feb 23 |
peter |
259 |
svn_opt_revision_t revision; |
1610 |
11 Feb 23 |
peter |
260 |
revision.kind = svn_opt_revision_number; |
1610 |
11 Feb 23 |
peter |
261 |
revision.value.number = rev; |
1547 |
20 Oct 12 |
peter |
262 |
|
1610 |
11 Feb 23 |
peter |
263 |
err = svn_client_cat3(NULL, out, path.c_str(), &peg, &revision, |
1610 |
11 Feb 23 |
peter |
264 |
false, context_, subpool.get(), scratchpool.get()); |
1547 |
20 Oct 12 |
peter |
265 |
|
1547 |
20 Oct 12 |
peter |
266 |
if (err) |
1610 |
11 Feb 23 |
peter |
267 |
throw SVNException("client_cat failed", err); |
1547 |
20 Oct 12 |
peter |
268 |
|
1547 |
20 Oct 12 |
peter |
// copy to result |
1547 |
20 Oct 12 |
peter |
270 |
result = std::string(str->data, str->len); |
1547 |
20 Oct 12 |
peter |
271 |
} |
1547 |
20 Oct 12 |
peter |
272 |
|
1547 |
20 Oct 12 |
peter |
273 |
|
140 |
04 Aug 06 |
jari |
274 |
void SVN::client_info(const std::string& path, svn_info_receiver_t receiver, |
140 |
04 Aug 06 |
jari |
275 |
void *baton) |
140 |
04 Aug 06 |
jari |
276 |
{ |
1546 |
13 Oct 12 |
peter |
277 |
AprPool subpool(pool_); |
140 |
04 Aug 06 |
jari |
278 |
if (svn_error_t *err=svn_client_info(path.c_str(), NULL, NULL, receiver, |
1546 |
13 Oct 12 |
peter |
279 |
baton, false, context_,subpool.get())) |
1546 |
13 Oct 12 |
peter |
280 |
throw SVNException("repository: svn_client_info failed", err); |
140 |
04 Aug 06 |
jari |
281 |
} |
140 |
04 Aug 06 |
jari |
282 |
|
140 |
04 Aug 06 |
jari |
283 |
|
318 |
18 May 07 |
jari |
284 |
void SVN::client_log(const std::string& path, |
318 |
18 May 07 |
jari |
285 |
svn_log_message_receiver_t receiver, void *baton) |
318 |
18 May 07 |
jari |
286 |
{ |
318 |
18 May 07 |
jari |
// Allocate space in subpool to pool_ for apr_path (here a string). |
1546 |
13 Oct 12 |
peter |
288 |
AprPool subpool(pool_); |
1546 |
13 Oct 12 |
peter |
289 |
apr_array_header_t* apr_path=apr_array_make(subpool.get(),1,4); |
318 |
18 May 07 |
jari |
// Copy path to apr_path. |
318 |
18 May 07 |
jari |
291 |
(*((const char **) apr_array_push(apr_path))) = |
1546 |
13 Oct 12 |
peter |
292 |
apr_pstrdup(subpool.get(), |
1546 |
13 Oct 12 |
peter |
293 |
svn_path_internal_style(path.c_str(), subpool.get())); |
318 |
18 May 07 |
jari |
294 |
|
318 |
18 May 07 |
jari |
// Setup to retrieve all commit logs. |
318 |
18 May 07 |
jari |
296 |
svn_opt_revision_t peg, start, head; |
318 |
18 May 07 |
jari |
297 |
peg.kind=svn_opt_revision_unspecified; |
318 |
18 May 07 |
jari |
298 |
start.kind=svn_opt_revision_number; |
318 |
18 May 07 |
jari |
299 |
start.value.number=0; |
318 |
18 May 07 |
jari |
300 |
head.kind = ( svn_path_is_url(path.c_str()) ? |
318 |
18 May 07 |
jari |
301 |
svn_opt_revision_head : svn_opt_revision_base ); |
318 |
18 May 07 |
jari |
302 |
svn_error_t* err=NULL; |
318 |
18 May 07 |
jari |
303 |
if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, false, |
1546 |
13 Oct 12 |
peter |
304 |
receiver, baton, context_, subpool.get()))) |
1546 |
13 Oct 12 |
peter |
305 |
throw SVNException("commit_dates: svn_client_log3 failed", err); |
318 |
18 May 07 |
jari |
306 |
} |
318 |
18 May 07 |
jari |
307 |
|
318 |
18 May 07 |
jari |
308 |
|
185 |
06 Sep 06 |
jari |
309 |
void SVN::client_proplist(const std::string& path, |
185 |
06 Sep 06 |
jari |
310 |
std::map<std::string, std::string>& property) |
185 |
06 Sep 06 |
jari |
311 |
{ |
185 |
06 Sep 06 |
jari |
312 |
svn_opt_revision_t peg, revision; |
185 |
06 Sep 06 |
jari |
313 |
peg.kind=svn_opt_revision_unspecified; |
318 |
18 May 07 |
jari |
314 |
revision.kind = ( svn_path_is_url(path.c_str()) ? |
318 |
18 May 07 |
jari |
315 |
svn_opt_revision_head : svn_opt_revision_base ); |
1546 |
13 Oct 12 |
peter |
316 |
AprPool subpool(pool_); |
185 |
06 Sep 06 |
jari |
317 |
apr_array_header_t * properties; |
185 |
06 Sep 06 |
jari |
318 |
svn_error_t *err=svn_client_proplist2(&properties, path.c_str(), &peg, |
1546 |
13 Oct 12 |
peter |
319 |
&revision, false, context_, |
1546 |
13 Oct 12 |
peter |
320 |
subpool.get()); |
191 |
07 Sep 06 |
jari |
321 |
if (err) |
1546 |
13 Oct 12 |
peter |
322 |
throw SVNException("repository: svn_client_proplist2 failed", err); |
191 |
07 Sep 06 |
jari |
323 |
|
185 |
06 Sep 06 |
jari |
324 |
for (int j = 0; j < properties->nelts; ++j) { |
1513 |
23 Sep 12 |
peter |
325 |
svn_client_proplist_item_t *item = |
185 |
06 Sep 06 |
jari |
326 |
((svn_client_proplist_item_t **)properties->elts)[j]; |
1546 |
13 Oct 12 |
peter |
327 |
for (apr_hash_index_t *hi =apr_hash_first(subpool.get(),item->prop_hash); |
1546 |
13 Oct 12 |
peter |
328 |
hi; hi = apr_hash_next (hi)) { |
185 |
06 Sep 06 |
jari |
329 |
const void *key; |
185 |
06 Sep 06 |
jari |
330 |
void *val; |
185 |
06 Sep 06 |
jari |
331 |
apr_hash_this (hi, &key, NULL, &val); |
185 |
06 Sep 06 |
jari |
332 |
svn_string_t *value; |
185 |
06 Sep 06 |
jari |
333 |
err=svn_subst_detranslate_string(&value, |
185 |
06 Sep 06 |
jari |
334 |
static_cast<const svn_string_t*>(val), |
1546 |
13 Oct 12 |
peter |
335 |
false, subpool.get()); |
191 |
07 Sep 06 |
jari |
336 |
if (err) |
1546 |
13 Oct 12 |
peter |
337 |
throw SVNException(path + |
195 |
07 Sep 06 |
jari |
338 |
" property: svn_subst_detranslate_string failed on key " + |
1546 |
13 Oct 12 |
peter |
339 |
static_cast<const char*>(key), err); |
185 |
06 Sep 06 |
jari |
340 |
property[static_cast<const char*>(key)]=value->data; |
185 |
06 Sep 06 |
jari |
341 |
} |
185 |
06 Sep 06 |
jari |
342 |
} |
185 |
06 Sep 06 |
jari |
343 |
} |
185 |
06 Sep 06 |
jari |
344 |
|
185 |
06 Sep 06 |
jari |
345 |
|
318 |
18 May 07 |
jari |
346 |
SVN* SVN::instance(void) |
233 |
26 Mar 07 |
peter |
347 |
{ |
318 |
18 May 07 |
jari |
348 |
if (!instance_) |
318 |
18 May 07 |
jari |
349 |
throw SVNException("SVN::instance(void): SVN singleton not initialized"); |
318 |
18 May 07 |
jari |
350 |
return instance_; |
233 |
26 Mar 07 |
peter |
351 |
} |
233 |
26 Mar 07 |
peter |
352 |
|
233 |
26 Mar 07 |
peter |
353 |
|
318 |
18 May 07 |
jari |
354 |
SVN* SVN::instance(const std::string& url) |
140 |
04 Aug 06 |
jari |
355 |
{ |
318 |
18 May 07 |
jari |
356 |
if (!instance_) { |
318 |
18 May 07 |
jari |
357 |
instance_=new SVN(url); |
318 |
18 May 07 |
jari |
358 |
} |
318 |
18 May 07 |
jari |
359 |
return instance_; |
185 |
06 Sep 06 |
jari |
360 |
} |
185 |
06 Sep 06 |
jari |
361 |
|
185 |
06 Sep 06 |
jari |
362 |
|
1547 |
20 Oct 12 |
peter |
363 |
svn_error_t* SVN::url_receiver(void *baton, const char *, |
1547 |
20 Oct 12 |
peter |
364 |
const svn_info_t *info, apr_pool_t*) |
185 |
06 Sep 06 |
jari |
365 |
{ |
318 |
18 May 07 |
jari |
366 |
if (!info) |
318 |
18 May 07 |
jari |
367 |
throw SVNException(std::string("SVN::url_receriver: ") + |
318 |
18 May 07 |
jari |
368 |
"Failed to acquire an svn info object"); |
140 |
04 Aug 06 |
jari |
369 |
|
1547 |
20 Oct 12 |
peter |
370 |
url_receiver_baton* rurb= |
1547 |
20 Oct 12 |
peter |
371 |
static_cast<struct url_receiver_baton*>(baton); |
318 |
18 May 07 |
jari |
372 |
if (info->repos_root_URL) |
1547 |
20 Oct 12 |
peter |
373 |
rurb->root_url = info->repos_root_URL; |
1547 |
20 Oct 12 |
peter |
374 |
if (info->URL) |
1547 |
20 Oct 12 |
peter |
375 |
rurb->url = info->URL; |
318 |
18 May 07 |
jari |
376 |
return SVN_NO_ERROR; |
123 |
29 Jul 06 |
jari |
377 |
} |
123 |
29 Jul 06 |
jari |
378 |
|
123 |
29 Jul 06 |
jari |
379 |
|
91 |
23 Mar 06 |
jari |
380 |
SVN::vc_status SVN::version_controlled(const std::string& path) |
91 |
23 Mar 06 |
jari |
381 |
{ |
91 |
23 Mar 06 |
jari |
382 |
svn_wc_status2_t* status=NULL; |
1546 |
13 Oct 12 |
peter |
383 |
AprPool subpool(pool_); |
140 |
04 Aug 06 |
jari |
384 |
if (svn_error_t *err= |
1546 |
13 Oct 12 |
peter |
385 |
svn_wc_status2(&status, |
1546 |
13 Oct 12 |
peter |
386 |
svn_path_internal_style(path.c_str(), subpool.get()), |
1546 |
13 Oct 12 |
peter |
387 |
adm_access_, subpool.get())) |
1546 |
13 Oct 12 |
peter |
388 |
throw SVNException("version_controlled(): svn_config_get_config failed", |
1546 |
13 Oct 12 |
peter |
389 |
err); |
91 |
23 Mar 06 |
jari |
390 |
|
91 |
23 Mar 06 |
jari |
391 |
if ((status->text_status==svn_wc_status_none) || |
91 |
23 Mar 06 |
jari |
392 |
(status->text_status==svn_wc_status_unversioned)) |
91 |
23 Mar 06 |
jari |
393 |
return unversioned; |
91 |
23 Mar 06 |
jari |
394 |
else if (status->text_status==svn_wc_status_normal) |
91 |
23 Mar 06 |
jari |
395 |
return uptodate; |
91 |
23 Mar 06 |
jari |
396 |
|
91 |
23 Mar 06 |
jari |
397 |
return unresolved; |
91 |
23 Mar 06 |
jari |
398 |
} |
91 |
23 Mar 06 |
jari |
399 |
|
1544 |
13 Oct 12 |
peter |
400 |
|
1544 |
13 Oct 12 |
peter |
401 |
SVN::AprPool::AprPool(apr_pool_t* pool) |
1544 |
13 Oct 12 |
peter |
402 |
: pool_(NULL) |
1544 |
13 Oct 12 |
peter |
403 |
{ |
1544 |
13 Oct 12 |
peter |
404 |
pool_ = svn_pool_create(pool); |
1544 |
13 Oct 12 |
peter |
405 |
assert(pool_); |
1544 |
13 Oct 12 |
peter |
406 |
} |
1544 |
13 Oct 12 |
peter |
407 |
|
1544 |
13 Oct 12 |
peter |
408 |
|
1544 |
13 Oct 12 |
peter |
409 |
SVN::AprPool::~AprPool(void) |
1544 |
13 Oct 12 |
peter |
410 |
{ |
1544 |
13 Oct 12 |
peter |
411 |
if (pool_) |
1544 |
13 Oct 12 |
peter |
412 |
svn_pool_destroy(pool_); |
1544 |
13 Oct 12 |
peter |
413 |
} |
1544 |
13 Oct 12 |
peter |
414 |
|
1544 |
13 Oct 12 |
peter |
415 |
|
1544 |
13 Oct 12 |
peter |
416 |
apr_pool_t* SVN::AprPool::get(void) |
1544 |
13 Oct 12 |
peter |
417 |
{ |
1544 |
13 Oct 12 |
peter |
418 |
return pool_; |
1544 |
13 Oct 12 |
peter |
419 |
} |
1544 |
13 Oct 12 |
peter |
420 |
|
149 |
12 Aug 06 |
jari |
421 |
}} // end of namespace svndigest and namespace theplu |