Skip to content

Commit ae71760

Browse files
committed
Merge git://git.bogomips.org/git-svn
* git://git.bogomips.org/git-svn: git svn: make minimize URL more reliable over http(s) git svn: avoid escaping '/' when renaming/copying files t9142: stop httpd after the test git svn: the branch command no longer needs the full path git svn: revert default behavior for --minimize-url git svn: add gc command
2 parents 71c020c + 5f8b2cb commit ae71760

File tree

4 files changed

+122
-6
lines changed

4 files changed

+122
-6
lines changed

Documentation/git-svn.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ COMMANDS
8080
When passed to 'init' or 'clone' this regular expression will
8181
be preserved as a config key. See 'fetch' for a description
8282
of '--ignore-paths'.
83+
--no-minimize-url;;
84+
When tracking multiple directories (using --stdlayout,
85+
--branches, or --tags options), git svn will attempt to connect
86+
to the root (or highest allowed level) of the Subversion
87+
repository. This default allows better tracking of history if
88+
entire projects are moved within a repository, but may cause
89+
issues on repositories where read access restrictions are in
90+
place. Passing '--no-minimize-url' will allow git svn to
91+
accept URLs as-is without attempting to connect to a higher
92+
level directory. This option is off by default when only
93+
one URL/branch is tracked (it would do little good).
8394

8495
'fetch'::
8596
Fetch unfetched revisions from the Subversion remote we are
@@ -338,6 +349,10 @@ Any other arguments are passed directly to 'git log'
338349
Shows the Subversion externals. Use -r/--revision to specify a
339350
specific revision.
340351

352+
'gc'::
353+
Compress $GIT_DIR/svn/<refname>/unhandled.log files in .git/svn
354+
and remove $GIT_DIR/svn/<refname>index files in .git/svn.
355+
341356
'reset'::
342357
Undoes the effects of 'fetch' back to the specified revision.
343358
This allows you to re-'fetch' an SVN revision. Normally the

git-svn.perl

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
$Git::SVN::default_repo_id = 'svn';
2020
$Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn';
2121
$Git::SVN::Ra::_log_window_size = 100;
22+
$Git::SVN::_minimize_url = 'unset';
2223

2324
$Git::SVN::Log::TZ = $ENV{TZ};
2425
$ENV{TZ} = 'UTC';
@@ -31,6 +32,7 @@
3132
if ($SVN::Core::VERSION lt '1.1.0') {
3233
fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
3334
}
35+
my $can_compress = eval { require Compress::Zlib; 1};
3436
push @Git::SVN::Ra::ISA, 'SVN::Ra';
3537
push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor';
3638
push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor';
@@ -40,6 +42,7 @@
4042
use File::Basename qw/dirname basename/;
4143
use File::Path qw/mkpath/;
4244
use File::Spec;
45+
use File::Find;
4346
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
4447
use IPC::Open3;
4548
use Git;
@@ -98,7 +101,7 @@ BEGIN
98101
'trunk|T=s' => \$_trunk, 'tags|t=s@' => \@_tags,
99102
'branches|b=s@' => \@_branches, 'prefix=s' => \$_prefix,
100103
'stdlayout|s' => \$_stdlayout,
101-
'minimize-url|m' => \$Git::SVN::_minimize_url,
104+
'minimize-url|m!' => \$Git::SVN::_minimize_url,
102105
'no-metadata' => sub { $icv{noMetadata} = 1 },
103106
'use-svm-props' => sub { $icv{useSvmProps} = 1 },
104107
'use-svnsync-props' => sub { $icv{useSvnsyncProps} = 1 },
@@ -217,6 +220,10 @@ BEGIN
217220
"Undo fetches back to the specified SVN revision",
218221
{ 'revision|r=s' => \$_revision,
219222
'parent|p' => \$_fetch_parent } ],
223+
'gc' => [ \&cmd_gc,
224+
"Compress unhandled.log files in .git/svn and remove " .
225+
"index files in .git/svn",
226+
{} ],
220227
);
221228

222229
my $cmd;
@@ -393,6 +400,10 @@ sub cmd_init {
393400
init_subdir(@_);
394401
do_git_init_db();
395402

403+
if ($Git::SVN::_minimize_url eq 'unset') {
404+
$Git::SVN::_minimize_url = 0;
405+
}
406+
396407
Git::SVN->init($url);
397408
}
398409

@@ -655,9 +666,22 @@ sub cmd_branch {
655666
}
656667
}
657668
unless (defined $glob) {
658-
die "Unknown ",
659-
$_tag ? "tag" : "branch",
660-
" destination $_branch_dest\n";
669+
my $dest_re = qr/\b\Q$_branch_dest\E\b/;
670+
foreach my $g (@{$allglobs}) {
671+
$g->{path}->{left} =~ /$dest_re/ or next;
672+
if (defined $glob) {
673+
die "Ambiguous destination: ",
674+
$_branch_dest, "\nmatches both '",
675+
$glob->{path}->{left}, "' and '",
676+
$g->{path}->{left}, "'\n";
677+
}
678+
$glob = $g;
679+
}
680+
unless (defined $glob) {
681+
die "Unknown ",
682+
$_tag ? "tag" : "branch",
683+
" destination $_branch_dest\n";
684+
}
661685
}
662686
}
663687
my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
@@ -1107,6 +1131,14 @@ sub cmd_reset {
11071131
print "r$r = $c ($gs->{ref_id})\n";
11081132
}
11091133

