4 use Fcntl qw
/:DEFAULT :seek/;
5 use constant rev_map_fmt
=> 'NH40';
6 use vars qw
/$_no_metadata
7 $_repack $_repack_flags $_use_svm_props $_head
8 $_use_svnsync_props $no_reuse_existing
9 $_use_log_author $_add_author_from $_localtime/;
11 use File
::Path qw
/mkpath/;
12 use File
::Copy qw
/copy/;
15 use Memoize
; # core since 5.8.0, Jul 2002
16 use Memoize
::Storable
;
17 use POSIX
qw(:signal_h);
26 use Git
::SVN
::Utils
qw(fatal can_compress);
30 $can_use_yaml = eval { require Git
::SVN
::Memoize
::YAML
; 1};
33 our $_follow_parent = 1;
34 our $_minimize_url = 'unset';
35 our $default_repo_id = 'svn';
36 our $default_ref_id = $ENV{GIT_SVN_ID
} || 'git-svn';
38 my ($_gc_nr, $_gc_period);
40 # properties that we do not log:
43 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
44 svn
:special svn
:executable
45 svn
:entry
:committed
-rev
48 svn
:entry
:committed
-date
/;
50 # some options are read globally, but can be overridden locally
51 # per [svn-remote "..."] section. Command-line options will *NOT*
52 # override options set in an [svn-remote "..."] section
54 for my $option (qw
/follow_parent no_metadata use_svm_props
58 my $prop = "-$option";
61 return $self->{$prop} if exists $self->{$prop};
62 my $k = "svn-remote.$self->{repo_id}.$key";
63 eval { command_oneline
(qw
/config --get/, $k) };
65 $self->{$prop} = ${"Git::SVN::_$option"};
67 my $v = command_oneline
(qw
/config --bool/,$k);
68 $self->{$prop} = $v eq 'false' ?
0 : 1;
70 return $self->{$prop};
76 my (%LOCKFILES, %INDEX_FILES);
78 unlink keys %LOCKFILES if %LOCKFILES;
79 unlink keys %INDEX_FILES if %INDEX_FILES;
82 sub resolve_local_globs
{
83 my ($url, $fetch, $glob_spec) = @_;
84 return unless defined $glob_spec;
85 my $ref = $glob_spec->{ref};
86 my $path = $glob_spec->{path
};
87 foreach (command
(qw
#for-each-ref --format=%(refname) refs/#)) {
88 next unless m
#^$ref->{regex}$#;
90 my $pathname = desanitize_refname
($path->full_path($p));
91 my $refname = desanitize_refname
($ref->full_path($p));
92 if (my $existing = $fetch->{$pathname}) {
93 if ($existing ne $refname) {
94 die "Refspec conflict:\n",
95 "existing: $existing\n",
96 " globbed: $refname\n";
98 my $u = (::cmt_metadata
("$refname"))[0];
99 $u =~ s!^\Q$url\E(/|$)!! or die
100 "$refname: '$url' not found in '$u'\n";
101 if ($pathname ne $u) {
102 warn "W: Refspec glob conflict ",
103 "(ref: $refname):\n",
104 "expected path: $pathname\n",
106 "Continuing ahead with $u\n";
110 $fetch->{$pathname} = $refname;
115 sub parse_revision_argument
{
116 my ($base, $head) = @_;
117 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
118 return ($base, $head);
120 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
121 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
122 return ($head, $head) if ($::_revision
eq 'HEAD');
123 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
124 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
125 die "revision argument: $::_revision not understood by git-svn\n";
129 my ($repo_id, $remotes) = @_;
133 $repo_id = $gs->{repo_id
};
135 $remotes ||= read_all_remotes
();
136 my $remote = $remotes->{$repo_id} or
137 die "[svn-remote \"$repo_id\"] unknown\n";
138 my $fetch = $remote->{fetch
};
139 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
141 my $ra = Git
::SVN
::Ra
->new($url);
142 my $uuid = $ra->get_uuid;
143 my $head = $ra->get_latest_revnum;
145 # ignore errors, $head revision may not even exist anymore
146 eval { $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }) };
147 warn "W: $@\n" if $@
;
149 my $base = defined $fetch ?
$head : 0;
151 # read the max revs for wildcard expansion (branches/*, tags/*)
152 foreach my $t (qw
/branches tags/) {
153 defined $remote->{$t} or next;
154 push @globs, @
{$remote->{$t}};
156 my $max_rev = eval { tmp_config
(qw
/--int --get/,
157 "svn-remote.$repo_id.${t}-maxRev") };
158 if (defined $max_rev && ($max_rev < $base)) {
160 } elsif (!defined $max_rev) {
166 foreach my $p (sort keys %$fetch) {
167 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
168 my $lr = $gs->rev_map_max;
170 $base = $lr if ($lr < $base);
176 ($base, $head) = parse_revision_argument
($base, $head);
177 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
180 sub read_all_remotes
{
182 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
184 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
185 my $svn_refspec = qr{\s*(.*?)\s*:\s*(.+?)\s*};
186 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
187 if (m!^(.+)\.fetch=$svn_refspec$!) {
188 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
189 die("svn-remote.$remote: remote ref '$remote_ref' "
190 . "must start with 'refs/'\n")
191 unless $remote_ref =~ m{^refs/};
192 $local_ref = uri_decode
($local_ref);
193 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
194 $r->{$remote}->{svm
} = {} if $use_svm_props;
195 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
196 $r->{$1}->{svm
} = {};
197 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
198 $r->{$1}->{url
} = $2;
199 } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
200 $r->{$1}->{pushurl
} = $2;
201 } elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
202 $r->{$1}->{ignore_refs_regex
} = $2;
203 } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
204 my ($remote, $t, $local_ref, $remote_ref) =
206 die("svn-remote.$remote: remote ref '$remote_ref' ($t) "
207 . "must start with 'refs/'\n")
208 unless $remote_ref =~ m{^refs/};
209 $local_ref = uri_decode
($local_ref);
211 require Git
::SVN
::GlobSpec
;
215 path
=> Git
::SVN
::GlobSpec
->new($local_ref, 1),
216 ref => Git
::SVN
::GlobSpec
->new($remote_ref, 0) };
217 if (length($rs->{ref}->{right
}) != 0) {
218 die "The '*' glob character must be the last ",
219 "character of '$remote_ref'\n";
221 push @
{ $r->{$remote}->{$t} }, $rs;
226 if (defined $r->{$_}->{svm
}) {
229 my $section = "svn-remote.$_";
231 source
=> tmp_config
('--get',
232 "$section.svm-source"),
233 replace
=> tmp_config
('--get',
234 "$section.svm-replace"),
237 $r->{$_}->{svm
} = $svm;
241 foreach my $remote (keys %$r) {
242 foreach ( grep { defined $_ }
243 map { $r->{$remote}->{$_} } qw(branches tags) ) {
244 foreach my $rs ( @
$_ ) {
245 $rs->{ignore_refs_regex
} =
246 $r->{$remote}->{ignore_refs_regex
};
255 $_gc_nr = $_gc_period = 1000;
256 if (defined $_repack || defined $_repack_flags) {
257 warn "Repack options are obsolete; they have no effect.\n";
261 sub verify_remotes_sanity
{
262 return unless -d
$ENV{GIT_DIR
};
264 foreach (command
(qw
/config -l/)) {
265 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
267 die "Remote ref refs/remote/$1 is tracked by",
268 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
269 "Please resolve this ambiguity in ",
270 "your git configuration file before ",
278 sub find_existing_remote
{
279 my ($url, $remotes) = @_;
280 return undef if $no_reuse_existing;
282 foreach my $repo_id (keys %$remotes) {
283 my $u = $remotes->{$repo_id}->{url
} or next;
285 $existing = $repo_id;
291 sub init_remote_config
{
292 my ($self, $url, $no_write) = @_;
293 $url =~ s!/+$!!; # strip trailing slash
294 my $r = read_all_remotes
();
295 my $existing = find_existing_remote
($url, $r);
298 print STDERR
"Using existing ",
299 "[svn-remote \"$existing\"]\n";
301 $self->{repo_id
} = $existing;
302 } elsif ($_minimize_url) {
303 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
304 $existing = find_existing_remote
($min_url, $r);
307 print STDERR
"Using existing ",
308 "[svn-remote \"$existing\"]\n";
310 $self->{repo_id
} = $existing;
312 if ($min_url ne $url) {
314 print STDERR
"Using higher level of URL: ",
315 "$url => $min_url\n";
317 my $old_path = $self->{path
};
318 $self->{path
} = $url;
319 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
320 if (length $old_path) {
321 $self->{path
} .= "/$old_path";
328 # verify that we aren't overwriting anything:
330 command_oneline
('config', '--get',
331 "svn-remote.$self->{repo_id}.url")
333 if ($orig_url && ($orig_url ne $url)) {
334 die "svn-remote.$self->{repo_id}.url already set: ",
335 "$orig_url\nwanted to set to: $url\n";
338 my ($xrepo_id, $xpath) = find_ref
($self->refname);
339 if (!$no_write && defined $xpath) {
340 die "svn-remote.$xrepo_id.fetch already set to track ",
341 "$xpath:", $self->refname, "\n";
344 command_noisy
('config',
345 "svn-remote.$self->{repo_id}.url", $url);
346 $self->{path
} =~ s{^/}{};
347 $self->{path
} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
348 command_noisy
('config', '--add',
349 "svn-remote.$self->{repo_id}.fetch",
350 "$self->{path}:".$self->refname);
355 sub find_by_url
{ # repos_root and, path are optional
356 my ($class, $full_url, $repos_root, $path) = @_;
358 return undef unless defined $full_url;
359 remove_username
($full_url);
360 remove_username
($repos_root) if defined $repos_root;
361 my $remotes = read_all_remotes
();
362 if (defined $full_url && defined $repos_root && !defined $path) {
364 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
366 foreach my $repo_id (keys %$remotes) {
367 my $u = $remotes->{$repo_id}->{url
} or next;
369 next if defined $repos_root && $repos_root ne $u;
371 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
372 foreach my $t (qw
/branches tags/) {
373 foreach my $globspec (@
{$remotes->{$repo_id}->{$t}}) {
374 resolve_local_globs
($u, $fetch, $globspec);
378 my $rwr = rewrite_root
({repo_id
=> $repo_id});
379 my $svm = $remotes->{$repo_id}->{svm
}
380 if defined $remotes->{$repo_id}->{svm
};
381 unless (defined $p) {
388 } elsif (defined $svm) {
390 $prefix = $svm->{replace
};
391 $prefix =~ s
#^\Q$u\E(?:/|$)##;
394 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
396 foreach my $f (keys %$fetch) {
398 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
405 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
406 my $self = _new
($class, $repo_id, $ref_id, $path);
408 $self->init_remote_config($url, $no_write);
415 foreach (command
(qw
/config -l/)) {
416 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
417 \s
*(.*?
)\s
*:\s
*(.+?
)\s
*$!x
;
418 my ($repo_id, $path, $ref) = ($1, $2, $3);
419 if ($ref eq $ref_id) {
420 $path = '' if ($path =~ m
#^\./?#);
421 return ($repo_id, $path);
424 (undef, undef, undef);
428 my ($class, $ref_id, $repo_id, $path) = @_;
429 if (defined $ref_id && !defined $repo_id && !defined $path) {
430 ($repo_id, $path) = find_ref
($ref_id);
431 if (!defined $repo_id) {
432 die "Could not find a \"svn-remote.*.fetch\" key ",
433 "in the repository configuration matching: ",
437 my $self = _new
($class, $repo_id, $ref_id, $path);
438 if (!defined $self->{path
} || !length $self->{path
}) {
439 my $fetch = command_oneline
('config', '--get',
440 "svn-remote.$repo_id.fetch",
442 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
443 "\":$ref_id\$\" in config\n";
444 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
446 $self->{path
} =~ s{/+}{/}g;
447 $self->{path
} =~ s{\A/}{};
448 $self->{path
} =~ s{/\z}{};
449 $self->{url
} = command_oneline
('config', '--get',
450 "svn-remote.$repo_id.url") or
451 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
452 $self->{pushurl
} = eval { command_oneline
('config', '--get',
453 "svn-remote.$repo_id.pushurl") };
459 my ($refname) = $_[0]->{ref_id
} ;
461 # It cannot end with a slash /, we'll throw up on this because
462 # SVN can't have directories with a slash in their name, either:
463 if ($refname =~ m{/$}) {
464 die "ref: '$refname' ends with a trailing slash, this is ",
465 "not permitted by git nor Subversion\n";
468 # It cannot have ASCII control character space, tilde ~, caret ^,
469 # colon :, question-mark ?, asterisk *, space, or open bracket [
472 # Additionally, % must be escaped because it is used for escaping
473 # and we want our escaped refname to be reversible
474 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
476 # no slash-separated component can begin with a dot .
478 $refname =~ s{/\.}{/%2E}g;
480 # It cannot have two consecutive dots .. anywhere
482 $refname =~ s{\.\.}{%2E%2E}g;
484 # trailing dots and .lock are not allowed
485 # .$ becomes %2E and .lock becomes %2Elock
486 $refname =~ s{\.(?=$|lock$)}{%2E};
488 # the sequence @{ is used to access the reflog
490 $refname =~ s{\@\{}{%40\{}g;
495 sub desanitize_refname
{
497 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
503 return $self->{svm
}->{uuid
} if $self->svm;
505 unless ($self->{svm
}) {
506 die "SVM UUID not cached, and reading remotely failed\n";
508 $self->{svm
}->{uuid
};
513 return $self->{svm
} if $self->{svm
};
515 # see if we have it in our config, first:
517 my $section = "svn-remote.$self->{repo_id}";
519 source
=> tmp_config
('--get', "$section.svm-source"),
520 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
521 replace
=> tmp_config
('--get', "$section.svm-replace"),
524 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
531 my ($self, $ra) = @_;
532 return $ra if $self->svm;
534 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
535 "(svm:source, svm:uuid) ",
536 "from the following URLs:\n" );
538 my ($self, $ra, $path, $r) = @_;
539 my $props = ($ra->get_dir($path, $r))[2];
540 my $src = $props->{'svm:source'};
541 my $uuid = $props->{'svm:uuid'};
542 return undef if (!$src || !$uuid);
546 $uuid =~ m{^[0-9a-f\-]{30,}$}i
547 or die "doesn't look right - svm:uuid is '$uuid'\n";
549 # the '!' is used to mark the repos_root!/relative/path
551 $src =~ s{/+$}{}; # no trailing slashes please
552 # username is of no interest
553 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
555 my $replace = $ra->{url
};
556 $replace .= "/$path" if length $path;
558 my $section = "svn-remote.$self->{repo_id}";
559 tmp_config
("$section.svm-source", $src);
560 tmp_config
("$section.svm-replace", $replace);
561 tmp_config
("$section.svm-uuid", $uuid);
569 my $r = $ra->get_latest_revnum;
570 my $path = $self->{path
};
572 while (length $path) {
573 unless ($tried{"$self->{url}/$path"}) {
574 return $ra if $self->read_svm_props($ra, $path, $r);
575 $tried{"$self->{url}/$path"} = 1;
577 $path =~ s
#/?[^/]+$##;
579 die "Path: '$path' should be ''\n" if $path ne '';
580 return $ra if $self->read_svm_props($ra, $path, $r);
581 $tried{"$self->{url}/$path"} = 1;
583 if ($ra->{repos_root
} eq $self->{url
}) {
584 die @err, (map { " $_\n" } keys %tried), "\n";
587 # nope, make sure we're connected to the repository root:
590 $path = $ra->{svn_path
};
591 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
592 while (length $path) {
593 unless ($tried{"$ra->{url}/$path"}) {
594 $ok = $self->read_svm_props($ra, $path, $r);
596 $tried{"$ra->{url}/$path"} = 1;
598 $path =~ s
#/?[^/]+$##;
600 die "Path: '$path' should be ''\n" if $path ne '';
601 $ok ||= $self->read_svm_props($ra, $path, $r);
602 $tried{"$ra->{url}/$path"} = 1;
604 die @err, (map { " $_\n" } keys %tried), "\n";
606 Git
::SVN
::Ra
->new($self->{url
});
611 return $self->{svnsync
} if $self->{svnsync
};
613 if ($self->no_metadata) {
614 die "Can't have both 'noMetadata' and ",
615 "'useSvnsyncProps' options set!\n";
617 if ($self->rewrite_root) {
618 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
621 if ($self->rewrite_uuid) {
622 die "Can't have both 'useSvnsyncProps' and 'rewriteUUID' ",
627 # see if we have it in our config, first:
629 my $section = "svn-remote.$self->{repo_id}";
631 my $url = tmp_config
('--get', "$section.svnsync-url");
632 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
633 die "doesn't look right - svn:sync-from-url is '$url'\n";
635 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
636 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
637 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
639 $svnsync = { url
=> $url, uuid
=> $uuid }
641 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
642 return $self->{svnsync
} = $svnsync;
645 my $err = "useSvnsyncProps set, but failed to read " .
646 "svnsync property: svn:sync-from-";
647 my $rp = $self->ra->rev_proplist(0);
649 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
650 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
651 die "doesn't look right - svn:sync-from-url is '$url'\n";
653 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
654 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
655 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
657 my $section = "svn-remote.$self->{repo_id}";
658 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
659 tmp_config
('--add', "$section.svnsync-url", $url);
660 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
663 # this allows us to memoize our SVN::Ra UUID locally and avoid a
664 # remote lookup (useful for 'git svn log').
667 unless ($self->{ra_uuid
}) {
668 my $key = "svn-remote.$self->{repo_id}.uuid";
669 my $uuid = eval { tmp_config
('--get', $key) };
670 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) {
671 $self->{ra_uuid
} = $uuid;
673 die "ra_uuid called without URL\n" unless $self->{url
};
674 $self->{ra_uuid
} = $self->ra->get_uuid;
675 tmp_config
('--add', $key, $self->{ra_uuid
});
681 sub _set_repos_root
{
682 my ($self, $repos_root) = @_;
683 my $k = "svn-remote.$self->{repo_id}.reposRoot";
684 $repos_root ||= $self->ra->{repos_root
};
685 tmp_config
($k, $repos_root);
691 my $k = "svn-remote.$self->{repo_id}.reposRoot";
692 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
697 my $ra = Git
::SVN
::Ra
->new($self->{url
});
698 $self->_set_repos_root($ra->{repos_root
});
699 if ($self->use_svm_props && !$self->{svm
}) {
700 if ($self->no_metadata) {
701 die "Can't have both 'noMetadata' and ",
702 "'useSvmProps' options set!\n";
703 } elsif ($self->use_svnsync_props) {
704 die "Can't have both 'useSvnsyncProps' and ",
705 "'useSvmProps' options set!\n";
707 $ra = $self->_set_svm_vars($ra);
708 $self->{-want_revprops
} = 1;
713 # prop_walk(PATH, REV, SUB)
714 # -------------------------
715 # Recursively traverse PATH at revision REV and invoke SUB for each
716 # directory that contains a SVN property. SUB will be invoked as
717 # follows: &SUB(gs, path, props); where `gs' is this instance of
718 # Git::SVN, `path' the path to the directory where the properties
719 # `props' were found. The `path' will be relative to point of checkout,
720 # that is, if url://repo/trunk is the current Git branch, and that
721 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
722 # as `path' (note the trailing `/').
724 my ($self, $path, $rev, $sub) = @_;
727 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
730 # Strip the irrelevant part of the path.
731 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
732 # Ensure the path is terminated by a `/'.
735 # The properties contain all the internal SVN stuff nobody
736 # (usually) cares about.
737 my $interesting_props = 0;
738 foreach (keys %{$props}) {
739 # If it doesn't start with `svn:', it must be a
740 # user-defined property.
741 ++$interesting_props and next if $_ !~ /^svn:/;
742 # FIXME: Fragile, if SVN adds new public properties,
743 # this needs to be updated.
744 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
746 |externals
|needs
-lock)$/x
;
748 &$sub($self, $p, $props) if $interesting_props;
750 foreach (sort keys %$dirent) {
751 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
752 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
756 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
757 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
759 # returns the newest SVN revision number and newest commit SHA1
760 sub last_rev_commit
{
762 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
763 return ($self->{last_rev
}, $self->{last_commit
});
765 my $c = ::verify_ref
($self->refname.'^0');
766 if ($c && !$self->use_svm_props && !$self->no_metadata) {
767 my $rev = (::cmt_metadata
($c))[1];
769 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
773 my $map_path = $self->map_path;
774 unless (-e
$map_path) {
775 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
776 return (undef, undef);
778 my ($rev, $commit) = $self->rev_map_max(1);
779 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
780 return ($rev, $commit);
783 sub get_fetch_range
{
784 my ($self, $min, $max) = @_;
785 $max ||= $self->ra->get_latest_revnum;
786 $min ||= $self->rev_map_max;
792 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
793 my $config = "$ENV{GIT_DIR}/svn/.metadata";
794 if (! -f
$config && -f
$old_def_config) {
795 rename $old_def_config, $config or
796 die "Failed rename $old_def_config => $config: $!\n";
798 my $old_config = $ENV{GIT_CONFIG
};
799 $ENV{GIT_CONFIG
} = $config;
802 unless (-f
$config) {
804 open my $fh, '>', $config or
805 die "Can't open $config: $!\n";
806 print $fh "; This file is used internally by ",
808 "Couldn't write to $config: $!\n";
809 print $fh "; You should not have to edit it\n" or
810 die "Couldn't write to $config: $!\n";
811 close $fh or die "Couldn't close $config: $!\n";
813 command
('config', @args);
816 if (defined $old_config) {
817 $ENV{GIT_CONFIG
} = $old_config;
819 delete $ENV{GIT_CONFIG
};
822 wantarray ?
@ret : $ret[0];
826 my ($self, $sub) = @_;
827 my $old_index = $ENV{GIT_INDEX_FILE
};
828 $ENV{GIT_INDEX_FILE
} = $self->{index};
831 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
832 mkpath
([$dir]) unless -d
$dir;
836 if (defined $old_index) {
837 $ENV{GIT_INDEX_FILE
} = $old_index;
839 delete $ENV{GIT_INDEX_FILE
};
842 wantarray ?
@ret : $ret[0];
845 sub assert_index_clean
{
846 my ($self, $treeish) = @_;
848 $self->tmp_index_do(sub {
849 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
850 my $x = command_oneline
('write-tree');
851 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
852 /^tree ($::sha1)/mo);
855 warn "Index mismatch: $y != $x\nrereading $treeish\n";
856 unlink $self->{index} or die "unlink $self->{index}: $!\n";
857 command_noisy
('read-tree', $treeish);
858 $x = command_oneline
('write-tree');
860 fatal
"trees ($treeish) $y != $x\n",
861 "Something is seriously wrong...";
866 sub get_commit_parents
{
867 my ($self, $log_entry) = @_;
868 my (%seen, @ret, @tmp);
869 # legacy support for 'set-tree'; this is only used by set_tree_cb:
870 if (my $ip = $self->{inject_parents
}) {
871 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
875 if (my $cur = ::verify_ref
($self->refname.'^0')) {
878 if (my $ipd = $self->{inject_parents_dcommit
}) {
879 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
883 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
884 while (my $p = shift @tmp) {
894 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
895 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
896 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
899 if ($rwr !~ m
#^[a-z\+]+://#) {
900 die "$rwr is not a valid URL (key: $k)\n";
903 $self->{-rewrite_root
} = $rwr;
908 return $self->{-rewrite_uuid
} if exists $self->{-rewrite_uuid
};
909 my $k = "svn-remote.$self->{repo_id}.rewriteUUID";
910 my $rwid = eval { command_oneline
(qw
/config --get/, $k) };
913 if ($rwid !~ m
#^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$#) {
914 die "$rwid is not a valid UUID (key: $k)\n";
917 $self->{-rewrite_uuid
} = $rwid;
922 ($self->rewrite_root || $self->{url
}) .
923 (length $self->{path
} ?
'/' . $self->{path
} : '');
928 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
933 if ($self->{pushurl
}) {
934 return $self->{pushurl
} . (length $self->{path
} ?
'/' .
937 return $self->full_url;
941 sub set_commit_header_env
{
942 my ($log_entry) = @_;
944 foreach my $ned (qw
/NAME EMAIL DATE/) {
945 foreach my $ac (qw
/AUTHOR COMMITTER/) {
946 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
950 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
951 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
952 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
954 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
955 ?
$log_entry->{commit_name
}
956 : $log_entry->{name
};
957 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
958 ?
$log_entry->{commit_email
}
959 : $log_entry->{email
};
963 sub restore_commit_header_env
{
965 foreach my $ned (qw
/NAME EMAIL DATE/) {
966 foreach my $ac (qw
/AUTHOR COMMITTER/) {
967 my $k = "GIT_${ac}_${ned}";
968 if (defined $env->{$k}) {
969 $ENV{$k} = $env->{$k};
978 command_noisy
('gc', '--auto');
982 my ($self, $log_entry) = @_;
983 my $lr = $self->last_rev;
984 if (defined $lr && $lr >= $log_entry->{revision
}) {
985 die "Last fetched revision of ", $self->refname,
986 " was r$lr, but we are about to fetch: ",
987 "r$log_entry->{revision}!\n";
989 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
990 croak
"$log_entry->{revision} = $c already exists! ",
991 "Why are we refetching it?\n";
993 my $old_env = set_commit_header_env
($log_entry);
994 my $tree = $log_entry->{tree
};
995 if (!defined $tree) {
996 $tree = $self->tmp_index_do(sub {
997 command_oneline
('write-tree') });
999 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
1001 my @exec = ('git', 'commit-tree', $tree);
1002 foreach ($self->get_commit_parents($log_entry)) {
1003 push @exec, '-p', $_;
1005 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1009 # we always get UTF-8 from SVN, but we may want our commits in
1010 # a different encoding.
1011 if (my $enc = Git
::config
('i18n.commitencoding')) {
1013 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
1015 print $msg_fh $log_entry->{log} or croak
$!;
1016 restore_commit_header_env
($old_env);
1017 unless ($self->no_metadata) {
1018 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
1021 $msg_fh->flush == 0 or croak
$!;
1022 close $msg_fh or croak
$!;
1023 chomp(my $commit = do { local $/; <$out_fh> });
1024 close $out_fh or croak
$!;
1027 if ($commit !~ /^$::sha1$/o) {
1028 die "Failed to commit, invalid sha1: $commit\n";
1031 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
1033 $self->{last_rev
} = $log_entry->{revision
};
1034 $self->{last_commit
} = $commit;
1035 print "r$log_entry->{revision}" unless $::_q
> 1;
1036 if (defined $log_entry->{svm_revision
}) {
1037 print " (\@$log_entry->{svm_revision})" unless $::_q
> 1;
1038 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
1039 0, $self->svm_uuid);
1041 print " = $commit ($self->{ref_id})\n" unless $::_q
> 1;
1042 if (--$_gc_nr == 0) {
1043 $_gc_nr = $_gc_period;
1050 my ($self, $paths, $r) = @_;
1051 return 1 if $self->{path
} eq '';
1052 if (my $path = $paths->{"/$self->{path}"}) {
1053 return ($path->{action
} eq 'D') ?
0 : 1;
1055 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
1056 if (grep /$self->{path_regex}/, keys %$paths) {
1060 foreach (split m
#/#, $self->{path}) {
1062 next unless ($paths->{$c} &&
1063 ($paths->{$c}->{action
} =~ /^[AR]$/));
1064 if ($self->ra->check_path($self->{path
}, $r) ==
1072 sub find_parent_branch
{
1073 my ($self, $paths, $rev) = @_;
1074 return undef unless $self->follow_parent;
1075 unless (defined $paths) {
1076 my $err_handler = $SVN::Error
::handler
;
1077 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
1078 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
1079 sub { $paths = $_[0] });
1080 $SVN::Error
::handler
= $err_handler;
1082 return undef unless defined $paths;
1084 # look for a parent from another branch:
1085 my @b_path_components = split m
#/#, $self->{path};
1086 my @a_path_components;
1088 while (@b_path_components) {
1089 $i = $paths->{'/'.join('/', @b_path_components)};
1090 last if $i && defined $i->{copyfrom_path
};
1091 unshift(@a_path_components, pop(@b_path_components));
1093 return undef unless defined $i && defined $i->{copyfrom_path
};
1094 my $branch_from = $i->{copyfrom_path
};
1095 if (@a_path_components) {
1096 print STDERR
"branch_from: $branch_from => ";
1097 $branch_from .= '/'.join('/', @a_path_components);
1098 print STDERR
$branch_from, "\n";
1100 my $r = $i->{copyfrom_rev
};
1101 my $repos_root = $self->ra->{repos_root
};
1102 my $url = $self->ra->{url
};
1103 my $new_url = $url . $branch_from;
1104 print STDERR
"Found possible branch point: ",
1105 "$new_url => ", $self->full_url, ", $r\n"
1107 $branch_from =~ s
#^/##;
1108 my $gs = $self->other_gs($new_url, $url,
1109 $branch_from, $r, $self->{ref_id
});
1110 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1113 if (!defined $r0 || !defined $parent) {
1114 ($base, $head) = parse_revision_argument
(0, $r);
1117 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
1118 0, 1, sub { $base = $_[1] - 1 });
1121 if (defined $base && $base <= $r) {
1122 $gs->fetch($base, $r);
1124 ($r0, $parent) = $gs->find_rev_before($r, 1);
1126 if (defined $r0 && defined $parent) {
1127 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n"
1130 if ($self->ra->can_do_switch) {
1131 $self->assert_index_clean($parent);
1132 print STDERR
"Following parent with do_switch\n"
1134 # do_switch works with svn/trunk >= r22312, but that
1135 # is not included with SVN 1.4.3 (the latest version
1136 # at the moment), so we can't rely on it
1137 $self->{last_rev
} = $r0;
1138 $self->{last_commit
} = $parent;
1139 $ed = Git
::SVN
::Fetcher
->new($self, $gs->{path
});
1140 $gs->ra->gs_do_switch($r0, $rev, $gs,
1141 $self->full_url, $ed)
1142 or die "SVN connection failed somewhere...\n";
1143 } elsif ($self->ra->trees_match($new_url, $r0,
1144 $self->full_url, $rev)) {
1145 print STDERR
"Trees match:\n",
1147 " ${\$self->full_url}\@$rev\n",
1148 "Following parent with no changes\n"
1150 $self->tmp_index_do(sub {
1151 command_noisy
('read-tree', $parent);
1153 $self->{last_commit
} = $parent;
1155 print STDERR
"Following parent with do_update\n"
1157 $ed = Git
::SVN
::Fetcher
->new($self);
1158 $self->ra->gs_do_update($rev, $rev, $self, $ed)
1159 or die "SVN connection failed somewhere...\n";
1161 print STDERR
"Successfully followed parent\n" unless $::_q
> 1;
1162 return $self->make_log_entry($rev, [$parent], $ed);
1168 my ($self, $paths, $rev) = @_;
1170 my ($last_rev, @parents);
1171 if (my $lc = $self->last_commit) {
1172 # we can have a branch that was deleted, then re-added
1173 # under the same name but copied from another path, in
1174 # which case we'll have multiple parents (we don't
1175 # want to break the original ref, nor lose copypath info):
1176 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1177 push @
{$log_entry->{parents
}}, $lc;
1180 $ed = Git
::SVN
::Fetcher
->new($self);
1181 $last_rev = $self->{last_rev
};
1186 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1189 $ed = Git
::SVN
::Fetcher
->new($self);
1191 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1192 die "SVN connection failed somewhere...\n";
1194 $self->make_log_entry($rev, \
@parents, $ed);
1198 my ($self, $r) = @_;
1201 my ($r, $empty_dirs, $line) = @_;
1202 if (defined $r && $line =~ /^r(\d+)$/) {
1203 return 0 if $1 > $r;
1204 } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
1205 $empty_dirs->{$1} = 1;
1206 } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
1207 my @d = grep {m
[^\Q
$1\E
(/|$)]} (keys %$empty_dirs);
1208 delete @
$empty_dirs{@d};
1213 my %empty_dirs = ();
1214 my $gz_file = "$self->{dir}/unhandled.log.gz";
1216 if (!can_compress
()) {
1217 warn "Compress::Zlib could not be found; ",
1218 "empty directories in $gz_file will not be read\n";
1220 my $gz = Compress
::Zlib
::gzopen
($gz_file, "rb") or
1221 die "Unable to open $gz_file: $!\n";
1223 while ($gz->gzreadline($line) > 0) {
1224 scan
($r, \
%empty_dirs, $line) or last;
1230 if (open my $fh, '<', "$self->{dir}/unhandled.log") {
1231 binmode $fh or croak
"binmode: $!";
1233 scan
($r, \
%empty_dirs, $_) or last;
1238 my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
1239 foreach my $d (sort keys %empty_dirs) {
1240 $d = uri_decode
($d);
1242 next unless length($d);
1245 warn "$d exists but is not a directory\n";
1247 print "creating empty directory: $d\n";
1254 my ($self, $ed) = @_;
1256 my $h = $ed->{empty
};
1257 foreach (sort keys %$h) {
1258 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
1259 push @out, " $act: " . uri_encode
($_);
1260 warn "W: $act: $_\n";
1262 foreach my $t (qw
/dir_prop file_prop/) {
1263 $h = $ed->{$t} or next;
1264 foreach my $path (sort keys %$h) {
1265 my $ppath = $path eq '' ?
'.' : $path;
1266 foreach my $prop (sort keys %{$h->{$path}}) {
1267 next if $SKIP_PROP{$prop};
1268 my $v = $h->{$path}->{$prop};
1269 my $t_ppath_prop = "$t: " .
1270 uri_encode
($ppath) . ' ' .
1273 push @out, " +$t_ppath_prop " .
1276 push @out, " -$t_ppath_prop";
1281 foreach my $t (qw
/absent_file absent_directory/) {
1282 $h = $ed->{$t} or next;
1283 foreach my $parent (sort keys %$h) {
1284 foreach my $path (sort @
{$h->{$parent}}) {
1285 push @out, " $t: " .
1286 uri_encode
("$parent/$path");
1287 warn "W: $t: $parent/$path ",
1288 "Insufficient permissions?\n";
1296 # some systmes don't handle or mishandle %z, so be creative.
1297 my $t = shift || time;
1298 my $gm = timelocal
(gmtime($t));
1299 my $sign = qw( + + - )[ $t <=> $gm ];
1300 return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
1303 # parse_svn_date(DATE)
1304 # --------------------
1305 # Given a date (in UTC) from Subversion, return a string in the format
1306 # "<TZ Offset> <local date/time>" that Git will use.
1308 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
1309 # is true we'll convert it to the local timezone instead.
1310 sub parse_svn_date
{
1311 my $date = shift || return '+0000 1970-01-01 00:00:00';
1312 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
1313 (\d\d
)\
:(\d\d
)\
:(\d\d
)\
.\d
*Z
$/x
) or
1314 croak
"Unable to parse date: $date\n";
1315 my $parsed_date; # Set next.
1317 if ($Git::SVN
::_localtime
) {
1318 # Translate the Subversion datetime to an epoch time.
1319 # Begin by switching ourselves to $date's timezone, UTC.
1320 my $old_env_TZ = $ENV{TZ
};
1324 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
1326 # Determine our local timezone (including DST) at the
1327 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
1328 # value of TZ, if any, at the time we were run.
1329 if (defined $Git::SVN
::Log
::TZ
) {
1330 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
1335 my $our_TZ = get_tz
();
1337 # This converts $epoch_in_UTC into our local timezone.
1338 my ($sec, $min, $hour, $mday, $mon, $year,
1339 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
1341 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
1342 $our_TZ, $year + 1900, $mon + 1,
1343 $mday, $hour, $min, $sec);
1345 # Reset us to the timezone in effect when we entered
1347 if (defined $old_env_TZ) {
1348 $ENV{TZ
} = $old_env_TZ;
1353 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
1356 return $parsed_date;
1360 my ($self, $new_url, $url,
1361 $branch_from, $r, $old_ref_id) = @_;
1362 my $gs = Git
::SVN
->find_by_url($new_url, $url, $branch_from);
1364 my $ref_id = $old_ref_id;
1365 $ref_id =~ s/\@\d+-*$//;
1367 # just grow a tail if we're not unique enough :x
1368 $ref_id .= '-' while find_ref
($ref_id);
1369 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
1370 if ($u =~ s
#^\Q$url\E(/|$)##) {
1373 $repo_id = $self->{repo_id
};
1376 # It is possible to tag two different subdirectories at
1377 # the same revision. If the url for an existing ref
1378 # does not match, we must either find a ref with a
1379 # matching url or create a new ref by growing a tail.
1380 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
1381 my (undef, $max_commit) = $gs->rev_map_max(1);
1382 last if (!$max_commit);
1383 my ($url) = ::cmt_metadata
($max_commit);
1384 last if ($url eq $gs->metadata_url);
1387 print STDERR
"Initializing parent: $ref_id\n" unless $::_q
> 1;
1392 sub call_authors_prog
{
1393 my ($orig_author) = @_;
1394 $orig_author = command_oneline
('rev-parse', '--sq-quote', $orig_author);
1395 my $author = `$::_authors_prog $orig_author`;
1397 die "$::_authors_prog failed with exit code $?\n"
1399 if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
1400 my ($name, $email) = ($1, $2);
1401 $email = undef if length $2 == 0;
1402 return [$name, $email];
1404 die "Author: $orig_author: $::_authors_prog returned "
1405 . "invalid author format: $author\n";
1411 if (!defined $author || length $author == 0) {
1412 $author = '(no author)';
1414 if (!defined $::users
{$author}) {
1415 if (defined $::_authors_prog
) {
1416 $::users
{$author} = call_authors_prog
($author);
1417 } elsif (defined $::_authors
) {
1418 die "Author: $author not defined in $::_authors file\n";
1424 sub find_extra_svk_parents
{
1425 my ($self, $ed, $tickets, $parents) = @_;
1426 # aha! svk:merge property changed...
1427 my @tickets = split "\n", $tickets;
1429 for my $ticket ( @tickets ) {
1430 my ($uuid, $path, $rev) = split /:/, $ticket;
1431 if ( $uuid eq $self->ra_uuid ) {
1432 my $url = $self->{url
};
1433 my $repos_root = $url;
1434 my $branch_from = $path;
1435 $branch_from =~ s{^/}{};
1436 my $gs = $self->other_gs($repos_root."/".$branch_from,
1441 if ( my $commit = $gs->rev_map_get($rev, $uuid) ) {
1442 # wahey! we found it, but it might be
1444 push @known_parents, [ $rev, $commit ];
1448 # Ordering matters; highest-numbered commit merge tickets
1449 # first, as they may account for later merge ticket additions
1451 @known_parents = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @known_parents;
1452 for my $parent ( @known_parents ) {
1453 my @cmd = ('rev-list', $parent, map { "^$_" } @
$parents );
1454 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
1456 while ( <$msg_fh> ) {
1459 command_close_pipe
($msg_fh, $ctx);
1462 "Found merge parent (svk:merge ticket): $parent\n";
1463 push @
$parents, $parent;
1468 sub lookup_svn_merge
{
1473 my ($source, $revs) = split ":", $merge;
1476 my $gs = Git
::SVN
->find_by_url($url.$source, $url, $path);
1478 warn "Couldn't find revmap for $url$source\n";
1481 my @ranges = split ",", $revs;
1482 my ($tip, $tip_commit);
1483 my @merged_commit_ranges;
1485 for my $range ( @ranges ) {
1486 my ($bottom, $top) = split "-", $range;
1488 my $bottom_commit = $gs->find_rev_after( $bottom, 1, $top );
1489 my $top_commit = $gs->find_rev_before( $top, 1, $bottom );
1491 unless ($top_commit and $bottom_commit) {
1492 warn "W:unknown path/rev in svn:mergeinfo "
1493 ."dirprop: $source:$range\n";
1497 if (scalar(command
('rev-parse', "$bottom_commit^@"))) {
1498 push @merged_commit_ranges,
1499 "$bottom_commit^..$top_commit";
1501 push @merged_commit_ranges, "$top_commit";
1504 if ( !defined $tip or $top > $tip ) {
1506 $tip_commit = $top_commit;
1509 return ($tip_commit, @merged_commit_ranges);
1513 my ($msg_fh, $ctx) = command_output_pipe
(
1517 while ( <$msg_fh> ) {
1521 command_close_pipe
($msg_fh, $ctx);
1525 sub check_cherry_pick
{
1528 my $parents = shift;
1530 my %commits = map { $_ => 1 }
1531 _rev_list
("--no-merges", $tip, "--not", $base, @
$parents, "--");
1532 for my $range ( @ranges ) {
1533 delete @commits{_rev_list
($range, "--")};
1535 for my $commit (keys %commits) {
1536 if (has_no_changes
($commit)) {
1537 delete $commits{$commit};
1540 return (keys %commits);
1543 sub has_no_changes
{
1546 my @revs = split / /, command_oneline
(
1547 qw(rev-list --parents -1 -m), $commit);
1549 # Commits with no parents, e.g. the start of a partial branch,
1550 # have changes by definition.
1551 return 1 if (@revs < 2);
1553 # Commits with multiple parents, e.g a merge, have no changes
1555 return 0 if (@revs > 2);
1557 return (command_oneline
("rev-parse", "$commit^{tree}") eq
1558 command_oneline
("rev-parse", "$commit~1^{tree}"));
1561 sub tie_for_persistent_memoization
{
1565 if ($can_use_yaml) {
1566 tie
%$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
1568 tie
%$hash => 'Memoize::Storable', "$path.db", 'nstore';
1572 # The GIT_DIR environment variable is not always set until after the command
1573 # line arguments are processed, so we can't memoize in a BEGIN block.
1577 sub memoize_svn_mergeinfo_functions
{
1578 return if $memoized;
1581 my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
1582 mkpath
([$cache_path]) unless -d
$cache_path;
1584 my %lookup_svn_merge_cache;
1585 my %check_cherry_pick_cache;
1586 my %has_no_changes_cache;
1588 tie_for_persistent_memoization
(\
%lookup_svn_merge_cache,
1589 "$cache_path/lookup_svn_merge");
1590 memoize
'lookup_svn_merge',
1591 SCALAR_CACHE
=> 'FAULT',
1592 LIST_CACHE
=> ['HASH' => \
%lookup_svn_merge_cache],
1595 tie_for_persistent_memoization
(\
%check_cherry_pick_cache,
1596 "$cache_path/check_cherry_pick");
1597 memoize
'check_cherry_pick',
1598 SCALAR_CACHE
=> 'FAULT',
1599 LIST_CACHE
=> ['HASH' => \
%check_cherry_pick_cache],
1602 tie_for_persistent_memoization
(\
%has_no_changes_cache,
1603 "$cache_path/has_no_changes");
1604 memoize
'has_no_changes',
1605 SCALAR_CACHE
=> ['HASH' => \
%has_no_changes_cache],
1606 LIST_CACHE
=> 'FAULT',
1610 sub unmemoize_svn_mergeinfo_functions
{
1611 return if not $memoized;
1614 Memoize
::unmemoize
'lookup_svn_merge';
1615 Memoize
::unmemoize
'check_cherry_pick';
1616 Memoize
::unmemoize
'has_no_changes';
1619 sub clear_memoized_mergeinfo_caches
{
1620 die "Only call this method in non-memoized context" if ($memoized);
1622 my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
1623 return unless -d
$cache_path;
1625 for my $cache_file (("$cache_path/lookup_svn_merge",
1626 "$cache_path/check_cherry_pick",
1627 "$cache_path/has_no_changes")) {
1628 for my $suffix (qw(yaml db)) {
1629 my $file = "$cache_file.$suffix";
1630 next unless -e
$file;
1631 unlink($file) or die "unlink($file) failed: $!\n";
1637 Memoize
::memoize
'Git::SVN::repos_root';
1641 # Force cache writeout explicitly instead of waiting for
1642 # global destruction to avoid segfault in Storable:
1643 # http://rt.cpan.org/Public/Bug/Display.html?id=36087
1644 unmemoize_svn_mergeinfo_functions
();
1647 sub parents_exclude
{
1648 my $parents = shift;
1650 return unless @commits;
1655 my @cmd = ('rev-list', "-1", @commits, "--not", @
$parents );
1656 $excluded = command_oneline
(@cmd);
1660 for my $commit ( @commits ) {
1661 if ( $commit eq $excluded ) {
1662 push @excluded, $commit;
1670 die "saw commit '$excluded' in rev-list output, "
1671 ."but we didn't ask for that commit (wanted: @commits --not @$parents)"
1676 while ($excluded and @commits);
1682 # note: this function should only be called if the various dirprops
1683 # have actually changed
1684 sub find_extra_svn_parents
{
1685 my ($self, $ed, $mergeinfo, $parents) = @_;
1686 # aha! svk:merge property changed...
1688 memoize_svn_mergeinfo_functions
();
1690 # We first search for merged tips which are not in our
1691 # history. Then, we figure out which git revisions are in
1692 # that tip, but not this revision. If all of those revisions
1693 # are now marked as merge, we can add the tip as a parent.
1694 my @merges = split "\n", $mergeinfo;
1696 my $url = $self->{url
};
1697 my $uuid = $self->ra_uuid;
1699 for my $merge ( @merges ) {
1700 my ($tip_commit, @ranges) =
1701 lookup_svn_merge
( $uuid, $url, $merge );
1702 unless (!$tip_commit or
1703 grep { $_ eq $tip_commit } @
$parents ) {
1704 push @merge_tips, $tip_commit;
1705 $ranges{$tip_commit} = \
@ranges;
1707 push @merge_tips, undef;
1711 my %excluded = map { $_ => 1 }
1712 parents_exclude
($parents, grep { defined } @merge_tips);
1714 # check merge tips for new parents
1716 for my $merge_tip ( @merge_tips ) {
1717 my $spec = shift @merges;
1718 next unless $merge_tip and $excluded{$merge_tip};
1720 my $ranges = $ranges{$merge_tip};
1722 # check out 'new' tips
1725 $merge_base = command_oneline
(
1727 @
$parents, $merge_tip,
1731 die "An error occurred during merge-base"
1732 unless $@
->isa("Git::Error::Command");
1734 warn "W: Cannot find common ancestor between ".
1735 "@$parents and $merge_tip. Ignoring merge info.\n";
1739 # double check that there are no missing non-merge commits
1740 my (@incomplete) = check_cherry_pick
(
1741 $merge_base, $merge_tip,
1746 if ( @incomplete ) {
1747 warn "W:svn cherry-pick ignored ($spec) - missing "
1748 .@incomplete." commit(s) (eg $incomplete[0])\n";
1751 "Found merge parent (svn:mergeinfo prop): ",
1753 push @new_parents, $merge_tip;
1757 # cater for merges which merge commits from multiple branches
1758 if ( @new_parents > 1 ) {
1759 for ( my $i = 0; $i <= $#new_parents; $i++ ) {
1760 for ( my $j = 0; $j <= $#new_parents; $j++ ) {
1762 next unless $new_parents[$i];
1763 next unless $new_parents[$j];
1764 my $revs = command_oneline
(
1766 "$new_parents[$i]..$new_parents[$j]",
1769 undef($new_parents[$j]);
1774 push @
$parents, grep { defined } @new_parents;
1777 sub make_log_entry
{
1778 my ($self, $rev, $parents, $ed) = @_;
1779 my $untracked = $self->get_untracked($ed);
1781 my @parents = @
$parents;
1782 my $ps = $ed->{path_strip
} || "";
1783 for my $path ( grep { m/$ps/ } %{$ed->{dir_prop
}} ) {
1784 my $props = $ed->{dir_prop
}{$path};
1785 if ( $props->{"svk:merge"} ) {
1786 $self->find_extra_svk_parents
1787 ($ed, $props->{"svk:merge"}, \
@parents);
1789 if ( $props->{"svn:mergeinfo"} ) {
1790 $self->find_extra_svn_parents
1792 $props->{"svn:mergeinfo"},
1797 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
1798 print $un "r$rev\n" or croak
$!;
1799 print $un $_, "\n" foreach @
$untracked;
1800 my %log_entry = ( parents
=> \
@parents, revision
=> $rev,
1804 my $logged = delete $self->{logged_rev_props
};
1805 if (!$logged || $self->{-want_revprops
}) {
1806 my $rp = $self->ra->rev_proplist($rev);
1807 foreach (sort keys %$rp) {
1809 if (/^svn:(author|date|log)$/) {
1810 $log_entry{$1} = $v;
1811 } elsif ($_ eq 'svm:headrev') {
1814 print $un " rev_prop: ", uri_encode
($_), ' ',
1815 uri_encode
($v), "\n";
1819 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
1821 close $un or croak
$!;
1823 $log_entry{date
} = parse_svn_date
($log_entry{date
});
1824 $log_entry{log} .= "\n";
1825 my $author = $log_entry{author
} = check_author
($log_entry{author
});
1826 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
1829 my ($commit_name, $commit_email) = ($name, $email);
1830 if ($_use_log_author) {
1832 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
1834 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
1837 if (!defined $name_field) {
1838 if (!defined $email) {
1841 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
1842 ($name, $email) = ($1, $2);
1843 } elsif ($name_field =~ /(.*)@/) {
1844 ($name, $email) = ($1, $name_field);
1846 ($name, $email) = ($name_field, $name_field);
1849 if (defined $headrev && $self->use_svm_props) {
1850 if ($self->rewrite_root) {
1851 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
1854 if ($self->rewrite_uuid) {
1855 die "Can't have both 'useSvmProps' and 'rewriteUUID' ",
1858 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$}i
;
1859 # we don't want "SVM: initializing mirror for junk" ...
1860 return undef if $r == 0;
1861 my $svm = $self->svm;
1862 if ($uuid ne $svm->{uuid
}) {
1863 die "UUID mismatch on SVM path:\n",
1864 "expected: $svm->{uuid}\n",
1867 my $full_url = $self->full_url;
1868 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
1869 die "Failed to replace '$svm->{replace}' with ",
1870 "'$svm->{source}' in $full_url\n";
1871 # throw away username for storing in records
1872 remove_username
($full_url);
1873 $log_entry{metadata
} = "$full_url\@$r $uuid";
1874 $log_entry{svm_revision
} = $r;
1875 $email ||= "$author\@$uuid";
1876 $commit_email ||= "$author\@$uuid";
1877 } elsif ($self->use_svnsync_props) {
1878 my $full_url = $self->svnsync->{url
};
1879 $full_url .= "/$self->{path}" if length $self->{path
};
1880 remove_username
($full_url);
1881 my $uuid = $self->svnsync->{uuid
};
1882 $log_entry{metadata
} = "$full_url\@$rev $uuid";
1883 $email ||= "$author\@$uuid";
1884 $commit_email ||= "$author\@$uuid";
1886 my $url = $self->metadata_url;
1887 remove_username
($url);
1888 my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
1889 $log_entry{metadata
} = "$url\@$rev " . $uuid;
1890 $email ||= "$author\@" . $uuid;
1891 $commit_email ||= "$author\@" . $uuid;
1893 $log_entry{name
} = $name;
1894 $log_entry{email
} = $email;
1895 $log_entry{commit_name
} = $commit_name;
1896 $log_entry{commit_email
} = $commit_email;
1901 my ($self, $min_rev, $max_rev, @parents) = @_;
1902 my ($last_rev, $last_commit) = $self->last_rev_commit;
1903 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
1904 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
1908 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
1909 $self->{inject_parents
} = { $rev => $tree };
1910 $self->fetch(undef, undef);
1914 my ($self, $tree) = (shift, shift);
1915 my $log_entry = ::get_commit_entry
($tree);
1916 unless ($self->{last_rev
}) {
1917 fatal
("Must have an existing revision to commit");
1919 my %ed_opts = ( r
=> $self->{last_rev
},
1920 log => $log_entry->{log},
1922 tree_a
=> $self->{last_commit
},
1925 $self->set_tree_cb($log_entry, $tree, @_) },
1926 svn_path
=> $self->{path
} );
1927 if (!Git
::SVN
::Editor
->new(\
%ed_opts)->apply_diff) {
1928 print "No changes\nr$self->{last_rev} = $tree\n";
1932 sub rebuild_from_rev_db
{
1933 my ($self, $path) = @_;
1935 open my $fh, '<', $path or croak
"open: $!";
1936 binmode $fh or croak
"binmode: $!";
1938 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
1941 next if $_ eq ('0' x
40);
1942 $self->rev_map_set($r, $_);
1945 close $fh or croak
"close: $!";
1946 unlink $path or croak
"unlink: $!";
1951 my $map_path = $self->map_path;
1952 my $partial = (-e
$map_path && ! -z
$map_path);
1953 return unless ::verify_ref
($self->refname.'^0');
1954 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
1955 my $rev_db = $self->rev_db_path;
1956 $self->rebuild_from_rev_db($rev_db);
1957 if ($self->use_svm_props) {
1958 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
1959 $self->rebuild_from_rev_db($svm_rev_db);
1961 $self->unlink_rev_db_symlink;
1964 print "Rebuilding $map_path ...\n" if (!$partial);
1965 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
1968 command_output_pipe
(qw
/rev-list --pretty=raw --reverse/,
1969 ($head ?
"$head.." : "") . $self->refname,
1971 my $metadata_url = $self->metadata_url;
1972 remove_username
($metadata_url);
1973 my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
1976 if ( m{^commit ($::sha1)$} ) {
1980 next unless s{^\s*(git-svn-id:)}{$1};
1981 my ($url, $rev, $uuid) = ::extract_metadata
($_);
1982 remove_username
($url);
1984 # ignore merges (from set-tree)
1985 next if (!defined $rev || !$uuid);
1987 # if we merged or otherwise started elsewhere, this is
1988 # how we break out of it
1989 if (($uuid ne $svn_uuid) ||
1990 ($metadata_url && $url && ($url ne $metadata_url))) {
1993 if ($partial && $head) {
1994 print "Partial-rebuilding $map_path ...\n";
1995 print "Currently at $base_rev = $head\n";
1999 $self->rev_map_set($rev, $c);
2000 print "r$rev = $c\n";
2002 command_close_pipe
($log, $ctx);
2003 print "Done rebuilding $map_path\n" if (!$partial || !$head);
2004 my $rev_db_path = $self->rev_db_path;
2005 if (-f
$self->rev_db_path) {
2006 unlink $self->rev_db_path or croak
"unlink: $!";
2008 $self->unlink_rev_db_symlink;
2012 # Tie::File seems to be prone to offset errors if revisions get sparse,
2013 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
2014 # one of my favorite modules is out :< Next up would be one of the DBM
2015 # modules, but I'm not sure which is most portable...
2017 # This is the replacement for the rev_db format, which was too big
2018 # and inefficient for large repositories with a lot of sparse history
2021 # The format is this:
2022 # - 24 bytes for every record,
2023 # * 4 bytes for the integer representing an SVN revision number
2024 # * 20 bytes representing the sha1 of a git commit
2025 # - No empty padding records like the old format
2026 # (except the last record, which can be overwritten)
2027 # - new records are written append-only since SVN revision numbers
2028 # increase monotonically
2029 # - lookups on SVN revision number are done via a binary search
2030 # - Piping the file to xxd -c24 is a good way of dumping it for
2031 # viewing or editing (piped back through xxd -r), should the need
2033 # - The last record can be padding revision with an all-zero sha1
2034 # This is used to optimize fetch performance when using multiple
2035 # "fetch" directives in .git/config
2037 # These files are disposable unless noMetadata or useSvmProps is set
2040 my ($fh, $rev, $commit) = @_;
2042 binmode $fh or croak
"binmode: $!";
2043 my $size = (stat($fh))[7];
2044 ($size % 24) == 0 or croak
"inconsistent size: $size";
2048 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2049 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
2050 $read == 24 or croak
"read only $read bytes (!= 24)";
2051 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
2052 if ($last_commit eq ('0' x40
)) {
2054 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2055 $read = sysread($fh, $buf, 24) or
2058 croak
"read only $read bytes (!= 24)";
2059 ($last_rev, $last_commit) =
2060 unpack(rev_map_fmt
, $buf);
2061 if ($last_commit eq ('0' x40
)) {
2062 croak
"inconsistent .rev_map\n";
2065 if ($last_rev >= $rev) {
2066 croak
"last_rev is higher!: $last_rev >= $rev";
2071 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
2072 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
2076 sub _rev_map_reset
{
2077 my ($fh, $rev, $commit) = @_;
2078 my $c = _rev_map_get
($fh, $rev);
2079 $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n";
2080 my $offset = sysseek($fh, 0, SEEK_CUR
) or croak
"seek: $!";
2081 truncate $fh, $offset or croak
"truncate: $!";
2087 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2088 mkpath
([$dir]) unless -d
$dir;
2089 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
2090 close $fh or die "Couldn't close (create) $path: $!\n";
2095 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
2096 defined $commit or die "missing arg3\n";
2097 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
2098 my $db = $self->map_path($uuid);
2099 my $db_lock = "$db.lock";
2103 $sigmask = POSIX
::SigSet
->new();
2104 my $signew = POSIX
::SigSet
->new(SIGINT
, SIGHUP
, SIGTERM
,
2105 SIGALRM
, SIGUSR1
, SIGUSR2
);
2106 sigprocmask
(SIG_BLOCK
, $signew, $sigmask) or
2107 croak
"Can't block signals: $!";
2111 $LOCKFILES{$db_lock} = 1;
2113 # both of these options make our .rev_db file very, very important
2114 # and we can't afford to lose it because rebuild() won't work
2115 if ($self->use_svm_props || $self->no_metadata) {
2117 copy
($db, $db_lock) or die "rev_map_set(@_): ",
2119 "$db => $db_lock ($!)\n";
2121 rename $db, $db_lock or die "rev_map_set(@_): ",
2122 "Failed to rename: ",
2123 "$db => $db_lock ($!)\n";
2126 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
2127 or croak
"Couldn't open $db_lock: $!\n";
2128 if ($update_ref eq 'reset') {
2129 clear_memoized_mergeinfo_caches
();
2130 _rev_map_reset
($fh, $rev, $commit);
2132 _rev_map_set
($fh, $rev, $commit);
2136 $fh->flush or die "Couldn't flush $db_lock: $!\n";
2137 $fh->sync or die "Couldn't sync $db_lock: $!\n";
2139 close $fh or croak
$!;
2143 $note = " ($update_ref)" if ($update_ref !~ /^\d*$/);
2144 command_noisy
('update-ref', '-m', "r$rev$note",
2145 $self->refname, $commit);
2147 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
2148 "$db_lock => $db ($!)\n";
2149 delete $LOCKFILES{$db_lock};
2151 sigprocmask
(SIG_SETMASK
, $sigmask) or
2152 croak
"Can't restore signal mask: $!";
2156 # If want_commit, this will return an array of (rev, commit) where
2157 # commit _must_ be a valid commit in the archive.
2158 # Otherwise, it'll return the max revision (whether or not the
2159 # commit is valid or just a 0x40 placeholder).
2161 my ($self, $want_commit) = @_;
2163 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
2164 $want_commit ?
($r, $c) : $r;
2167 sub rev_map_max_norebuild
{
2168 my ($self, $want_commit) = @_;
2169 my $map_path = $self->map_path;
2170 stat $map_path or return $want_commit ?
(0, undef) : 0;
2171 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2172 binmode $fh or croak
"binmode: $!";
2173 my $size = (stat($fh))[7];
2174 ($size % 24) == 0 or croak
"inconsistent size: $size";
2177 close $fh or croak
"close: $!";
2178 return $want_commit ?
(0, undef) : 0;
2181 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2182 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2183 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2184 if ($want_commit && $c eq ('0' x40
)) {
2186 return $want_commit ?
(0, undef) : 0;
2188 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2189 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
2190 ($r, $c) = unpack(rev_map_fmt
, $buf);
2191 if ($c eq ('0'x40
)) {
2192 croak
"Penultimate record is all-zeroes in $map_path";
2195 close $fh or croak
"close: $!";
2196 $want_commit ?
($r, $c) : $r;
2200 my ($self, $rev, $uuid) = @_;
2201 my $map_path = $self->map_path($uuid);
2202 return undef unless -e
$map_path;
2204 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2205 my $c = _rev_map_get
($fh, $rev);
2206 close($fh) or croak
"close: $!";
2211 my ($fh, $rev) = @_;
2213 binmode $fh or croak
"binmode: $!";
2214 my $size = (stat($fh))[7];
2215 ($size % 24) == 0 or croak
"inconsistent size: $size";
2221 my ($l, $u) = (0, $size - 24);
2225 my $i = int(($l/24 + $u/24) / 2) * 24;
2226 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
2227 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2228 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2232 } elsif ($r > $rev) {
2234 } else { # $r == $rev
2235 return $c eq ('0' x
40) ?
undef : $c;
2241 # Finds the first svn revision that exists on (if $eq_ok is true) or
2242 # before $rev for the current branch. It will not search any lower
2243 # than $min_rev. Returns the git commit hash and svn revision number
2244 # if found, else (undef, undef).
2245 sub find_rev_before
{
2246 my ($self, $rev, $eq_ok, $min_rev) = @_;
2247 --$rev unless $eq_ok;
2249 my $max_rev = $self->rev_map_max;
2250 $rev = $max_rev if ($rev > $max_rev);
2251 while ($rev >= $min_rev) {
2252 if (my $c = $self->rev_map_get($rev)) {
2257 return (undef, undef);
2260 # Finds the first svn revision that exists on (if $eq_ok is true) or
2261 # after $rev for the current branch. It will not search any higher
2262 # than $max_rev. Returns the git commit hash and svn revision number
2263 # if found, else (undef, undef).
2264 sub find_rev_after
{
2265 my ($self, $rev, $eq_ok, $max_rev) = @_;
2266 ++$rev unless $eq_ok;
2267 $max_rev ||= $self->rev_map_max;
2268 while ($rev <= $max_rev) {
2269 if (my $c = $self->rev_map_get($rev)) {
2274 return (undef, undef);
2278 my ($class, $repo_id, $ref_id, $path) = @_;
2279 unless (defined $repo_id && length $repo_id) {
2280 $repo_id = $default_repo_id;
2282 unless (defined $ref_id && length $ref_id) {
2283 # Access the prefix option from the git-svn main program if it's loaded.
2284 my $prefix = defined &::opt_prefix ?
::opt_prefix
() : "";
2286 "refs/remotes/$prefix$default_ref_id";
2289 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
2291 # Older repos imported by us used $GIT_DIR/svn/foo instead of
2292 # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
2293 if ($ref_id =~ m{^refs/remotes/(.*)}) {
2294 my $old_dir = "$ENV{GIT_DIR}/svn/$1";
2295 if (-d
$old_dir && ! -d
$dir) {
2300 $_[3] = $path = '' unless (defined $path);
2303 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
2304 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
2305 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
2308 # for read-only access of old .rev_db formats
2309 sub unlink_rev_db_symlink
{
2311 my $link = $self->rev_db_path;
2312 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
2314 unlink $link or croak
"unlink: $link failed!";
2319 my ($self, $uuid) = @_;
2320 my $db_path = $self->map_path($uuid);
2321 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
2322 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
2326 # the new replacement for .rev_db
2328 my ($self, $uuid) = @_;
2329 $uuid ||= $self->ra_uuid;
2330 "$self->{map_root}.$uuid";
2335 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
2341 $f =~ s
#%([0-9a-fA-F]{2})#chr(hex($1))#eg;
2345 sub remove_username
{
2346 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};