git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [WIP PATCH] Add a skeleton RA SVN client
  2010-06-02 13:08 [WIP PATCH] The SVN RA client, finally Ramkumar Ramachandra
@ 2010-06-02 13:08 ` Ramkumar Ramachandra
  0 siblings, 0 replies; 3+ messages in thread
From: Ramkumar Ramachandra @ 2010-06-02 13:08 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Sverre Rabbelier, Jonathan Nieder, David Michael Barr

The SVN client uses the RA API to connect to a remote server and
replay revisions. In future, it will dump the data in every revision
to stdout in dumpfile format (hopefully) without resorting to the FS
API and svn_repos_dump_fs2.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Makefile       |    2 +
 svnclient_ra.c |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 Makefile
 create mode 100644 svnclient_ra.c

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..480c526
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+svnclient_ra: svnclient_ra.c
+	cc -Wall -Werror -ggdb -O1 -o $@ -lsvn_client-1 svnclient_ra.c -I/usr/include/subversion-1 -I/usr/include/apr-1.0
diff --git a/svnclient_ra.c b/svnclient_ra.c
new file mode 100644
index 0000000..4113cb8
--- /dev/null
+++ b/svnclient_ra.c
@@ -0,0 +1,113 @@
+#include "svn_pools.h"
+#include "svn_cmdline.h"
+#include "svn_client.h"
+#include "svn_ra.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static apr_pool_t *pool = NULL;
+static svn_client_ctx_t *ctx = NULL;
+static svn_ra_session_t *session = NULL;
+
+static svn_error_t *replay_start(svn_revnum_t revision,
+                                 void *replay_baton,
+                                 const svn_delta_editor_t **editor,
+                                 void **edit_baton,
+                                 apr_hash_t *rev_props,
+                                 apr_pool_t *pool)
+{
+	/* TODO: Dump the data in revision to stdout in dumpfile
+	 * format so it can be parsed by the exporter
+	 */
+	return SVN_NO_ERROR;
+}
+static svn_error_t *replay_end(svn_revnum_t revision,
+                               void *replay_baton,
+                               const svn_delta_editor_t *editor,
+                               void *edit_baton,
+                               apr_hash_t *rev_props,
+                               apr_pool_t *pool)
+{
+	SVN_ERR(editor->close_edit(edit_baton, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *build_auth_baton()
+{
+	svn_auth_provider_object_t *provider;
+	apr_array_header_t *providers
+		= apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *));
+
+	svn_auth_get_simple_prompt_provider (&provider,
+	                                     NULL,
+	                                     NULL,
+	                                     2,
+	                                     pool);
+	APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
+
+	svn_auth_get_username_prompt_provider (&provider,
+	                                       NULL,
+	                                       NULL,
+	                                       2,
+	                                       pool);
+	APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
+
+	svn_auth_open (&ctx->auth_baton, providers, pool);
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *populate_context()
+{
+	SVN_ERR(svn_config_get_config(&(ctx->config), NULL, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *open_connection(const char *url)
+{
+	SVN_ERR(svn_config_ensure (NULL, pool));
+	SVN_ERR(svn_client_create_context (&ctx, pool));
+	SVN_ERR(svn_ra_initialize(pool));
+
+#if defined(WIN32) || defined(__CYGWIN__)
+	if (getenv("SVN_ASP_DOT_NET_HACK"))
+		SVN_ERR(svn_wc_set_adm_dir("_svn", pool));
+#endif
+	
+	SVN_ERR(populate_context());
+	SVN_ERR(build_auth_baton());
+	SVN_ERR(svn_client_open_ra_session(&session, url, ctx, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *replay_range(svn_revnum_t start_revision, svn_revnum_t end_revision)
+{
+	svn_revnum_t latest_revision;
+	SVN_ERR(svn_ra_get_latest_revnum(session, &latest_revision, pool));
+	printf("%ld\n", latest_revision);
+	SVN_ERR(svn_ra_replay_range(session, start_revision, end_revision,
+	                            0, TRUE, replay_start, replay_end, NULL, pool));
+	return SVN_NO_ERROR;
+}
+
+void close_connection()
+{
+	svn_pool_destroy(pool);
+}
+
+int main()
+{
+	const char url[] = "http://svn.apache.org/repos/asf/subversion/trunk";
+	svn_revnum_t start_revision = 0, end_revision = 5;
+	if (svn_cmdline_init ("svnclient_ra", stderr) != EXIT_SUCCESS)
+		return EXIT_FAILURE;
+	pool = svn_pool_create(NULL);
+
+	if(open_connection(url) != SVN_NO_ERROR)
+		return 1;
+	if(replay_range(start_revision, end_revision) != SVN_NO_ERROR)
+		return 1;
+
+	close_connection();
+	return 0;
+}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [GSoC update] git-remote-svn: Week 7
@ 2010-06-14 16:19 Ramkumar Ramachandra
  2010-06-14 16:19 ` [WIP PATCH] Add a skeleton RA SVN client Ramkumar Ramachandra
  0 siblings, 1 reply; 3+ messages in thread
