You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/09/22 00:15:01 UTC
svn commit: r999667 - in /subversion/branches/object-model/subversion:
bindings/c++/ bindings/c++/include/ tests/libsvn++/
Author: hwright
Date: Tue Sep 21 22:15:00 2010
New Revision: 999667
URL: http://svn.apache.org/viewvc?rev=999667&view=rev
Log:
On the object-model branch:
Wrap the client commit API, along with the associated plumbing and tests.
* subversion/bindings/c++/Client.cpp
(commit, commit): New.
* subversion/bindings/c++/Callbacks.cpp:
New.
* subversion/bindings/c++/include/Callback.h:
New.
* subversion/bindings/c++/include/Client.h
(commit, commit): New.
* subversion/bindings/c++/include/Revision.h:
Make the "with revnum" constructor public.
* subversion/bindings/c++/include/Types.h
(CommitInfo): New.
* subversion/bindings/c++/Types.cpp:
New.
* subversion/tests/libsvn++
(svn:ignore): Add 'test-wcs'.
* subversion/tests/libsvn++/client-test.cpp
(REPOS_NAME, WCS_ROOT, WC_PATH): New.
(test_cat, test_checkout): Use the new defines.
(test_checkout, CommitHandler, CommitHandlerEx): New.
(test_funcs): Run the new tests.
Added:
subversion/branches/object-model/subversion/bindings/c++/Callbacks.cpp
subversion/branches/object-model/subversion/bindings/c++/Types.cpp
subversion/branches/object-model/subversion/bindings/c++/include/Callback.h
Modified:
subversion/branches/object-model/subversion/bindings/c++/Client.cpp
subversion/branches/object-model/subversion/bindings/c++/include/Client.h
subversion/branches/object-model/subversion/bindings/c++/include/Revision.h
subversion/branches/object-model/subversion/bindings/c++/include/Types.h
subversion/branches/object-model/subversion/tests/libsvn++/ (props changed)
subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp
Added: subversion/branches/object-model/subversion/bindings/c++/Callbacks.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Callbacks.cpp?rev=999667&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Callbacks.cpp (added)
+++ subversion/branches/object-model/subversion/bindings/c++/Callbacks.cpp Tue Sep 21 22:15:00 2010
@@ -0,0 +1,58 @@
+/**
+ * @copyright
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ */
+
+#include "Pool.h"
+#include "Core.h"
+#include "Types.h"
+#include "Common.h"
+#include "Callback.h"
+
+#include "svn_error.h"
+#include "svn_pools.h"
+
+#include <iostream>
+
+namespace SVN {
+
+namespace Callback {
+
+svn_error_t *
+Commit::callback(const svn_commit_info_t *commit_info,
+ void *baton, apr_pool_t *pool)
+{
+ if (baton)
+ try
+ {
+ reinterpret_cast<Commit *>(baton)->sendInfo(CommitInfo(commit_info));
+ }
+ catch (Exception ex)
+ {
+ return ex.c_err();
+ }
+
+ return SVN_NO_ERROR;
+}
+
+}
+}
Modified: subversion/branches/object-model/subversion/bindings/c++/Client.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Client.cpp?rev=999667&r1=999666&r2=999667&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Client.cpp (original)
+++ subversion/branches/object-model/subversion/bindings/c++/Client.cpp Tue Sep 21 22:15:00 2010
@@ -88,4 +88,30 @@ Client::checkout(const std::string &url,
return Revision::getNumberRev(result_rev);
}
+void
+Client::commit(const std::vector<std::string> &targets,
+ Callback::Commit &callback)
+{
+ commit(targets, svn_depth_infinity, false, false, std::vector<std::string>(),
+ PropTable(), callback);
+}
+
+void
+Client::commit(const std::vector<std::string> &targets,
+ svn_depth_t depth, bool keep_locks, bool keep_changelists,
+ const std::vector<std::string> &changelists,
+ const PropTable &revprop_table,
+ Callback::Commit &callback)
+{
+ Pool pool;
+
+ SVN_CPP_ERR(svn_client_commit5(
+ Private::Utility::make_string_array(targets, pool),
+ depth, keep_locks, keep_changelists,
+ Private::Utility::make_string_array(changelists, pool),
+ Private::Utility::make_prop_table(revprop_table, pool),
+ Callback::Commit::callback, &callback,
+ m_ctx, pool.pool()));
+}
+
}
Added: subversion/branches/object-model/subversion/bindings/c++/Types.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Types.cpp?rev=999667&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Types.cpp (added)
+++ subversion/branches/object-model/subversion/bindings/c++/Types.cpp Tue Sep 21 22:15:00 2010
@@ -0,0 +1,45 @@
+/**
+ * @copyright
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#include "Common.h"
+#include "Pool.h"
+#include "Types.h"
+
+#include "svn_time.h"
+
+namespace SVN
+{
+
+CommitInfo::CommitInfo(const svn_commit_info_t *info)
+ : m_author(info->author),
+ m_post_commit_err(info->post_commit_err == NULL ? ""
+ : info->post_commit_err),
+ m_repos_root(info->repos_root == NULL ? "" : info->repos_root),
+ m_revision(info->revision)
+{
+ Pool pool;
+
+ SVN_CPP_ERR(svn_time_from_cstring(&m_date, info->date, pool.pool()));
+}
+
+}
Added: subversion/branches/object-model/subversion/bindings/c++/include/Callback.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Callback.h?rev=999667&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Callback.h (added)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Callback.h Tue Sep 21 22:15:00 2010
@@ -0,0 +1,51 @@
+/**
+ * @copyright
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#ifndef CALLBACK_H
+#define CALLBACK_H
+
+#include "Types.h"
+
+#include "svn_error.h"
+
+namespace SVN
+{
+
+class CommitInfo;
+
+namespace Callback
+{
+
+class Commit
+{
+ public:
+ virtual void sendInfo(const CommitInfo &info) = 0;
+
+ static svn_error_t *callback(const svn_commit_info_t *commit_info,
+ void *baton, apr_pool_t *pool);
+};
+
+}
+}
+
+#endif // CALLBACK_H
Modified: subversion/branches/object-model/subversion/bindings/c++/include/Client.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Client.h?rev=999667&r1=999666&r2=999667&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Client.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Client.h Tue Sep 21 22:15:00 2010
@@ -27,6 +27,9 @@
#ifndef CLIENT_H
#define CLIENT_H
+#include "Types.h"
+#include "Common.h"
+#include "Callback.h"
#include "Version.h"
#include "Revision.h"
#include "Pool.h"
@@ -34,6 +37,8 @@
#include "svn_client.h"
#include <ostream>
+#include <string>
+#include <vector>
namespace SVN
{
@@ -62,6 +67,14 @@ namespace SVN
const Revision &peg_revisio, const Revision &revision,
svn_depth_t depth, bool ignore_externals,
bool allow_unver_obstructions);
+
+ void commit(const std::vector<std::string> &targets,
+ Callback::Commit &callback);
+ void commit(const std::vector<std::string> &targets,
+ svn_depth_t depth, bool keep_locks, bool keep_changelists,
+ const std::vector<std::string> &changelists,
+ const PropTable &revprop_table,
+ Callback::Commit &callback);
};
}
Modified: subversion/branches/object-model/subversion/bindings/c++/include/Revision.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Revision.h?rev=999667&r1=999666&r2=999667&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Revision.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Revision.h Tue Sep 21 22:15:00 2010
@@ -39,12 +39,13 @@ namespace SVN
private:
/** The constructors. */
Revision(svn_opt_revision_kind kind);
- Revision(svn_revnum_t revnum);
Revision(apr_time_t date, bool foo);
svn_opt_revision_t m_revision;
public:
+ Revision(svn_revnum_t revnum);
+
/** The destructor needs to be public. */
virtual ~Revision();
Modified: subversion/branches/object-model/subversion/bindings/c++/include/Types.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Types.h?rev=999667&r1=999666&r2=999667&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Types.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Types.h Tue Sep 21 22:15:00 2010
@@ -27,14 +27,32 @@
#ifndef TYPES_H
#define TYPES_H
+#include "Revision.h"
+
#include <map>
#include <string>
namespace SVN
{
+// Typedefs
typedef std::map<std::string, std::string> PropTable;
+
+// C-struct wrapper classes
+class CommitInfo
+{
+ private:
+ Revision m_revision;
+ apr_time_t m_date;
+ std::string m_author;
+ std::string m_post_commit_err;
+ std::string m_repos_root;
+
+ public:
+ CommitInfo(const svn_commit_info_t *info);
+};
+
}
Propchange: subversion/branches/object-model/subversion/tests/libsvn++/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Sep 21 22:15:00 2010
@@ -3,3 +3,4 @@ client-cpp-test
util-cpp-test
test-cpp-client-repos
test-cpp-client-wc
+test-wcs
Modified: subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/client-test.cpp?rev=999667&r1=999666&r2=999667&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp (original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp Tue Sep 21 22:15:00 2010
@@ -24,12 +24,17 @@
#include "../svn_test.h"
#include "../svn_test_fs.h"
+#include "Common.h"
#include "Client.h"
#include "Pool.h"
#include <sstream>
#include <iostream>
+#define REPOS_NAME "test-cpp-client-repos"
+#define WCS_ROOT "test-wcs"
+#define WC_PATH "test-cpp-client-wc"
+
using namespace SVN;
static svn_error_t *
@@ -79,9 +84,8 @@ test_cat(const svn_test_opts_t *opts,
std::string iota_url;
std::string iota_path;
- SVN_ERR(create_greek_repo(&repos, "test-cpp-client-repos", opts,
- pool.pool()));
- SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, "test-cpp-client-repos",
+ SVN_ERR(create_greek_repo(&repos, REPOS_NAME, opts, pool.pool()));
+ SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, REPOS_NAME,
pool.pool()));
iota_url = svn_path_url_add_component2(repos_url, "iota", pool.pool());
@@ -115,15 +119,18 @@ test_checkout(const svn_test_opts_t *opt
const char *wc_path;
const char *cwd;
- SVN_ERR(create_greek_repo(&repos, "test-cpp-client-repos", opts,
- pool.pool()));
- SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, "test-cpp-client-repos",
+ SVN_ERR(create_greek_repo(&repos, REPOS_NAME, opts, pool.pool()));
+ SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, REPOS_NAME,
pool.pool()));
Client client;
SVN_ERR(svn_dirent_get_absolute(&cwd, "", pool.pool()));
- wc_path = svn_dirent_join(cwd, "test-cpp-client-wc", pool.pool());
+ wc_path = svn_dirent_join(cwd, WCS_ROOT, pool.pool());
+ SVN_ERR(svn_io_make_dir_recursively(wc_path, pool.pool()));
+ svn_test_add_dir_cleanup(wc_path);
+
+ wc_path = svn_dirent_join(wc_path, WC_PATH, pool.pool());
SVN_ERR(svn_io_remove_dir2(wc_path, TRUE, NULL, NULL, pool.pool()));
Revision result_rev = client.checkout(repos_url, wc_path);
@@ -132,6 +139,89 @@ test_checkout(const svn_test_opts_t *opt
return SVN_NO_ERROR;
}
+// A class which counts the number of commits
+class CommitHandler : public Callback::Commit
+{
+ public:
+ CommitHandler()
+ : commit_count(0)
+ {
+ }
+
+ void sendInfo(const CommitInfo &info)
+ {
+ ++commit_count;
+ }
+
+ // Making this public just makes life easier.
+ int commit_count;
+};
+
+// A class which throws and exception on commit
+class CommitHandlerEx : public Callback::Commit
+{
+ public:
+ void sendInfo(const CommitInfo &info)
+ {
+ throw Exception("This commit is exceptional!");
+ }
+};
+
+static svn_error_t *
+test_commit(const svn_test_opts_t *opts,
+ apr_pool_t *ap)
+{
+ Pool pool;
+ svn_repos_t *repos;
+ const char *wc_path;
+ const char *repos_url;
+ const char *cwd;
+
+ SVN_ERR(create_greek_repo(&repos, REPOS_NAME, opts, pool.pool()));
+ SVN_ERR(svn_uri_get_file_url_from_dirent(&repos_url, REPOS_NAME,
+ pool.pool()));
+
+ Client client;
+ SVN_ERR(svn_dirent_get_absolute(&cwd, "", pool.pool()));
+ wc_path = svn_dirent_join(cwd, WCS_ROOT, pool.pool());
+ SVN_ERR(svn_io_make_dir_recursively(wc_path, pool.pool()));
+ svn_test_add_dir_cleanup(wc_path);
+
+ wc_path = svn_dirent_join(wc_path, WC_PATH, pool.pool());
+ SVN_ERR(svn_io_remove_dir2(wc_path, TRUE, NULL, NULL, pool.pool()));
+ client.checkout(repos_url, wc_path);
+
+ const char *iota_path = svn_dirent_join(wc_path, "iota", pool.pool());
+ apr_size_t written;
+ apr_file_t *iota_file;
+ SVN_ERR(svn_io_file_open(&iota_file, iota_path, APR_WRITE, APR_OS_DEFAULT,
+ pool.pool()));
+ SVN_ERR(svn_io_file_write_full(iota_file, "12345", 5, &written, pool.pool()));
+
+ std::vector<std::string> targets;
+ targets.push_back(wc_path);
+ CommitHandler handler;
+ client.commit(targets, handler);
+
+ SVN_TEST_ASSERT(handler.commit_count == 1);
+
+ SVN_ERR(svn_io_file_write_full(iota_file, "67890", 5, &written, pool.pool()));
+ try
+ {
+ CommitHandlerEx handler_ex;
+ client.commit(targets, handler_ex);
+
+ // Shouldn't get here, 'cause an exception should be thrown
+ return svn_error_create(SVN_ERR_TEST_FAILED, NULL, NULL);
+ }
+ catch (Exception ex)
+ {
+ SVN_TEST_ASSERT(ex.getAPRErr() == SVN_ERR_CPP_EXCEPTION);
+ }
+
+ return SVN_NO_ERROR;
+}
+
/* The test table. */
struct svn_test_descriptor_t test_funcs[] =
@@ -143,5 +233,7 @@ struct svn_test_descriptor_t test_funcs[
"test client cat"),
SVN_TEST_OPTS_PASS(test_checkout,
"test client checkout"),
+ SVN_TEST_OPTS_PASS(test_commit,
+ "test client commit"),
SVN_TEST_NULL
};