summaryrefslogtreecommitdiff
path: root/remote-testsvn.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-08-13 15:00:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-13 18:02:15 (GMT)
commitfc47391e2478b26d33cae033f13405b6ee6af97b (patch)
tree9cebfb9d4bbbcee8feea178c17976ec28652145c /remote-testsvn.c
parenta006f875e2689cb7df543d5950beadb0416d305b (diff)
downloadgit-fc47391e2478b26d33cae033f13405b6ee6af97b.zip
git-fc47391e2478b26d33cae033f13405b6ee6af97b.tar.gz
git-fc47391e2478b26d33cae033f13405b6ee6af97b.tar.bz2
drop vcs-svn experiment
The code in vcs-svn was started in 2010 as an attempt to build a remote-helper for interacting with svn repositories (as opposed to git-svn). However, we never got as far as shipping a mature remote helper, and the last substantive commit was e99d012a6bc in 2012. We do have a git-remote-testsvn, and it is even installed as part of "make install". But given the name, it seems unlikely to be used by anybody (you'd have to explicitly "git clone testsvn::$url", and there have been zero mentions of that on the mailing list since 2013, and even that includes the phrase "you might need to hack a bit to get it working properly"[1]). We also ship contrib/svn-fe, which builds on the vcs-svn work. However, it does not seem to build out of the box for me, as the link step misses some required libraries for using libgit.a. Curiously, the original build breakage bisects for me to eff80a9fd9 (Allow custom "comment char", 2013-01-16), which seems unrelated. There was an attempt to fix it in da011cb0e7 (contrib/svn-fe: fix Makefile, 2014-08-28), but on my system that only switches the error message. So it seems like the result is not really usable by anybody in practice. It would be wonderful if somebody wanted to pick up the topic again, and potentially it's worth carrying around for that reason. But the flip side is that people doing tree-wide operations have to deal with this code. And you can see the list with (replace "HEAD" with this commit as appropriate): { echo "--" git diff-tree --diff-filter=D -r --name-only HEAD^ HEAD } | git log --no-merges --oneline e99d012a6bc.. --stdin which shows 58 times somebody had to deal with the code, generally due to a compile or test failure, or a tree-wide style fix or API change. Let's drop it and let anybody who wants to pick it up do so by resurrecting it from the git history. As a bonus, this also reduces the size of a stripped installation of Git from 21MB to 19MB. [1] https://lore.kernel.org/git/CALkWK0mPHzKfzFKKpZkfAus3YVC9NFYDbFnt+5JQYVKipk3bQQ@mail.gmail.com/ Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote-testsvn.c')
-rw-r--r--remote-testsvn.c341
1 files changed, 0 insertions, 341 deletions
diff --git a/remote-testsvn.c b/remote-testsvn.c
deleted file mode 100644
index 636b2b6..0000000
--- a/remote-testsvn.c
+++ /dev/null
@@ -1,341 +0,0 @@
-#include "cache.h"
-#include "refs.h"
-#include "remote.h"
-#include "object-store.h"
-#include "strbuf.h"
-#include "url.h"
-#include "exec-cmd.h"
-#include "run-command.h"
-#include "vcs-svn/svndump.h"
-#include "notes.h"
-#include "strvec.h"
-
-static const char *url;
-static int dump_from_file;
-static const char *private_ref;
-static char *remote_ref;
-static const char *marksfilename, *notes_ref;
-struct rev_note { unsigned int rev_nr; };
-
-static int cmd_capabilities(const char *line);
-static int cmd_import(const char *line);
-static int cmd_list(const char *line);
-
-typedef int (*input_command_handler)(const char *);
-struct input_command_entry {
- const char *name;
- input_command_handler fn;
- 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 }
-};
-
-static int cmd_capabilities(const char *line)
-{
- printf("import\n");
- printf("bidi-import\n");
- printf("refspec %s:%s\n\n", remote_ref, private_ref);
- fflush(stdout);
- return 0;
-}
-
-static void terminate_batch(void)
-{
- /* terminate a current batch's fast-import stream */
- printf("done\n");
- fflush(stdout);
-}
-
-/* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */
-static char *read_ref_note(const struct object_id *oid)
-{
- const struct object_id *note_oid;
- char *msg = NULL;
- unsigned long msglen;
- enum object_type type;
-
- init_notes(NULL, notes_ref, NULL, 0);
- if (!(note_oid = get_note(NULL, oid)))
- return NULL; /* note tree not found */
- if (!(msg = read_object_file(note_oid, &type, &msglen)))
- error("Empty notes tree. %s", notes_ref);
- else if (!msglen || type != OBJ_BLOB) {
- error("Note contains unusable content. "
- "Is something else using this notes tree? %s", notes_ref);
- FREE_AND_NULL(msg);
- }
- free_notes(NULL);
- return msg;
-}
-
-static int parse_rev_note(const char *msg, struct rev_note *res)
-{
- const char *key, *value, *end;
- size_t len;
-
- while (*msg) {
- end = strchrnul(msg, '\n');
- len = end - msg;
-
- key = "Revision-number: ";
- if (starts_with(msg, key)) {
- long i;
- char *end;
- value = msg + strlen(key);
- i = strtol(value, &end, 0);
- if (end == value || i < 0 || i > UINT32_MAX)
- return -1;
- res->rev_nr = i;
- return 0;
- }
- msg += len + 1;
- }
- /* didn't find it */
- return -1;
-}
-
-static int note2mark_cb(const struct object_id *object_oid,
- const struct object_id *note_oid, char *note_path,
- void *cb_data)
-{
- FILE *file = (FILE *)cb_data;
- char *msg;
- unsigned long msglen;
- enum object_type type;
- struct rev_note note;
-
- if (!(msg = read_object_file(note_oid, &type, &msglen)) ||
- !msglen || type != OBJ_BLOB) {
- free(msg);
- return 1;
- }
- if (parse_rev_note(msg, &note))
- return 2;
- if (fprintf(file, ":%d %s\n", note.rev_nr, oid_to_hex(object_oid)) < 1)
- return 3;
- return 0;
-}
-
-static void regenerate_marks(void)
-{
- int ret;
- FILE *marksfile = xfopen(marksfilename, "w+");
-
- ret = for_each_note(NULL, 0, note2mark_cb, marksfile);
- if (ret)
- die("Regeneration of marks failed, returned %d.", ret);
- fclose(marksfile);
-}
-
-static void check_or_regenerate_marks(int latestrev)
-{
- FILE *marksfile;
- struct strbuf sb = STRBUF_INIT;
- struct strbuf line = STRBUF_INIT;
- int found = 0;
-
- if (latestrev < 1)
- return;
-
- init_notes(NULL, notes_ref, NULL, 0);
- marksfile = fopen(marksfilename, "r");
- if (!marksfile) {
- regenerate_marks();
- marksfile = xfopen(marksfilename, "r");
- fclose(marksfile);
- } else {
- strbuf_addf(&sb, ":%d ", latestrev);
- while (strbuf_getline_lf(&line, marksfile) != EOF) {
- if (starts_with(line.buf, sb.buf)) {
- found++;
- break;
- }
- }
- fclose(marksfile);
- if (!found)
- regenerate_marks();
- }
- free_notes(NULL);
- strbuf_release(&sb);
- strbuf_release(&line);
-}
-
-static int cmd_import(const char *line)
-{
- int code;
- int dumpin_fd;
- char *note_msg;
- struct object_id head_oid;
- unsigned int startrev;
- struct child_process svndump_proc = CHILD_PROCESS_INIT;
- const char *command = "svnrdump";
-
- if (read_ref(private_ref, &head_oid))
- startrev = 0;
- else {
- note_msg = read_ref_note(&head_oid);
- if(note_msg == NULL) {
- warning("No note found for %s.", private_ref);
- startrev = 0;
- } else {
- struct rev_note note = { 0 };
- if (parse_rev_note(note_msg, &note))
- die("Revision number couldn't be parsed from note.");
- startrev = note.rev_nr + 1;
- free(note_msg);
- }
- }
- check_or_regenerate_marks(startrev - 1);
-
- if (dump_from_file) {
- dumpin_fd = open(url, O_RDONLY);
- if(dumpin_fd < 0)
- die_errno("Couldn't open svn dump file %s.", url);
- } else {
- svndump_proc.out = -1;
- strvec_push(&svndump_proc.args, command);
- strvec_push(&svndump_proc.args, "dump");
- strvec_push(&svndump_proc.args, url);
- strvec_pushf(&svndump_proc.args, "-r%u:HEAD", startrev);
-
- code = start_command(&svndump_proc);
- if (code)
- die("Unable to start %s, code %d", command, code);
- dumpin_fd = svndump_proc.out;
- }
- /* setup marks file import/export */
- printf("feature import-marks-if-exists=%s\n"
- "feature export-marks=%s\n", marksfilename, marksfilename);
-
- svndump_init_fd(dumpin_fd, STDIN_FILENO);
- svndump_read(url, private_ref, notes_ref);
- svndump_deinit();
- svndump_reset();
-
- close(dumpin_fd);
- if (!dump_from_file) {
- code = finish_command(&svndump_proc);
- if (code)
- warning("%s, returned %d", command, code);
- }
-
- return 0;
-}
-
-static int cmd_list(const char *line)
-{
- printf("? %s\n\n", remote_ref);
- fflush(stdout);
- return 0;
-}
-
-static int do_command(struct strbuf *line)
-{
- const struct input_command_entry *p = input_command_list;
- static struct string_list batchlines = STRING_LIST_INIT_DUP;
- static const struct input_command_entry *batch_cmd;
- /*
- * commands can be grouped together in a batch.
- * Batches are ended by \n. If no batch is active the program ends.
- * During a batch all lines are buffered and passed to the handler function
- * when the batch is terminated.
- */
- if (line->len == 0) {
- if (batch_cmd) {
- struct string_list_item *item;
- for_each_string_list_item(item, &batchlines)
- batch_cmd->fn(item->string);
- terminate_batch();
- batch_cmd = NULL;
- string_list_clear(&batchlines, 0);
- return 0; /* end of the batch, continue reading other commands. */
- }
- return 1; /* end of command stream, quit */
- }
- if (batch_cmd) {
- if (!starts_with(batch_cmd->name, line->buf))
- die("Active %s batch interrupted by %s", batch_cmd->name, line->buf);
- /* buffer batch lines */
- string_list_append(&batchlines, line->buf);
- return 0;
- }
-
- for (p = input_command_list; p->name; p++) {
- if (starts_with(line->buf, p->name) && (strlen(p->name) == line->len ||
- line->buf[strlen(p->name)] == ' ')) {
- if (p->batchable) {
- batch_cmd = p;
- string_list_append(&batchlines, line->buf);
- return 0;
- }
- return p->fn(line->buf);
- }
- }
- die("Unknown command '%s'\n", line->buf);
- return 0;
-}
-
-int cmd_main(int argc, const char **argv)
-{
- struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
- private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
- notes_ref_sb = STRBUF_INIT;
- static struct remote *remote;
- const char *url_in, *remote_ref_short;
-
- setup_git_directory();
- if (argc < 2 || argc > 3) {
- usage("git-remote-svn <remote-name> [<url>]");
- return 1;
- }
-
- remote_ref_short = git_default_branch_name();
- remote_ref = xstrfmt("refs/heads/%s", remote_ref_short);
-
- remote = remote_get(argv[1]);
- url_in = (argc == 3) ? argv[2] : remote->url[0];
-
- if (starts_with(url_in, "file://")) {
- dump_from_file = 1;
- url = url_decode(url_in + sizeof("file://")-1);
- } else {
- dump_from_file = 0;
- end_url_with_slash(&url_sb, url_in);
- url = url_sb.buf;
- }
-
- strbuf_addf(&private_ref_sb, "refs/svn/%s/%s",
- remote->name, remote_ref_short);
- private_ref = private_ref_sb.buf;
-
- strbuf_addf(&notes_ref_sb, "refs/notes/%s/revs", remote->name);
- notes_ref = notes_ref_sb.buf;
-
- strbuf_addf(&marksfilename_sb, "%s/info/fast-import/remote-svn/%s.marks",
- get_git_dir(), remote->name);
- marksfilename = marksfilename_sb.buf;
-
- while (1) {
- if (strbuf_getline_lf(&buf, stdin) == EOF) {
- if (ferror(stdin))
- die("Error reading command stream");
- else
- die("Unexpected end of command stream");
- }
- if (do_command(&buf))
- break;
- strbuf_reset(&buf);
- }
-
- strbuf_release(&buf);
- strbuf_release(&url_sb);
- strbuf_release(&private_ref_sb);
- strbuf_release(&notes_ref_sb);
- strbuf_release(&marksfilename_sb);
- return 0;
-}