From 74d817cf8cf68104564cf6c93c1361f66dad1901 Mon Sep 17 00:00:00 2001 From: Jochen Voss Date: Sat, 28 Jun 2008 17:04:24 +0100 Subject: [PATCH 1/5] avoid off-by-one error in run_upload_archive Make sure that buf has enough space to store the trailing \0 of the command line argument, too. Signed-off-by: Jochen Voss Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index 48ae09e9b..371400d49 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -30,7 +30,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) if (argc != 2) usage(upload_archive_usage); - if (strlen(argv[1]) > sizeof(buf)) + if (strlen(argv[1]) + 1 > sizeof(buf)) die("insanely long repository name"); strcpy(buf, argv[1]); /* enter-repo smudges its argument */ From 762656e03e80a77aeca6163597640d4e48eee55c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Jun 2008 16:02:47 -0400 Subject: [PATCH 2/5] fix git config example syntax git-config expects a space, not '=' between option and value. Also, quote the value since it contains globs, which some shells will not pass through unchanged, or will abort if the glob doesn't expand. Signed-off-by: Joey Hess Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 97bed54fb..c350ad0f8 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -513,7 +513,7 @@ have each person clone that repository with 'git clone': cd project git-init git remote add origin server:/pub/project - git config --add remote.origin.fetch=+refs/remotes/*:refs/remotes/* + git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*' git fetch # Initialize git-svn locally (be sure to use the same URL and -T/-b/-t options as were used on server) git-svn init http://svn.foo.org/project From 5b8a94b1db4beba969d8cbb0e6e45033834b5913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Sun, 29 Jun 2008 03:21:25 +0200 Subject: [PATCH 3/5] git cat-file: Fix memory leak in batch mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When run in batch mode, git cat-file never frees the memory for the blob contents it is printing. This quickly adds up and causes git-svn to be hardly usable for imports of large svn repos, because it uses cat-file in batch mode and cat-file's memory usage easily reaches several hundred MB without any good reason. Signed-off-by: Björn Steinbrink Signed-off-by: Junio C Hamano --- builtin-cat-file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin-cat-file.c b/builtin-cat-file.c index bd343efae..880e75af5 100644 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@ -181,6 +181,7 @@ static int batch_one_object(const char *obj_name, int print_contents) write_or_die(1, contents, size); printf("\n"); fflush(stdout); + free(contents); } return 0; From 29c70e0b3e3183f86f93500882177d0c74069988 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 28 Jun 2008 19:33:56 -0400 Subject: [PATCH 4/5] git-svn: avoid filling up the disk with temp files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit ffe256f9bac8a40ff751a9341a5869d98f72c285 ("git-svn: Speed up fetch") introduced changes that create a temporary file for each object fetched by svn. These files should be deleted automatically, but perl apparently doesn't do this until the process exits (or perhaps when its garbage collector runs). This means that on a large fetch, especially with lots of branches, we sometimes fill up /tmp completely, which prevents the next temp file from being written completely. This is aggravated by the fact that a new temp file is created for each updated file, even if that update produces a file identical to one already in git. Thus, it can happen even if there's lots of disk space to store the finished repository. We weren't adequately checking for write errors, so this would result in an invalid file getting committed, which caused git-svn to fail later with an invalid checksum. This patch adds a check to syswrite() so similar problems don't lead to corruption in the future. It also unlink()'s each temp file explicitly when we're done with it, so the disk doesn't need to fill up. Signed-off-by: Avery Pennarun Tested-by: Björn Steinbrink Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index 4c9c59bc3..50ace22da 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3243,7 +3243,9 @@ sub close_file { my ($tmp_fh, $tmp_filename) = File::Temp::tempfile(UNLINK => 1); my $result; while ($result = sysread($fh, my $string, 1024)) { - syswrite($tmp_fh, $string, $result); + my $wrote = syswrite($tmp_fh, $string, $result); + defined($wrote) && $wrote == $result + or croak("write $tmp_filename: $!\n"); } defined $result or croak $!; close $tmp_fh or croak $!; @@ -3251,6 +3253,7 @@ sub close_file { close $fh or croak $!; $hash = $::_repository->hash_and_insert_object($tmp_filename); + unlink($tmp_filename); $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n"; close $fb->{base} or croak $!; } else { From 7829f20f5beabe3e21866ae53109a58370571158 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 28 Jun 2008 20:40:32 -0700 Subject: [PATCH 5/5] git-svn: don't sanitize remote names in config The original sanitization code was just taken from the remotes2config.sh shell script in contrib. Credit to Avery Pennarun for noticing this mistake, and Junio for clarifying the rules for config section names: Junio C Hamano wrote in <7vfxr23s6m.fsf@gitster.siamese.dyndns.org>: > In > > [foo "bar"] baz = value > > foo and baz must be config.c::iskeychar() (and baz must be isalpha()), but > "bar" can be almost anything. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 50ace22da..f789a6eec 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1462,13 +1462,6 @@ sub verify_remotes_sanity { } } -# we allow more chars than remotes2config.sh... -sub sanitize_remote_name { - my ($name) = @_; - $name =~ tr{A-Za-z0-9:,/+-}{.}c; - $name; -} - sub find_existing_remote { my ($url, $remotes) = @_; return undef if $no_reuse_existing; @@ -2853,7 +2846,7 @@ sub _new { unless (defined $ref_id && length $ref_id) { $_[2] = $ref_id = $Git::SVN::default_ref_id; } - $_[1] = $repo_id = sanitize_remote_name($repo_id); + $_[1] = $repo_id; my $dir = "$ENV{GIT_DIR}/svn/$ref_id"; $_[3] = $path = '' unless (defined $path); mkpath(["$ENV{GIT_DIR}/svn"]); @@ -4707,8 +4700,7 @@ sub minimize_connections { # skip existing cases where we already connect to the root if (($ra->{url} eq $ra->{repos_root}) || - (Git::SVN::sanitize_remote_name($ra->{repos_root}) eq - $repo_id)) { + ($ra->{repos_root} eq $repo_id)) { $root_repos->{$ra->{url}} = $repo_id; next; } @@ -4747,8 +4739,7 @@ sub minimize_connections { foreach my $url (keys %$new_urls) { # see if we can re-use an existing [svn-remote "repo_id"] # instead of creating a(n ugly) new section: - my $repo_id = $root_repos->{$url} || - Git::SVN::sanitize_remote_name($url); + my $repo_id = $root_repos->{$url} || $url; my $fetch = $new_urls->{$url}; foreach my $path (keys %$fetch) {