Skip to content

Commit 251641b

Browse files
committed
Merge branch 'svn-wt' of git://bogomips.org/git-svn
* 'svn-wt' of git://bogomips.org/git-svn: git-svn: "git worktree" awareness git-svn: reduce scope of input record separator change
2 parents 6503602 + 112423e commit 251641b

File tree

6 files changed

+69
-48
lines changed

6 files changed

+69
-48
lines changed

git-svn.perl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
command_close_pipe
4545
command_bidi_pipe
4646
command_close_bidi_pipe
47+
get_record
4748
);
4849

4950
BEGIN {
@@ -1699,7 +1700,7 @@ sub cmd_gc {
16991700
"files will not be compressed.\n";
17001701
}
17011702
File::Find::find({ wanted => \&gc_directory, no_chdir => 1},
1702-
"$ENV{GIT_DIR}/svn");
1703+
Git::SVN::svn_dir());
17031704
}
17041705

17051706
########################### utility functions #########################
@@ -1733,7 +1734,7 @@ sub post_fetch_checkout {
17331734
return unless verify_ref('HEAD^0');
17341735

17351736
return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
1736-
my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
1737+
my $index = command_oneline(qw(rev-parse --git-path index));
17371738
return if -f $index;
17381739

17391740
return if command_oneline(qw/rev-parse --is-inside-work-tree/) eq 'false';
@@ -1835,8 +1836,9 @@ sub get_tree_from_treeish {
18351836
sub get_commit_entry {
18361837
my ($treeish) = shift;
18371838
my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish) );
1838-
my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1839-
my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1839+
my @git_path = qw(rev-parse --git-path);
1840+
my $commit_editmsg = command_oneline(@git_path, 'COMMIT_EDITMSG');
1841+
my $commit_msg = command_oneline(@git_path, 'COMMIT_MSG');
18401842
open my $log_fh, '>', $commit_editmsg or croak $!;
18411843

18421844
my $type = command_oneline(qw/cat-file -t/, $treeish);
@@ -1880,10 +1882,9 @@ sub get_commit_entry {
18801882
{
18811883
require Encode;
18821884
# SVN requires messages to be UTF-8 when entering the repo
1883-
local $/;
18841885
open $log_fh, '<', $commit_msg or croak $!;
18851886
binmode $log_fh;
1886-
chomp($log_entry{log} = <$log_fh>);
1887+
chomp($log_entry{log} = get_record($log_fh, undef));
18871888

18881889
my $enc = Git::config('i18n.commitencoding') || 'UTF-8';
18891890
my $msg = $log_entry{log};

perl/Git.pm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ require Exporter;
5959
command_bidi_pipe command_close_bidi_pipe
6060
version exec_path html_path hash_object git_cmd_try
6161
remote_refs prompt
62-
get_tz_offset
62+
get_tz_offset get_record
6363
credential credential_read credential_write
6464
temp_acquire temp_is_locked temp_release temp_reset temp_path);
6565

@@ -538,6 +538,20 @@ sub get_tz_offset {
538538
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
539539
}
540540

541+
=item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )
542+
543+
Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
544+
removing any trailing INPUT_RECORD_SEPARATOR.
545+
546+
=cut
547+
548+
sub get_record {
549+
my ($fh, $rs) = @_;
550+
local $/ = $rs;
551+
my $rec = <$fh>;
552+
chomp $rec if defined $rs;
553+
$rec;
554+
}
541555

542556
=item prompt ( PROMPT , ISPASSWORD )
543557

perl/Git/SVN.pm

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,15 @@ sub get_fetch_range {
807807
(++$min, $max);
808808
}
809809

810+
sub svn_dir {
811+
command_oneline(qw(rev-parse --git-path svn));
812+
}
813+
810814
sub tmp_config {
811815
my (@args) = @_;
812-
my $old_def_config = "$ENV{GIT_DIR}/svn/config";
813-
my $config = "$ENV{GIT_DIR}/svn/.metadata";
816+
my $svn_dir = svn_dir();
817+
my $old_def_config = "$svn_dir/config";
818+
my $config = "$svn_dir/.metadata";
814819
if (! -f $config && -f $old_def_config) {
815820
rename $old_def_config, $config or
816821
die "Failed rename $old_def_config => $config: $!\n";
@@ -1671,7 +1676,7 @@ sub tie_for_persistent_memoization {
16711676
return if $memoized;
16721677
$memoized = 1;
16731678

1674-
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
1679+
my $cache_path = svn_dir() . '/.caches/';
16751680
mkpath([$cache_path]) unless -d $cache_path;
16761681

16771682
my %lookup_svn_merge_cache;
@@ -1712,7 +1717,7 @@ sub tie_for_persistent_memoization {
17121717
sub clear_memoized_mergeinfo_caches {
17131718
die "Only call this method in non-memoized context" if ($memoized);
17141719

1715-
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
1720+
my $cache_path = svn_dir() . '/.caches/';
17161721
return unless -d $cache_path;
17171722

17181723
for my $cache_file (("$cache_path/lookup_svn_merge",
@@ -2446,12 +2451,13 @@ sub _new {
24462451
"refs/remotes/$prefix$default_ref_id";
24472452
}
24482453
$_[1] = $repo_id;
2449-
my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
2454+
my $svn_dir = svn_dir();
2455+
my $dir = "$svn_dir/$ref_id";
24502456

2451-
# Older repos imported by us used $GIT_DIR/svn/foo instead of
2452-
# $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
2457+
# Older repos imported by us used $svn_dir/foo instead of
2458+
# $svn_dir/refs/remotes/foo when tracking refs/remotes/foo
24532459
if ($ref_id =~ m{^refs/remotes/(.+)}) {
2454-
my $old_dir = "$ENV{GIT_DIR}/svn/$1";
2460+
my $old_dir = "$svn_dir/$1";
24552461
if (-d $old_dir && ! -d $dir) {
24562462
$dir = $old_dir;
24572463
}
@@ -2461,7 +2467,7 @@ sub _new {
24612467
mkpath([$dir]);
24622468
my $obj = bless {
24632469
ref_id => $ref_id, dir => $dir, index => "$dir/index",
2464-
config => "$ENV{GIT_DIR}/svn/config",
2470+
config => "$svn_dir/config",
24652471
map_root => "$dir/.rev_map", repo_id => $repo_id }, $class;
24662472

24672473
# Ensure it gets canonicalized

perl/Git/SVN/Editor.pm

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use SVN::Delta;
77
use Carp qw/croak/;
88
use Git qw/command command_oneline command_noisy command_output_pipe
99
command_input_pipe command_close_pipe
10-
command_bidi_pipe command_close_bidi_pipe/;
10+
command_bidi_pipe command_close_bidi_pipe
11+
get_record/;
12+
1113
BEGIN {
1214
@ISA = qw(SVN::Delta::Editor);
1315
}
@@ -57,11 +59,9 @@ sub generate_diff {
5759
push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
5860
push @diff_tree, $tree_a, $tree_b;
5961
my ($diff_fh, $ctx) = command_output_pipe(@diff_tree);
60-
local $/ = "\0";
6162
my $state = 'meta';
6263
my @mods;
63-
while (<$diff_fh>) {
64-
chomp $_; # this gets rid of the trailing "\0"
64+
while (defined($_ = get_record($diff_fh, "\0"))) {
6565
if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
6666
($::sha1)\s($::sha1)\s
6767
([MTCRAD])\d*$/xo) {
@@ -173,9 +173,7 @@ sub rmdirs {
173173

174174
my ($fh, $ctx) = command_output_pipe(qw/ls-tree --name-only -r -z/,
175175
$self->{tree_b});
176-
local $/ = "\0";
177-
while (<$fh>) {
178-
chomp;
176+
while (defined($_ = get_record($fh, "\0"))) {
179177
my @dn = split m#/#, $_;
180178
while (pop @dn) {
181179
delete $rm->{join '/', @dn};

perl/Git/SVN/Fetcher.pm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use Carp qw/croak/;
99
use File::Basename qw/dirname/;
1010
use Git qw/command command_oneline command_noisy command_output_pipe
1111
command_input_pipe command_close_pipe
12-
command_bidi_pipe command_close_bidi_pipe/;
12+
command_bidi_pipe command_close_bidi_pipe
13+
get_record/;
1314
BEGIN {
1415
@ISA = qw(SVN::Delta::Editor);
1516
}
@@ -86,11 +87,9 @@ sub _mark_empty_symlinks {
8687
my $printed_warning;
8788
chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
8889
my ($ls, $ctx) = command_output_pipe(qw/ls-tree -r -z/, $cmt);
89-
local $/ = "\0";
9090
my $pfx = defined($switch_path) ? $switch_path : $git_svn->path;
9191
$pfx .= '/' if length($pfx);
92-
while (<$ls>) {
93-
chomp;
92+
while (defined($_ = get_record($ls, "\0"))) {
9493
s/\A100644 blob $empty_blob\t//o or next;
9594
unless ($printed_warning) {
9695
print STDERR "Scanning for empty symlinks, ",
@@ -179,9 +178,7 @@ sub delete_entry {
179178
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
180179
-r --name-only -z/,
181180
$tree);
182-
local $/ = "\0";
183-
while (<$ls>) {
184-
chomp;
181+
while (defined($_ = get_record($ls, "\0"))) {
185182
my $rmpath = "$gpath/$_";
186183
$self->{gii}->remove($rmpath);
187184
print "\tD\t$rmpath\n" unless $::_q;
@@ -247,9 +244,7 @@ sub add_directory {
247244
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
248245
-r --name-only -z/,
249246
$self->{c});
250-
local $/ = "\0";
251-
while (<$ls>) {
252-
chomp;
247+
while (defined($_ = get_record($ls, "\0"))) {
253248
$self->{gii}->remove($_);
254249
print "\tD\t$_\n" unless $::_q;
255250
push @deleted_gpath, $gpath;

perl/Git/SVN/Migration.pm

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ use Git qw(
4444
command_noisy
4545
command_output_pipe
4646
command_close_pipe
47+
command_oneline
4748
);
49+
use Git::SVN;
4850

4951
sub migrate_from_v0 {
5052
my $git_dir = $ENV{GIT_DIR};
@@ -55,7 +57,9 @@ sub migrate_from_v0 {
5557
chomp;
5658
my ($id, $orig_ref) = ($_, $_);
5759
next unless $id =~ s#^refs/heads/(.+)-HEAD$#$1#;
58-
next unless -f "$git_dir/$id/info/url";
60+
my $info_url = command_oneline(qw(rev-parse --git-path),
61+
"$id/info/url");
62+
next unless -f $info_url;
5963
my $new_ref = "refs/remotes/$id";
6064
if (::verify_ref("$new_ref^0")) {
6165
print STDERR "W: $orig_ref is probably an old ",
@@ -82,7 +86,7 @@ sub migrate_from_v1 {
8286
my $git_dir = $ENV{GIT_DIR};
8387
my $migrated = 0;
8488
return $migrated unless -d $git_dir;
85-
my $svn_dir = "$git_dir/svn";
89+
my $svn_dir = Git::SVN::svn_dir();
8690

8791
# just in case somebody used 'svn' as their $id at some point...
8892
return $migrated if -d $svn_dir && ! -f "$svn_dir/info/url";
@@ -97,27 +101,28 @@ sub migrate_from_v1 {
97101
my $x = $_;
98102
next unless $x =~ s#^refs/remotes/##;
99103
chomp $x;
100-
next unless -f "$git_dir/$x/info/url";
101-
my $u = eval { ::file_to_s("$git_dir/$x/info/url") };
104+
my $info_url = command_oneline(qw(rev-parse --git-path),
105+
"$x/info/url");
106+
next unless -f $info_url;
107+
my $u = eval { ::file_to_s($info_url) };
102108
next unless $u;
103-
my $dn = dirname("$git_dir/svn/$x");
109+
my $dn = dirname("$svn_dir/$x");
104110
mkpath([$dn]) unless -d $dn;
105111
if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
106-
mkpath(["$git_dir/svn/svn"]);
112+
mkpath(["$svn_dir/svn"]);
107113
print STDERR " - $git_dir/$x/info => ",
108-
"$git_dir/svn/$x/info\n";
109-
rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
114+
"$svn_dir/$x/info\n";
115+
rename "$git_dir/$x/info", "$svn_dir/$x/info" or
110116
croak "$!: $x";
111117
# don't worry too much about these, they probably
112118
# don't exist with repos this old (save for index,
113119
# and we can easily regenerate that)
114120
foreach my $f (qw/unhandled.log index .rev_db/) {
115-
rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
121+
rename "$git_dir/$x/$f", "$svn_dir/$x/$f";
116122
}
117123
} else {
118-
print STDERR " - $git_dir/$x => $git_dir/svn/$x\n";
119-
rename "$git_dir/$x", "$git_dir/svn/$x" or
120-
croak "$!: $x";
124+
print STDERR " - $git_dir/$x => $svn_dir/$x\n";
125+
rename "$git_dir/$x", "$svn_dir/$x" or croak "$!: $x";
121126
}
122127
$migrated++;
123128
}
@@ -139,9 +144,10 @@ sub read_old_urls {
139144
push @dir, $_;
140145
}
141146
}
147+
my $svn_dir = Git::SVN::svn_dir();
142148
foreach (@dir) {
143149
my $x = $_;
144-
$x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
150+
$x =~ s!^\Q$svn_dir\E/!!o;
145151
read_old_urls($l_map, $x, $_);
146152
}
147153
}
@@ -150,7 +156,7 @@ sub migrate_from_v2 {
150156
my @cfg = command(qw/config -l/);
151157
return if grep /^svn-remote\..+\.url=/, @cfg;
152158
my %l_map;
153-
read_old_urls(\%l_map, '', "$ENV{GIT_DIR}/svn");
159+
read_old_urls(\%l_map, '', Git::SVN::svn_dir());
154160
my $migrated = 0;
155161

156162
require Git::SVN;
@@ -239,7 +245,8 @@ sub minimize_connections {
239245
}
240246
}
241247
if (@emptied) {
242-
my $file = $ENV{GIT_CONFIG} || "$ENV{GIT_DIR}/config";
248+
my $file = $ENV{GIT_CONFIG} ||
249+
command_oneline(qw(rev-parse --git-path config));
243250
print STDERR <<EOF;
244251
The following [svn-remote] sections in your config file ($file) are empty
245252
and can be safely removed:

0 commit comments

Comments
 (0)