{"thread":{"id":"23764","subject":"[WIP PATCH] Write stubby remote helper for SVN","startedAt":"2010-05-10T11:39:33Z","lastAt":"2010-05-10T13:21:17Z","messageCount":7,"participants":["Ramkumar Ramachandra","Tay Ray Chuan","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141385","messageId":"1273491574-31870-1-git-send-email-artagnon@gmail.com","threadId":"23764","inReplyTo":null,"subject":"[WIP PATCH] Write stubby remote helper for SVN","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-05-10T11:39:33Z","receivedAt":"2010-05-10T11:39:33Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"This is a WIP patch based on master, and is part of my GSoC project\ngit-remote-svn. It is not intended for inclusion- the purpose of the\npatch is to get feedback on aspects such as style and overall\ndesign. I plan to put an SVN client, fast-import and fast-export\nhelpers for SVN inside a directory vcs-svn. Only this file will be in\nthe root directory.\n\nI've also included a Makefile target git-remote-svn, which should\nbuild just fine, but do nothing except list capabilities.\n\nRamkumar Ramachandra (1):\n  Add skeleton remote helper for SVN\n\n Makefile     |    6 ++-\n remote-svn.c |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 207 insertions(+), 1 deletions(-)\n create mode 100644 remote-svn.c\n"},{"id":"141386","messageId":"1273491574-31870-2-git-send-email-artagnon@gmail.com","threadId":"23764","inReplyTo":"1273491574-31870-1-git-send-email-artagnon@gmail.com","subject":"[WIP PATCH] Add skeleton remote helper for SVN","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-05-10T11:39:34Z","receivedAt":"2010-05-10T11:39:34Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Create remote-svn.c, which is essentially a stripped-down version of\nremote-curl.c to build the SVN remote helper upon. Also add a Makefile\nrule to build it.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Makefile     |    6 ++-\n remote-svn.c |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 207 insertions(+), 1 deletions(-)\n create mode 100644 remote-svn.c\n\ndiff --git a/Makefile b/Makefile\nindex 4f7224a..06b969f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1658,7 +1658,7 @@ git.o git.spec \\\n \n TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))\n GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \\\n-\tgit.o http.o http-walker.o remote-curl.o\n+\tgit.o http.o http-walker.o remote-curl.o remote-svn.o\n XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \\\n \txdiff/xmerge.o xdiff/xpatience.o\n OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)\n@@ -1824,6 +1824,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(GITLIBS)\n \t$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \\\n \t\t$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)\n \n+git-remote-svn$X: remote-svn.o $(GITLIBS)\n+\t$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@\t\\\n+\t\t$(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n+\n $(LIB_FILE): $(LIB_OBJS)\n \t$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)\n \ndiff --git a/remote-svn.c b/remote-svn.c\nnew file mode 100644\nindex 0000000..dafbd6a\n--- /dev/null\n+++ b/remote-svn.c\n@@ -0,0 +1,202 @@\n+#include \"cache.h\"\n+#include \"strbuf.h\"\n+#include \"remote.h\"\n+#include \"strbuf.h\"\n+\n+static struct remote *remote;\n+static const char *url;\n+\n+struct options {\n+\tint verbosity;\n+\tunsigned long depth;\n+\tunsigned progress : 1,\n+\t\tdry_run : 1;\n+};\n+static struct options options;\n+\n+static int set_option(const char *name, const char *value)\n+{\n+\tif (!strcmp(name, \"verbosity\")) {\n+\t\tchar *end;\n+\t\tint v = strtol(value, &end, 10);\n+\t\tif (value == end || *end)\n+\t\t\treturn -1;\n+\t\toptions.verbosity = v;\n+\t\treturn 0;\n+\t}\n+\telse if (!strcmp(name, \"progress\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.progress = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.progress = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n+\telse if (!strcmp(name, \"dry-run\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.dry_run = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.dry_run = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n+\telse {\n+\t\treturn 1;\n+\t}\n+}\n+\n+static int export_handler(int nr_spec, char **specs)\n+{\n+\tint err = 0;\n+\n+\t// TODO: The real exporting\n+        // TODO: Write an importer for SVN\n+\t\n+\treturn err;\n+}\n+\n+static int import_handler(int nr_spec, char **specs)\n+{\n+\tint err = 0;\n+\t\n+\t// TODO: The real importing\n+\t// TODO: Hook up an SVN exporter's fast-export stream\n+\n+\treturn err;\n+}\n+\n+static void parse_import(struct strbuf *buf)\n+{\n+\tchar **specs = NULL;\n+\tint alloc_spec = 0, nr_spec = 0, i;\n+\n+\tdo {\n+\t\tif (!prefixcmp(buf->buf, \"import \")) {\n+\t\t\tALLOC_GROW(specs, nr_spec + 1, alloc_spec);\n+\t\t\tspecs[nr_spec++] = xstrdup(buf->buf + 5);\n+\t\t}\n+\t\telse\n+\t\t\tdie(\"remote helper does not support %s\", buf->buf);\n+\n+\t\tstrbuf_reset(buf);\n+\t\tif (strbuf_getline(buf, stdin, '\\n') == EOF)\n+\t\t\treturn;\n+\t\tif (!*buf->buf)\n+\t\t\tbreak;\n+\t} while (1);\n+\n+\tif (import_handler(nr_spec, specs))\n+\t\texit(128); /* error already reported */\n+\tfor (i = 0; i < nr_spec; i++)\n+\t\tfree(specs[i]);\n+\tfree(specs);\n+\n+\tprintf(\"\\n\");\n+\tfflush(stdout);\n+}\n+\n+static void parse_export(struct strbuf *buf)\n+{\n+\tchar **specs = NULL;\n+\tint alloc_spec = 0, nr_spec = 0, i;\n+\n+\tdo {\n+\t\tif (!prefixcmp(buf->buf, \"export \")) {\n+\t\t\tALLOC_GROW(specs, nr_spec + 1, alloc_spec);\n+\t\t\tspecs[nr_spec++] = xstrdup(buf->buf + 5);\n+\t\t}\n+\t\telse\n+\t\t\tdie(\"remote helper does not support %s\", buf->buf);\n+\n+\t\tstrbuf_reset(buf);\n+\t\tif (strbuf_getline(buf, stdin, '\\n') == EOF)\n+\t\t\treturn;\n+\t\tif (!*buf->buf)\n+\t\t\tbreak;\n+\t} while (1);\n+\n+\tif (export_handler(nr_spec, specs))\n+\t\texit(128); /* error already reported */\n+\tfor (i = 0; i < nr_spec; i++)\n+\t\tfree(specs[i]);\n+\tfree(specs);\n+\n+\tprintf(\"\\n\");\n+\tfflush(stdout);\n+}\n+\n+int main(int argc, const char **argv)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint nongit;\n+\n+\t// git_extract_argv0_path(argv[0]);\n+\tsetup_git_directory_gently(&nongit);\n+\tif (argc < 2) {\n+\t\tfprintf(stderr, \"Remote needed\\n\");\n+\t\treturn 1;\n+\t}\n+\n+\toptions.verbosity = 1;\n+\toptions.progress = !!isatty(2);\n+\n+\tremote = remote_get(argv[1]);\n+\n+\tif (argc > 2) {\n+\t\turl = argv[2];\n+\t} else {\n+\t\turl = remote->url[0];\n+\t}\n+\n+\t// open_svn_connection(remote);\n+\tdo {\n+\t\tif (strbuf_getline(&buf, stdin, '\\n') == EOF)\n+\t\t\tbreak;\n+\n+\t\telse if (!strcmp(buf.buf, \"list\")) {\n+\t\t\t// TODO: Code to list refs\n+\t\t\tbreak;\n+\n+\t\t} else if (!prefixcmp(buf.buf, \"import \")) {\n+\t\t\tif (nongit)\n+\t\t\t\tdie(\"Import attempted without a local repo\");\n+\n+\t\t\tparse_import(&buf);\n+\n+\t\t} else if (!prefixcmp(buf.buf, \"export \")) {\n+\t\t\tparse_export(&buf);\n+\n+\t\t} else if (!prefixcmp(buf.buf, \"option \")) {\n+\t\t\tchar *name = buf.buf + strlen(\"option \");\n+\t\t\tchar *value = strchr(name, ' ');\n+\t\t\tint result;\n+\t\t\tif (value)\n+\t\t\t\t*value++ = '\\0';\n+\t\t\telse\n+\t\t\t\tvalue = \"true\";\n+\t\t\tresult = set_option(name, value);\n+\t\t\tif (!result)\n+\t\t\t\tprintf(\"ok\\n\");\n+\t\t\telse if (result < 0)\n+\t\t\t\tprintf(\"error invalid value\\n\");\n+\t\t\telse\n+\t\t\t\tprintf(\"unsupported\\n\");\n+\t\t\tfflush(stdout);\n+\n+\t\t} else if (!strcmp(buf.buf, \"capabilities\")) {\n+\t\t\tprintf(\"option\\n\");\n+\t\t\tprintf(\"import\\n\");\n+\t\t\tprintf(\"export\\n\");\n+\t\t\tprintf(\"\\n\");\n+\t\t\tfflush(stdout);\n+\t\t} else\n+\t\t\treturn 1;\n+\n+\t\tstrbuf_reset(&buf);\n+\t} while (1);\n+\n+\t// close_svn_connection(remote);\n+\treturn 0;\n+}\n-- \n1.7.1\n"},{"id":"141390","messageId":"AANLkTilzn2GLbxz3vLD4SoNIrYDU9_YzFfPI5Wv_WFs2@mail.gmail.com","threadId":"23764","inReplyTo":"1273491574-31870-2-git-send-email-artagnon@gmail.com","subject":"Re: [WIP PATCH] Add skeleton remote helper for SVN","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-05-10T12:00:42Z","receivedAt":"2010-05-10T12:00:42Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Mon, May 10, 2010 at 7:39 PM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> diff --git a/Makefile b/Makefile\n> index 4f7224a..06b969f 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1658,7 +1658,7 @@ git.o git.spec \\\n>\n>  TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))\n>  GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \\\n> -       git.o http.o http-walker.o remote-curl.o\n> +       git.o http.o http-walker.o remote-curl.o remote-svn.o\n>  XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \\\n>        xdiff/xmerge.o xdiff/xpatience.o\n>  OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)\n\nJohnathan (Cc'ed) had a recent patch\n(<20100509035728.GA8198@progeny.tock>) that changed this area, and I\nthink it would be good to build on top of that.\n\n> [snip]\n> diff --git a/remote-svn.c b/remote-svn.c\n> new file mode 100644\n> index 0000000..dafbd6a\n> --- /dev/null\n> +++ b/remote-svn.c\n> @@ -0,0 +1,202 @@\n> [snip]\n> +static int set_option(const char *name, const char *value)\n> +{\n> +       if (!strcmp(name, \"verbosity\")) {\n> +               char *end;\n> +               int v = strtol(value, &end, 10);\n> +               if (value == end || *end)\n> +                       return -1;\n> +               options.verbosity = v;\n> +               return 0;\n> +       }\n> +       else if (!strcmp(name, \"progress\")) {\n\nWe usually put the brace on the same line as the \"else\":\n\n    if (...) {\n      /* stuff */\n    } else if (...) {\n      /* stuff */\n    }\n\n(of course, tabs should be used - gmail doesn't allow me to do it here.)\n\n> [snip]\n> +static int export_handler(int nr_spec, char **specs)\n> +{\n> +       int err = 0;\n> +\n> +       // TODO: The real exporting\n> +        // TODO: Write an importer for SVN\n\nHere and elsewhere - no C++-style comments please.\n\n> [snip]\n> +static void parse_import(struct strbuf *buf)\n> +{\n> +       char **specs = NULL;\n> +       int alloc_spec = 0, nr_spec = 0, i;\n> +\n> +       do {\n> +               if (!prefixcmp(buf->buf, \"import \")) {\n> +                       ALLOC_GROW(specs, nr_spec + 1, alloc_spec);\n> +                       specs[nr_spec++] = xstrdup(buf->buf + 5);\n> +               }\n> +               else\n> +                       die(\"remote helper does not support %s\", buf->buf);\n\nSee note on else-brace style.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"141391","messageId":"AANLkTikFl25Hay7UEvsz5bsdg8fdT8485SxqgAZXCYqd@mail.gmail.com","threadId":"23764","inReplyTo":"AANLkTilzn2GLbxz3vLD4SoNIrYDU9_YzFfPI5Wv_WFs2@mail.gmail.com","subject":"Re: [WIP PATCH] Add skeleton remote helper for SVN","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-05-10T12:31:22Z","receivedAt":"2010-05-10T12:31:22Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Tay,\n\nThanks for the style nitpicks.\n\nOn Mon, May 10, 2010 at 2:00 PM, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> Johnathan (Cc'ed) had a recent patch\n> (<20100509035728.GA8198@progeny.tock>) that changed this area, and I\n> think it would be good to build on top of that.\n\nThis'll probably be ready for inclusion atleast into `pu` in a few\nweeks- I'll rebase it on top of the `master` then before sending it\nout anyway. It'll be good if Jonathan's patch makes it to `master` by\nthen, but I don't think I should prematurely rebase on patches that\naren't in `master` yet.\n\n-- Ram\n"},{"id":"141393","messageId":"20100510125953.GA5642@progeny.tock","threadId":"23764","inReplyTo":"AANLkTikFl25Hay7UEvsz5bsdg8fdT8485SxqgAZXCYqd@mail.gmail.com","subject":"Re: [WIP PATCH] Add skeleton remote helper for SVN","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-05-10T12:59:53Z","receivedAt":"2010-05-10T12:59:53Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Ram,\n\nRamkumar Ramachandra wrote:\n\n> It'll be good if Jonathan's patch makes it to `master` by\n> then, but I don't think I should prematurely rebase on patches that\n> aren't in `master` yet.\n\nSince the conflict resolution is trivial, I agree.  When there is an\nactual dependency between patches, I think there is nothing wrong\nwith basing one patch on another; as long as you make it clear\nwhat your patch applies to, humans and Junio’s scripts can cope with\nthe task of applying one series on top of the topic branch for\nanother.\n\nRe your skeleton code, it looks reasonable to me.  I could nitpick the\nnames of the import_handler() and export_handler() functions and the\nneedless use of do ... while, but I will refrain. :)\n\nMuch more importantly, there is something to play with now.  On that\nnote, is David’s code out there somewhere for people to fool around\nwith?  At this point, I am not interested in a stable interface or\npermanent history, just a way to try out the code and start to get\nused to it.\n\nThanks,\nJonathan\n\n[1] git://repo.or.cz/svn-all-fast-export.git\n"},{"id":"141395","messageId":"AANLkTil8Ezw3rE-q6pQHr4o-aUNXr-HYbFwbX597VlT1@mail.gmail.com","threadId":"23764","inReplyTo":"20100510125953.GA5642@progeny.tock","subject":"Re: [WIP PATCH] Add skeleton remote helper for SVN","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-05-10T13:08:14Z","receivedAt":"2010-05-10T13:08:14Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nOn Mon, May 10, 2010 at 2:59 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Since the conflict resolution is trivial, I agree.  When there is an\n> actual dependency between patches, I think there is nothing wrong\n> with basing one patch on another; as long as you make it clear\n> what your patch applies to, humans and Junio’s scripts can cope with\n> the task of applying one series on top of the topic branch for\n> another.\n\nOkay, got it.\n\n> Re your skeleton code, it looks reasonable to me.  I could nitpick the\n> names of the import_handler() and export_handler() functions and the\n> needless use of do ... while, but I will refrain. :)\n\nYeah, I suppose that can wait for a couple of weeks- atleast until I\nhave something minimally working :)\n\n> Much more importantly, there is something to play with now.  On that\n> note, is David’s code out there somewhere for people to fool around\n> with?  At this point, I am not interested in a stable interface or\n> permanent history, just a way to try out the code and start to get\n> used to it.\n\nYes. You can see it on David's GitHub [1] and my fork [2]. I send\npatches to David by email, so both should be in sync.\n\n-- Ram\n\n[1] http://github.com/barrbrain/svn-dump-fast-export.git\n[2] http://github.com/artagnon/svn-dump-fast-export.git\n"},{"id":"141396","messageId":"20100510132117.GA5746@progeny.tock","threadId":"23764","inReplyTo":"AANLkTil8Ezw3rE-q6pQHr4o-aUNXr-HYbFwbX597VlT1@mail.gmail.com","subject":"Re: [WIP PATCH] Add skeleton remote helper for SVN","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-05-10T13:21:17Z","receivedAt":"2010-05-10T13:21:17Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> [1] http://github.com/barrbrain/svn-dump-fast-export.git\n> [2] http://github.com/artagnon/svn-dump-fast-export.git\n\n>From README.textile:\n\n| h1. A tool to convert a subversion dump for input to git-fast-import\n|\n| This project is now largely functionally complete. There is still\n| quite a bit of testing and code cleanup to be done before the first\n| major release.\n\nAwesome. :) Thank you.\n\nCheers,\nJonathan\n"}]}