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 e99d012a6b 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>
pull/985/head
Jeff King 2 years ago committed by Junio C Hamano
parent a006f875e2
commit fc47391e24
  1. 1
      .gitignore
  2. 26
      Makefile
  3. 26
      contrib/buildsystems/CMakeLists.txt
  4. 4
      contrib/svn-fe/.gitignore
  5. 105
      contrib/svn-fe/Makefile
  6. 18
      contrib/svn-fe/svn-fe.c
  7. 71
      contrib/svn-fe/svn-fe.txt
  8. 68
      contrib/svn-fe/svnrdump_sim.py
  9. 341
      remote-testsvn.c
  10. 2
      t/helper/.gitignore
  11. 81
      t/helper/test-line-buffer.c
  12. 52
      t/helper/test-svn-fe.c
  13. 90
      t/t0081-line-buffer.sh
  14. 1105
      t/t9010-svn-fe.sh
  15. 248
      t/t9011-svn-da.sh
  16. 95
      t/t9020-remote-svn.sh
  17. 2
      t/test-lib-functions.sh
  18. 32
      vcs-svn/LICENSE
  19. 365
      vcs-svn/fast_export.c
  20. 126
      vcs-svn/line_buffer.c
  21. 77
      vcs-svn/line_buffer.txt
  22. 79
      vcs-svn/sliding_window.c
  23. 309
      vcs-svn/svndiff.c
  24. 540
      vcs-svn/svndump.c

1
.gitignore vendored

@ -134,7 +134,6 @@
/git-remote-fd
/git-remote-ext
/git-remote-testpy
/git-remote-testsvn
/git-repack
/git-replace
/git-request-pull