1134+
sub cmd_gc {
1135+
if (!$can_compress) {
1136+
warn "Compress::Zlib could not be found; unhandled.log " .
1137+
"files will not be compressed.\n";
1138+
}
1139+
find({ wanted => \&gc_directory, no_chdir => 1}, "$ENV{GIT_DIR}/svn");
1140+
}
1141+
11101142
########################### utility functions #########################
11111143

11121144
sub rebase_cmd {
@@ -1527,6 +1559,25 @@ sub md5sum {
15271559
return $md5->hexdigest();
15281560
}
15291561

1562+
sub gc_directory {
1563+
if ($can_compress && -f $_ && basename($_) eq "unhandled.log") {
1564+
my $out_filename = $_ . ".gz";
1565+
open my $in_fh, "<", $_ or die "Unable to open $_: $!\n";
1566+
binmode $in_fh;
1567+
my $gz = Compress::Zlib::gzopen($out_filename, "ab") or
1568+
die "Unable to open $out_filename: $!\n";
1569+
1570+
my $res;
1571+
while ($res = sysread($in_fh, my $str, 1024)) {
1572+
$gz->gzwrite($str) or
1573+
die "Unable to write: ".$gz->gzerror()."!\n";
1574+
}
1575+
unlink $_ or die "unlink $File::Find::name: $!\n";
1576+
} elsif (-f $_ && basename($_) eq "index") {
1577+
unlink $_ or die "unlink $_: $!\n";
1578+
}
1579+
}
1580+
15301581
package Git::SVN;
15311582
use strict;
15321583
use warnings;
@@ -3954,7 +4005,7 @@ sub repo_path {
39544005
sub url_path {
39554006
my ($self, $path) = @_;
39564007
if ($self->{url} =~ m#^https?://#) {
3957-
$path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
4008+
$path =~ s!([^~a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg;
39584009
}
39594010
$self->{url} . '/' . $self->repo_path($path);
39604011
}
@@ -4780,7 +4831,11 @@ sub minimize_url {
47804831
my $c = '';
47814832
do {
47824833
$url .= "/$c" if length $c;
4783-
eval { (ref $self)->new($url)->get_latest_revnum };
4834+
eval {
4835+
my $ra = (ref $self)->new($url);
4836+
my $latest = $ra->get_latest_revnum;
4837+
$ra->get_log("", $latest, 0, 1, 0, 1, sub {});
4838+
};
47844839
} while ($@ && ($c = shift @components));
47854840
$url;
47864841
}

t/t9142-git-svn-shallow-clone.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ test_expect_success 'clone trunk with "-r HEAD"' '
2727
( cd g && git rev-parse --symbolic --verify HEAD )
2828
'
2929

30+
stop_httpd
31+
3032
test_done

t/t9143-git-svn-gc.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Robert Allan Zeh
4+
5+
test_description='git svn gc basic tests'
6+
7+
. ./lib-git-svn.sh
8+
9+
test_expect_success 'setup directories and test repo' '
10+
mkdir import &&
11+
mkdir tmp &&
12+
echo "Sample text for Subversion repository." > import/test.txt &&
13+
svn_cmd import -m "import for git svn" import "$svnrepo" > /dev/null
14+
'
15+
16+
test_expect_success 'checkout working copy from svn' \
17+
'svn_cmd co "$svnrepo" test_wc'
18+
19+
test_expect_success 'set some properties to create an unhandled.log file' '
20+
(
21+
cd test_wc &&
22+
svn_cmd propset foo bar test.txt &&
23+
svn_cmd commit -m "property set"
24+
)'
25+
26+
test_expect_success 'Setup repo' 'git svn init "$svnrepo"'
27+
28+
test_expect_success 'Fetch repo' 'git svn fetch'
29+
30+
test_expect_success 'make backup copy of unhandled.log' '
31+
cp .git/svn/git-svn/unhandled.log tmp
32+
'
33+
34+
test_expect_success 'git svn gc runs' 'git svn gc'
35+
36+
test_expect_success 'git svn gc produces a valid gzip file' '
37+
gunzip .git/svn/git-svn/unhandled.log.gz
38+
'
39+
40+
test_expect_success 'git svn gc does not change unhandled.log files' '
41+
test_cmp .git/svn/git-svn/unhandled.log tmp/unhandled.log
42+
'
43+
44+
test_done

0 commit comments

Comments
 (0)