git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: David Michael Barr <david.barr@cordelta.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	avarab@gmail.com, Daniel Shahaf <d.s@daniel.shahaf.name>,
	Bert Huijben <rhuijben@collab.net>,
	Junio C Hamano <gitster@pobox.com>,
	Eric Wong <normalperson@yhbt.net>,
	Will Palmer <wpalmer@gmail.com>, Greg Stein <gstein@gmail.com>
Subject: [PATCH 2/9] Add skeleton SVN client and Makefile
Date: Wed, 14 Jul 2010 01:36:09 +0200	[thread overview]
Message-ID: <1279064176-6645-3-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1279064176-6645-1-git-send-email-artagnon@gmail.com>

Add a basic SVN command-line client along with a Makefile that does
just enough to establish a connection with the ASF subversion server;
it initializes a memory pool, sees that configuration files are in
order, builds up a context object, sets up an authentication baton,
and finally opens a session to the subversion server.

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

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..55f28e5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+svnrdump: *.c
+	$(CC) -Wall -Werror -DAPR_POOL_DEBUG -ggdb3 -O0 -o $@ svnrdump.c -lsvn_client-1 -I. -I/usr/include/subversion-1 -I/usr/include/apr-1.0
+
+svnrdump_bench: *.c
+	$(CC) -O2 -o $@ svnrdump.c -lsvn_client-1 -I. -I/usr/include/subversion-1 -I/usr/include/apr-1.0
+
+clean:
+	$(RM) svnrdump svnrdump_bench
diff --git a/svnrdump.c b/svnrdump.c
new file mode 100644
index 0000000..35c1a73
--- /dev/null
+++ b/svnrdump.c
@@ -0,0 +1,102 @@
+/* Licensed under a two-clause BSD-style license.
+ * See LICENSE for details.
+ */
+
+#include "svn_pools.h"
+#include "svn_cmdline.h"
+#include "svn_client.h"
+#include "svn_ra.h"
+#include "svn_repos.h"
+#include "svn_path.h"
+
+static int verbose = 0;
+static apr_pool_t *pool = NULL;
+static svn_client_ctx_t *ctx = NULL;
+static svn_ra_session_t *session = NULL;
+
+static 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));
+
+	SVN_ERR(svn_config_get_config(&(ctx->config), NULL, pool));
+
+	/* Default authentication providers for non-interactive use */
+	SVN_ERR(svn_cmdline_create_auth_baton(&(ctx->auth_baton), TRUE,
+					      NULL, NULL, NULL, FALSE,
+					      FALSE, NULL, NULL, NULL,
+					      pool));
+	SVN_ERR(svn_client_open_ra_session(&session, url, ctx, pool));
+	return SVN_NO_ERROR;
+}
+
+static svn_error_t *replay_range(svn_revnum_t start_revision, svn_revnum_t end_revision)
+{
+	return SVN_NO_ERROR;
+}
+
+static svn_error_t *usage(FILE *out_stream)
+{
+	fprintf(out_stream,
+		"usage: svnrdump URL [-r LOWER[:UPPER]]\n\n"
+		"Dump the contents of repository at remote URL to stdout in a 'dumpfile'\n"
+		"v3 portable format.  Dump revisions LOWER rev through UPPER rev.\n"
+		"LOWER defaults to 1 and UPPER defaults to the highest possible revision\n"
+		"if omitted.\n");
+	return SVN_NO_ERROR;
+}
+
+
+int main(int argc, const char **argv)
+{
+	int i;
+	const char *url = NULL;
+	char *revision_cut = NULL;
+	svn_revnum_t start_revision = svn_opt_revision_unspecified;
+	svn_revnum_t end_revision = svn_opt_revision_unspecified;
+
+	if (svn_cmdline_init ("svnrdump", stderr) != EXIT_SUCCESS)
+		return EXIT_FAILURE;
+
+	pool = svn_pool_create(NULL);
+
+	for (i = 1; i < argc; i++) {
+		if (!strncmp("-r", argv[i], 2)) {
+			revision_cut = strchr(argv[i] + 2, ':');
+			if (revision_cut) {
+				start_revision = (svn_revnum_t) strtoul(argv[i] + 2, &revision_cut, 10);
+				end_revision = (svn_revnum_t) strtoul(revision_cut + 1, NULL, 10);
+			}
+			else
+				start_revision = (svn_revnum_t) strtoul(argv[i] + 2, NULL, 10);
+		} else if (!strcmp("-v", argv[i]) || !strcmp("--verbose", argv[i])) {
+			verbose = 1;
+		} else if (!strcmp("help", argv[i]) || !strcmp("--help", argv[i])) {
+			SVN_INT_ERR(usage(stdout));
+			return EXIT_SUCCESS;
+		} else if (*argv[i] == '-' || url) {
+			SVN_INT_ERR(usage(stderr));
+			return EXIT_FAILURE;
+		} else
+			url = argv[i];
+	}
+
+	if (!url || !svn_path_is_url(url)) {
+		usage(stderr);
+		return EXIT_FAILURE;
+	}
+	SVN_INT_ERR(open_connection(url));
+
+	/* Have sane start_revision and end_revision defaults if unspecified */
+	if (start_revision == svn_opt_revision_unspecified)
+		start_revision = 1;
+	if (end_revision == svn_opt_revision_unspecified)
+		SVN_INT_ERR(svn_ra_get_latest_revnum(session, &end_revision, pool));
+
+	SVN_INT_ERR(replay_range(start_revision, end_revision));
+
+	svn_pool_destroy(pool);
+	
+	return 0;
+}
-- 
1.7.1

  parent reply	other threads:[~2010-07-13 23:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13 23:36 [PATCH 0/9] Get svnrdump merged into git.git Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 1/9] Add LICENSE Ramkumar Ramachandra
2010-07-14  4:47   ` Daniel Shahaf
2010-07-14 11:23     ` Ramkumar Ramachandra
2010-07-13 23:36 ` Ramkumar Ramachandra [this message]
2010-07-13 23:36 ` [PATCH 3/9] Add debug editor from Subversion trunk Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 4/9] Drive the debug editor Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 5/9] Dump the revprops at the start of every revision Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 6/9] Implement directory-related functions Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 7/9] Implement file-related functions Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 8/9] Implement close_file Ramkumar Ramachandra
2010-07-13 23:36 ` [PATCH 9/9] Add a validation script Ramkumar Ramachandra
2010-07-13 23:58 ` [PATCH 0/9] Get svnrdump merged into git.git Ramkumar Ramachandra
2010-07-14  0:15   ` Jonathan Nieder
2010-07-14  0:22     ` Ramkumar Ramachandra
2010-07-14  0:28       ` Jonathan Nieder
2010-07-14  0:49         ` Ramkumar Ramachandra
2010-07-14  7:03           ` Stefan Sperling
2010-07-14 11:26             ` Ramkumar Ramachandra
2010-07-14 12:55               ` Stefan Sperling
2010-07-14 14:54 ` Junio C Hamano
2010-07-15 10:55   ` Ramkumar Ramachandra
     [not found]     ` <20100806175709.GA2683@burratino>
2010-08-06 18:37       ` [PATCH svnrdump-standalone] Sync with upstream Jonathan Nieder
2010-08-07  2:30       ` Jonathan Nieder
2010-08-07  2:47         ` Ramkumar Ramachandra
2010-08-07  2:51         ` Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279064176-6645-3-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=avarab@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=david.barr@cordelta.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=gstein@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=normalperson@yhbt.net \
    --cc=rhuijben@collab.net \
    --cc=srabbelier@gmail.com \
    --cc=wpalmer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).