From: Florian Achleitner <florian.achleitner.2.6.31@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>,
David Michael Barr <davidbarr@google.com>,
git@vger.kernel.org
Cc: florian.achleitner.2.6.31@gmail.com
Subject: [RFC v2 01/16] Implement a remote helper for svn in C.
Date: Mon, 30 Jul 2012 16:31:08 +0200 [thread overview]
Message-ID: <1343658683-10713-2-git-send-email-florian.achleitner.2.6.31@gmail.com> (raw)
In-Reply-To: <1343658683-10713-1-git-send-email-florian.achleitner.2.6.31@gmail.com>
Enables basic fetching from subversion repositories. When processing Remote URLs
starting with svn::, git invokes this remote-helper.
It starts svnrdump to extract revisions from the subversion repository in the
'dump file format', and converts them to a git-fast-import stream using
the functions of vcs-svn/.
Imported refs are created in a private namespace at refs/svn/<remote-name/master.
The revision history is imported linearly (no branch detection) and completely,
i.e. from revision 0 to HEAD.
Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@gmail.com>
---
contrib/svn-fe/remote-svn.c | 190 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 190 insertions(+)
create mode 100644 contrib/svn-fe/remote-svn.c
diff --git a/contrib/svn-fe/remote-svn.c b/contrib/svn-fe/remote-svn.c
new file mode 100644
index 0000000..d5c2df8
--- /dev/null
+++ b/contrib/svn-fe/remote-svn.c
@@ -0,0 +1,190 @@
+
+#include "cache.h"
+#include "remote.h"
+#include "strbuf.h"
+#include "url.h"
+#include "exec_cmd.h"
+#include "run-command.h"
+#include "svndump.h"
+#include "argv-array.h"
+
+static const char *url;
+static const char *private_ref;
+static const char *remote_ref = "refs/heads/master";
+
+int cmd_capabilities(struct strbuf *line);
+int cmd_import(struct strbuf *line);
+int cmd_list(struct strbuf *line);
+
+typedef int (*input_command_handler)(struct strbuf *);
+struct input_command_entry {
+ const char *name;
+ input_command_handler fct;
+ unsigned char batchable; /* whether the command starts or is part of a batch */
+};
+
+static const struct input_command_entry input_command_list[] = {
+ { "capabilities", cmd_capabilities, 0 },
+ { "import", cmd_import, 1 },
+ { "list", cmd_list, 0 },
+ { NULL, NULL }
+};
+
+int cmd_capabilities(struct strbuf *line)
+{
+ printf("import\n");
+ printf("refspec %s:%s\n\n", remote_ref, private_ref);
+ fflush(stdout);
+ return 0;
+}
+
+static void terminate_batch() {
+ /* terminate a current batch's fast-import stream */
+ printf("done\n");
+ fflush(stdout);
+}
+
+int cmd_import(struct strbuf *line)
+{
+ int code, report_fd;
+ char *back_pipe_env;
+ int dumpin_fd;
+ unsigned int startrev = 0;
+ struct argv_array svndump_argv = ARGV_ARRAY_INIT;
+ struct child_process svndump_proc;
+
+ /*
+ * When the remote-helper is invoked by transport-helper.c it passes the
+ * filename of this pipe in the env-var.
+ */
+ back_pipe_env = getenv("GIT_REPORT_FIFO");
+ if (!back_pipe_env) {
+ die("Cannot get cat-blob-pipe from environment! GIT_REPORT_FIFO has to"
+ "be set by the caller.");
+ }
+
+ /*
+ * Opening a fifo for reading usually blocks until a writer has opened it too.
+ * Opening a fifo for writing usually blocks until a reader has opened it too.
+ * Therefore, we open with RDWR on both sides to avoid deadlocks.
+ * Especially if there's nothing to do and one pipe end is closed immediately.
+ */
+ report_fd = open(back_pipe_env, O_RDWR);
+ if (report_fd < 0) {
+ die("Unable to open fast-import back-pipe! %s", strerror(errno));
+ }
+
+ memset(&svndump_proc, 0, sizeof (struct child_process));
+ svndump_proc.out = -1;
+ argv_array_push(&svndump_argv, "svnrdump");
+ argv_array_push(&svndump_argv, "dump");
+ argv_array_push(&svndump_argv, url);
+ argv_array_pushf(&svndump_argv, "-r%u:HEAD", startrev);
+ svndump_proc.argv = svndump_argv.argv;
+
+ code = start_command(&svndump_proc);
+ if (code)
+ die("Unable to start %s, code %d", svndump_proc.argv[0], code);
+ dumpin_fd = svndump_proc.out;
+
+ svndump_init_fd(dumpin_fd, report_fd);
+ svndump_read(url, private_ref);
+ svndump_deinit();
+ svndump_reset();
+
+ close(dumpin_fd);
+ close(report_fd);
+ code = finish_command(&svndump_proc);
+ if (code)
+ warning("%s, returned %d", svndump_proc.argv[0], code);
+ argv_array_clear(&svndump_argv);
+
+ return 0;
+}
+
+int cmd_list(struct strbuf *line)
+{
+ printf("? HEAD\n");
+ printf("? %s\n\n", remote_ref);
+ fflush(stdout);
+ return 0;
+}
+
+int do_command(struct strbuf *line)
+{
+ const struct input_command_entry *p = input_command_list;
+ static int batch_active;
+ static struct strbuf batch_command = STRBUF_INIT;
+ /*
+ * import commands can be grouped together in a batch.
+ * Batches are ended by \n. If no batch is active the program ends.
+ */
+ if (line->len == 0 ) {
+ if (batch_active) {
+ terminate_batch();
+ batch_active = 0;
+ return 0;
+ }
+ return 1;
+ }
+ if (batch_active && strcmp(batch_command.buf, line->buf))
+ die("Active %s batch interrupted by %s", batch_command.buf, line->buf);
+
+ for(p = input_command_list; p->name; p++) {
+ if (!prefixcmp(line->buf, p->name) &&
+ (strlen(p->name) == line->len || line->buf[strlen(p->name)] == ' ')) {
+ if (p->batchable) {
+ batch_active = 1;
+ strbuf_release(&batch_command);
+ strbuf_addbuf(&batch_command, line);
+ }
+ return p->fct(line);
+ }
+ }
+ warning("Unknown command '%s'\n", line->buf);
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ struct strbuf buf = STRBUF_INIT;
+ int nongit;
+ static struct remote *remote;
+ const char *url_in;
+
+ git_extract_argv0_path(argv[0]);
+ setup_git_directory_gently(&nongit);
+ if (argc < 2 || argc > 3) {
+ usage("git-remote-svn <remote-name> [<url>]");
+ return 1;
+ }
+
+ remote = remote_get(argv[1]);
+ url_in = remote->url[0];
+ if (argc == 3)
+ url_in = argv[2];
+
+ end_url_with_slash(&buf, url_in);
+ url = strbuf_detach(&buf, NULL);
+
+ strbuf_init(&buf, 0);
+ strbuf_addf(&buf, "refs/svn/%s/master", remote->name);
+ private_ref = strbuf_detach(&buf, NULL);
+
+ while(1) {
+ if (strbuf_getline(&buf, stdin, '\n') == EOF) {
+ if (ferror(stdin))
+ die_errno("Error reading command stream");
+ else
+ die_errno("Unexpected end of command stream");
+ }
+ if (do_command(&buf))
+ break;
+ strbuf_reset(&buf);
+ }
+
+ strbuf_release(&buf);
+ free((void*)url);
+ free((void*)private_ref);
+ return 0;
+}
--
1.7.9.5
next prev parent reply other threads:[~2012-07-30 14:39 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-26 7:32 [RFC 00/16] GSOC remote-svn, rewritten patch series Florian Achleitner
2012-07-26 7:32 ` [RFC 01/16] Implement a remote helper for svn in C Florian Achleitner
2012-07-26 7:32 ` [RFC 02/16] Integrate remote-svn into svn-fe/Makefile Florian Achleitner
2012-07-26 7:32 ` [RFC 03/16] Add svndump_init_fd to allow reading dumps from arbitrary FDs Florian Achleitner
2012-07-26 7:32 ` [RFC 04/16] Add cat-blob report fifo from fast-import to remote-helper Florian Achleitner
2012-07-26 7:32 ` [RFC 05/16] remote-svn, vcs-svn: Enable fetching to private refs Florian Achleitner
2012-07-26 7:32 ` [RFC 06/16] Add a symlink 'git-remote-svn' in base dir Florian Achleitner
2012-07-26 7:32 ` [RFC 07/16] Allow reading svn dumps from files via file:// urls Florian Achleitner
2012-07-26 7:32 ` [RFC 08/16] vcs-svn: add fast_export_note to create notes Florian Achleitner
2012-07-26 7:32 ` [RFC 09/16] Create a note for every imported commit containing svn metadata Florian Achleitner
2012-07-26 7:32 ` [RFC 10/16] When debug==1, start fast-import with "--stats" instead of "--quiet" Florian Achleitner
2012-07-26 7:32 ` [RFC 11/16] Add explanatory comment for transport-helpers refs mapping Florian Achleitner
2012-07-26 7:32 ` [RFC 12/16] remote-svn: add incremental import Florian Achleitner
2012-07-26 7:32 ` [RFC 13/16] Add a svnrdump-simulator replaying a dump file for testing Florian Achleitner
2012-07-26 7:32 ` [RFC 14/16] transport-helper: add import|export-marks to fast-import command line Florian Achleitner
2012-07-26 7:32 ` [RFC 15/16] remote-svn: add marks-file regeneration Florian Achleitner
2012-07-26 7:32 ` [RFC 16/16] Add a test script for remote-svn Florian Achleitner
2012-07-26 16:15 ` [RFC 14/16] transport-helper: add import|export-marks to fast-import command line Florian Achleitner
2012-07-28 7:06 ` Jonathan Nieder
2012-07-26 7:46 ` [RFC 01/16] Implement a remote helper for svn in C Jonathan Nieder
2012-07-26 8:02 ` Florian Achleitner
2012-07-26 8:14 ` Jonathan Nieder
2012-07-26 8:37 ` Florian Achleitner
2012-07-30 14:31 ` [RFC v2 00/16] GSOC remote-svn, rewritten patch series Florian Achleitner
2012-07-30 14:31 ` Florian Achleitner [this message]
2012-07-30 14:31 ` [RFC v2 02/16] Integrate remote-svn into svn-fe/Makefile Florian Achleitner
2012-07-30 14:31 ` [RFC v2 03/16] Add svndump_init_fd to allow reading dumps from arbitrary FDs Florian Achleitner
2012-07-30 14:31 ` [RFC v2 04/16] Add cat-blob report fifo from fast-import to remote-helper Florian Achleitner
2012-07-30 14:31 ` [RFC v2 05/16] remote-svn, vcs-svn: Enable fetching to private refs Florian Achleitner
2012-07-30 14:31 ` [RFC v2 06/16] Add a symlink 'git-remote-svn' in base dir Florian Achleitner
2012-07-30 14:31 ` [RFC v2 07/16] Allow reading svn dumps from files via file:// urls Florian Achleitner
2012-07-30 14:31 ` [RFC v2 08/16] vcs-svn: add fast_export_note to create notes Florian Achleitner
2012-07-30 14:31 ` [RFC v2 09/16] Create a note for every imported commit containing svn metadata Florian Achleitner
2012-07-30 14:31 ` [RFC v2 10/16] When debug==1, start fast-import with "--stats" instead of "--quiet" Florian Achleitner
2012-07-30 14:31 ` [RFC v2 11/16] Add explanatory comment for transport-helpers refs mapping Florian Achleitner
2012-07-30 14:31 ` [RFC v2 12/16] remote-svn: add incremental import Florian Achleitner
2012-07-30 14:31 ` [RFC v2 13/16] Add a svnrdump-simulator replaying a dump file for testing Florian Achleitner
2012-07-30 14:31 ` [RFC v2 14/16] transport-helper: add import|export-marks to fast-import command line Florian Achleitner
2012-07-30 14:31 ` [RFC v2 15/16] remote-svn: add marks-file regeneration Florian Achleitner
2012-07-30 14:31 ` [RFC v2 16/16] Add a test script for remote-svn Florian Achleitner
2012-07-30 17:08 ` [RFC v2 11/16] Add explanatory comment for transport-helpers refs mapping Jonathan Nieder
2012-07-30 17:25 ` Junio C Hamano
2012-07-30 17:38 ` Junio C Hamano
2012-07-30 19:15 ` Jonathan Nieder
2012-07-30 20:15 ` Florian Achleitner
2012-07-30 16:28 ` [RFC v2 01/16] Implement a remote helper for svn in C Junio C Hamano
2012-07-31 19:26 ` Florian Achleitner
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343658683-10713-2-git-send-email-florian.achleitner.2.6.31@gmail.com \
--to=florian.achleitner.2.6.31@gmail.com \
--cc=davidbarr@google.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).