4 use Fcntl qw
/:DEFAULT :seek/;
5 use constant rev_map_fmt
=> 'NH40';
6 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
7 $_repack $_repack_flags $_use_svm_props $_head
8 $_use_svnsync_props $no_reuse_existing $_minimize_url
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 my ($_gc_nr, $_gc_period);
35 # properties that we do not log:
38 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
39 svn
:special svn
:executable
40 svn
:entry
:committed
-rev
43 svn
:entry
:committed
-date
/;
45 # some options are read globally, but can be overridden locally
46 # per [svn-remote "..."] section. Command-line options will *NOT*
47 # override options set in an [svn-remote "..."] section
49 for my $option (qw
/follow_parent no_metadata use_svm_props
53 my $prop = "-$option";
56 return $self->{$prop} if exists $self->{$prop};
57 my $k = "svn-remote.$self->{repo_id}.$key";
58 eval { command_oneline
(qw
/config --get/, $k) };
60 $self->{$prop} = ${"Git::SVN::_$option"};
62 my $v = command_oneline
(qw
/config --bool/,$k);
63 $self->{$prop} = $v eq 'false' ?
0 : 1;
65 return $self->{$prop};
71 my (%LOCKFILES, %INDEX_FILES);
73 unlink keys %LOCKFILES if %LOCKFILES;
74 unlink keys %INDEX_FILES if %INDEX_FILES;
77 sub resolve_local_globs
{
78 my ($url, $fetch, $glob_spec) = @_;
79 return unless defined $glob_spec;
80 my $ref = $glob_spec->{ref};
81 my $path = $glob_spec->{path
};
82 foreach (command
(qw
#for-each-ref --format=%(refname) refs/#)) {
83 next unless m
#^$ref->{regex}$#;
85 my $pathname = desanitize_refname
($path->full_path($p));
86 my $refname = desanitize_refname
($ref->full_path($p));
87 if (my $existing = $fetch->{$pathname}) {
88 if ($existing ne $refname) {
89 die "Refspec conflict:\n",
90 "existing: $existing\n",
91 " globbed: $refname\n";
93 my $u = (::cmt_metadata
("$refname"))[0];
94 $u =~ s!^\Q$url\E(/|$)!! or die
95 "$refname: '$url' not found in '$u'\n";
96 if ($pathname ne $u) {
97 warn "W: Refspec glob conflict ",
99 "expected path: $pathname\n",
101 "Continuing ahead with $u\n";
105 $fetch->{$pathname} = $refname;
110 sub parse_revision_argument
{
111 my ($base, $head) = @_;
112 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
113 return ($base, $head);
115 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
116 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
117 return ($head, $head) if ($::_revision
eq 'HEAD');
118 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
119 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
120 die "revision argument: $::_revision not understood by git-svn\n";
124 my ($repo_id, $remotes) = @_;
128 $repo_id = $gs->{repo_id
};
130 $remotes ||= read_all_remotes
();
131 my $remote = $remotes->{$repo_id} or
132 die "[svn-remote \"$repo_id\"] unknown\n";
133 my $fetch = $remote->{fetch
};
134 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
136 my $ra = Git
::SVN
::Ra
->new($url);
137 my $uuid = $ra->get_uuid;
138 my $head = $ra->get_latest_revnum;
140 # ignore errors, $head revision may not even exist anymore
141 eval { $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }) };
142 warn "W: $@\n" if $@
;
144 my $base = defined $fetch ?
$head : 0;
146 # read the max revs for wildcard expansion (branches/*, tags/*)
147 foreach my $t (qw
/branches tags/) {
148 defined $remote->{$t} or next;
149 push @globs, @
{$remote->{$t}};
151 my $max_rev = eval { tmp_config
(qw
/--int --get/,
152 "svn-remote.$repo_id.${t}-maxRev") };
153 if (defined $max_rev && ($max_rev < $base)) {
155 } elsif (!defined $max_rev) {
161 foreach my $p (sort keys %$fetch) {
162 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
163 my $lr = $gs->rev_map_max;
165 $base = $lr if ($lr < $base);
171 ($base, $head) = parse_revision_argument
($base, $head);
172 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
175 sub read_all_remotes
{
177 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
179 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
180 my $svn_refspec = qr{\s*(.*?)\s*:\s*(.+?)\s*};
181 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
182 if (m!^(.+)\.fetch=$svn_refspec$!) {
183 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
184 die("svn-remote.$remote: remote ref '$remote_ref' "
185 . "must start with 'refs/'\n")
186 unless $remote_ref =~ m{^refs/};
187 $local_ref = uri_decode
($local_ref);
188 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
189 $r->{$remote}->{svm
} = {} if $use_svm_props;
190 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
191 $r->{$1}->{svm
} = {};
192 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
193 $r->{$1}->{url
} = $2;
194 } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
195 $r->{$1}->{pushurl
} = $2;
196 } elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
197 $r->{$1}->{ignore_refs_regex
} = $2;
198 } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
199 my ($remote, $t, $local_ref, $remote_ref) =
201 die("svn-remote.$remote: remote ref '$remote_ref' ($t) "
202 . "must start with 'refs/'\n")
203 unless $remote_ref =~ m{^refs/};
204 $local_ref = uri_decode
($local_ref);
208 path
=> Git
::SVN
::GlobSpec
->new($local_ref, 1),
209 ref => Git
::SVN
::GlobSpec
->new($remote_ref, 0) };
210 if (length($rs->{ref}->{right
}) != 0) {
211 die "The '*' glob character must be the last ",
212 "character of '$remote_ref'\n";
214 push @
{ $r->{$remote}->{$t} }, $rs;
219 if (defined $r->{$_}->{svm
}) {
222 my $section = "svn-remote.$_";
224 source
=> tmp_config
('--get',
225 "$section.svm-source"),
226 replace
=> tmp_config
('--get',
227 "$section.svm-replace"),
230 $r->{$_}->{svm
} = $svm;
234 foreach my $remote (keys %$r) {
235 foreach ( grep { defined $_ }
236 map { $r->{$remote}->{$_} } qw(branches tags) ) {
237 foreach my $rs ( @
$_ ) {
238 $rs->{ignore_refs_regex
} =
239 $r->{$remote}->{ignore_refs_regex
};
248 $_gc_nr = $_gc_period = 1000;
249 if (defined $_repack || defined $_repack_flags) {
250 warn "Repack options are obsolete; they have no effect.\n";
254 sub verify_remotes_sanity
{
255 return unless -d
$ENV{GIT_DIR
};
257 foreach (command
(qw
/config -l/)) {
258 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
260 die "Remote ref refs/remote/$1 is tracked by",
261 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
262 "Please resolve this ambiguity in ",
263 "your git configuration file before ",
271 sub find_existing_remote
{
272 my ($url, $remotes) = @_;
273 return undef if $no_reuse_existing;
275 foreach my $repo_id (keys %$remotes) {
276 my $u = $remotes->{$repo_id}->{url
} or next;
278 $existing = $repo_id;
284 sub init_remote_config
{
285 my ($self, $url, $no_write) = @_;
286 $url =~ s!/+$!!; # strip trailing slash
287 my $r = read_all_remotes
();
288 my $existing = find_existing_remote
($url, $r);
291 print STDERR
"Using existing ",
292 "[svn-remote \"$existing\"]\n";
294 $self->{repo_id
} = $existing;
295 } elsif ($_minimize_url) {
296 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
297 $existing = find_existing_remote
($min_url, $r);
300 print STDERR
"Using existing ",
301 "[svn-remote \"$existing\"]\n";
303 $self->{repo_id
} = $existing;
305 if ($min_url ne $url) {
307 print STDERR
"Using higher level of URL: ",
308 "$url => $min_url\n";
310 my $old_path = $self->{path
};
311 $self->{path
} = $url;
312 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
313 if (length $old_path) {
314 $self->{path
} .= "/$old_path";
321 # verify that we aren't overwriting anything:
323 command_oneline
('config', '--get',
324 "svn-remote.$self->{repo_id}.url")
326 if ($orig_url && ($orig_url ne $url)) {
327 die "svn-remote.$self->{repo_id}.url already set: ",
328 "$orig_url\nwanted to set to: $url\n";
331 my ($xrepo_id, $xpath) = find_ref
($self->refname);
332 if (!$no_write && defined $xpath) {
333 die "svn-remote.$xrepo_id.fetch already set to track ",
334 "$xpath:", $self->refname, "\n";
337 command_noisy
('config',
338 "svn-remote.$self->{repo_id}.url", $url);
339 $self->{path
} =~ s{^/}{};
340 $self->{path
} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
341 command_noisy
('config', '--add',
342 "svn-remote.$self->{repo_id}.fetch",
343 "$self->{path}:".$self->refname);
348 sub find_by_url
{ # repos_root and, path are optional
349 my ($class, $full_url, $repos_root, $path) = @_;
351 return undef unless defined $full_url;
352 remove_username
($full_url);
353 remove_username
($repos_root) if defined $repos_root;
354 my $remotes = read_all_remotes
();
355 if (defined $full_url && defined $repos_root && !defined $path) {
357 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
359 foreach my $repo_id (keys %$remotes) {
360 my $u = $remotes->{$repo_id}->{url
} or next;
362 next if defined $repos_root && $repos_root ne $u;
364 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
365 foreach my $t (qw
/branches tags/) {
366 foreach my $globspec (@
{$remotes->{$repo_id}->{$t}}) {
367 resolve_local_globs
($u, $fetch, $globspec);
371 my $rwr = rewrite_root
({repo_id
=> $repo_id});
372 my $svm = $remotes->{$repo_id}->{svm
}
373 if defined $remotes->{$repo_id}->{svm
};
374 unless (defined $p) {
381 } elsif (defined $svm) {
383 $prefix = $svm->{replace
};
384 $prefix =~ s
#^\Q$u\E(?:/|$)##;
387 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
389 foreach my $f (keys %$fetch) {
391 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
398 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
399 my $self = _new
($class, $repo_id, $ref_id, $path);
401 $self->init_remote_config($url, $no_write);
408 foreach (command
(qw
/config -l/)) {
409 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
410 \s
*(.*?
)\s
*:\s
*(.+?
)\s
*$!x
;
411 my ($repo_id, $path, $ref) = ($1, $2, $3);
412 if ($ref eq $ref_id) {
413 $path = '' if ($path =~ m
#^\./?#);
414 return ($repo_id, $path);
417 (undef, undef, undef);
421 my ($class, $ref_id, $repo_id, $path) = @_;
422 if (defined $ref_id && !defined $repo_id && !defined $path) {
423 ($repo_id, $path) = find_ref
($ref_id);
424 if (!defined $repo_id) {
425 die "Could not find a \"svn-remote.*.fetch\" key ",
426 "in the repository configuration matching: ",
430 my $self = _new
($class, $repo_id, $ref_id, $path);
431 if (!defined $self->{path
} || !length $self->{path
}) {
432 my $fetch = command_oneline
('config', '--get',
433 "svn-remote.$repo_id.fetch",
435 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
436 "\":$ref_id\$\" in config\n";
437 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
439 $self->{path
} =~ s{/+}{/}g;
440 $self->{path
} =~ s{\A/}{};
441 $self->{path
} =~ s{/\z}{};
442 $self->{url
} = command_oneline
('config', '--get',
443 "svn-remote.$repo_id.url") or
444 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
445 $self->{pushurl
} = eval { command_oneline
('config', '--get',
446 "svn-remote.$repo_id.pushurl") };
452 my ($refname) = $_[0]->{ref_id
} ;
454 # It cannot end with a slash /, we'll throw up on this because
455 # SVN can't have directories with a slash in their name, either:
456 if ($refname =~ m{/$}) {
457 die "ref: '$refname' ends with a trailing slash, this is ",
458 "not permitted by git nor Subversion\n";
461 # It cannot have ASCII control character space, tilde ~, caret ^,
462 # colon :, question-mark ?, asterisk *, space, or open bracket [
465 # Additionally, % must be escaped because it is used for escaping
466 # and we want our escaped refname to be reversible
467 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
469 # no slash-separated component can begin with a dot .
471 $refname =~ s{/\.}{/%2E}g;
473 # It cannot have two consecutive dots .. anywhere
475 $refname =~ s{\.\.}{%2E%2E}g;
477 # trailing dots and .lock are not allowed
478 # .$ becomes %2E and .lock becomes %2Elock
479 $refname =~ s{\.(?=$|lock$)}{%2E};
481 # the sequence @{ is used to access the reflog
483 $refname =~ s{\@\{}{%40\{}g;
488 sub desanitize_refname
{
490 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
496 return $self->{svm
}->{uuid
} if $self->svm;
498 unless ($self->{svm
}) {
499 die "SVM UUID not cached, and reading remotely failed\n";
501 $self->{svm
}->{uuid
};
506 return $self->{svm
} if $self->{svm
};
508 # see if we have it in our config, first:
510 my $section = "svn-remote.$self->{repo_id}";
512 source
=> tmp_config
('--get', "$section.svm-source"),
513 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
514 replace
=> tmp_config
('--get', "$section.svm-replace"),
517 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
524 my ($self, $ra) = @_;
525 return $ra if $self->svm;
527 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
528 "(svm:source, svm:uuid) ",
529 "from the following URLs:\n" );
531 my ($self, $ra, $path, $r) = @_;
532 my $props = ($ra->get_dir($path, $r))[2];
533 my $src = $props->{'svm:source'};
534 my $uuid = $props->{'svm:uuid'};
535 return undef if (!$src || !$uuid);
539 $uuid =~ m{^[0-9a-f\-]{30,}$}i
540 or die "doesn't look right - svm:uuid is '$uuid'\n";
542 # the '!' is used to mark the repos_root!/relative/path
544 $src =~ s{/+$}{}; # no trailing slashes please
545 # username is of no interest
546 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
548 my $replace = $ra->{url
};
549 $replace .= "/$path" if length $path;
551 my $section = "svn-remote.$self->{repo_id}";
552 tmp_config
("$section.svm-source", $src);
553 tmp_config
("$section.svm-replace", $replace);
554 tmp_config
("$section.svm-uuid", $uuid);
562 my $r = $ra->get_latest_revnum;
563 my $path = $self->{path
};
565 while (length $path) {
566 unless ($tried{"$self->{url}/$path"}) {
567 return $ra if $self->read_svm_props($ra, $path, $r);
568 $tried{"$self->{url}/$path"} = 1;
570 $path =~ s
#/?[^/]+$##;
572 die "Path: '$path' should be ''\n" if $path ne '';
573 return $ra if $self->read_svm_props($ra, $path, $r);
574 $tried{"$self->{url}/$path"} = 1;
576 if ($ra->{repos_root
} eq $self->{url
}) {
577 die @err, (map { " $_\n" } keys %tried), "\n";
580 # nope, make sure we're connected to the repository root:
583 $path = $ra->{svn_path
};
584 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
585 while (length $path) {
586 unless ($tried{"$ra->{url}/$path"}) {
587 $ok = $self->read_svm_props($ra, $path, $r);
589 $tried{"$ra->{url}/$path"} = 1;
591 $path =~ s
#/?[^/]+$##;
593 die "Path: '$path' should be ''\n" if $path ne '';
594 $ok ||= $self->read_svm_props($ra, $path, $r);
595 $tried{"$ra->{url}/$path"} = 1;
597 die @err, (map { " $_\n" } keys %tried), "\n";
599 Git
::SVN
::Ra
->new($self->{url
});
604 return $self->{svnsync
} if $self->{svnsync
};
606 if ($self->no_metadata) {
607 die "Can't have both 'noMetadata' and ",
608 "'useSvnsyncProps' options set!\n";
610 if ($self->rewrite_root) {
611 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
614 if ($self->rewrite_uuid) {
615 die "Can't have both 'useSvnsyncProps' and 'rewriteUUID' ",
620 # see if we have it in our config, first:
622 my $section = "svn-remote.$self->{repo_id}";
624 my $url = tmp_config
('--get', "$section.svnsync-url");
625 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
626 die "doesn't look right - svn:sync-from-url is '$url'\n";
628 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
629 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
630 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
632 $svnsync = { url
=> $url, uuid
=> $uuid }
634 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
635 return $self->{svnsync
} = $svnsync;
638 my $err = "useSvnsyncProps set, but failed to read " .
639 "svnsync property: svn:sync-from-";
640 my $rp = $self->ra->rev_proplist(0);
642 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
643 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
644 die "doesn't look right - svn:sync-from-url is '$url'\n";
646 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
647 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
648 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
650 my $section = "svn-remote.$self->{repo_id}";
651 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
652 tmp_config
('--add', "$section.svnsync-url", $url);
653 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
656 # this allows us to memoize our SVN::Ra UUID locally and avoid a
657 # remote lookup (useful for 'git svn log').
660 unless ($self->{ra_uuid
}) {
661 my $key = "svn-remote.$self->{repo_id}.uuid";
662 my $uuid = eval { tmp_config
('--get', $key) };
663 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) {
664 $self->{ra_uuid
} = $uuid;
666 die "ra_uuid called without URL\n" unless $self->{url
};
667 $self->{ra_uuid
} = $self->ra->get_uuid;
668 tmp_config
('--add', $key, $self->{ra_uuid
});
674 sub _set_repos_root
{
675 my ($self, $repos_root) = @_;
676 my $k = "svn-remote.$self->{repo_id}.reposRoot";
677 $repos_root ||= $self->ra->{repos_root
};
678 tmp_config
($k, $repos_root);
684 my $k = "svn-remote.$self->{repo_id}.reposRoot";
685 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
690 my $ra = Git
::SVN
::Ra
->new($self->{url
});
691 $self->_set_repos_root($ra->{repos_root
});
692 if ($self->use_svm_props && !$self->{svm
}) {
693 if ($self->no_metadata) {
694 die "Can't have both 'noMetadata' and ",
695 "'useSvmProps' options set!\n";
696 } elsif ($self->use_svnsync_props) {
697 die "Can't have both 'useSvnsyncProps' and ",
698 "'useSvmProps' options set!\n";
700 $ra = $self->_set_svm_vars($ra);
701 $self->{-want_revprops
} = 1;
706 # prop_walk(PATH, REV, SUB)
707 # -------------------------
708 # Recursively traverse PATH at revision REV and invoke SUB for each
709 # directory that contains a SVN property. SUB will be invoked as
710 # follows: &SUB(gs, path, props); where `gs' is this instance of
711 # Git::SVN, `path' the path to the directory where the properties
712 # `props' were found. The `path' will be relative to point of checkout,
713 # that is, if url://repo/trunk is the current Git branch, and that
714 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
715 # as `path' (note the trailing `/').
717 my ($self, $path, $rev, $sub) = @_;
720 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
723 # Strip the irrelevant part of the path.
724 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
725 # Ensure the path is terminated by a `/'.
728 # The properties contain all the internal SVN stuff nobody
729 # (usually) cares about.
730 my $interesting_props = 0;
731 foreach (keys %{$props}) {
732 # If it doesn't start with `svn:', it must be a
733 # user-defined property.
734 ++$interesting_props and next if $_ !~ /^svn:/;
735 # FIXME: Fragile, if SVN adds new public properties,
736 # this needs to be updated.
737 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
739 |externals
|needs
-lock)$/x
;
741 &$sub($self, $p, $props) if $interesting_props;
743 foreach (sort keys %$dirent) {
744 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
745 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
749 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
750 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
752 # returns the newest SVN revision number and newest commit SHA1
753 sub last_rev_commit
{
755 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
756 return ($self->{last_rev
}, $self->{last_commit
});
758 my $c = ::verify_ref
($self->refname.'^0');
759 if ($c && !$self->use_svm_props && !$self->no_metadata) {
760 my $rev = (::cmt_metadata
($c))[1];
762 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
766 my $map_path = $self->map_path;
767 unless (-e
$map_path) {
768 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
769 return (undef, undef);
771 my ($rev, $commit) = $self->rev_map_max(1);
772 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
773 return ($rev, $commit);
776 sub get_fetch_range
{
777 my ($self, $min, $max) = @_;
778 $max ||= $self->ra->get_latest_revnum;
779 $min ||= $self->rev_map_max;
785 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
786 my $config = "$ENV{GIT_DIR}/svn/.metadata";
787 if (! -f
$config && -f
$old_def_config) {
788 rename $old_def_config, $config or
789 die "Failed rename $old_def_config => $config: $!\n";
791 my $old_config = $ENV{GIT_CONFIG
};
792 $ENV{GIT_CONFIG
} = $config;
795 unless (-f
$config) {
797 open my $fh, '>', $config or
798 die "Can't open $config: $!\n";
799 print $fh "; This file is used internally by ",
801 "Couldn't write to $config: $!\n";
802 print $fh "; You should not have to edit it\n" or
803 die "Couldn't write to $config: $!\n";
804 close $fh or die "Couldn't close $config: $!\n";
806 command
('config', @args);
809 if (defined $old_config) {
810 $ENV{GIT_CONFIG
} = $old_config;
812 delete $ENV{GIT_CONFIG
};
815 wantarray ?
@ret : $ret[0];
819 my ($self, $sub) = @_;
820 my $old_index = $ENV{GIT_INDEX_FILE
};
821 $ENV{GIT_INDEX_FILE
} = $self->{index};
824 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
825 mkpath
([$dir]) unless -d
$dir;
829 if (defined $old_index) {
830 $ENV{GIT_INDEX_FILE
} = $old_index;
832 delete $ENV{GIT_INDEX_FILE
};
835 wantarray ?
@ret : $ret[0];
838 sub assert_index_clean
{
839 my ($self, $treeish) = @_;
841 $self->tmp_index_do(sub {
842 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
843 my $x = command_oneline
('write-tree');
844 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
845 /^tree ($::sha1)/mo);
848 warn "Index mismatch: $y != $x\nrereading $treeish\n";
849 unlink $self->{index} or die "unlink $self->{index}: $!\n";
850 command_noisy
('read-tree', $treeish);
851 $x = command_oneline
('write-tree');
853 fatal
"trees ($treeish) $y != $x\n",
854 "Something is seriously wrong...";
859 sub get_commit_parents
{
860 my ($self, $log_entry) = @_;
861 my (%seen, @ret, @tmp);
862 # legacy support for 'set-tree'; this is only used by set_tree_cb:
863 if (my $ip = $self->{inject_parents
}) {
864 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
868 if (my $cur = ::verify_ref
($self->refname.'^0')) {
871 if (my $ipd = $self->{inject_parents_dcommit
}) {
872 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
876 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
877 while (my $p = shift @tmp) {
887 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
888 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
889 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
892 if ($rwr !~ m
#^[a-z\+]+://#) {
893 die "$rwr is not a valid URL (key: $k)\n";
896 $self->{-rewrite_root
} = $rwr;
901 return $self->{-rewrite_uuid
} if exists $self->{-rewrite_uuid
};
902 my $k = "svn-remote.$self->{repo_id}.rewriteUUID";
903 my $rwid = eval { command_oneline
(qw
/config --get/, $k) };
906 if ($rwid !~ m
#^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$#) {
907 die "$rwid is not a valid UUID (key: $k)\n";
910 $self->{-rewrite_uuid
} = $rwid;
915 ($self->rewrite_root || $self->{url
}) .
916 (length $self->{path
} ?
'/' . $self->{path
} : '');
921 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
926 if ($self->{pushurl
}) {
927 return $self->{pushurl
} . (length $self->{path
} ?
'/' .
930 return $self->full_url;
934 sub set_commit_header_env
{
935 my ($log_entry) = @_;
937 foreach my $ned (qw
/NAME EMAIL DATE/) {
938 foreach my $ac (qw
/AUTHOR COMMITTER/) {
939 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
943 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
944 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
945 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
947 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
948 ?
$log_entry->{commit_name
}
949 : $log_entry->{name
};
950 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
951 ?
$log_entry->{commit_email
}
952 : $log_entry->{email
};
956 sub restore_commit_header_env
{
958 foreach my $ned (qw
/NAME EMAIL DATE/) {
959 foreach my $ac (qw
/AUTHOR COMMITTER/) {
960 my $k = "GIT_${ac}_${ned}";
961 if (defined $env->{$k}) {
962 $ENV{$k} = $env->{$k};
971 command_noisy
('gc', '--auto');
975 my ($self, $log_entry) = @_;
976 my $lr = $self->last_rev;
977 if (defined $lr && $lr >= $log_entry->{revision
}) {
978 die "Last fetched revision of ", $self->refname,
979 " was r$lr, but we are about to fetch: ",
980 "r$log_entry->{revision}!\n";
982 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
983 croak
"$log_entry->{revision} = $c already exists! ",
984 "Why are we refetching it?\n";
986 my $old_env = set_commit_header_env
($log_entry);
987 my $tree = $log_entry->{tree
};
988 if (!defined $tree) {
989 $tree = $self->tmp_index_do(sub {
990 command_oneline
('write-tree') });
992 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
994 my @exec = ('git', 'commit-tree', $tree);
995 foreach ($self->get_commit_parents($log_entry)) {
996 push @exec, '-p', $_;
998 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1002 # we always get UTF-8 from SVN, but we may want our commits in
1003 # a different encoding.
1004 if (my $enc = Git
::config
('i18n.commitencoding')) {
1006 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
1008 print $msg_fh $log_entry->{log} or croak
$!;
1009 restore_commit_header_env
($old_env);
1010 unless ($self->no_metadata) {
1011 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
1014 $msg_fh->flush == 0 or croak
$!;
1015 close $msg_fh or croak
$!;
1016 chomp(my $commit = do { local $/; <$out_fh> });
1017 close $out_fh or croak
$!;
1020 if ($commit !~ /^$::sha1$/o) {
1021 die "Failed to commit, invalid sha1: $commit\n";
1024 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
1026 $self->{last_rev
} = $log_entry->{revision
};
1027 $self->{last_commit
} = $commit;
1028 print "r$log_entry->{revision}" unless $::_q
> 1;
1029 if (defined $log_entry->{svm_revision
}) {
1030 print " (\@$log_entry->{svm_revision})" unless $::_q
> 1;
1031 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
1032 0, $self->svm_uuid);
1034 print " = $commit ($self->{ref_id})\n" unless $::_q
> 1;
1035 if (--$_gc_nr == 0) {
1036 $_gc_nr = $_gc_period;
1043 my ($self, $paths, $r) = @_;
1044 return 1 if $self->{path
} eq '';
1045 if (my $path = $paths->{"/$self->{path}"}) {
1046 return ($path->{action
} eq 'D') ?
0 : 1;
1048 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
1049 if (grep /$self->{path_regex}/, keys %$paths) {
1053 foreach (split m
#/#, $self->{path}) {
1055 next unless ($paths->{$c} &&
1056 ($paths->{$c}->{action
} =~ /^[AR]$/));
1057 if ($self->ra->check_path($self->{path
}, $r) ==
1065 sub find_parent_branch
{
1066 my ($self, $paths, $rev) = @_;
1067 return undef unless $self->follow_parent;
1068 unless (defined $paths) {
1069 my $err_handler = $SVN::Error
::handler
;
1070 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
1071 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
1072 sub { $paths = $_[0] });
1073 $SVN::Error
::handler
= $err_handler;
1075 return undef unless defined $paths;
1077 # look for a parent from another branch:
1078 my @b_path_components = split m
#/#, $self->{path};
1079 my @a_path_components;
1081 while (@b_path_components) {
1082 $i = $paths->{'/'.join('/', @b_path_components)};
1083 last if $i && defined $i->{copyfrom_path
};
1084 unshift(@a_path_components, pop(@b_path_components));
1086 return undef unless defined $i && defined $i->{copyfrom_path
};
1087 my $branch_from = $i->{copyfrom_path
};
1088 if (@a_path_components) {
1089 print STDERR
"branch_from: $branch_from => ";
1090 $branch_from .= '/'.join('/', @a_path_components);
1091 print STDERR
$branch_from, "\n";
1093 my $r = $i->{copyfrom_rev
};
1094 my $repos_root = $self->ra->{repos_root
};
1095 my $url = $self->ra->{url
};
1096 my $new_url = $url . $branch_from;
1097 print STDERR
"Found possible branch point: ",
1098 "$new_url => ", $self->full_url, ", $r\n"
1100 $branch_from =~ s
#^/##;
1101 my $gs = $self->other_gs($new_url, $url,
1102 $branch_from, $r, $self->{ref_id
});
1103 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1106 if (!defined $r0 || !defined $parent) {
1107 ($base, $head) = parse_revision_argument
(0, $r);
1110 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
1111 0, 1, sub { $base = $_[1] - 1 });
1114 if (defined $base && $base <= $r) {
1115 $gs->fetch($base, $r);
1117 ($r0, $parent) = $gs->find_rev_before($r, 1);
1119 if (defined $r0 && defined $parent) {
1120 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n"
1123 if ($self->ra->can_do_switch) {
1124 $self->assert_index_clean($parent);
1125 print STDERR
"Following parent with do_switch\n"
1127 # do_switch works with svn/trunk >= r22312, but that
1128 # is not included with SVN 1.4.3 (the latest version
1129 # at the moment), so we can't rely on it
1130 $self->{last_rev
} = $r0;
1131 $self->{last_commit
} = $parent;
1132 $ed = Git
::SVN
::Fetcher
->new($self, $gs->{path
});
1133 $gs->ra->gs_do_switch($r0, $rev, $gs,
1134 $self->full_url, $ed)
1135 or die "SVN connection failed somewhere...\n";
1136 } elsif ($self->ra->trees_match($new_url, $r0,
1137 $self->full_url, $rev)) {
1138 print STDERR
"Trees match:\n",
1140 " ${\$self->full_url}\@$rev\n",
1141 "Following parent with no changes\n"
1143 $self->tmp_index_do(sub {
1144 command_noisy
('read-tree', $parent);
1146 $self->{last_commit
} = $parent;
1148 print STDERR
"Following parent with do_update\n"
1150 $ed = Git
::SVN
::Fetcher
->new($self);
1151 $self->ra->gs_do_update($rev, $rev, $self, $ed)
1152 or die "SVN connection failed somewhere...\n";
1154 print STDERR
"Successfully followed parent\n" unless $::_q
> 1;
1155 return $self->make_log_entry($rev, [$parent], $ed);
1161 my ($self, $paths, $rev) = @_;
1163 my ($last_rev, @parents);
1164 if (my $lc = $self->last_commit) {
1165 # we can have a branch that was deleted, then re-added
1166 # under the same name but copied from another path, in
1167 # which case we'll have multiple parents (we don't
1168 # want to break the original ref, nor lose copypath info):
1169 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1170 push @
{$log_entry->{parents
}}, $lc;
1173 $ed = Git
::SVN
::Fetcher
->new($self);
1174 $last_rev = $self->{last_rev
};
1179 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1182 $ed = Git
::SVN
::Fetcher
->new($self);
1184 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1185 die "SVN connection failed somewhere...\n";
1187 $self->make_log_entry($rev, \
@parents, $ed);
1191 my ($self, $r) = @_;
1194 my ($r, $empty_dirs, $line) = @_;
1195 if (defined $r && $line =~ /^r(\d+)$/) {
1196 return 0 if $1 > $r;
1197 } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
1198 $empty_dirs->{$1} = 1;
1199 } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
1200 my @d = grep {m
[^\Q
$1\E
(/|$)]} (keys %$empty_dirs);
1201 delete @
$empty_dirs{@d};
1206 my %empty_dirs = ();
1207 my $gz_file = "$self->{dir}/unhandled.log.gz";
1209 if (!can_compress
()) {
1210 warn "Compress::Zlib could not be found; ",
1211 "empty directories in $gz_file will not be read\n";
1213 my $gz = Compress
::Zlib
::gzopen
($gz_file, "rb") or
1214 die "Unable to open $gz_file: $!\n";
1216 while ($gz->gzreadline($line) > 0) {
1217 scan
($r, \
%empty_dirs, $line) or last;
1223 if (open my $fh, '<', "$self->{dir}/unhandled.log") {
1224 binmode $fh or croak
"binmode: $!";
1226 scan
($r, \
%empty_dirs, $_) or last;
1231 my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
1232 foreach my $d (sort keys %empty_dirs) {
1233 $d = uri_decode
($d);
1235 next unless length($d);
1238 warn "$d exists but is not a directory\n";
1240 print "creating empty directory: $d\n";
1247 my ($self, $ed) = @_;
1249 my $h = $ed->{empty
};
1250 foreach (sort keys %$h) {
1251 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
1252 push @out, " $act: " . uri_encode
($_);
1253 warn "W: $act: $_\n";
1255 foreach my $t (qw
/dir_prop file_prop/) {
1256 $h = $ed->{$t} or next;
1257 foreach my $path (sort keys %$h) {
1258 my $ppath = $path eq '' ?
'.' : $path;
1259 foreach my $prop (sort keys %{$h->{$path}}) {
1260 next if $SKIP_PROP{$prop};
1261 my $v = $h->{$path}->{$prop};
1262 my $t_ppath_prop = "$t: " .
1263 uri_encode
($ppath) . ' ' .
1266 push @out, " +$t_ppath_prop " .
1269 push @out, " -$t_ppath_prop";
1274 foreach my $t (qw
/absent_file absent_directory/) {
1275 $h = $ed->{$t} or next;
1276 foreach my $parent (sort keys %$h) {
1277 foreach my $path (sort @
{$h->{$parent}}) {
1278 push @out, " $t: " .
1279 uri_encode
("$parent/$path");
1280 warn "W: $t: $parent/$path ",
1281 "Insufficient permissions?\n";
1289 # some systmes don't handle or mishandle %z, so be creative.
1290 my $t = shift || time;
1291 my $gm = timelocal
(gmtime($t));
1292 my $sign = qw( + + - )[ $t <=> $gm ];
1293 return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
1296 # parse_svn_date(DATE)
1297 # --------------------
1298 # Given a date (in UTC) from Subversion, return a string in the format
1299 # "<TZ Offset> <local date/time>" that Git will use.
1301 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
1302 # is true we'll convert it to the local timezone instead.
1303 sub parse_svn_date
{
1304 my $date = shift || return '+0000 1970-01-01 00:00:00';
1305 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
1306 (\d\d
)\
:(\d\d
)\
:(\d\d
)\
.\d
*Z
$/x
) or
1307 croak
"Unable to parse date: $date\n";
1308 my $parsed_date; # Set next.
1310 if ($Git::SVN
::_localtime
) {
1311 # Translate the Subversion datetime to an epoch time.
1312 # Begin by switching ourselves to $date's timezone, UTC.
1313 my $old_env_TZ = $ENV{TZ
};
1317 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
1319 # Determine our local timezone (including DST) at the
1320 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
1321 # value of TZ, if any, at the time we were run.
1322 if (defined $Git::SVN
::Log
::TZ
) {
1323 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
1328 my $our_TZ = get_tz
();
1330 # This converts $epoch_in_UTC into our local timezone.
1331 my ($sec, $min, $hour, $mday, $mon, $year,
1332 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
1334 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
1335 $our_TZ, $year + 1900, $mon + 1,
1336 $mday, $hour, $min, $sec);
1338 # Reset us to the timezone in effect when we entered
1340 if (defined $old_env_TZ) {
1341 $ENV{TZ
} = $old_env_TZ;
1346 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
1349 return $parsed_date;
1353 my ($self, $new_url, $url,
1354 $branch_from, $r, $old_ref_id) = @_;
1355 my $gs = Git
::SVN
->find_by_url($new_url, $url, $branch_from);
1357 my $ref_id = $old_ref_id;
1358 $ref_id =~ s/\@\d+-*$//;
1360 # just grow a tail if we're not unique enough :x
1361 $ref_id .= '-' while find_ref
($ref_id);
1362 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
1363 if ($u =~ s
#^\Q$url\E(/|$)##) {
1366 $repo_id = $self->{repo_id
};
1369 # It is possible to tag two different subdirectories at
1370 # the same revision. If the url for an existing ref
1371 # does not match, we must either find a ref with a
1372 # matching url or create a new ref by growing a tail.
1373 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
1374 my (undef, $max_commit) = $gs->rev_map_max(1);
1375 last if (!$max_commit);
1376 my ($url) = ::cmt_metadata
($max_commit);
1377 last if ($url eq $gs->metadata_url);
1380 print STDERR
"Initializing parent: $ref_id\n" unless $::_q
> 1;
1385 sub call_authors_prog
{
1386 my ($orig_author) = @_;
1387 $orig_author = command_oneline
('rev-parse', '--sq-quote', $orig_author);
1388 my $author = `$::_authors_prog $orig_author`;
1390 die "$::_authors_prog failed with exit code $?\n"
1392 if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
1393 my ($name, $email) = ($1, $2);
1394 $email = undef if length $2 == 0;
1395 return [$name, $email];
1397 die "Author: $orig_author: $::_authors_prog returned "
1398 . "invalid author format: $author\n";
1404 if (!defined $author || length $author == 0) {
1405 $author = '(no author)';
1407 if (!defined $::users
{$author}) {
1408 if (defined $::_authors_prog
) {
1409 $::users
{$author} = call_authors_prog
($author);
1410 } elsif (defined $::_authors
) {
1411 die "Author: $author not defined in $::_authors file\n";
1417 sub find_extra_svk_parents
{
1418 my ($self, $ed, $tickets, $parents) = @_;
1419 # aha! svk:merge property changed...
1420 my @tickets = split "\n", $tickets;
1422 for my $ticket ( @tickets ) {
1423 my ($uuid, $path, $rev) = split /:/, $ticket;
1424 if ( $uuid eq $self->ra_uuid ) {
1425 my $url = $self->{url
};
1426 my $repos_root = $url;
1427 my $branch_from = $path;
1428 $branch_from =~ s{^/}{};
1429 my $gs = $self->other_gs($repos_root."/".$branch_from,
1434 if ( my $commit = $gs->rev_map_get($rev, $uuid) ) {
1435 # wahey! we found it, but it might be
1437 push @known_parents, [ $rev, $commit ];
1441 # Ordering matters; highest-numbered commit merge tickets
1442 # first, as they may account for later merge ticket additions
1444 @known_parents = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @known_parents;
1445 for my $parent ( @known_parents ) {
1446 my @cmd = ('rev-list', $parent, map { "^$_" } @
$parents );
1447 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
1449 while ( <$msg_fh> ) {
1452 command_close_pipe
($msg_fh, $ctx);
1455 "Found merge parent (svk:merge ticket): $parent\n";
1456 push @
$parents, $parent;
1461 sub lookup_svn_merge
{
1466 my ($source, $revs) = split ":", $merge;
1469 my $gs = Git
::SVN
->find_by_url($url.$source, $url, $path);
1471 warn "Couldn't find revmap for $url$source\n";
1474 my @ranges = split ",", $revs;
1475 my ($tip, $tip_commit);
1476 my @merged_commit_ranges;
1478 for my $range ( @ranges ) {
1479 my ($bottom, $top) = split "-", $range;
1481 my $bottom_commit = $gs->find_rev_after( $bottom, 1, $top );
1482 my $top_commit = $gs->find_rev_before( $top, 1, $bottom );
1484 unless ($top_commit and $bottom_commit) {
1485 warn "W:unknown path/rev in svn:mergeinfo "
1486 ."dirprop: $source:$range\n";
1490 if (scalar(command
('rev-parse', "$bottom_commit^@"))) {
1491 push @merged_commit_ranges,
1492 "$bottom_commit^..$top_commit";
1494 push @merged_commit_ranges, "$top_commit";
1497 if ( !defined $tip or $top > $tip ) {
1499 $tip_commit = $top_commit;
1502 return ($tip_commit, @merged_commit_ranges);
1506 my ($msg_fh, $ctx) = command_output_pipe
(
1510 while ( <$msg_fh> ) {
1514 command_close_pipe
($msg_fh, $ctx);
1518 sub check_cherry_pick
{
1521 my $parents = shift;
1523 my %commits = map { $_ => 1 }
1524 _rev_list
("--no-merges", $tip, "--not", $base, @
$parents, "--");
1525 for my $range ( @ranges ) {
1526 delete @commits{_rev_list
($range, "--")};
1528 for my $commit (keys %commits) {
1529 if (has_no_changes
($commit)) {
1530 delete $commits{$commit};
1533 return (keys %commits);
1536 sub has_no_changes
{
1539 my @revs = split / /, command_oneline
(
1540 qw(rev-list --parents -1 -m), $commit);
1542 # Commits with no parents, e.g. the start of a partial branch,
1543 # have changes by definition.
1544 return 1 if (@revs < 2);
1546 # Commits with multiple parents, e.g a merge, have no changes
1548 return 0 if (@revs > 2);
1550 return (command_oneline
("rev-parse", "$commit^{tree}") eq
1551 command_oneline
("rev-parse", "$commit~1^{tree}"));
1554 sub tie_for_persistent_memoization
{
1558 if ($can_use_yaml) {
1559 tie
%$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
1561 tie
%$hash => 'Memoize::Storable', "$path.db", 'nstore';
1565 # The GIT_DIR environment variable is not always set until after the command
1566 # line arguments are processed, so we can't memoize in a BEGIN block.
1570 sub memoize_svn_mergeinfo_functions
{
1571 return if $memoized;
1574 my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
1575 mkpath
([$cache_path]) unless -d
$cache_path;
1577 my %lookup_svn_merge_cache;
1578 my %check_cherry_pick_cache;
1579 my %has_no_changes_cache;
1581 tie_for_persistent_memoization
(\
%lookup_svn_merge_cache,
1582 "$cache_path/lookup_svn_merge");
1583 memoize
'lookup_svn_merge',
1584 SCALAR_CACHE
=> 'FAULT',
1585 LIST_CACHE
=> ['HASH' => \
%lookup_svn_merge_cache],
1588 tie_for_persistent_memoization
(\
%check_cherry_pick_cache,
1589 "$cache_path/check_cherry_pick");
1590 memoize
'check_cherry_pick',
1591 SCALAR_CACHE
=> 'FAULT',
1592 LIST_CACHE
=> ['HASH' => \
%check_cherry_pick_cache],
1595 tie_for_persistent_memoization
(\
%has_no_changes_cache,
1596 "$cache_path/has_no_changes");
1597 memoize
'has_no_changes',
1598 SCALAR_CACHE
=> ['HASH' => \
%has_no_changes_cache],
1599 LIST_CACHE
=> 'FAULT',
1603 sub unmemoize_svn_mergeinfo_functions
{
1604 return if not $memoized;
1607 Memoize
::unmemoize
'lookup_svn_merge';
1608 Memoize
::unmemoize
'check_cherry_pick';
1609 Memoize
::unmemoize
'has_no_changes';
1612 Memoize
::memoize
'Git::SVN::repos_root';
1616 # Force cache writeout explicitly instead of waiting for
1617 # global destruction to avoid segfault in Storable:
1618 # http://rt.cpan.org/Public/Bug/Display.html?id=36087
1619 unmemoize_svn_mergeinfo_functions
();
1622 sub parents_exclude
{
1623 my $parents = shift;
1625 return unless @commits;
1630 my @cmd = ('rev-list', "-1", @commits, "--not", @
$parents );
1631 $excluded = command_oneline
(@cmd);
1635 for my $commit ( @commits ) {
1636 if ( $commit eq $excluded ) {
1637 push @excluded, $commit;
1645 die "saw commit '$excluded' in rev-list output, "
1646 ."but we didn't ask for that commit (wanted: @commits --not @$parents)"
1651 while ($excluded and @commits);
1657 # note: this function should only be called if the various dirprops
1658 # have actually changed
1659 sub find_extra_svn_parents
{
1660 my ($self, $ed, $mergeinfo, $parents) = @_;
1661 # aha! svk:merge property changed...
1663 memoize_svn_mergeinfo_functions
();
1665 # We first search for merged tips which are not in our
1666 # history. Then, we figure out which git revisions are in
1667 # that tip, but not this revision. If all of those revisions
1668 # are now marked as merge, we can add the tip as a parent.
1669 my @merges = split "\n", $mergeinfo;
1671 my $url = $self->{url
};
1672 my $uuid = $self->ra_uuid;
1674 for my $merge ( @merges ) {
1675 my ($tip_commit, @ranges) =
1676 lookup_svn_merge
( $uuid, $url, $merge );
1677 unless (!$tip_commit or
1678 grep { $_ eq $tip_commit } @
$parents ) {
1679 push @merge_tips, $tip_commit;
1680 $ranges{$tip_commit} = \
@ranges;
1682 push @merge_tips, undef;
1686 my %excluded = map { $_ => 1 }
1687 parents_exclude
($parents, grep { defined } @merge_tips);
1689 # check merge tips for new parents
1691 for my $merge_tip ( @merge_tips ) {
1692 my $spec = shift @merges;
1693 next unless $merge_tip and $excluded{$merge_tip};
1695 my $ranges = $ranges{$merge_tip};
1697 # check out 'new' tips
1700 $merge_base = command_oneline
(
1702 @
$parents, $merge_tip,
1706 die "An error occurred during merge-base"
1707 unless $@
->isa("Git::Error::Command");
1709 warn "W: Cannot find common ancestor between ".
1710 "@$parents and $merge_tip. Ignoring merge info.\n";
1714 # double check that there are no missing non-merge commits
1715 my (@incomplete) = check_cherry_pick
(
1716 $merge_base, $merge_tip,
1721 if ( @incomplete ) {
1722 warn "W:svn cherry-pick ignored ($spec) - missing "
1723 .@incomplete." commit(s) (eg $incomplete[0])\n";
1726 "Found merge parent (svn:mergeinfo prop): ",
1728 push @new_parents, $merge_tip;
1732 # cater for merges which merge commits from multiple branches
1733 if ( @new_parents > 1 ) {
1734 for ( my $i = 0; $i <= $#new_parents; $i++ ) {
1735 for ( my $j = 0; $j <= $#new_parents; $j++ ) {
1737 next unless $new_parents[$i];
1738 next unless $new_parents[$j];
1739 my $revs = command_oneline
(
1741 "$new_parents[$i]..$new_parents[$j]",
1744 undef($new_parents[$j]);
1749 push @
$parents, grep { defined } @new_parents;
1752 sub make_log_entry
{
1753 my ($self, $rev, $parents, $ed) = @_;
1754 my $untracked = $self->get_untracked($ed);
1756 my @parents = @
$parents;
1757 my $ps = $ed->{path_strip
} || "";
1758 for my $path ( grep { m/$ps/ } %{$ed->{dir_prop
}} ) {
1759 my $props = $ed->{dir_prop
}{$path};
1760 if ( $props->{"svk:merge"} ) {
1761 $self->find_extra_svk_parents
1762 ($ed, $props->{"svk:merge"}, \
@parents);
1764 if ( $props->{"svn:mergeinfo"} ) {
1765 $self->find_extra_svn_parents
1767 $props->{"svn:mergeinfo"},
1772 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
1773 print $un "r$rev\n" or croak
$!;
1774 print $un $_, "\n" foreach @
$untracked;
1775 my %log_entry = ( parents
=> \
@parents, revision
=> $rev,
1779 my $logged = delete $self->{logged_rev_props
};
1780 if (!$logged || $self->{-want_revprops
}) {
1781 my $rp = $self->ra->rev_proplist($rev);
1782 foreach (sort keys %$rp) {
1784 if (/^svn:(author|date|log)$/) {
1785 $log_entry{$1} = $v;
1786 } elsif ($_ eq 'svm:headrev') {
1789 print $un " rev_prop: ", uri_encode
($_), ' ',
1790 uri_encode
($v), "\n";
1794 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
1796 close $un or croak
$!;
1798 $log_entry{date
} = parse_svn_date
($log_entry{date
});
1799 $log_entry{log} .= "\n";
1800 my $author = $log_entry{author
} = check_author
($log_entry{author
});
1801 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
1804 my ($commit_name, $commit_email) = ($name, $email);
1805 if ($_use_log_author) {
1807 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
1809 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
1812 if (!defined $name_field) {
1813 if (!defined $email) {
1816 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
1817 ($name, $email) = ($1, $2);
1818 } elsif ($name_field =~ /(.*)@/) {
1819 ($name, $email) = ($1, $name_field);
1821 ($name, $email) = ($name_field, $name_field);
1824 if (defined $headrev && $self->use_svm_props) {
1825 if ($self->rewrite_root) {
1826 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
1829 if ($self->rewrite_uuid) {
1830 die "Can't have both 'useSvmProps' and 'rewriteUUID' ",
1833 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$}i
;
1834 # we don't want "SVM: initializing mirror for junk" ...
1835 return undef if $r == 0;
1836 my $svm = $self->svm;
1837 if ($uuid ne $svm->{uuid
}) {
1838 die "UUID mismatch on SVM path:\n",
1839 "expected: $svm->{uuid}\n",
1842 my $full_url = $self->full_url;
1843 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
1844 die "Failed to replace '$svm->{replace}' with ",
1845 "'$svm->{source}' in $full_url\n";
1846 # throw away username for storing in records
1847 remove_username
($full_url);
1848 $log_entry{metadata
} = "$full_url\@$r $uuid";
1849 $log_entry{svm_revision
} = $r;
1850 $email ||= "$author\@$uuid";
1851 $commit_email ||= "$author\@$uuid";
1852 } elsif ($self->use_svnsync_props) {
1853 my $full_url = $self->svnsync->{url
};
1854 $full_url .= "/$self->{path}" if length $self->{path
};
1855 remove_username
($full_url);
1856 my $uuid = $self->svnsync->{uuid
};
1857 $log_entry{metadata
} = "$full_url\@$rev $uuid";
1858 $email ||= "$author\@$uuid";
1859 $commit_email ||= "$author\@$uuid";
1861 my $url = $self->metadata_url;
1862 remove_username
($url);
1863 my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
1864 $log_entry{metadata
} = "$url\@$rev " . $uuid;
1865 $email ||= "$author\@" . $uuid;
1866 $commit_email ||= "$author\@" . $uuid;
1868 $log_entry{name
} = $name;
1869 $log_entry{email
} = $email;
1870 $log_entry{commit_name
} = $commit_name;
1871 $log_entry{commit_email
} = $commit_email;
1876 my ($self, $min_rev, $max_rev, @parents) = @_;
1877 my ($last_rev, $last_commit) = $self->last_rev_commit;
1878 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
1879 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
1883 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
1884 $self->{inject_parents
} = { $rev => $tree };
1885 $self->fetch(undef, undef);
1889 my ($self, $tree) = (shift, shift);
1890 my $log_entry = ::get_commit_entry
($tree);
1891 unless ($self->{last_rev
}) {
1892 fatal
("Must have an existing revision to commit");
1894 my %ed_opts = ( r
=> $self->{last_rev
},
1895 log => $log_entry->{log},
1897 tree_a
=> $self->{last_commit
},
1900 $self->set_tree_cb($log_entry, $tree, @_) },
1901 svn_path
=> $self->{path
} );
1902 if (!Git
::SVN
::Editor
->new(\
%ed_opts)->apply_diff) {
1903 print "No changes\nr$self->{last_rev} = $tree\n";
1907 sub rebuild_from_rev_db
{
1908 my ($self, $path) = @_;
1910 open my $fh, '<', $path or croak
"open: $!";
1911 binmode $fh or croak
"binmode: $!";
1913 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
1916 next if $_ eq ('0' x
40);
1917 $self->rev_map_set($r, $_);
1920 close $fh or croak
"close: $!";
1921 unlink $path or croak
"unlink: $!";
1926 my $map_path = $self->map_path;
1927 my $partial = (-e
$map_path && ! -z
$map_path);
1928 return unless ::verify_ref
($self->refname.'^0');
1929 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
1930 my $rev_db = $self->rev_db_path;
1931 $self->rebuild_from_rev_db($rev_db);
1932 if ($self->use_svm_props) {
1933 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
1934 $self->rebuild_from_rev_db($svm_rev_db);
1936 $self->unlink_rev_db_symlink;
1939 print "Rebuilding $map_path ...\n" if (!$partial);
1940 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
1943 command_output_pipe
(qw
/rev-list --pretty=raw --reverse/,
1944 ($head ?
"$head.." : "") . $self->refname,
1946 my $metadata_url = $self->metadata_url;
1947 remove_username
($metadata_url);
1948 my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
1951 if ( m{^commit ($::sha1)$} ) {
1955 next unless s{^\s*(git-svn-id:)}{$1};
1956 my ($url, $rev, $uuid) = ::extract_metadata
($_);
1957 remove_username
($url);
1959 # ignore merges (from set-tree)
1960 next if (!defined $rev || !$uuid);
1962 # if we merged or otherwise started elsewhere, this is
1963 # how we break out of it
1964 if (($uuid ne $svn_uuid) ||
1965 ($metadata_url && $url && ($url ne $metadata_url))) {
1968 if ($partial && $head) {
1969 print "Partial-rebuilding $map_path ...\n";
1970 print "Currently at $base_rev = $head\n";
1974 $self->rev_map_set($rev, $c);
1975 print "r$rev = $c\n";
1977 command_close_pipe
($log, $ctx);
1978 print "Done rebuilding $map_path\n" if (!$partial || !$head);
1979 my $rev_db_path = $self->rev_db_path;
1980 if (-f
$self->rev_db_path) {
1981 unlink $self->rev_db_path or croak
"unlink: $!";
1983 $self->unlink_rev_db_symlink;
1987 # Tie::File seems to be prone to offset errors if revisions get sparse,
1988 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
1989 # one of my favorite modules is out :< Next up would be one of the DBM
1990 # modules, but I'm not sure which is most portable...
1992 # This is the replacement for the rev_db format, which was too big
1993 # and inefficient for large repositories with a lot of sparse history
1996 # The format is this:
1997 # - 24 bytes for every record,
1998 # * 4 bytes for the integer representing an SVN revision number
1999 # * 20 bytes representing the sha1 of a git commit
2000 # - No empty padding records like the old format
2001 # (except the last record, which can be overwritten)
2002 # - new records are written append-only since SVN revision numbers
2003 # increase monotonically
2004 # - lookups on SVN revision number are done via a binary search
2005 # - Piping the file to xxd -c24 is a good way of dumping it for
2006 # viewing or editing (piped back through xxd -r), should the need
2008 # - The last record can be padding revision with an all-zero sha1
2009 # This is used to optimize fetch performance when using multiple
2010 # "fetch" directives in .git/config
2012 # These files are disposable unless noMetadata or useSvmProps is set
2015 my ($fh, $rev, $commit) = @_;
2017 binmode $fh or croak
"binmode: $!";
2018 my $size = (stat($fh))[7];
2019 ($size % 24) == 0 or croak
"inconsistent size: $size";
2023 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2024 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
2025 $read == 24 or croak
"read only $read bytes (!= 24)";
2026 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
2027 if ($last_commit eq ('0' x40
)) {
2029 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2030 $read = sysread($fh, $buf, 24) or
2033 croak
"read only $read bytes (!= 24)";
2034 ($last_rev, $last_commit) =
2035 unpack(rev_map_fmt
, $buf);
2036 if ($last_commit eq ('0' x40
)) {
2037 croak
"inconsistent .rev_map\n";
2040 if ($last_rev >= $rev) {
2041 croak
"last_rev is higher!: $last_rev >= $rev";
2046 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
2047 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
2051 sub _rev_map_reset
{
2052 my ($fh, $rev, $commit) = @_;
2053 my $c = _rev_map_get
($fh, $rev);
2054 $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n";
2055 my $offset = sysseek($fh, 0, SEEK_CUR
) or croak
"seek: $!";
2056 truncate $fh, $offset or croak
"truncate: $!";
2062 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2063 mkpath
([$dir]) unless -d
$dir;
2064 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
2065 close $fh or die "Couldn't close (create) $path: $!\n";
2070 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
2071 defined $commit or die "missing arg3\n";
2072 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
2073 my $db = $self->map_path($uuid);
2074 my $db_lock = "$db.lock";
2078 $sigmask = POSIX
::SigSet
->new();
2079 my $signew = POSIX
::SigSet
->new(SIGINT
, SIGHUP
, SIGTERM
,
2080 SIGALRM
, SIGUSR1
, SIGUSR2
);
2081 sigprocmask
(SIG_BLOCK
, $signew, $sigmask) or
2082 croak
"Can't block signals: $!";
2086 $LOCKFILES{$db_lock} = 1;
2088 # both of these options make our .rev_db file very, very important
2089 # and we can't afford to lose it because rebuild() won't work
2090 if ($self->use_svm_props || $self->no_metadata) {
2092 copy
($db, $db_lock) or die "rev_map_set(@_): ",
2094 "$db => $db_lock ($!)\n";
2096 rename $db, $db_lock or die "rev_map_set(@_): ",
2097 "Failed to rename: ",
2098 "$db => $db_lock ($!)\n";
2101 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
2102 or croak
"Couldn't open $db_lock: $!\n";
2103 $update_ref eq 'reset' ? _rev_map_reset
($fh, $rev, $commit) :
2104 _rev_map_set
($fh, $rev, $commit);
2106 $fh->flush or die "Couldn't flush $db_lock: $!\n";
2107 $fh->sync or die "Couldn't sync $db_lock: $!\n";
2109 close $fh or croak
$!;
2113 $note = " ($update_ref)" if ($update_ref !~ /^\d*$/);
2114 command_noisy
('update-ref', '-m', "r$rev$note",
2115 $self->refname, $commit);
2117 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
2118 "$db_lock => $db ($!)\n";
2119 delete $LOCKFILES{$db_lock};
2121 sigprocmask
(SIG_SETMASK
, $sigmask) or
2122 croak
"Can't restore signal mask: $!";
2126 # If want_commit, this will return an array of (rev, commit) where
2127 # commit _must_ be a valid commit in the archive.
2128 # Otherwise, it'll return the max revision (whether or not the
2129 # commit is valid or just a 0x40 placeholder).
2131 my ($self, $want_commit) = @_;
2133 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
2134 $want_commit ?
($r, $c) : $r;
2137 sub rev_map_max_norebuild
{
2138 my ($self, $want_commit) = @_;
2139 my $map_path = $self->map_path;
2140 stat $map_path or return $want_commit ?
(0, undef) : 0;
2141 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2142 binmode $fh or croak
"binmode: $!";
2143 my $size = (stat($fh))[7];
2144 ($size % 24) == 0 or croak
"inconsistent size: $size";
2147 close $fh or croak
"close: $!";
2148 return $want_commit ?
(0, undef) : 0;
2151 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2152 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2153 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2154 if ($want_commit && $c eq ('0' x40
)) {
2156 return $want_commit ?
(0, undef) : 0;
2158 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2159 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
2160 ($r, $c) = unpack(rev_map_fmt
, $buf);
2161 if ($c eq ('0'x40
)) {
2162 croak
"Penultimate record is all-zeroes in $map_path";
2165 close $fh or croak
"close: $!";
2166 $want_commit ?
($r, $c) : $r;
2170 my ($self, $rev, $uuid) = @_;
2171 my $map_path = $self->map_path($uuid);
2172 return undef unless -e
$map_path;
2174 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2175 my $c = _rev_map_get
($fh, $rev);
2176 close($fh) or croak
"close: $!";
2181 my ($fh, $rev) = @_;
2183 binmode $fh or croak
"binmode: $!";
2184 my $size = (stat($fh))[7];
2185 ($size % 24) == 0 or croak
"inconsistent size: $size";
2191 my ($l, $u) = (0, $size - 24);
2195 my $i = int(($l/24 + $u/24) / 2) * 24;
2196 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
2197 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2198 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2202 } elsif ($r > $rev) {
2204 } else { # $r == $rev
2205 return $c eq ('0' x
40) ?
undef : $c;
2211 # Finds the first svn revision that exists on (if $eq_ok is true) or
2212 # before $rev for the current branch. It will not search any lower
2213 # than $min_rev. Returns the git commit hash and svn revision number
2214 # if found, else (undef, undef).
2215 sub find_rev_before
{
2216 my ($self, $rev, $eq_ok, $min_rev) = @_;
2217 --$rev unless $eq_ok;
2219 my $max_rev = $self->rev_map_max;
2220 $rev = $max_rev if ($rev > $max_rev);
2221 while ($rev >= $min_rev) {
2222 if (my $c = $self->rev_map_get($rev)) {
2227 return (undef, undef);
2230 # Finds the first svn revision that exists on (if $eq_ok is true) or
2231 # after $rev for the current branch. It will not search any higher
2232 # than $max_rev. Returns the git commit hash and svn revision number
2233 # if found, else (undef, undef).
2234 sub find_rev_after
{
2235 my ($self, $rev, $eq_ok, $max_rev) = @_;
2236 ++$rev unless $eq_ok;
2237 $max_rev ||= $self->rev_map_max;
2238 while ($rev <= $max_rev) {
2239 if (my $c = $self->rev_map_get($rev)) {
2244 return (undef, undef);
2248 my ($class, $repo_id, $ref_id, $path) = @_;
2249 unless (defined $repo_id && length $repo_id) {
2250 $repo_id = $default_repo_id;
2252 unless (defined $ref_id && length $ref_id) {
2253 # Access the prefix option from the git-svn main program if it's loaded.
2254 my $prefix = defined &::opt_prefix ?
::opt_prefix
() : "";
2256 "refs/remotes/$prefix$default_ref_id";
2259 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
2261 # Older repos imported by us used $GIT_DIR/svn/foo instead of
2262 # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
2263 if ($ref_id =~ m{^refs/remotes/(.*)}) {
2264 my $old_dir = "$ENV{GIT_DIR}/svn/$1";
2265 if (-d
$old_dir && ! -d
$dir) {
2270 $_[3] = $path = '' unless (defined $path);
2273 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
2274 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
2275 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
2278 # for read-only access of old .rev_db formats
2279 sub unlink_rev_db_symlink
{
2281 my $link = $self->rev_db_path;
2282 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
2284 unlink $link or croak
"unlink: $link failed!";
2289 my ($self, $uuid) = @_;
2290 my $db_path = $self->map_path($uuid);
2291 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
2292 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
2296 # the new replacement for .rev_db
2298 my ($self, $uuid) = @_;
2299 $uuid ||= $self->ra_uuid;
2300 "$self->{map_root}.$uuid";
2305 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
2311 $f =~ s
#%([0-9a-fA-F]{2})#chr(hex($1))#eg;
2315 sub remove_username
{
2316 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};