@ -569,7 +569,6 @@ BUILT_INS =
COMPAT_CFLAGS =
COMPAT_OBJS =
XDIFF_OBJS =
VCSSVN_OBJS =
GENERATED_H =
EXTRA_CPPFLAGS =
FUZZ_OBJS =
@ -674,7 +673,6 @@ PROGRAMS += $(EXTRA_PROGRAMS)
PROGRAM_OBJS += daemon.o
PROGRAM_OBJS += http-backend.o
PROGRAM_OBJS += imap-send.o
PROGRAM_OBJS += remote-testsvn.o
PROGRAM_OBJS += sh-i18n--envsubst.o
PROGRAM_OBJS += shell.o
@ -746,8 +744,6 @@ TEST_BUILTINS_OBJS += test-xml-encode.o
# Do not add more tests here unless they have extra dependencies. Add
# them in TEST_BUILTINS_OBJS above.
TEST_PROGRAMS_NEED_X += test-fake-ssh
TEST_PROGRAMS_NEED_X += test-line-buffer
TEST_PROGRAMS_NEED_X += test-svn-fe
TEST_PROGRAMS_NEED_X += test-tool
TEST_PROGRAMS = $(patsubst %,t/helper/%$X,$(TEST_PROGRAMS_NEED_X))
@ -803,7 +799,6 @@ TEST_SHELL_PATH = $(SHELL_PATH)
LIB_FILE = libgit.a
XDIFF_LIB = xdiff/lib.a
VCSSVN_LIB = vcs-svn/lib.a
GENERATED_H += config-list.h
GENERATED_H += command-list.h
@ -2345,16 +2340,9 @@ XDIFF_OBJS += xdiff/xpatience.o
XDIFF_OBJS += xdiff/xprepare.o
XDIFF_OBJS += xdiff/xutils.o
VCSSVN_OBJS += vcs-svn/fast_export.o
VCSSVN_OBJS += vcs-svn/line_buffer.o
VCSSVN_OBJS += vcs-svn/sliding_window.o
VCSSVN_OBJS += vcs-svn/svndiff.o
VCSSVN_OBJS += vcs-svn/svndump.o
TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
$(XDIFF_OBJS) \
$(VCSSVN_OBJS) \
$(FUZZ_OBJS) \
common-main.o \
git.o
@ -2469,10 +2457,6 @@ git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
$(VCSSVN_LIB)
$(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
$(QUIET_LNCP)$(RM) $@ && \
ln $< $@ 2>/dev/null || \
@ -2489,9 +2473,6 @@ $(LIB_FILE): $(LIB_OBJS)
$(XDIFF_LIB): $(XDIFF_OBJS)
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
$(VCSSVN_LIB): $(VCSSVN_OBJS)
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
export DEFAULT_EDITOR DEFAULT_PAGER
Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
@ -2766,10 +2747,6 @@ perf: all
.PHONY: test perf
t/helper/test-line-buffer$X: $(VCSSVN_LIB)
t/helper/test-svn-fe$X: $(VCSSVN_LIB)
.PRECIOUS: $(TEST_OBJS)
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
@ -2902,7 +2879,6 @@ ifdef MSVC
$(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
$(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
$(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
$(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
$(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
ifndef DEBUG
$(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
@ -3103,7 +3079,7 @@ cocciclean:
clean: profile-clean coverage-clean cocciclean
$(RM) *.res
$(RM) $(OBJECTS)
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
$(RM) $(LIB_FILE) $(XDIFF_LIB)
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
$(RM) $(TEST_PROGRAMS)
$(RM) $(FUZZ_PROGRAMS)

@ -502,7 +502,7 @@ unset(CMAKE_REQUIRED_INCLUDES)
#programs
set(PROGRAMS_BUILT
git git-daemon git-http-backend git-sh-i18n--envsubst
git-shell git-remote-testsvn)
git-shell)
if(NOT CURL_FOUND)
list(APPEND excluded_progs git-http-fetch git-http-push)
@ -568,12 +568,6 @@ parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
add_library(xdiff STATIC ${libxdiff_SOURCES})
#libvcs-svn
parse_makefile_for_sources(libvcs-svn_SOURCES "VCSSVN_OBJS")
list(TRANSFORM libvcs-svn_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
add_library(vcs-svn STATIC ${libvcs-svn_SOURCES})
if(WIN32)
if(NOT MSVC)#use windres when compiling with gcc and clang
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
@ -654,9 +648,6 @@ if(CURL_FOUND)
endif()
endif()
add_executable(git-remote-testsvn ${CMAKE_SOURCE_DIR}/remote-testsvn.c)
target_link_libraries(git-remote-testsvn common-main vcs-svn)
set(git_builtin_extra
cherry cherry-pick format-patch fsck-objects
init merge-subtree restore show
@ -832,12 +823,6 @@ if(BUILD_TESTING)
add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
target_link_libraries(test-fake-ssh common-main)
add_executable(test-line-buffer ${CMAKE_SOURCE_DIR}/t/helper/test-line-buffer.c)
target_link_libraries(test-line-buffer common-main vcs-svn)
add_executable(test-svn-fe ${CMAKE_SOURCE_DIR}/t/helper/test-svn-fe.c)
target_link_libraries(test-svn-fe common-main vcs-svn)
#test-tool
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
@ -845,13 +830,13 @@ list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
target_link_libraries(test-tool common-main)
set_target_properties(test-fake-ssh test-line-buffer test-svn-fe test-tool
set_target_properties(test-fake-ssh test-tool
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
if(MSVC)
set_target_properties(test-fake-ssh test-line-buffer test-svn-fe test-tool
set_target_properties(test-fake-ssh test-tool
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
set_target_properties(test-fake-ssh test-line-buffer test-svn-fe test-tool
set_target_properties(test-fake-ssh test-tool
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
endif()
@ -860,7 +845,7 @@ set(wrapper_scripts
git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext)
set(wrapper_test_scripts
test-fake-ssh test-line-buffer test-svn-fe test-tool)
test-fake-ssh test-tool)
foreach(script ${wrapper_scripts})
@ -961,7 +946,6 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
file(COPY ${CMAKE_SOURCE_DIR}/contrib/svn-fe/svnrdump_sim.py DESTINATION ${CMAKE_BINARY_DIR}/contrib/svn-fe/)
endif()
file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")

@ -1,4 +0,0 @@
/*.xml
/*.1
/*.html
/svn-fe

@ -1,105 +0,0 @@
all:: svn-fe$X
CC = cc
RM = rm -f
MV = mv
CFLAGS = -g -O2 -Wall
LDFLAGS =
EXTLIBS = -lz
include ../../config.mak.uname
-include ../../config.mak.autogen
-include ../../config.mak
ifeq ($(uname_S),Darwin)
ifndef NO_FINK
ifeq ($(shell test -d /sw/lib && echo y),y)
CFLAGS += -I/sw/include
LDFLAGS += -L/sw/lib
endif
endif
ifndef NO_DARWIN_PORTS
ifeq ($(shell test -d /opt/local/lib && echo y),y)
CFLAGS += -I/opt/local/include
LDFLAGS += -L/opt/local/lib
endif
endif
endif
ifndef NO_OPENSSL
EXTLIBS += -lssl
ifdef NEEDS_CRYPTO_WITH_SSL
EXTLIBS += -lcrypto
endif
endif
ifndef NO_PTHREADS
CFLAGS += $(PTHREADS_CFLAGS)
EXTLIBS += $(PTHREAD_LIBS)
endif
ifdef HAVE_CLOCK_GETTIME
CFLAGS += -DHAVE_CLOCK_GETTIME
EXTLIBS += -lrt
endif
ifdef NEEDS_LIBICONV
EXTLIBS += -liconv
endif
GIT_LIB = ../../libgit.a
VCSSVN_LIB = ../../vcs-svn/lib.a
XDIFF_LIB = ../../xdiff/lib.a
LIBS = $(VCSSVN_LIB) $(GIT_LIB) $(XDIFF_LIB)
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =
ifneq ($(findstring $(MAKEFLAGS),w),w)
PRINT_DIR = --no-print-directory
else # "make -w"
NO_SUBDIR = :
endif
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_CC = @echo ' ' CC $@;
QUIET_LINK = @echo ' ' LINK $@;
QUIET_SUBDIR0 = +@subdir=
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
$(MAKE) $(PRINT_DIR) -C $$subdir
endif
endif
svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(XDIFF_LIB) $(GIT_LIB)
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(EXTLIBS) -o $@ svn-fe.o $(LIBS)
svn-fe.o: svn-fe.c ../../vcs-svn/svndump.h
$(QUIET_CC)$(CC) $(CFLAGS) -I../../vcs-svn -o $*.o -c $<
svn-fe.html: svn-fe.txt
$(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
MAN_TXT=../contrib/svn-fe/svn-fe.txt \
../contrib/svn-fe/$@
svn-fe.1: svn-fe.txt
$(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
MAN_TXT=../contrib/svn-fe/svn-fe.txt \
../contrib/svn-fe/$@
$(MV) ../../Documentation/svn-fe.1 .
../../vcs-svn/lib.a: FORCE
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) vcs-svn/lib.a
../../xdiff/lib.a: FORCE
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) xdiff/lib.a
../../libgit.a: FORCE
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) libgit.a
clean:
$(RM) svn-fe$X svn-fe.o svn-fe.html svn-fe.xml svn-fe.1
.PHONY: all clean FORCE

@ -1,18 +0,0 @@
/*
* This file is in the public domain.
* You may freely use, modify, distribute, and relicense it.
*/
#include <stdlib.h>
#include "svndump.h"
int main(int argc, char **argv)
{
if (svndump_init(NULL))
return 1;
svndump_read((argc > 1) ? argv[1] : NULL, "refs/heads/master",
"refs/notes/svn/revs");
svndump_deinit();
svndump_reset();
return 0;
}

@ -1,71 +0,0 @@
svn-fe(1)
=========
NAME
----
svn-fe - convert an SVN "dumpfile" to a fast-import stream
SYNOPSIS
--------
[verse]
mkfifo backchannel &&
svnadmin dump --deltas REPO |
svn-fe [url] 3<backchannel |
git fast-import --cat-blob-fd=3 3>backchannel
DESCRIPTION
-----------
Converts a Subversion dumpfile into input suitable for
git-fast-import(1) and similar importers. REPO is a path to a
Subversion repository mirrored on the local disk. Remote Subversion
repositories can be mirrored on local disk using the `svnsync`
command.
Note: this tool is very young. The details of its commandline
interface may change in backward incompatible ways.
INPUT FORMAT
------------
Subversion's repository dump format is documented in full in
`notes/dump-load-format.txt` from the Subversion source tree.
Files in this format can be generated using the 'svnadmin dump' or
'svk admin dump' command.
OUTPUT FORMAT
-------------
The fast-import format is documented by the git-fast-import(1)
manual page.
NOTES
-----
Subversion dumps do not record a separate author and committer for
each revision, nor do they record a separate display name and email
address for each author. Like git-svn(1), 'svn-fe' will use the name
---------
user <user@UUID>
---------
as committer, where 'user' is the value of the `svn:author` property
and 'UUID' the repository's identifier.
To support incremental imports, 'svn-fe' puts a `git-svn-id` line at
the end of each commit log message if passed a URL on the command
line. This line has the form `git-svn-id: URL@REVNO UUID`.
The resulting repository will generally require further processing
to put each project in its own repository and to separate the history
of each branch. The 'git filter-repo --subdirectory-filter' command
may be useful for this purpose.
BUGS
----
Empty directories and unknown properties are silently discarded.
The exit status does not reflect whether an error was detected.
SEE ALSO
--------
git-svn(1), svn2git(1), svk(1), git-filter-repo(1), git-fast-import(1),
https://svn.apache.org/repos/asf/subversion/trunk/notes/dump-load-format.txt

@ -1,68 +0,0 @@
#!/usr/bin/env python
"""
Simulates svnrdump by replaying an existing dump from a file, taking care
of the specified revision range.
To simulate incremental imports the environment variable SVNRMAX can be set
to the highest revision that should be available.
"""
import sys
import os
if sys.hexversion < 0x02040000:
# The limiter is the ValueError() calls. This may be too conservative
sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
sys.exit(1)
def getrevlimit():
var = 'SVNRMAX'
if var in os.environ:
return os.environ[var]
return None
def writedump(url, lower, upper):
if url.startswith('sim://'):
filename = url[6:]
if filename[-1] == '/':
filename = filename[:-1] # remove terminating slash
else:
raise ValueError('sim:// url required')
f = open(filename, 'r')
state = 'header'
wroterev = False
while(True):
l = f.readline()
if l == '':
break
if state == 'header' and l.startswith('Revision-number: '):
state = 'prefix'
if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
state = 'selection'
if not upper == 'HEAD' and state == 'selection' and \
l == 'Revision-number: %s\n' % upper:
break
if state == 'header' or state == 'selection':
if state == 'selection':
wroterev = True
sys.stdout.write(l)
return wroterev
if __name__ == "__main__":
if not (len(sys.argv) in (3, 4, 5)):
print("usage: %s dump URL -rLOWER:UPPER")
sys.exit(1)
if not sys.argv[1] == 'dump':
raise NotImplementedError('only "dump" is supported.')
url = sys.argv[2]
r = ('0', 'HEAD')
if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
r = sys.argv[3][2:].lstrip().split(':')
if not getrevlimit() is None:
r[1] = getrevlimit()
if writedump(url, r[0], r[1]):
ret = 0
else:
ret = 1
sys.exit(ret)

@ -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;
}

@ -1,4 +1,2 @@
/test-tool
/test-fake-ssh
/test-line-buffer
/test-svn-fe

@ -1,81 +0,0 @@
/*
* test-line-buffer.c: code to exercise the svn importer's input helper
*/
#include "git-compat-util.h"
#include "strbuf.h"
#include "vcs-svn/line_buffer.h"
static uint32_t strtouint32(const char *s)
{
char *end;
uintmax_t n = strtoumax(s, &end, 10);
if (*s == '\0' || *end != '\0')
die("invalid count: %s", s);
return (uint32_t) n;
}
static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
{
if (starts_with(command, "binary ")) {
struct strbuf sb = STRBUF_INIT;
strbuf_addch(&sb, '>');
buffer_read_binary(buf, &sb, strtouint32(arg));
fwrite(sb.buf, 1, sb.len, stdout);
strbuf_release(&sb);
} else if (starts_with(command, "copy ")) {
buffer_copy_bytes(buf, strtouint32(arg));
} else if (starts_with(command, "skip ")) {
buffer_skip_bytes(buf, strtouint32(arg));
} else {
die("unrecognized command: %s", command);
}
}
static void handle_line(const char *line, struct line_buffer *stdin_buf)
{
const char *arg = strchr(line, ' ');
if (!arg)
die("no argument in line: %s", line);
handle_command(line, arg + 1, stdin_buf);
}
int cmd_main(int argc, const char **argv)
{
struct line_buffer stdin_buf = LINE_BUFFER_INIT;
struct line_buffer file_buf = LINE_BUFFER_INIT;
struct line_buffer *input = &stdin_buf;
const char *filename;
char *s;
if (argc == 1)
filename = NULL;
else if (argc == 2)
filename = argv[1];
else
usage("test-line-buffer [file | &fd] < script");
if (buffer_init(&stdin_buf, NULL))
die_errno("open error");
if (filename) {
if (*filename == '&') {
if (buffer_fdinit(&file_buf, strtouint32(filename + 1)))
die_errno("error opening fd %s", filename + 1);
} else {
if (buffer_init(&file_buf, filename))
die_errno("error opening %s", filename);
}
input = &file_buf;
}
while ((s = buffer_read_line(&stdin_buf)))
handle_line(s, input);
if (filename && buffer_deinit(&file_buf))
die("error reading from %s", filename);
if (buffer_deinit(&stdin_buf))
die("input error");
if (ferror(stdout))
die("output error");
return 0;
}

@ -1,52 +0,0 @@
/*
* test-svn-fe: Code to exercise the svn import lib
*/
#include "git-compat-util.h"
#include "vcs-svn/svndump.h"
#include "vcs-svn/svndiff.h"
#include "vcs-svn/sliding_window.h"
#include "vcs-svn/line_buffer.h"
static const char test_svnfe_usage[] =
"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
static int apply_delta(int argc, const char **argv)
{
struct line_buffer preimage = LINE_BUFFER_INIT;
struct line_buffer delta = LINE_BUFFER_INIT;
struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage, -1);
if (argc != 5)
usage(test_svnfe_usage);
if (buffer_init(&preimage, argv[2]))
die_errno("cannot open preimage");
if (buffer_init(&delta, argv[3]))
die_errno("cannot open delta");
if (svndiff0_apply(&delta, (off_t) strtoumax(argv[4], NULL, 0),
&preimage_view, stdout))
return 1;
if (buffer_deinit(&preimage))
die_errno("cannot close preimage");
if (buffer_deinit(&delta))
die_errno("cannot close delta");
strbuf_release(&preimage_view.buf);
return 0;
}
int cmd_main(int argc, const char **argv)
{
if (argc == 2) {
if (svndump_init(argv[1]))
return 1;
svndump_read(NULL, "refs/heads/master", "refs/notes/svn/revs");
svndump_deinit();
svndump_reset();
return 0;
}
if (argc >= 2 && !strcmp(argv[1], "-d"))
return apply_delta(argc, argv);
usage(test_svnfe_usage);
}

@ -1,90 +0,0 @@
#!/bin/sh
test_description="Test the svn importer's input handling routines.
These tests provide some simple checks that the line_buffer API
behaves as advertised.
While at it, check that input of newlines and null bytes are handled
correctly.
"
. ./test-lib.sh
test_expect_success 'hello world' '
echo ">HELLO" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 6
HELLO
EOF
test_cmp expect actual
'
test_expect_success '0-length read, send along greeting' '
echo ">HELLO" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 0
copy 6
HELLO
EOF
test_cmp expect actual
'
test_expect_success !MINGW 'read from file descriptor' '
rm -f input &&
echo hello >expect &&
echo hello >input &&
echo copy 6 |
test-line-buffer "&4" 4<input >actual &&
test_cmp expect actual
'
test_expect_success 'skip, copy null byte' '
echo Q | q_to_nul >expect &&
q_to_nul <<-\EOF | test-line-buffer >actual &&
skip 2
Q
copy 2
Q
EOF
test_cmp expect actual
'
test_expect_success 'read null byte' '
echo ">QhelloQ" | q_to_nul >expect &&
q_to_nul <<-\EOF | test-line-buffer >actual &&
binary 8
QhelloQ
EOF
test_cmp expect actual
'
test_expect_success 'long reads are truncated' '
echo ">foo" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 5
foo
EOF
test_cmp expect actual
'
test_expect_success 'long copies are truncated' '
printf "%s\n" ">" foo >expect &&
test-line-buffer <<-\EOF >actual &&
binary 1
copy 5
foo
EOF
test_cmp expect actual
'
test_expect_success 'long binary reads are truncated' '
echo ">foo" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 5
foo
EOF
test_cmp expect actual
'
test_done

@ -1,1105 +0,0 @@
#!/bin/sh
test_description='check svn dumpfile importer'
. ./test-lib.sh
if test_have_prereq !PIPE
then
skip_all="svn dumpfile importer testing requires the PIPE prerequisite"
test_done
fi
reinit_git () {
rm -fr .git &&
rm -f stream backflow &&
git init &&
mkfifo stream backflow
}
try_dump () {
input=$1 &&
maybe_fail_svnfe=${2:+test_$2} &&
maybe_fail_fi=${3:+test_$3} &&
{
$maybe_fail_svnfe test-svn-fe "$input" >stream 3<backflow &
} &&
$maybe_fail_fi git fast-import --cat-blob-fd=3 <stream 3>backflow &&
wait $!
}
properties () {
while test "$#" -ne 0
do
property="$1" &&
value="$2" &&
printf "%s\n" "K ${#property}" &&
printf "%s\n" "$property" &&
printf "%s\n" "V ${#value}" &&
printf "%s\n" "$value" &&
shift 2 ||
return 1
done
}
text_no_props () {
text="$1
" &&
printf "%s\n" "Prop-content-length: 10" &&
printf "%s\n" "Text-content-length: ${#text}" &&
printf "%s\n" "Content-length: $((${#text} + 10))" &&
printf "%s\n" "" "PROPS-END" &&
printf "%s\n" "$text"
}
test_expect_success 'empty dump' '
reinit_git &&
echo "SVN-fs-dump-format-version: 2" >input &&
try_dump input
'
test_expect_success 'v4 dumps not supported' '
reinit_git &&
echo "SVN-fs-dump-format-version: 4" >v4.dump &&
try_dump v4.dump must_fail
'
test_expect_failure 'empty revision' '
reinit_git &&
printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
cat >emptyrev.dump <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 0
Content-length: 0
Revision-number: 2
Prop-content-length: 0
Content-length: 0
EOF
try_dump emptyrev.dump &&
git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
test_cmp expect actual
'
test_expect_success 'empty properties' '
reinit_git &&
printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
cat >emptyprop.dump <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 10
Content-length: 10
PROPS-END
Revision-number: 2
Prop-content-length: 10
Content-length: 10
PROPS-END
EOF
try_dump emptyprop.dump &&
git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
test_cmp expect actual
'
test_expect_success 'author name and commit message' '
reinit_git &&
echo "<author@example.com, author@example.com@local>" >expect.author &&
cat >message <<-\EOF &&
A concise summary of the change
A detailed description of the change, why it is needed, what
was broken and why applying this is the best course of action.
* file.c
Details pertaining to an individual file.
EOF
{
properties \
svn:author author@example.com \
svn:log "$(cat message)" &&
echo PROPS-END
} >props &&
{
echo "SVN-fs-dump-format-version: 3" &&
echo &&
echo "Revision-number: 1" &&
echo Prop-content-length: $(wc -c <props) &&
echo Content-length: $(wc -c <props) &&
echo &&
cat props
} >log.dump &&
try_dump log.dump &&
git log -p --format="%B" HEAD >actual.log &&
git log --format="<%an, %ae>" >actual.author &&
test_cmp message actual.log &&
test_cmp expect.author actual.author
'
test_expect_success 'unsupported properties are ignored' '
reinit_git &&
echo author >expect &&
cat >extraprop.dump <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 56
Content-length: 56
K 8
nonsense
V 1
y
K 10
svn:author
V 6
author
PROPS-END
EOF
try_dump extraprop.dump &&
git log -p --format=%an HEAD >actual &&
test_cmp expect actual
'
test_expect_failure 'timestamp and empty file' '
echo author@example.com >expect.author &&
echo 1999-01-01 >expect.date &&
echo file >expect.files &&
reinit_git &&
{
properties \
svn:author author@example.com \
svn:date "1999-01-01T00:01:002.000000Z" \
svn:log "add empty file" &&
echo PROPS-END
} >props &&
{
cat <<-EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
EOF
echo Prop-content-length: $(wc -c <props) &&
echo Content-length: $(wc -c <props) &&
echo &&
cat props &&
cat <<-\EOF
Node-path: empty-file
Node-kind: file
Node-action: add
Content-length: 0
EOF
} >emptyfile.dump &&
try_dump emptyfile.dump &&
git log --format=%an HEAD >actual.author &&
git log --date=short --format=%ad HEAD >actual.date &&
git ls-tree -r --name-only HEAD >actual.files &&
test_cmp expect.author actual.author &&
test_cmp expect.date actual.date &&
test_cmp expect.files actual.files &&
git checkout HEAD empty-file &&
test_must_be_empty file
'
test_expect_success 'directory with files' '
reinit_git &&
printf "%s\n" directory/file1 directory/file2 >expect.files &&
echo hi >hi &&
echo hello >hello &&
{
properties \
svn:author author@example.com \
svn:date "1999-02-01T00:01:002.000000Z" \
svn:log "add directory with some files in it" &&
echo PROPS-END
} >props &&
{
cat <<-EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
EOF
echo Prop-content-length: $(wc -c <props) &&
echo Content-length: $(wc -c <props) &&
echo &&
cat props &&
cat <<-\EOF &&
Node-path: directory
Node-kind: dir
Node-action: add
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: directory/file1
Node-kind: file
Node-action: add
EOF
text_no_props hello &&
cat <<-\EOF &&
Node-path: directory/file2
Node-kind: file
Node-action: add
EOF
text_no_props hi
} >directory.dump &&
try_dump directory.dump &&
git ls-tree -r --name-only HEAD >actual.files &&
git checkout HEAD directory &&
test_cmp expect.files actual.files &&
test_cmp hello directory/file1 &&
test_cmp hi directory/file2
'
test_expect_success 'branch name with backslash' '
reinit_git &&
sort <<-\EOF >expect.branch-files &&
trunk/file1
trunk/file2
"branches/UpdateFOPto094\\/file1"
"branches/UpdateFOPto094\\/file2"
EOF
echo hi >hi &&
echo hello >hello &&
{
properties \
svn:author author@example.com \
svn:date "1999-02-02T00:01:02.000000Z" \
svn:log "add directory with some files in it" &&
echo PROPS-END
} >props.setup &&
{
properties \
svn:author brancher@example.com \
svn:date "2007-12-06T21:38:34.000000Z" \
svn:log "Updating fop to .94 and adjust fo-stylesheets" &&
echo PROPS-END
} >props.branch &&
{
cat <<-EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
EOF
echo Prop-content-length: $(wc -c <props.setup) &&
echo Content-length: $(wc -c <props.setup) &&
echo &&
cat props.setup &&
cat <<-\EOF &&
Node-path: trunk
Node-kind: dir
Node-action: add
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: branches
Node-kind: dir
Node-action: add
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: trunk/file1
Node-kind: file
Node-action: add
EOF
text_no_props hello &&
cat <<-\EOF &&
Node-path: trunk/file2
Node-kind: file
Node-action: add
EOF
text_no_props hi &&
cat <<-\EOF &&
Revision-number: 2
EOF
echo Prop-content-length: $(wc -c <props.branch) &&
echo Content-length: $(wc -c <props.branch) &&
echo &&
cat props.branch &&
cat <<-\EOF
Node-path: branches/UpdateFOPto094\