From: Ramkumar Ramachandra @ 2010-06-14 16:19 UTC (permalink / raw)
  To: Git Mailing List
  Cc: David Michael Barr, Jonathan Nieder, Sverre Rabbelier,
	Michael J Gruber, Ævar Arnfjörð Bjarmason,
	Jonas Gehring

Hi,

I suspect that people are confused about what I'm exactly doing and
how to review/ test all the work since I've been posting updates in
rapid bursts, and writing relatively short emails. For a change, this
email is going to be (relatively) long and detailed since things are
finally starting to take shape. So, the project involves the following
components:
1. The remote helper application or remote-svn (90% complete): There's
nothing much to see here; I just stripped down remote-curl.c and
posted a remote-svn.c along with the relevant Makefile rule to build
it a few weeks ago [1]. What this needs: Some infrastructure to do the
importing/ exporting in $GIT_ROOT/vcs-svn/.
2. David's SVN exporter or svn-fe (80% complete): This is quite an
excellent piece of software for turning an SVN dumpfile into a stream
that git-fast-import can import [2]. David has validated it against
940,000 commits of the ASF repository, and it works perfectly. It's
80% complete because there's some room for refactoring certain parts,
and cosmetic beautification before the merge into `next`. I work on
both `master` and a special `git-merge` branch specifically for
merging it into git.git. Jonathan has suggested that two separate
components should be merged into git.git: svn-fe itself as an
independent program in $GIT_ROOT/contrib/ and the `git-merge` branch
for creating infrastructure for the remote helper in
$GIT_ROOT/vcs-svn/. We are currently preparing a series for the
former, while the latter was just merged into pu this week [3].
3. The RA SVN Client or svnclient_ra (15% complete): This piece of
sofware will be invoked by the remote helper and will use the libsvn
API (yuck!) to contact a remote server and produce output in dumpfile
format for the exporter component. Jonas has written a software called
rsvndump which already does this [4], but the codebase is too clunky
and outdated (it doesn't use the replay API); I'm therefore attempting
a complete rewrite, and you can find the latest update in a patch in
the second part of this series. Note that the replay API forces a
server version >= 1.5 restriction, but Sverre and I are alright with
this. The cost of backward compatibility is a LOT of ugly code (seen
in rsvndump).
4. The importer (0% complete): I'll probably only get started with
this after the mid-term evaluations.

[1]: http://article.gmane.org/gmane.comp.version-control.git/147716
[2]: http://github.com/artagnon/svn-dump-fast-export
[3]: Commit 9c55c48
[4]: http://github.com/jgehring/rsvndump

-- Ram

Ramkumar Ramachandra (1):
  Add a skeleton RA SVN client

 Makefile       |    2 +
 delta_editor.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++
 delta_editor.h |   66 +++++++++++++++++++++++++++
 svnclient_ra.c |  135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 315 insertions(+), 0 deletions(-)
 create mode 100644 Makefile
 create mode 100644 delta_editor.c
 create mode 100644 delta_editor.h
 create mode 100644 svnclient_ra.c

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [WIP PATCH] Add a skeleton RA SVN client
  2010-06-14 16:19 [GSoC update] git-remote-svn: Week 7 Ramkumar Ramachandra
@ 2010-06-14 16:19 ` Ramkumar Ramachandra
  0 siblings, 0 replies; 3+ messages in thread
From: Ramkumar Ramachandra @ 2010-06-14 16:19 UTC (permalink / raw)
  To: Git Mailing List
  Cc: David Michael Barr, Jonathan Nieder, Sverre Rabbelier,
	Michael J Gruber, Ævar Arnfjörð Bjarmason,
	Jonas Gehring

The SVN client uses the RA API to connect to a remote server and
replay revisions. In future, it will dump the data in every revision
to stdout in dumpfile format (hopefully) without resorting to the FS
API and svn_repos_dump_fs2.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Makefile       |    2 +
 delta_editor.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++
 delta_editor.h |   66 +++++++++++++++++++++++++++
 svnclient_ra.c |  135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 315 insertions(+), 0 deletions(-)
 create mode 100644 Makefile
 create mode 100644 delta_editor.c
 create mode 100644 delta_editor.h
 create mode 100644 svnclient_ra.c

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..662061b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+svnclient_ra: svnclient_ra.c
+	cc -Wall -Werror -ggdb -O1 -o $@ -lsvn_client-1 svnclient_ra.c delta_editor.c -I. -I/usr/include/subversion-1 -I/usr/include/apr-1.0
diff --git a/delta_editor.c b/delta_editor.c
new file mode 100644
index 0000000..8c722cd
--- /dev/null
+++ b/delta_editor.c
@@ -0,0 +1,112 @@
+#include "svn_pools.h"
+#include "svn_cmdline.h"
+#include "svn_client.h"
+#include "svn_ra.h"
+
+#include "delta_editor.h"
+
+svn_error_t *set_target_revision(void *edit_baton,
+                                 svn_revnum_t target_revision,
+                                 apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+
+svn_error_t *open_root(void *edit_baton, svn_revnum_t base_revision,
+                       apr_pool_t *dir_pool, void **root_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *delete_entry(const char *path, svn_revnum_t revision,
+                          void *parent_baton, apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *add_directory(const char *path, void *parent_baton,
+                           const char *copyfrom_path,
+                           svn_revnum_t copyfrom_revision,
+                           apr_pool_t *dir_pool, void **child_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+
+svn_error_t *open_directory(const char *path, void *parent_baton,
+                            svn_revnum_t base_revision,
+                            apr_pool_t *dir_pool, void **child_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *change_dir_prop(void *dir_baton, const char *name,
+                             const svn_string_t *value, apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *close_directory(void *dir_baton, apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *absent_directory(const char *path, void *parent_baton,
+                              apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *add_file(const char *path, void *parent_baton,
+                      const char *copyfrom_path,
+                      svn_revnum_t copyfrom_revision,
+                      apr_pool_t *file_pool, void **file_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *open_file(const char *path, void *parent_baton,
+                       svn_revnum_t base_revision, apr_pool_t *file_pool,
+                       void **file_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *apply_textdelta(void *file_baton,
+                             const char *base_checksum,
+                             apr_pool_t *pool,
+                             svn_txdelta_window_handler_t *handler,
+                             void **handler_baton)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *change_file_prop(void *file_baton, const char *name,
+                              const svn_string_t *value,
+                              apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *close_file(void *file_baton, const char *text_checksum,
+                        apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *absent_file(const char *path, void *parent_baton,
+                         apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *close_edit(void *edit_baton, apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *abort_edit(void *edit_baton, apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
diff --git a/delta_editor.h b/delta_editor.h
new file mode 100644
index 0000000..49652d7
--- /dev/null
+++ b/delta_editor.h
@@ -0,0 +1,66 @@
+#ifndef DELTA_EDITOR_H_
+#define DELTA_EDITOR_H_
+
+#include "svn_pools.h"
+#include "svn_cmdline.h"
+#include "svn_client.h"
+#include "svn_ra.h"
+
+svn_error_t *set_target_revision(void *edit_baton,
+                                 svn_revnum_t target_revision,
+                                 apr_pool_t *pool);
+
+svn_error_t *open_root(void *edit_baton, svn_revnum_t base_revision,
+                       apr_pool_t *dir_pool, void **root_baton);
+
+svn_error_t *delete_entry(const char *path, svn_revnum_t revision,
+                          void *parent_baton, apr_pool_t *pool);
+
+svn_error_t *add_directory(const char *path, void *parent_baton,
+                           const char *copyfrom_path,
+                           svn_revnum_t copyfrom_revision,
+                           apr_pool_t *dir_pool, void **child_baton);
+
+
+svn_error_t *open_directory(const char *path, void *parent_baton,
+                            svn_revnum_t base_revision,
+                            apr_pool_t *dir_pool, void **child_baton);
+
+svn_error_t *change_dir_prop(void *dir_baton, const char *name,
+                             const svn_string_t *value, apr_pool_t *pool);
+
+svn_error_t *close_directory(void *dir_baton, apr_pool_t *pool);
+
+svn_error_t *absent_directory(const char *path, void *parent_baton,
+                              apr_pool_t *pool);
+
+svn_error_t *add_file(const char *path, void *parent_baton,
+                      const char *copyfrom_path,
+                      svn_revnum_t copyfrom_revision,
+                      apr_pool_t *file_pool, void **file_baton);
+
+svn_error_t *open_file(const char *path, void *parent_baton,
+                       svn_revnum_t base_revision, apr_pool_t *file_pool,
+                       void **file_baton);
+
+svn_error_t *apply_textdelta(void *file_baton,
+                             const char *base_checksum,
+                             apr_pool_t *pool,
+                             svn_txdelta_window_handler_t *handler,
+                             void **handler_baton);
+
+svn_error_t *change_file_prop(void *file_baton, const char *name,
+                              const svn_string_t *value,
+                              apr_pool_t *pool);
+
+svn_error_t *close_file(void *file_baton, const char *text_checksum,
+                        apr_pool_t *pool);
+
+svn_error_t *absent_file(const char *path, void *parent_baton,
+                         apr_pool_t *pool);
+
+svn_error_t *close_edit(void *edit_baton, apr_pool_t *pool);
+
+svn_error_t *abort_edit(void *edit_baton, apr_pool_t *pool);
+
+#endif
diff --git a/svnclient_ra.c b/svnclient_ra.c
new file mode 100644
index 0000000..a754494
--- /dev/null
+++ b/svnclient_ra.c
@@ -0,0 +1,135 @@
+#include "svn_pools.h"
+#include "svn_cmdline.h"
+#include "svn_client.h"
+#include "svn_ra.h"
+
+#include "delta_editor.h"
+
+static apr_pool_t *pool = NULL;
+static svn_client_ctx_t *ctx = NULL;
+static svn_ra_session_t *session = NULL;
+
+static svn_error_t *setup_delta_editor(svn_delta_editor_t **editor)
+{
+	*editor = svn_delta_default_editor(pool);
+	(*editor)->set_target_revision = set_target_revision;
+	(*editor)->open_root = open_root;
+	(*editor)->delete_entry = delete_entry;
+	(*editor)->add_directory = add_directory;
+	(*editor)->open_directory = open_directory;
+	(*editor)->add_file = add_file;
+	(*editor)->open_file = open_file;
+	(*editor)->apply_textdelta = apply_textdelta;
+	(*editor)->close_file = close_file;
+	(*editor)->close_directory = close_directory;
+	(*editor)->change_file_prop = change_file_prop;
+	(*editor)->change_dir_prop = change_dir_prop;
+	(*editor)->close_edit = close_edit;
+	(*editor)->absent_directory = absent_directory;
+	(*editor)->absent_file = absent_file;
+	(*editor)->abort_edit = abort_edit;
+	return SVN_NO_ERROR;
+}
+
+static svn_error_t *replay_revstart(svn_revnum_t revision,
+                                    void *replay_baton,
+                                    const svn_delta_editor_t **editor,
+                                    void **edit_baton,
+                                    apr_hash_t *rev_props,
+                                    apr_pool_t *pool)
+{
+	return SVN_NO_ERROR;
+}
+
+static svn_error_t *replay_revend(svn_revnum_t revision,
+                                  void *replay_baton,
+                                  const svn_delta_editor_t *editor,
+                                  void *edit_baton,
+                                  apr_hash_t *rev_props,
+                                  apr_pool_t *pool)
+{
+	SVN_ERR(editor->close_edit(edit_baton, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *build_auth_baton()
+{
+	svn_auth_provider_object_t *provider;
+	apr_array_header_t *providers
+		= apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *));
+
+	svn_auth_get_simple_prompt_provider (&provider,
+	                                     NULL,
+	                                     NULL,
+	                                     2,
+	                                     pool);
+	APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
+
+	svn_auth_get_username_prompt_provider (&provider,
+	                                       NULL,
+	                                       NULL,
+	                                       2,
+	                                       pool);
+	APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
+
+	svn_auth_open (&ctx->auth_baton, providers, pool);
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *populate_context()
+{
+	SVN_ERR(svn_config_get_config(&(ctx->config), NULL, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *open_connection(const char *url)
+{
+	SVN_ERR(svn_config_ensure (NULL, pool));
+	SVN_ERR(svn_client_create_context (&ctx, pool));
+	SVN_ERR(svn_ra_initialize(pool));
+
+#if defined(WIN32) || defined(__CYGWIN__)
+	if (getenv("SVN_ASP_DOT_NET_HACK"))
+		SVN_ERR(svn_wc_set_adm_dir("_svn", pool));
+#endif
+
+	SVN_ERR(populate_context());
+	SVN_ERR(build_auth_baton());
+	SVN_ERR(svn_client_open_ra_session(&session, url, ctx, pool));
+	return SVN_NO_ERROR;
+}
+
+svn_error_t *replay_range(svn_revnum_t start_revision, svn_revnum_t end_revision)
+{
+	svn_revnum_t latest_revision;
+	svn_delta_editor_t *editor;
+	svn_error_t *err;
+	SVN_ERR(svn_ra_get_latest_revnum(session, &latest_revision, pool));
+	printf("%ld\n", latest_revision);
+	SVN_ERR(setup_delta_editor(&editor));
+	SVN_ERR(svn_ra_replay_range(session, start_revision, end_revision,
+	                            0, TRUE, replay_revstart, replay_revend, NULL, pool));
+	return SVN_NO_ERROR;
+}
+
+void close_connection()
+{
+	svn_pool_destroy(pool);
+}
+
+int main()
+{
+	const char url[] = "http://svn.apache.org/repos/asf/subversion/trunk";
+	svn_revnum_t start_revision = 0, end_revision = 5;
+	if (svn_cmdline_init ("svnclient_ra", stderr) != EXIT_SUCCESS)
+		return EXIT_FAILURE;
+	pool = svn_pool_create(NULL);
+
+	if(open_connection(url) != SVN_NO_ERROR)
+		return 1;
+	if(replay_range(start_revision, end_revision) != SVN_NO_ERROR)
+		return 1;
+
+	close_connection();
+	return 0;
+}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-14 16:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14 16:19 [GSoC update] git-remote-svn: Week 7 Ramkumar Ramachandra
2010-06-14 16:19 ` [WIP PATCH] Add a skeleton RA SVN client Ramkumar Ramachandra
  -- strict thread matches above, loose matches on Subject: below --
2010-06-02 13:08 [WIP PATCH] The SVN RA client, finally Ramkumar Ramachandra
2010-06-02 13:08 ` [WIP PATCH] Add a skeleton RA SVN client Ramkumar Ramachandra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).