2 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
3 # License: GPL v2 or later
6 use vars qw
/ $AUTHOR $VERSION
7 $sha1 $sha1_short $_revision
9 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
10 $VERSION = '@@GIT_VERSION@@';
12 $ENV{GIT_DIR
} ||= '.git';
13 $Git::SVN
::default_repo_id
= 'git-svn';
14 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
16 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
18 $| = 1; # unbuffer STDOUT
20 sub fatal
(@
) { print STDERR
@_; exit 1 }
21 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
24 if ($SVN::Core
::VERSION
lt '1.1.0') {
25 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n";
27 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
28 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
29 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
32 use File
::Basename qw
/dirname basename/;
33 use File
::Path qw
/mkpath/;
34 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
40 foreach (qw
/command command_oneline command_noisy command_output_pipe
41 command_input_pipe command_close_pipe
/) {
42 $s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ".
43 "*Git::SVN::Migration::$_ = ".
44 "*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; ";
51 my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS
};
52 $sha1 = qr/[a-f\d]{40}/;
53 $sha1_short = qr/[a-f\d]{4,40}/;
54 my ($_stdin, $_help, $_edit,
58 $_merge, $_strategy, $_dry_run,
61 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
62 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
63 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
);
64 my %fc_opts = ( 'follow-parent|follow' => \
$Git::SVN
::_follow_parent
,
65 'authors-file|A=s' => \
$_authors,
66 'repack:i' => \
$Git::SVN
::_repack
,
67 'no-metadata' => \
$Git::SVN
::_no_metadata
,
69 'repack-flags|repack-args|repack-opts=s' =>
70 \
$Git::SVN
::_repack_flags
,
73 my ($_trunk, $_tags, $_branches);
74 my %multi_opts = ( 'trunk|T=s' => \
$_trunk,
75 'tags|t=s' => \
$_tags,
76 'branches|b=s' => \
$_branches );
77 my %init_opts = ( 'template=s' => \
$_template, 'shared' => \
$_shared );
78 my %cmt_opts = ( 'edit|e' => \
$_edit,
79 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
80 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
81 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
82 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
86 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
87 { 'revision|r=s' => \
$_revision, %fc_opts } ],
88 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
89 " (requires URL argument)",
91 dcommit
=> [ \
&cmd_dcommit
,
92 'Commit several diffs to merge with upstream',
93 { 'merge|m|M' => \
$_merge,
94 'strategy|s=s' => \
$_strategy,
95 'dry-run|n' => \
$_dry_run,
96 %cmt_opts, %fc_opts } ],
97 'set-tree' => [ \
&cmd_set_tree
,
98 "Set an SVN repository to a git tree-ish",
99 { 'stdin|' => \
$_stdin, %cmt_opts, %fc_opts, } ],
100 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
101 { 'revision|r=i' => \
$_revision } ],
102 'multi-init' => [ \
&cmd_multi_init
,
103 'Initialize multiple trees (like git-svnimport)',
104 { %multi_opts, %init_opts, %remote_opts,
105 'revision|r=i' => \
$_revision,
106 'prefix=s' => \
$_prefix,
108 'multi-fetch' => [ \
&cmd_multi_fetch
,
109 'Fetch multiple trees (like git-svnimport)',
111 'migrate' => [ sub { },
112 # no-op, we automatically run this anyways,
113 'Migrate configuration/metadata/layout from
114 previous versions of git-svn',
116 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
117 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
118 'revision|r=s' => \
$_revision,
119 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
120 'incremental' => \
$Git::SVN
::Log
::incremental
,
121 'oneline' => \
$Git::SVN
::Log
::oneline
,
122 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
123 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
124 'authors-file|A=s' => \
$_authors,
125 'color' => \
$Git::SVN
::Log
::color
,
126 'pager=s' => \
$Git::SVN
::Log
::pager
,
128 'commit-diff' => [ \
&cmd_commit_diff
,
129 'Commit a diff between two trees',
130 { 'message|m=s' => \
$_message,
131 'file|F=s' => \
$_file,
132 'revision|r=s' => \
$_revision,
137 for (my $i = 0; $i < @ARGV; $i++) {
138 if (defined $cmd{$ARGV[$i]}) {
145 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
147 read_repo_config
(\
%opts);
148 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help, 'version|V' => \
$_version,
149 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
150 'id|i=s' => \
$Git::SVN
::default_ref_id
,
151 'svn-remote|remote|R=s' => \
$Git::SVN
::default_repo_id
);
152 exit 1 if (!$rv && $cmd ne 'log');
155 version
() if $_version;
156 usage
(1) unless defined $cmd;
157 load_authors
() if $_authors;
158 unless ($cmd =~ /^(?:init|multi-init|commit-diff)$/) {
159 Git
::SVN
::Migration
::migration_check
();
161 Git
::SVN
::init_vars
();
163 Git
::SVN
::verify_remotes_sanity
();
164 $cmd{$cmd}->[0]->(@ARGV);
169 ####################### primary functions ######################
171 my $exit = shift || 0;
172 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
174 git
-svn
- bidirectional operations between a single Subversion tree
and git
175 Usage
: $0 <command
> [options
] [arguments
]\n
177 print $fd "Available commands:\n" unless $cmd;
179 foreach (sort keys %cmd) {
180 next if $cmd && $cmd ne $_;
181 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
182 foreach (keys %{$cmd{$_}->[2]}) {
183 # prints out arguments as they should be passed:
184 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
185 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
187 split /\|/,$_)," $x\n";
191 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
192 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
193 one git repository and want to keep them separate. See git-svn(1) for more
200 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
205 unless (-d $ENV{GIT_DIR}) {
206 my @init_db = ('init
');
207 push @init_db, "--template=$_template" if defined $_template;
208 push @init_db, "--shared" if defined $_shared;
209 command_noisy(@init_db);
214 my $url = shift or die "SVN repository location required " .
215 "as a command-line argument\n";
216 if (my $repo_path = shift) {
217 unless (-d $repo_path) {
218 mkpath([$repo_path]);
220 chdir $repo_path or croak $!;
221 $ENV{GIT_DIR} = $repo_path . "/.git";
225 Git::SVN->init($url);
230 die "Additional fetch arguments are no longer supported.\n",
231 "Use --follow-parent if you have moved/copied directories
234 my $gs = Git::SVN->new;
235 $gs->fetch(parse_revision_argument());
236 if ($gs->{last_commit} && !verify_ref('refs
/heads/master
^0')) {
237 command_noisy(qw(update-ref refs/heads/master),
244 if ($_stdin || !@commits) {
245 print "Reading from stdin...\n";
248 if (/\b($sha1_short)\b/o) {
249 unshift @commits, $1;
254 foreach my $c (@commits) {
255 my @tmp = command
('rev-parse',$c);
256 if (scalar @tmp == 1) {
258 } elsif (scalar @tmp > 1) {
259 push @revs, reverse(command
('rev-list',@tmp));
261 fatal
"Failed to rev-parse $c\n";
264 my $gs = Git
::SVN
->new;
265 my ($r_last, $cmt_last) = $gs->last_rev_commit;
267 if (defined $gs->{last_rev
} && $r_last != $gs->{last_rev
}) {
268 fatal
"There are new revisions that were fetched ",
269 "and need to be merged (or acknowledged) ",
270 "before committing.\nlast rev: $r_last\n",
271 " current: $gs->{last_rev}\n";
273 $gs->set_tree($_) foreach @revs;
274 print "Done committing ",scalar @revs," revisions to SVN\n";
279 my $gs = Git
::SVN
->new;
281 my @refs = command
(qw
/rev-list --no-merges/, $gs->refname."..$head");
283 foreach my $d (reverse @refs) {
284 if (!verify_ref
("$d~1")) {
286 "has no parent commit, and therefore ",
287 "nothing to diff against.\n",
288 "You should be working from a repository ",
289 "originally created by git-svn\n";
291 unless (defined $last_rev) {
292 (undef, $last_rev, undef) = cmt_metadata
("$d~1");
293 unless (defined $last_rev) {
294 fatal
"Unable to extract revision information ",
295 "from commit $d~1\n";
299 print "diff-tree $d~1 $d\n";
301 my %ed_opts = ( r
=> $last_rev,
302 log => get_commit_entry
($d)->{log},
307 print "Committed r$_[0]\n";
308 $last_rev = $_[0]; },
309 svn_path
=> $gs->{path
} );
310 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
311 print "No changes\n$d~1 == $d\n";
317 # we always want to rebase against the current HEAD, not any
318 # head that was passed to us
319 my @diff = command
('diff-tree', 'HEAD', $gs->refname, '--');
322 @finish = qw
/rebase/;
323 push @finish, qw
/--merge/ if $_merge;
324 push @finish, "--strategy=$_strategy" if $_strategy;
325 print STDERR
"W: HEAD and ", $gs->refname, " differ, ",
326 "using @finish:\n", "@diff";
328 print "No changes between current HEAD and ",
329 $gs->refname, "\nResetting to the latest ",
331 @finish = qw
/reset --mixed/;
333 command_noisy
(@finish, $gs->refname);
336 sub cmd_show_ignore
{
337 my $gs = Git
::SVN
->new;
338 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
339 $gs->traverse_ignore(\
*STDOUT
, '', $r);
344 unless (defined $_trunk || defined $_branches || defined $_tags) {
348 $_prefix = '' unless defined $_prefix;
349 $url =~ s
#/+$## if defined $url;
350 if (defined $_trunk) {
351 my $trunk_ref = $_prefix . 'trunk';
352 # try both old-style and new-style lookups:
353 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
355 my ($trunk_url, $trunk_path) =
356 complete_svn_url
($url, $_trunk);
357 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
361 return unless defined $_branches || defined $_tags;
362 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
363 complete_url_ls_init
($ra, $_branches, '--branches/-b', $_prefix);
364 complete_url_ls_init
($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
367 sub cmd_multi_fetch
{
368 my $remotes = Git
::SVN
::read_all_remotes
();
369 foreach my $repo_id (sort keys %$remotes) {
370 my $url = $remotes->{$repo_id}->{url
} or next;
371 my $fetch = $remotes->{$repo_id}->{fetch
} or next;
372 Git
::SVN
::fetch_all
($repo_id, $url, $fetch);
376 # this command is special because it requires no metadata
377 sub cmd_commit_diff
{
378 my ($ta, $tb, $url) = @_;
379 my $usage = "Usage: $0 commit-diff -r<revision> ".
380 "<tree-ish> <tree-ish> [<URL>]\n";
381 fatal
($usage) if (!defined $ta || !defined $tb);
384 my $gs = eval { Git
::SVN
->new };
386 fatal
("Needed URL or usable git-svn --id in ",
387 "the command-line\n", $usage);
390 $svn_path = $gs->{path
};
392 unless (defined $_revision) {
393 fatal
("-r|--revision is a required argument\n", $usage);
395 if (defined $_message && defined $_file) {
396 fatal
("Both --message/-m and --file/-F specified ",
397 "for the commit message.\n",
398 "I have no idea what you mean\n");
400 if (defined $_file) {
401 $_message = file_to_s
($_file);
403 $_message ||= get_commit_entry
($tb)->{log};
405 my $ra ||= Git
::SVN
::Ra
->new($url);
406 $svn_path ||= $ra->{svn_path
};
409 $r = $ra->get_latest_revnum;
410 } elsif ($r !~ /^\d+$/) {
411 die "revision argument: $r not understood by git-svn\n";
413 my %ed_opts = ( r
=> $r,
418 editor_cb
=> sub { print "Committed r$_[0]\n" },
419 svn_path
=> $svn_path );
420 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
421 print "No changes\n$ta == $tb\n";
425 ########################### utility functions #########################
427 sub parse_revision_argument
{
428 if (!defined $_revision || $_revision eq 'BASE:HEAD') {
429 return (undef, undef);
431 return ($1, $2) if ($_revision =~ /^(\d+):(\d+)$/);
432 return ($_revision, $_revision) if ($_revision =~ /^\d+$/);
433 return (undef, $1) if ($_revision =~ /^BASE:(\d+)$/);
434 return ($1, undef) if ($_revision =~ /^(\d+):HEAD$/);
435 die "revision argument: $_revision not understood by git-svn\n",
436 "Try using the command-line svn client instead\n";
439 sub complete_svn_url
{
440 my ($url, $path) = @_;
442 if ($path !~ m
#^[a-z\+]+://#) {
443 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
444 fatal
("E: '$path' is not a complete URL ",
445 "and a separate URL is not specified\n");
447 return ($url, $path);
452 sub complete_url_ls_init
{
453 my ($ra, $repo_path, $switch, $pfx) = @_;
454 unless ($repo_path) {
455 print STDERR
"W: $switch not specified\n";
458 $repo_path =~ s
#/+$##;
459 if ($repo_path =~ m
#^[a-z\+]+://#) {
460 $ra = Git
::SVN
::Ra
->new($repo_path);
463 $repo_path =~ s
#^/+##;
465 fatal
("E: '$repo_path' is not a complete URL ",
466 "and a separate URL is not specified\n");
469 my $r = defined $_revision ?
$_revision : $ra->get_latest_revnum;
470 my ($dirent, undef, undef) = $ra->get_dir($repo_path, $r);
471 my $url = $ra->{url
};
474 foreach my $d (sort keys %$dirent) {
475 next if ($dirent->{$d}->kind != $SVN::Node
::dir
);
476 my $path = "$repo_path/$d";
478 my $gs = eval { Git
::SVN
->new($ref) };
479 # don't try to init already existing refs
481 print "init $url/$path => $ref\n";
482 $gs = Git
::SVN
->init($url, $path, undef, $ref);
484 $remote_id ||= $gs->{repo_id
} if $gs;
486 if (defined $remote_id) {
487 $remote_path = "$ra->{svn_path}/$repo_path/*";
488 $remote_path =~ s
#/+#/#g;
489 $remote_path =~ s
#^/##g;
490 my ($n) = ($switch =~ /^--(\w+)/);
491 command_noisy
('config', "svn-remote.$remote_id.$n",
498 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
502 sub get_tree_from_treeish
{
504 # $treeish can be a symbolic ref, too:
505 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
507 while ($type eq 'tag') {
508 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
510 if ($type eq 'commit') {
511 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
513 ($expected) = ($expected =~ /^tree ($sha1)$/o);
514 die "Unable to get tree from $treeish\n" unless $expected;
515 } elsif ($type eq 'tree') {
516 $expected = $treeish;
518 die "$treeish is a $type, expected tree, tag or commit\n";
523 sub get_commit_entry
{
524 my ($treeish) = shift;
525 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
526 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
527 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
528 open my $log_fh, '>', $commit_editmsg or croak
$!;
530 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
531 if ($type eq 'commit' || $type eq 'tag') {
532 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
537 $in_msg = 1 if (/^\s*$/);
538 } elsif (/^git-svn-id: /) {
539 # skip this for now, we regenerate the
540 # correct one on re-fetch anyways
541 # TODO: set *:merge properties or like...
543 print $log_fh $_ or croak
$!;
546 command_close_pipe
($msg_fh, $ctx);
548 close $log_fh or croak
$!;
550 if ($_edit || ($type eq 'tree')) {
551 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
552 # TODO: strip out spaces, comments, like git-commit.sh
553 system($editor, $commit_editmsg);
555 rename $commit_editmsg, $commit_msg or croak
$!;
556 open $log_fh, '<', $commit_msg or croak
$!;
557 { local $/; chomp($log_entry{log} = <$log_fh>); }
558 close $log_fh or croak
$!;
564 my ($str, $file, $mode) = @_;
565 open my $fd,'>',$file or croak
$!;
566 print $fd $str,"\n" or croak
$!;
567 close $fd or croak
$!;
568 chmod ($mode &~ umask, $file) if (defined $mode);
573 open my $fd,'<',$file or croak
"$!: file: $file\n";
576 close $fd or croak
$!;
581 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
583 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
584 my $log = $cmd eq 'log';
587 next unless /^(\S+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
588 my ($user, $name, $email) = ($1, $2, $3);
590 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
592 $users{$user} = [$name, $email];
595 close $authors or croak
$!;
598 # convert GetOpt::Long specs for use by git-config
599 sub read_repo_config
{
600 return unless -d
$ENV{GIT_DIR
};
602 foreach my $o (keys %$opts) {
604 my ($key) = ($o =~ /^([a-z\-]+)/);
606 my $arg = 'git-config';
607 $arg .= ' --int' if ($o =~ /[:=]i$/);
608 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
609 if (ref $v eq 'ARRAY') {
610 chomp(my @tmp = `$arg --get-all svn.$key`);
613 chomp(my $tmp = `$arg --get svn.$key`);
614 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
621 sub extract_metadata
{
622 my $id = shift or return (undef, undef, undef);
623 my ($url, $rev, $uuid) = ($id =~ /^git
-svn
-id
:\s
(\S
+?
)\@
(\d
+)
625 if (!defined $rev || !$uuid || !$url) {
626 # some of the original repositories I made had
627 # identifiers like this:
628 ($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
630 return ($url, $rev, $uuid);
634 return extract_metadata
((grep(/^git-svn-id: /,
635 command
(qw
/cat-file commit/, shift)))[-1]);
641 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
642 $_repack $_repack_flags/;
644 use File
::Path qw
/mkpath/;
645 use File
::Copy qw
/copy/;
649 # properties that we do not log:
652 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
653 svn
:special svn
:executable
654 svn
:entry
:committed
-rev
655 svn
:entry
:last-author
657 svn
:entry
:committed
-date
/;
661 END { unlink keys %LOCKFILES if %LOCKFILES }
664 my ($repo_id, $url, $fetch) = @_;
666 my $ra = Git
::SVN
::Ra
->new($url);
667 my $head = $ra->get_latest_revnum;
669 foreach my $p (sort keys %$fetch) {
670 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
671 my $lr = $gs->rev_db_max;
673 $base = $lr if ($lr < $base);
677 return if (++$base > $head);
678 $ra->gs_fetch_loop_common($base, $head, @gs);
681 sub read_all_remotes
{
683 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
684 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) {
685 $r->{$1}->{fetch
}->{$2} = $3;
686 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
687 $r->{$1}->{url
} = $2;
694 if (defined $_repack) {
695 $_repack = 1000 if ($_repack <= 0);
696 $_repack_nr = $_repack;
697 $_repack_flags ||= '-d';
701 sub verify_remotes_sanity
{
702 return unless -d
$ENV{GIT_DIR
};
704 foreach (command
(qw
/config -l/)) {
705 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
707 die "Remote ref refs/remote/$1 is tracked by",
708 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
709 "Please resolve this ambiguity in ",
710 "your git configuration file before ",
718 # we allow more chars than remotes2config.sh...
719 sub sanitize_remote_name
{
721 $name =~ tr{A-Za-z0-9:,/+-}{.}c;
725 sub find_existing_remote
{
726 my ($url, $remotes) = @_;
728 foreach my $repo_id (keys %$remotes) {
729 my $u = $remotes->{$repo_id}->{url
} or next;
731 $existing = $repo_id;
737 sub init_remote_config
{
738 my ($self, $url, $no_write) = @_;
739 $url =~ s!/+$!!; # strip trailing slash
740 my $r = read_all_remotes
();
741 my $existing = find_existing_remote
($url, $r);
743 print STDERR
"Using existing ",
744 "[svn-remote \"$existing\"]\n";
745 $self->{repo_id
} = $existing;
747 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
748 $existing = find_existing_remote
($min_url, $r);
750 print STDERR
"Using existing ",
751 "[svn-remote \"$existing\"]\n";
752 $self->{repo_id
} = $existing;
754 if ($min_url ne $url) {
755 print STDERR
"Using higher level of URL: ",
756 "$url => $min_url\n";
757 my $old_path = $self->{path
};
758 $self->{path
} = $url;
759 $self->{path
} =~ s!^\Q$min_url\E/*!!;
760 if (length $old_path) {
761 $self->{path
} .= "/$old_path";
768 # verify that we aren't overwriting anything:
770 command_oneline
('config', '--get',
771 "svn-remote.$self->{repo_id}.url")
773 if ($orig_url && ($orig_url ne $url)) {
774 die "svn-remote.$self->{repo_id}.url already set: ",
775 "$orig_url\nwanted to set to: $url\n";
778 my ($xrepo_id, $xpath) = find_ref
($self->refname);
779 if (defined $xpath) {
780 die "svn-remote.$xrepo_id.fetch already set to track ",
781 "$xpath:refs/remotes/", $self->refname, "\n";
784 command_noisy
('config',
785 "svn-remote.$self->{repo_id}.url", $url);
786 command_noisy
('config', '--add',
787 "svn-remote.$self->{repo_id}.fetch",
788 "$self->{path}:".$self->refname);
794 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
795 my $self = _new
($class, $repo_id, $ref_id, $path);
797 $self->init_remote_config($url, $no_write);
804 foreach (command
(qw
/config -l/)) {
805 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
806 \s
*(.*)\s
*:\s
*refs
/remotes/(.+)\s
*$!x
;
807 my ($repo_id, $path, $ref) = ($1, $2, $3);
808 if ($ref eq $ref_id) {
809 $path = '' if ($path =~ m
#^\./?#);
810 return ($repo_id, $path);
813 (undef, undef, undef);
817 my ($class, $ref_id, $repo_id, $path) = @_;
818 if (defined $ref_id && !defined $repo_id && !defined $path) {
819 ($repo_id, $path) = find_ref
($ref_id);
820 if (!defined $repo_id) {
821 die "Could not find a \"svn-remote.*.fetch\" key ",
822 "in the repository configuration matching: ",
823 "refs/remotes/$ref_id\n";
826 my $self = _new
($class, $repo_id, $ref_id, $path);
827 if (!defined $self->{path
} || !length $self->{path
}) {
828 my $fetch = command_oneline
('config', '--get',
829 "svn-remote.$repo_id.fetch",
830 ":refs/remotes/$ref_id\$") or
831 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
832 "\":refs/remotes/$ref_id\$\" in config\n";
833 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
835 $self->{url
} = command_oneline
('config', '--get',
836 "svn-remote.$repo_id.url") or
837 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
838 if (-z
$self->{db_path
} && ::verify_ref
($self->refname.'^0')) {
844 sub refname
{ "refs/remotes/$_[0]->{ref_id}" }
848 Git
::SVN
::Ra
->new($self->{url
});
853 my $repos_root = $self->ra->{repos_root
};
854 return $self->{path
} if ($self->{url
} eq $repos_root);
855 my $url = $self->{url
} .
856 (length $self->{path
} ?
"/$self->{path}" : $self->{path
});
857 $url =~ s!^\Q$repos_root\E/*!!g;
861 sub traverse_ignore
{
862 my ($self, $fh, $path, $r) = @_;
865 my ($dirent, undef, $props) = $ra->get_dir($path, $r);
867 $p =~ s
#^\Q$ra->{svn_path}\E/##;
868 print $fh length $p ?
"\n# $p\n" : "\n# /\n";
869 if (my $s = $props->{'svn:ignore'}) {
870 $s =~ s/[\r\n]+/\n/g;
872 if (length $p == 0) {
877 print $fh "/$p/$s\n";
880 foreach (sort keys %$dirent) {
881 next if $dirent->{$_}->kind != $SVN::Node
::dir
;
882 $self->traverse_ignore($fh, "$path/$_", $r);
886 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
887 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
889 # returns the newest SVN revision number and newest commit SHA1
890 sub last_rev_commit
{
892 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
893 return ($self->{last_rev
}, $self->{last_commit
});
895 my $c = ::verify_ref
($self->refname.'^0');
897 my $rev = (::cmt_metadata
($c))[1];
899 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
903 my $offset = -41; # from tail
905 open my $fh, '<', $self->{db_path
} or
906 croak
"$self->{db_path} not readable: $!\n";
907 sysseek($fh, $offset, 2); # don't care for errors
908 sysread($fh, $rl, 41) == 41 or return (undef, undef);
910 while (('0' x40
) eq $rl && sysseek($fh, 0, 1) != 0) {
912 sysseek($fh, $offset, 2); # don't care for errors
913 sysread($fh, $rl, 41) == 41 or return (undef, undef);
917 die "$self->{db_path} and ", $self->refname,
918 " inconsistent!:\n$c != $rl\n";
920 my $rev = sysseek($fh, 0, 1) or croak
$!;
921 $rev = ($rev - 41) / 41;
922 close $fh or croak
$!;
923 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
927 sub get_fetch_range
{
928 my ($self, $min, $max) = @_;
929 $max ||= $self->ra->get_latest_revnum;
930 $min ||= $self->rev_db_max;
935 my ($self, $sub) = @_;
936 my $old_index = $ENV{GIT_INDEX_FILE
};
937 $ENV{GIT_INDEX_FILE
} = $self->{index};
940 $ENV{GIT_INDEX_FILE
} = $old_index;
942 delete $ENV{GIT_INDEX_FILE
};
944 wantarray ?
@ret : $ret[0];
947 sub assert_index_clean
{
948 my ($self, $treeish) = @_;
950 $self->tmp_index_do(sub {
951 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
952 my $x = command_oneline
('write-tree');
953 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
954 /^tree ($::sha1)/mo);
956 unlink $self->{index} or croak
$!;
957 command_noisy
('read-tree', $treeish);
959 $x = command_oneline
('write-tree');
961 ::fatal
"trees ($treeish) $y != $x\n",
962 "Something is seriously wrong...\n";
967 sub get_commit_parents
{
968 my ($self, $log_entry) = @_;
969 my (%seen, @ret, @tmp);
970 # legacy support for 'set-tree'; this is only used by set_tree_cb:
971 if (my $ip = $self->{inject_parents
}) {
972 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
976 if (my $cur = ::verify_ref
($self->refname.'^0')) {
979 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
980 while (my $p = shift @tmp) {
984 # MAXPARENT is defined to 16 in commit-tree.c:
988 die "r$log_entry->{revision}: No room for parents:\n\t",
989 join("\n\t", @tmp), "\n";
996 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
1000 my ($self, $log_entry) = @_;
1001 my $lr = $self->last_rev;
1002 if (defined $lr && $lr >= $log_entry->{revision
}) {
1003 die "Last fetched revision of ", $self->refname,
1004 " was r$lr, but we are about to fetch: ",
1005 "r$log_entry->{revision}!\n";
1007 if (my $c = $self->rev_db_get($log_entry->{revision
})) {
1008 croak
"$log_entry->{revision} = $c already exists! ",
1009 "Why are we refetching it?\n";
1011 my $author = $log_entry->{author
};
1012 my ($name, $email) = (defined $::users
{$author} ? @
{$::users
{$author}}
1013 : ($author, "$author\@".$self->ra->uuid));
1014 $ENV{GIT_AUTHOR_NAME
} = $ENV{GIT_COMMITTER_NAME
} = $name;
1015 $ENV{GIT_AUTHOR_EMAIL
} = $ENV{GIT_COMMITTER_EMAIL
} = $email;
1016 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
1018 my $tree = $log_entry->{tree
};
1019 if (!defined $tree) {
1020 $tree = $self->tmp_index_do(sub {
1021 command_oneline
('write-tree') });
1023 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
1025 my @exec = ('git-commit-tree', $tree);
1026 foreach ($self->get_commit_parents($log_entry)) {
1027 push @exec, '-p', $_;
1029 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1031 print $msg_fh $log_entry->{log} or croak
$!;
1032 unless ($_no_metadata) {
1033 print $msg_fh "\ngit-svn-id: ", $self->full_url, '@',
1034 $log_entry->{revision
}, ' ',
1035 $self->ra->uuid, "\n" or croak
$!;
1037 $msg_fh->flush == 0 or croak
$!;
1038 close $msg_fh or croak
$!;
1039 chomp(my $commit = do { local $/; <$out_fh> });
1040 close $out_fh or croak
$!;
1043 if ($commit !~ /^$::sha1$/o) {
1044 die "Failed to commit, invalid sha1: $commit\n";
1047 $self->rev_db_set($log_entry->{revision
}, $commit, 1);
1049 $self->{last_rev
} = $log_entry->{revision
};
1050 $self->{last_commit
} = $commit;
1051 print "r$log_entry->{revision} = $commit ($self->{ref_id})\n";
1052 if (defined $_repack && (--$_repack_nr == 0)) {
1053 $_repack_nr = $_repack;
1054 # repack doesn't use any arguments with spaces in them, does it?
1055 print "Running git repack $_repack_flags ...\n";
1056 command_noisy
('repack', split(/\s+/, $_repack_flags));
1057 print "Done repacking\n";
1063 my ($self, $r0, $r1) = @_;
1064 return 1 if $r0 == $r1;
1066 $self->ra->get_log([$self->{path
}], $r0, $r1,
1067 0, 0, 1, sub { $nr++ });
1068 return 0 if ($nr > 1);
1072 sub find_parent_branch
{
1073 my ($self, $paths, $rev) = @_;
1074 return undef unless $_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, sub {
1080 Git
::SVN
::Ra
::dup_changed_paths
($_[0]) });
1081 $SVN::Error
::handler
= $err_handler;
1083 return undef unless defined $paths;
1085 # look for a parent from another branch:
1086 my @b_path_components = split m
#/#, $self->rel_path;
1087 my @a_path_components;
1089 while (@b_path_components) {
1090 $i = $paths->{'/'.join('/', @b_path_components)};
1092 unshift(@a_path_components, pop(@b_path_components));
1094 goto not_found
unless defined $i;
1095 my $branch_from = $i->{copyfrom_path
} or goto not_found
;
1096 if (@a_path_components) {
1097 print STDERR
"branch_from: $branch_from => ";
1098 $branch_from .= '/'.join('/', @a_path_components);
1099 print STDERR
$branch_from, "\n";
1101 my $r = $i->{copyfrom_rev
};
1102 my $repos_root = $self->ra->{repos_root
};
1103 my $url = $self->ra->{url
};
1104 my $new_url = $repos_root . $branch_from;
1105 print STDERR
"Found possible branch point: ",
1106 "$new_url => ", $self->full_url, ", $r\n";
1107 $branch_from =~ s
#^/##;
1108 my $remotes = read_all_remotes
();
1110 foreach my $repo_id (keys %$remotes) {
1111 my $u = $remotes->{$repo_id}->{url
} or next;
1113 my $fetch = $remotes->{$repo_id}->{fetch
};
1114 foreach my $f (keys %$fetch) {
1115 next if $f ne $branch_from;
1116 $gs = Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
1122 my $ref_id = $self->{ref_id
};
1123 $ref_id =~ s/\@\d+$//;
1125 # just grow a tail if we're not unique enough :x
1126 $ref_id .= '-' while find_ref
($ref_id);
1127 print STDERR
"Initializing parent: $ref_id\n";
1128 $gs = Git
::SVN
->init($new_url, '', $ref_id, $ref_id, 1);
1130 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1131 if ($_follow_parent && (!defined $r0 || !defined $parent)) {
1133 ($r0, $parent) = $gs->last_rev_commit;
1135 if (defined $r0 && defined $parent && $gs->revisions_eq($r0, $r)) {
1136 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n";
1137 $self->assert_index_clean($parent);
1139 if ($self->ra->can_do_switch) {
1140 print STDERR
"Following parent with do_switch\n";
1141 # do_switch works with svn/trunk >= r22312, but that
1142 # is not included with SVN 1.4.3 (the latest version
1143 # at the moment), so we can't rely on it
1144 $self->{last_commit
} = $parent;
1145 $ed = SVN
::Git
::Fetcher
->new($self);
1146 $gs->ra->gs_do_switch($r0, $rev, $gs,
1147 $self->full_url, $ed)
1148 or die "SVN connection failed somewhere...\n";
1150 print STDERR
"Following parent with do_update\n";
1151 $ed = SVN
::Git
::Fetcher
->new($self);
1152 $self->ra->gs_do_update($rev, $rev, $self, $ed)
1153 or die "SVN connection failed somewhere...\n";
1155 print STDERR
"Successfully followed parent\n";
1156 return $self->make_log_entry($rev, [$parent], $ed);
1159 print STDERR
"Branch parent for path: '/",
1160 $self->rel_path, "' @ r$rev not found:\n";
1161 return undef unless $paths;
1162 print STDERR
"Changed paths:\n";
1163 foreach my $x (sort keys %$paths) {
1164 my $p = $paths->{$x};
1165 print STDERR
"\t$p->{action}\t$x";
1166 if ($p->{copyfrom_path
}) {
1167 print STDERR
"(from $p->{copyfrom_path}: ",
1168 "$p->{copyfrom_rev})";
1172 print STDERR
'-'x72
, "\n";
1177 my ($self, $paths, $rev) = @_;
1179 my ($last_rev, @parents);
1180 if ($self->{last_commit
}) {
1181 $ed = SVN
::Git
::Fetcher
->new($self);
1182 $last_rev = $self->{last_rev
};
1183 $ed->{c
} = $self->{last_commit
};
1184 @parents = ($self->{last_commit
});
1187 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1190 $ed = SVN
::Git
::Fetcher
->new($self);
1192 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1193 die "SVN connection failed somewhere...\n";
1195 $self->make_log_entry($rev, \
@parents, $ed);
1199 my ($self, $ed) = @_;
1201 my $h = $ed->{empty
};
1202 foreach (sort keys %$h) {
1203 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
1204 push @out, " $act: " . uri_encode
($_);
1205 warn "W: $act: $_\n";
1207 foreach my $t (qw
/dir_prop file_prop/) {
1208 $h = $ed->{$t} or next;
1209 foreach my $path (sort keys %$h) {
1210 my $ppath = $path eq '' ?
'.' : $path;
1211 foreach my $prop (sort keys %{$h->{$path}}) {
1212 next if $SKIP_PROP{$prop};
1213 my $v = $h->{$path}->{$prop};
1214 my $t_ppath_prop = "$t: " .
1215 uri_encode
($ppath) . ' ' .
1218 push @out, " +$t_ppath_prop " .
1221 push @out, " -$t_ppath_prop";
1226 foreach my $t (qw
/absent_file absent_directory/) {
1227 $h = $ed->{$t} or next;
1228 foreach my $parent (sort keys %$h) {
1229 foreach my $path (sort @
{$h->{$parent}}) {
1230 push @out, " $t: " .
1231 uri_encode
("$parent/$path");
1232 warn "W: $t: $parent/$path ",
1233 "Insufficient permissions?\n";
1240 sub parse_svn_date
{
1241 my $date = shift || return '+0000 1970-01-01 00:00:00';
1242 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
1243 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
) or
1244 croak
"Unable to parse date: $date\n";
1245 "+0000 $Y-$m-$d $H:$M:$S";
1250 if (!defined $author || length $author == 0) {
1251 $author = '(no author)';
1253 if (defined $::_authors
&& ! defined $::users
{$author}) {
1254 die "Author: $author not defined in $::_authors file\n";
1259 sub make_log_entry
{
1260 my ($self, $rev, $parents, $ed) = @_;
1261 my $untracked = $self->get_untracked($ed);
1263 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
1264 print $un "r$rev\n" or croak
$!;
1265 print $un $_, "\n" foreach @
$untracked;
1266 my %log_entry = ( parents
=> $parents || [], revision
=> $rev,
1268 my $rp = $self->ra->rev_proplist($rev);
1269 foreach (sort keys %$rp) {
1271 if (/^svn:(author|date|log)$/) {
1272 $log_entry{$1} = $v;
1274 print $un " rev_prop: ", uri_encode
($_), ' ',
1275 uri_encode
($v), "\n";
1278 close $un or croak
$!;
1280 $log_entry{date
} = parse_svn_date
($log_entry{date
});
1281 $log_entry{author
} = check_author
($log_entry{author
});
1282 $log_entry{log} .= "\n";
1287 my ($self, $min_rev, $max_rev, @parents) = @_;
1288 my ($last_rev, $last_commit) = $self->last_rev_commit;
1289 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
1290 return if ($base > $head);
1291 $self->ra->gs_fetch_loop_common($base, $head, $self);
1295 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
1296 # TODO: enable and test optimized commits:
1297 if (0 && $rev == ($self->{last_rev
} + 1)) {
1298 $log_entry->{revision
} = $rev;
1299 $log_entry->{author
} = $author;
1300 $self->do_git_commit($log_entry, "$rev=$tree");
1302 $self->{inject_parents
} = { $rev => $tree };
1303 $self->fetch(undef, undef);
1308 my ($self, $tree) = (shift, shift);
1309 my $log_entry = ::get_commit_entry
($tree);
1310 unless ($self->{last_rev
}) {
1311 fatal
("Must have an existing revision to commit\n");
1313 my %ed_opts = ( r
=> $self->{last_rev
},
1314 log => $log_entry->{log},
1316 tree_a
=> $self->{last_commit
},
1319 $self->set_tree_cb($log_entry, $tree, @_) },
1320 svn_path
=> $self->{path
} );
1321 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1322 print "No changes\nr$self->{last_rev} = $tree\n";
1328 print "Rebuilding $self->{db_path} ...\n";
1329 my ($rev_list, $ctx) = command_output_pipe
("rev-list", $self->refname);
1331 my $full_url = $self->full_url;
1333 while (<$rev_list>) {
1336 die "Non-SHA1: $c\n" unless $c =~ /^$::sha1$/o;
1337 my ($url, $rev, $uuid) = ::cmt_metadata
($c);
1339 # ignore merges (from set-tree)
1340 next if (!defined $rev || !$uuid);
1342 # if we merged or otherwise started elsewhere, this is
1343 # how we break out of it
1344 if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
1345 ($full_url && $url && ($url ne $full_url))) {
1349 $svn_uuid ||= $uuid;
1351 $self->rev_db_set($rev, $c);
1352 print "r$rev = $c\n";
1354 command_close_pipe
($rev_list, $ctx);
1355 print "Done rebuilding $self->{db_path}\n";
1359 # Tie::File seems to be prone to offset errors if revisions get sparse,
1360 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
1361 # one of my favorite modules is out :< Next up would be one of the DBM
1362 # modules, but I'm not sure which is most portable... So I'll just
1363 # go with something that's plain-text, but still capable of
1364 # being randomly accessed. So here's my ultra-simple fixed-width
1365 # database. All records are 40 characters + "\n", so it's easy to seek
1366 # to a revision: (41 * rev) is the byte offset.
1367 # A record of 40 0s denotes an empty revision.
1368 # And yes, it's still pretty fast (faster than Tie::File).
1369 # These files are disposable unless --no-metadata is set
1372 my ($self, $rev, $commit, $update_ref) = @_;
1373 length $commit == 40 or croak
"arg3 must be a full SHA1 hexsum\n";
1374 my ($db, $db_lock) = ($self->{db_path
}, "$self->{db_path}.lock");
1377 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
1378 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
1380 $LOCKFILES{$db_lock} = 1;
1381 if ($_no_metadata) {
1382 copy
($db, $db_lock) or die "rev_db_set(@_): ",
1384 "$db => $db_lock ($!)\n";
1386 rename $db, $db_lock or die "rev_db_set(@_): ",
1387 "Failed to rename: ",
1388 "$db => $db_lock ($!)\n";
1390 open my $fh, '+<', $db_lock or croak
$!;
1391 my $offset = $rev * 41;
1392 # assume that append is the common case:
1393 seek $fh, 0, 2 or croak
$!;
1395 if ($pos < $offset) {
1396 for (1 .. (($offset - $pos) / 41)) {
1397 print $fh (('0' x
40),"\n") or croak
$!;
1400 seek $fh, $offset, 0 or croak
$!;
1401 print $fh $commit,"\n" or croak
$!;
1402 close $fh or croak
$!;
1404 command_noisy
('update-ref', '-m', "r$rev",
1405 $self->refname, $commit);
1407 rename $db_lock, $db or die "rev_db_set(@_): ", "Failed to rename: ",
1408 "$db_lock => $db ($!)\n";
1409 delete $LOCKFILES{$db_lock};
1411 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
1412 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
1413 kill $sig, $$ if defined $sig;
1419 my @stat = stat $self->{db_path
} or
1420 die "Couldn't stat $self->{db_path}: $!\n";
1421 ($stat[7] % 41) == 0 or
1422 die "$self->{db_path} inconsistent size:$stat[7]\n";
1423 my $max = $stat[7] / 41;
1424 (($max > 0) ?
$max - 1 : 0);
1428 my ($self, $rev) = @_;
1430 my $offset = $rev * 41;
1431 open my $fh, '<', $self->{db_path
} or croak
$!;
1432 if (sysseek($fh, $offset, 0) == $offset) {
1433 my $read = sysread($fh, $ret, 40);
1434 $ret = undef if ($read != 40 || $ret eq ('0'x40
));
1436 close $fh or croak
$!;
1440 sub find_rev_before
{
1441 my ($self, $rev, $eq_ok) = @_;
1442 --$rev unless $eq_ok;
1444 if (my $c = $self->rev_db_get($rev)) {
1449 return (undef, undef);
1453 my ($class, $repo_id, $ref_id, $path) = @_;
1454 unless (defined $repo_id && length $repo_id) {
1455 $repo_id = $Git::SVN
::default_repo_id
;
1457 unless (defined $ref_id && length $ref_id) {
1458 $_[2] = $ref_id = $Git::SVN
::default_ref_id
;
1460 $_[1] = $repo_id = sanitize_remote_name
($repo_id);
1461 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
1462 $_[3] = $path = '' unless (defined $path);
1464 unless (-f
"$dir/.rev_db") {
1465 open my $fh, '>>', "$dir/.rev_db" or croak
$!;
1466 close $fh or croak
$!;
1468 bless { ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
1470 db_path
=> "$dir/.rev_db", repo_id
=> $repo_id }, $class;
1475 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
1479 package Git
::SVN
::Prompt
;
1483 use vars qw
/$_no_auth_cache $_username/;
1486 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
1487 $may_save = undef if $_no_auth_cache;
1488 $default_username = $_username if defined $_username;
1489 if (defined $default_username && length $default_username) {
1490 if (defined $realm && length $realm) {
1491 print STDERR
"Authentication realm: $realm\n";
1494 $cred->username($default_username);
1496 username
($cred, $realm, $may_save, $pool);
1498 $cred->password(_read_password
("Password for '" .
1499 $cred->username . "': ", $realm));
1500 $cred->may_save($may_save);
1501 $SVN::_Core
::SVN_NO_ERROR
;
1504 sub ssl_server_trust
{
1505 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
1506 $may_save = undef if $_no_auth_cache;
1507 print STDERR
"Error validating server certificate for '$realm':\n";
1508 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
1509 print STDERR
" - The certificate is not issued by a trusted ",
1510 "authority. Use the\n",
1511 " fingerprint to validate the certificate manually!\n";
1513 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
1514 print STDERR
" - The certificate hostname does not match.\n";
1516 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
1517 print STDERR
" - The certificate is not yet valid.\n";
1519 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
1520 print STDERR
" - The certificate has expired.\n";
1522 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
1523 print STDERR
" - The certificate has an unknown error.\n";
1526 "Certificate information:\n".
1527 " - Hostname: %s\n".
1528 " - Valid: from %s until %s\n".
1530 " - Fingerprint: %s\n",
1531 map $cert_info->$_, qw(hostname valid_from valid_until
1532 issuer_dname fingerprint);
1535 print STDERR
$may_save ?
1536 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
1537 "(R)eject or accept (t)emporarily? ";
1539 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
1540 if ($choice =~ /^t$/i) {
1541 $cred->may_save(undef);
1542 } elsif ($choice =~ /^r$/i) {
1544 } elsif ($may_save && $choice =~ /^p$/i) {
1545 $cred->may_save($may_save);
1549 $cred->accepted_failures($failures);
1550 $SVN::_Core
::SVN_NO_ERROR
;
1553 sub ssl_client_cert
{
1554 my ($cred, $realm, $may_save, $pool) = @_;
1555 $may_save = undef if $_no_auth_cache;
1556 print STDERR
"Client certificate filename: ";
1558 chomp(my $filename = <STDIN
>);
1559 $cred->cert_file($filename);
1560 $cred->may_save($may_save);
1561 $SVN::_Core
::SVN_NO_ERROR
;
1564 sub ssl_client_cert_pw
{
1565 my ($cred, $realm, $may_save, $pool) = @_;
1566 $may_save = undef if $_no_auth_cache;
1567 $cred->password(_read_password
("Password: ", $realm));
1568 $cred->may_save($may_save);
1569 $SVN::_Core
::SVN_NO_ERROR
;
1573 my ($cred, $realm, $may_save, $pool) = @_;
1574 $may_save = undef if $_no_auth_cache;
1575 if (defined $realm && length $realm) {
1576 print STDERR
"Authentication realm: $realm\n";
1579 if (defined $_username) {
1580 $username = $_username;
1582 print STDERR
"Username: ";
1584 chomp($username = <STDIN
>);
1586 $cred->username($username);
1587 $cred->may_save($may_save);
1588 $SVN::_Core
::SVN_NO_ERROR
;
1591 sub _read_password
{
1592 my ($prompt, $realm) = @_;
1593 print STDERR
$prompt;
1595 require Term
::ReadKey
;
1596 Term
::ReadKey
::ReadMode
('noecho');
1598 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
1599 last if $key =~ /[\012\015]/; # \n\r
1602 Term
::ReadKey
::ReadMode
('restore');
1611 my $kill_stupid_warnings = $SVN::Node
::none
.$SVN::Node
::file
.
1612 $SVN::Node
::dir
.$SVN::Node
::unknown
.
1613 $SVN::Node
::none
.$SVN::Node
::file
.
1614 $SVN::Node
::dir
.$SVN::Node
::unknown
.
1615 $SVN::Auth
::SSL
::CNMISMATCH
.
1616 $SVN::Auth
::SSL
::NOTYETVALID
.
1617 $SVN::Auth
::SSL
::EXPIRED
.
1618 $SVN::Auth
::SSL
::UNKNOWNCA
.
1619 $SVN::Auth
::SSL
::OTHER
;
1622 package SVN
::Git
::Fetcher
;
1630 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
1632 my ($class, $git_svn) = @_;
1633 my $self = SVN
::Delta
::Editor
->new;
1634 bless $self, $class;
1635 $self->{c
} = $git_svn->{last_commit
} if exists $git_svn->{last_commit
};
1636 $self->{empty
} = {};
1637 $self->{dir_prop
} = {};
1638 $self->{file_prop
} = {};
1639 $self->{absent_dir
} = {};
1640 $self->{absent_file
} = {};
1641 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
1645 sub set_path_strip
{
1646 my ($self, $path) = @_;
1647 $self->{path_strip
} = qr/^\Q$path\E\/?
/;
1654 sub open_directory
{
1655 my ($self, $path, $pb, $rev) = @_;
1660 my ($self, $path) = @_;
1661 if ($self->{path_strip
}) {
1662 $path =~ s!$self->{path_strip}!! or
1663 die "Failed to strip path '$path' ($self->{path_strip})\n";
1669 my ($self, $path, $rev, $pb) = @_;
1671 my $gpath = $self->git_path($path);
1672 return undef if ($gpath eq '');
1674 # remove entire directories.
1675 if (command
('ls-tree', $self->{c
}, '--', $gpath) =~ /^040000 tree/) {
1676 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
1678 $self->{c
}, '--', $gpath);
1682 $self->{gii
}->remove($_);
1683 print "\tD\t$_\n" unless $self->{q
};
1685 print "\tD\t$gpath/\n" unless $self->{q
};
1686 command_close_pipe
($ls, $ctx);
1687 $self->{empty
}->{$path} = 0
1689 $self->{gii
}->remove($gpath);
1690 print "\tD\t$gpath\n" unless $self->{q
};
1696 my ($self, $path, $pb, $rev) = @_;
1697 my $gpath = $self->git_path($path);
1698 my ($mode, $blob) = (command
('ls-tree', $self->{c
}, '--', $gpath)
1699 =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
1700 unless (defined $mode && defined $blob) {
1701 die "$path was not found in commit $self->{c} (r$rev)\n";
1703 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
1704 pool
=> SVN
::Pool
->new, action
=> 'M' };
1708 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
1709 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
1710 delete $self->{empty
}->{$dir};
1711 { path
=> $path, mode_a
=> 100644, mode_b
=> 100644,
1712 pool
=> SVN
::Pool
->new, action
=> 'A' };
1716 my ($self, $path, $cp_path, $cp_rev) = @_;
1717 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
1718 delete $self->{empty
}->{$dir};
1719 $self->{empty
}->{$path} = 1;
1723 sub change_dir_prop
{
1724 my ($self, $db, $prop, $value) = @_;
1725 $self->{dir_prop
}->{$db->{path
}} ||= {};
1726 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
1730 sub absent_directory
{
1731 my ($self, $path, $pb) = @_;
1732 $self->{absent_dir
}->{$pb->{path
}} ||= [];
1733 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
1738 my ($self, $path, $pb) = @_;
1739 $self->{absent_file
}->{$pb->{path
}} ||= [];
1740 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
1744 sub change_file_prop
{
1745 my ($self, $fb, $prop, $value) = @_;
1746 if ($prop eq 'svn:executable') {
1747 if ($fb->{mode_b
} != 120000) {
1748 $fb->{mode_b
} = defined $value ?
100755 : 100644;
1750 } elsif ($prop eq 'svn:special') {
1751 $fb->{mode_b
} = defined $value ?
120000 : 100644;
1753 $self->{file_prop
}->{$fb->{path
}} ||= {};
1754 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
1759 sub apply_textdelta
{
1760 my ($self, $fb, $exp) = @_;
1761 my $fh = IO
::File
->new_tmpfile;
1763 # $fh gets auto-closed() by SVN::TxDelta::apply(),
1764 # (but $base does not,) so dup() it for reading in close_file
1765 open my $dup, '<&', $fh or croak
$!;
1766 my $base = IO
::File
->new_tmpfile;
1767 $base->autoflush(1);
1769 defined (my $pid = fork) or croak
$!;
1771 open STDOUT
, '>&', $base or croak
$!;
1772 print STDOUT
'link ' if ($fb->{mode_a
} == 120000);
1773 exec qw
/git-cat-file blob/, $fb->{blob
} or croak
$!;
1779 seek $base, 0, 0 or croak
$!;
1780 my $md5 = Digest
::MD5
->new;
1781 $md5->addfile($base);
1782 my $got = $md5->hexdigest;
1783 die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
1785 " got: $got\n" if ($got ne $exp);
1788 seek $base, 0, 0 or croak
$!;
1790 $fb->{base
} = $base;
1791 [ SVN
::TxDelta
::apply
($base, $fh, undef, $fb->{path
}, $fb->{pool
}) ];
1795 my ($self, $fb, $exp) = @_;
1797 my $path = $self->git_path($fb->{path
});
1798 if (my $fh = $fb->{fh
}) {
1799 seek($fh, 0, 0) or croak
$!;
1800 my $md5 = Digest
::MD5
->new;
1802 my $got = $md5->hexdigest;
1803 die "Checksum mismatch: $path\n",
1804 "expected: $exp\n got: $got\n" if ($got ne $exp);
1805 seek($fh, 0, 0) or croak
$!;
1806 if ($fb->{mode_b
} == 120000) {
1807 read($fh, my $buf, 5) == 5 or croak
$!;
1808 $buf eq 'link ' or die "$path has mode 120000",
1809 "but is not a link\n";
1811 defined(my $pid = open my $out,'-|') or die "Can't fork: $!\n";
1813 open STDIN
, '<&', $fh or croak
$!;
1814 exec qw
/git-hash-object -w --stdin/ or croak
$!;
1816 chomp($hash = do { local $/; <$out> });
1817 close $out or croak
$!;
1818 close $fh or croak
$!;
1819 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
1820 close $fb->{base
} or croak
$!;
1822 $hash = $fb->{blob
} or die "no blob information\n";
1825 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
1826 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $self->{q
};
1832 $self->{nr
} = $self->{gii
}->{nr
};
1833 delete $self->{gii
};
1834 $self->SUPER::abort_edit
(@_);
1839 $self->{git_commit_ok
} = 1;
1840 $self->{nr
} = $self->{gii
}->{nr
};
1841 delete $self->{gii
};
1842 $self->SUPER::close_edit
(@_);
1845 package SVN
::Git
::Editor
;
1846 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
1854 my ($class, $opts) = @_;
1855 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
1856 die "$_ required!\n" unless (defined $opts->{$_});
1859 my $pool = SVN
::Pool
->new;
1860 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
1861 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
1864 # $opts->{ra} functions should not be used after this:
1865 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
1866 $opts->{editor_cb
}, $pool);
1867 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
1868 bless $self, $class;
1869 foreach (qw
/svn_path r tree_a tree_b/) {
1870 $self->{$_} = $opts->{$_};
1872 $self->{url
} = $opts->{ra
}->{url
};
1873 $self->{mods
} = $mods;
1874 $self->{types
} = $types;
1875 $self->{pool
} = $pool;
1876 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
1878 $self->{path_prefix
} = length $self->{svn_path
} ?
1879 "$self->{svn_path}/" : '';
1884 my ($tree_a, $tree_b) = @_;
1885 my @diff_tree = qw(diff-tree -z -r);
1886 if ($_cp_similarity) {
1887 push @diff_tree, "-C$_cp_similarity";
1889 push @diff_tree, '-C';
1891 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
1892 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
1893 push @diff_tree, $tree_a, $tree_b;
1894 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
1898 while (<$diff_fh>) {
1899 chomp $_; # this gets rid of the trailing "\0"
1900 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
1901 $::sha1\s
($::sha1
)\s
1902 ([MTCRAD
])\d
*$/xo
) {
1903 push @mods, { mode_a
=> $1, mode_b
=> $2,
1904 sha1_b
=> $3, chg
=> $4 };
1905 if ($4 =~ /^(?:C|R)$/) {
1910 } elsif ($state eq 'file_a') {
1911 my $x = $mods[$#mods] or croak
"Empty array\n";
1912 if ($x->{chg
} !~ /^(?:C|R)$/) {
1913 croak
"Error parsing $_, $x->{chg}\n";
1917 } elsif ($state eq 'file_b') {
1918 my $x = $mods[$#mods] or croak
"Empty array\n";
1919 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
1920 croak
"Error parsing $_, $x->{chg}\n";
1922 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
1923 croak
"Error parsing $_, $x->{chg}\n";
1928 croak
"Error parsing $_\n";
1931 command_close_pipe
($diff_fh, $ctx);
1935 sub check_diff_paths
{
1936 my ($ra, $pfx, $rev, $mods) = @_;
1938 $pfx .= '/' if length $pfx;
1940 sub type_diff_paths
{
1941 my ($ra, $types, $path, $rev) = @_;
1942 my @p = split m
#/+#, $path;
1944 unless (defined $types->{$c}) {
1945 $types->{$c} = $ra->check_path($c, $rev);
1948 $c .= '/' . shift @p;
1949 next if defined $types->{$c};
1950 $types->{$c} = $ra->check_path($c, $rev);
1954 foreach my $m (@
$mods) {
1955 foreach my $f (qw
/file_a file_b/) {
1956 next unless defined $m->{$f};
1957 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
1958 if (length $pfx.$dir && ! defined $types{$dir}) {
1959 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
1967 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
1971 my ($self, $path) = @_;
1972 $self->{path_prefix
}.(defined $path ?
$path : '');
1976 my ($self, $path) = @_;
1977 $self->{url
} . '/' . $self->repo_path($path);
1982 my $rm = $self->{rm
};
1983 delete $rm->{''}; # we never delete the url we're tracking
1986 foreach (keys %$rm) {
1987 my @d = split m
#/#, $_;
1991 $c .= '/' . shift @d;
1995 delete $rm->{$self->{svn_path
}};
1996 delete $rm->{''}; # we never delete the url we're tracking
1999 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
2004 my @dn = split m
#/#, $_;
2006 delete $rm->{join '/', @dn};
2013 command_close_pipe
($fh, $ctx);
2015 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
2016 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
2017 $self->close_directory($bat->{$d}, $p);
2018 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
2019 print "\tD+\t$d/\n" unless $::_q
;
2020 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
2025 sub open_or_add_dir
{
2026 my ($self, $full_path, $baton) = @_;
2027 my $t = $self->{types
}->{$full_path};
2029 die "$full_path not known in r$self->{r} or we have a bug!\n";
2031 if ($t == $SVN::Node
::none
) {
2032 return $self->add_directory($full_path, $baton,
2033 undef, -1, $self->{pool
});
2034 } elsif ($t == $SVN::Node
::dir
) {
2035 return $self->open_directory($full_path, $baton,
2036 $self->{r
}, $self->{pool
});
2038 print STDERR
"$full_path already exists in repository at ",
2039 "r$self->{r} and it is not a directory (",
2040 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
2045 my ($self, $path) = @_;
2046 my $bat = $self->{bat
};
2047 my $repo_path = $self->repo_path($path);
2048 return $bat->{''} unless (length $repo_path);
2049 my @p = split m
#/+#, $repo_path;
2051 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
2054 $c .= '/' . shift @p;
2055 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
2061 my ($self, $m) = @_;
2062 my ($dir, $file) = split_path
($m->{file_b
});
2063 my $pbat = $self->ensure_path($dir);
2064 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2066 print "\tA\t$m->{file_b}\n" unless $::_q
;
2067 $self->chg_file($fbat, $m);
2068 $self->close_file($fbat,undef,$self->{pool
});
2072 my ($self, $m) = @_;
2073 my ($dir, $file) = split_path
($m->{file_b
});
2074 my $pbat = $self->ensure_path($dir);
2075 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2076 $self->url_path($m->{file_a
}), $self->{r
});
2077 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2078 $self->chg_file($fbat, $m);
2079 $self->close_file($fbat,undef,$self->{pool
});
2083 my ($self, $path, $pbat) = @_;
2084 my $rpath = $self->repo_path($path);
2085 my ($dir, $file) = split_path
($rpath);
2086 $self->{rm
}->{$dir} = 1;
2087 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
2091 my ($self, $m) = @_;
2092 my ($dir, $file) = split_path
($m->{file_b
});
2093 my $pbat = $self->ensure_path($dir);
2094 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2095 $self->url_path($m->{file_a
}), $self->{r
});
2096 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2097 $self->chg_file($fbat, $m);
2098 $self->close_file($fbat,undef,$self->{pool
});
2100 ($dir, $file) = split_path
($m->{file_a
});
2101 $pbat = $self->ensure_path($dir);
2102 $self->delete_entry($m->{file_a
}, $pbat);
2106 my ($self, $m) = @_;
2107 my ($dir, $file) = split_path
($m->{file_b
});
2108 my $pbat = $self->ensure_path($dir);
2109 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
2110 $pbat,$self->{r
},$self->{pool
});
2111 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
2112 $self->chg_file($fbat, $m);
2113 $self->close_file($fbat,undef,$self->{pool
});
2116 sub T
{ shift->M(@_) }
2118 sub change_file_prop
{
2119 my ($self, $fbat, $pname, $pval) = @_;
2120 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
2124 my ($self, $fbat, $m) = @_;
2125 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
2126 $self->change_file_prop($fbat,'svn:executable','*');
2127 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
2128 $self->change_file_prop($fbat,'svn:executable',undef);
2130 my $fh = IO
::File
->new_tmpfile or croak
$!;
2131 if ($m->{mode_b
} =~ /^120/) {
2132 print $fh 'link ' or croak
$!;
2133 $self->change_file_prop($fbat,'svn:special','*');
2134 } elsif ($m->{mode_a
} =~ /^120/ && $m->{mode_b
} !~ /^120/) {
2135 $self->change_file_prop($fbat,'svn:special',undef);
2137 defined(my $pid = fork) or croak
$!;
2139 open STDOUT
, '>&', $fh or croak
$!;
2140 exec qw
/git-cat-file blob/, $m->{sha1_b
} or croak
$!;
2144 $fh->flush == 0 or croak
$!;
2145 seek $fh, 0, 0 or croak
$!;
2147 my $md5 = Digest
::MD5
->new;
2148 $md5->addfile($fh) or croak
$!;
2149 seek $fh, 0, 0 or croak
$!;
2151 my $exp = $md5->hexdigest;
2152 my $pool = SVN
::Pool
->new;
2153 my $atd = $self->apply_textdelta($fbat, undef, $pool);
2154 my $got = SVN
::TxDelta
::send_stream
($fh, @
$atd, $pool);
2155 die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
2158 close $fh or croak
$!;
2162 my ($self, $m) = @_;
2163 my ($dir, $file) = split_path
($m->{file_b
});
2164 my $pbat = $self->ensure_path($dir);
2165 print "\tD\t$m->{file_b}\n" unless $::_q
;
2166 $self->delete_entry($m->{file_b
}, $pbat);
2171 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
2172 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
2173 $self->close_directory($bat->{$_}, $p);
2175 $self->SUPER::close_edit
($p);
2181 $self->SUPER::abort_edit
($self->{pool
});
2186 $self->SUPER::DESTROY
(@_);
2187 $self->{pool
}->clear;
2190 # this drives the editor
2193 my $mods = $self->{mods
};
2194 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
2195 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
2197 if (defined $o{$f}) {
2200 fatal
("Invalid change type: $f\n");
2203 $self->rmdirs if $_rmdir;
2209 return scalar @
$mods;
2212 package Git
::SVN
::Ra
;
2213 use vars qw
/@ISA $config_dir/;
2216 my ($can_do_switch);
2220 # enforce temporary pool usage for some simple functions
2222 foreach (qw
/get_latest_revnum rev_proplist get_file
2223 check_path get_dir get_uuid get_repos_root
/) {
2226 my \$pool = SVN::Pool->new;
2227 my \@ret = \$self->SUPER::$_(\@_,\$pool);
2229 wantarray ? \@ret : \$ret[0]; }\n";
2235 my ($class, $url) = @_;
2237 return $RA if ($RA && $RA->{url
} eq $url);
2239 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
2240 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
([
2241 SVN
::Client
::get_simple_provider
(),
2242 SVN
::Client
::get_ssl_server_trust_file_provider
(),
2243 SVN
::Client
::get_simple_prompt_provider
(
2244 \
&Git
::SVN
::Prompt
::simple
, 2),
2245 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
2246 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
2247 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
2248 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
2249 SVN
::Client
::get_username_provider
(),
2250 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
2251 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
2252 SVN
::Client
::get_username_prompt_provider
(
2253 \
&Git
::SVN
::Prompt
::username
, 2),
2255 my $config = SVN
::Core
::config_get_config
($config_dir);
2256 my $self = SVN
::Ra
->new(url
=> $url, auth
=> $baton,
2258 pool
=> SVN
::Pool
->new,
2259 auth_provider_callbacks
=> $callbacks);
2260 $self->{svn_path
} = $url;
2261 $self->{repos_root
} = $self->get_repos_root;
2262 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E/*##;
2263 $RA = bless $self, $class;
2267 # do not call the real DESTROY since we store ourselves in $RA
2271 my ($self, @args) = @_;
2272 my $pool = SVN
::Pool
->new;
2273 splice(@args, 3, 1) if ($SVN::Core
::VERSION
le '1.2.0');
2274 my $ret = $self->SUPER::get_log
(@args, $pool);
2279 sub get_commit_editor
{
2280 my ($self, $log, $cb, $pool) = @_;
2281 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
2282 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
2287 $self->{uuid
} ||= $self->get_uuid;
2291 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
2292 my $new = ($rev_a == $rev_b);
2293 my $path = $gs->{path
};
2295 my $ta = $self->check_path($path, $rev_a);
2296 my $tb = $new ?
$ta : $self->check_path($path, $rev_b);
2297 return 1 if ($tb != $SVN::Node
::dir
&& $ta != $SVN::Node
::dir
);
2298 if ($ta == $SVN::Node
::none
) {
2303 my $pool = SVN
::Pool
->new;
2304 $editor->set_path_strip($path);
2305 my (@pc) = split m
#/#, $path;
2306 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
2308 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2310 # Since we can't rely on svn_ra_reparent being available, we'll
2311 # just have to do some magic with set_path to make it so
2312 # we only want a partial path.
2314 my $final = join('/', @pc);
2316 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
2317 $sp .= '/' if length $sp;
2320 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
2322 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
2324 $reporter->finish_report($pool);
2326 $editor->{git_commit_ok
};
2329 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
2330 # svn_ra_reparent didn't work before 1.4)
2332 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
2333 my $path = $gs->{path
};
2334 my $pool = SVN
::Pool
->new;
2336 my $full_url = $self->{url
};
2337 my $old_url = $full_url;
2338 $full_url .= "/$path" if length $path;
2339 my ($ra, $reparented);
2340 if ($old_url ne $full_url) {
2341 if ($old_url !~ m
#^svn(\+ssh)?://#) {
2342 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url,
2344 $self->{url
} = $full_url;
2347 $ra = Git
::SVN
::Ra
->new($full_url);
2351 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
2352 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2353 $reporter->set_path('', $rev_a, 0, @lock, $pool);
2354 $reporter->finish_report($pool);
2357 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
2358 $self->{url
} = $old_url;
2362 $editor->{git_commit_ok
};
2365 sub gs_fetch_loop_common
{
2366 my ($self, $base, $head, @gs) = @_;
2368 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
2369 foreach my $gs (@gs) {
2370 if (my $last_commit = $gs->last_commit) {
2371 $gs->assert_index_clean($last_commit);
2377 my $err_handler = $SVN::Error
::handler
;
2378 $SVN::Error
::handler
= sub {
2380 skip_unknown_revs
($err);
2382 foreach my $gs (@gs) {
2383 $self->get_log([$gs->{path
}], $min, $max, 0, 1, 1, sub
2384 { my ($paths, $rev) = @_;
2385 push @
{$revs{$rev}},
2387 dup_changed_paths
($paths) ] });
2389 next unless ($err && $max >= $head);
2391 print STDERR
"Path '$gs->{path}' ",
2392 "was probably deleted:\n",
2393 $err->expanded_message,
2394 "\nWill attempt to follow ",
2395 "revisions r$min .. r$max ",
2396 "committed before the deletion\n";
2398 while (--$hi >= $min) {
2400 $self->get_log([$gs->{path
}], $min, $hi,
2402 my ($paths, $rev) = @_;
2404 push @
{$revs{$rev}}, [ $gs,
2405 dup_changed_paths
($_[0])]});
2407 print STDERR
"r$min .. r$ok OK\n";
2412 $SVN::Error
::handler
= $err_handler;
2413 foreach my $r (sort {$a <=> $b} keys %revs) {
2414 foreach (@
{$revs{$r}}) {
2415 my ($gs, $paths) = @
$_;
2416 my $lr = $gs->last_rev;
2417 next if defined $lr && $lr >= $r;
2418 next if defined $gs->rev_db_get($r);
2419 if (my $log_entry = $gs->do_fetch($paths, $r)) {
2420 $gs->do_git_commit($log_entry);
2424 # pre-fill the .rev_db since it'll eventually get filled in
2425 # with '0' x40 if something new gets committed
2426 foreach my $gs (@gs) {
2427 next if defined $gs->rev_db_get($max);
2428 $gs->rev_db_set($max, 0 x40
);
2430 last if $max >= $head;
2433 $max = $head if ($max > $head);
2439 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
2440 my $url = $self->{repos_root
};
2441 my @components = split(m!/!, $self->{svn_path
});
2444 $url .= "/$c" if length $c;
2445 eval { (ref $self)->new($url)->get_latest_revnum };
2446 } while ($@
&& ($c = shift @components));
2452 unless (defined $can_do_switch) {
2453 my $pool = SVN
::Pool
->new;
2455 $self->do_switch(1, '', 0, $self->{url
},
2456 SVN
::Delta
::Editor
->new, $pool);
2461 $rep->abort_report($pool);
2469 sub skip_unknown_revs
{
2471 my $errno = $err->apr_err();
2472 # Maybe the branch we're tracking didn't
2473 # exist when the repo started, so it's
2474 # not an error if it doesn't, just continue
2476 # Wonderfully consistent library, eh?
2477 # 160013 - svn:// and file://
2478 # 175002 - http(s)://
2479 # 175007 - http(s):// (this repo required authorization, too...)
2480 # More codes may be discovered later...
2481 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
2484 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
2487 # svn_log_changed_path_t objects passed to get_log are likely to be
2488 # overwritten even if only the refs are copied to an external variable,
2489 # so we should dup the structures in their entirety. Using an externally
2490 # passed pool (instead of our temporary and quickly cleared pool in
2491 # Git::SVN::Ra) does not help matters at all...
2492 sub dup_changed_paths
{
2494 return undef unless $paths;
2496 foreach my $p (keys %$paths) {
2497 my $i = $paths->{$p};
2498 my %s = map { $_ => $i->$_ }
2499 qw
/copyfrom_path copyfrom_rev action/;
2505 package Git
::SVN
::Log
;
2508 use POSIX qw
/strftime/;
2509 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
2510 %rusers $show_commit $incremental/;
2515 return 1 if defined $c->{r
};
2516 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
2517 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
2518 my @log = command
(qw
/cat-file commit/, $c->{c
});
2519 shift @log while ($log[0] ne "\n");
2521 @
{$c->{l
}} = grep !/^git-svn-id: /, @log;
2523 (undef, $c->{r
}, undef) = ::extract_metadata
(
2524 (grep(/^git-svn-id: /, @log))[-1]);
2526 return defined $c->{r
};
2532 $dcvar = 'color.diff';
2533 $dc = `git-config --get $dcvar`;
2535 # nothing at all; fallback to "diff.color"
2536 $dcvar = 'diff.color';
2537 $dc = `git-config --get $dcvar`;
2540 if ($dc eq 'auto') {
2542 $pc = `git-config --get color.pager`;
2544 # does not have it -- fallback to pager.color
2545 $pc = `git-config --bool --get pager.color`;
2548 $pc = `git-config --bool --get color.pager`;
2554 if (-t
*STDOUT
|| (defined $pager && $pc eq 'true')) {
2555 return ($ENV{TERM
} && $ENV{TERM
} ne 'dumb');
2559 return 0 if $dc eq 'never';
2560 return 1 if $dc eq 'always';
2561 chomp($dc = `git-config --bool --get $dcvar`);
2562 return ($dc eq 'true');
2565 sub git_svn_log_cmd
{
2566 my ($r_min, $r_max) = @_;
2567 my $gs = Git
::SVN
->_new;
2568 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
2570 push @cmd, '-r' unless $non_recursive;
2571 push @cmd, qw
/--raw --name-status/ if $verbose;
2572 push @cmd, '--color' if log_use_color
();
2573 return @cmd unless defined $r_max;
2574 if ($r_max == $r_min) {
2575 push @cmd, '--max-count=1';
2576 if (my $c = $gs->rev_db_get($r_max)) {
2580 my ($c_min, $c_max);
2581 $c_max = $gs->rev_db_get($r_max);
2582 $c_min = $gs->rev_db_get($r_min);
2583 if (defined $c_min && defined $c_max) {
2584 if ($r_max > $r_max) {
2585 push @cmd, "$c_min..$c_max";
2587 push @cmd, "$c_max..$c_min";
2589 } elsif ($r_max > $r_min) {
2598 # adapted from pager.c
2600 $pager ||= $ENV{GIT_PAGER
} || $ENV{PAGER
};
2601 if (!defined $pager) {
2603 } elsif (length $pager == 0 || $pager eq 'cat') {
2609 return unless -t
*STDOUT
;
2610 pipe my $rfd, my $wfd or return;
2611 defined(my $pid = fork) or ::fatal
"Can't fork: $!\n";
2613 open STDOUT
, '>&', $wfd or
2614 ::fatal
"Can't redirect to stdout: $!\n";
2617 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!\n";
2618 $ENV{LESS
} ||= 'FRSX';
2619 exec $pager or ::fatal
"Can't run pager: $! ($pager)\n";
2622 sub tz_to_s_offset
{
2625 return ($1 * 60) + ($tz * 3600);
2628 sub get_author_info
{
2629 my ($dest, $author, $t, $tz) = @_;
2630 $author =~ s/(?:^\s*|\s*$)//g;
2631 $dest->{a_raw
} = $author;
2634 $au = $rusers{$author} || undef;
2637 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
2642 # Date::Parse isn't in the standard Perl distro :(
2643 if ($tz =~ s/^\+//) {
2644 $t += tz_to_s_offset
($tz);
2645 } elsif ($tz =~ s/^\-//) {
2646 $t -= tz_to_s_offset
($tz);
2648 $dest->{t_utc
} = $t;
2651 sub process_commit
{
2652 my ($c, $r_min, $r_max, $defer) = @_;
2653 if (defined $r_min && defined $r_max) {
2654 if ($r_min == $c->{r
} && $r_min == $r_max) {
2658 return 1 if $r_min == $r_max;
2659 if ($r_min < $r_max) {
2660 # we need to reverse the print order
2661 return 0 if (defined $limit && --$limit < 0);
2665 if ($r_min != $r_max) {
2666 return 1 if ($r_min < $c->{r
});
2667 return 1 if ($r_max > $c->{r
});
2670 return 0 if (defined $limit && --$limit < 0);
2679 if (my $l = $c->{l
}) {
2680 while ($l->[0] =~ /^\s*$/) { shift @
$l }
2683 $l_fmt ||= 'A' . length($c->{r
});
2684 print 'r',pack($l_fmt, $c->{r
}),' | ';
2685 print "$c->{c} | " if $show_commit;
2688 show_commit_normal
($c);
2692 sub show_commit_changed_paths
{
2694 return unless $c->{changed
};
2695 print "Changed paths:\n", @
{$c->{changed
}};
2698 sub show_commit_normal
{
2700 print '-' x72
, "\nr$c->{r} | ";
2701 print "$c->{c} | " if $show_commit;
2702 print "$c->{a} | ", strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
2703 localtime($c->{t_utc
})), ' | ';
2706 if (my $l = $c->{l
}) {
2707 while ($l->[$#$l] eq "\n" && $#$l > 0
2708 && $l->[($#$l - 1)] eq "\n") {
2711 $nr_line = scalar @
$l;
2713 print "1 line\n\n\n";
2715 if ($nr_line == 1) {
2716 $nr_line = '1 line';
2718 $nr_line .= ' lines';
2720 print $nr_line, "\n";
2721 show_commit_changed_paths
($c);
2723 print $_ foreach @
$l;
2727 show_commit_changed_paths
($c);
2731 foreach my $x (qw
/raw diff/) {
2734 print $_ foreach @
{$c->{$x}}
2741 my ($r_min, $r_max);
2742 my $r_last = -1; # prevent dupes
2748 if (defined $::_revision
) {
2749 if ($::_revision
=~ /^(\d+):(\d+)$/) {
2750 ($r_min, $r_max) = ($1, $2);
2751 } elsif ($::_revision
=~ /^\d+$/) {
2752 $r_min = $r_max = $::_revision
;
2754 ::fatal
"-r$::_revision is not supported, use ",
2755 "standard \'git log\' arguments instead\n";
2760 @args = (git_svn_log_cmd
($r_min, $r_max), @args);
2761 my $log = command_output_pipe
(@args);
2764 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
2766 if (/^${esc_color}commit ($::sha1_short)/o) {
2768 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
2770 process_commit
($c, $r_min, $r_max, \
@k) or
2775 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
2776 get_author_info
($c, $1, $2, $3);
2777 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
2779 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
2780 push @
{$c->{raw
}}, $_;
2781 } elsif (/^${esc_color}[ACRMDT]\t/) {
2782 # we could add $SVN->{svn_path} here, but that requires
2783 # remote access at the moment (repo_path_split)...
2784 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
2785 push @
{$c->{changed
}}, $_;
2786 } elsif (/^${esc_color}diff /o) {
2788 push @
{$c->{diff
}}, $_;
2790 push @
{$c->{diff
}}, $_;
2791 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
2792 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
2793 } elsif (s/^${esc_color} //o) {
2794 push @
{$c->{l
}}, $_;
2797 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
2799 process_commit
($c, $r_min, $r_max, \
@k);
2805 process_commit
($_, $r_min, $r_max) foreach reverse @k;
2809 print '-' x72
,"\n" unless $incremental || $oneline;
2812 package Git
::SVN
::Migration
;
2813 # these version numbers do NOT correspond to actual version numbers
2814 # of git nor git-svn. They are just relative.
2816 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
2818 # v1 layout: .git/$id/info/url, refs/remotes/$id
2820 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
2822 # v3 layout: .git/svn/$id, refs/remotes/$id
2823 # - info/url may remain for backwards compatibility
2824 # - this is what we migrate up to this layout automatically,
2825 # - this will be used by git svn init on single branches
2827 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
2828 # - this is only created for newly multi-init-ed
2829 # repositories. Similar in spirit to the
2830 # --use-separate-remotes option in git-clone (now default)
2831 # - we do not automatically migrate to this (following
2832 # the example set by core git)
2836 use File
::Path qw
/mkpath/;
2837 use File
::Basename qw
/dirname basename/;
2838 use vars qw
/$_minimize/;
2840 sub migrate_from_v0
{
2841 my $git_dir = $ENV{GIT_DIR
};
2842 return undef unless -d
$git_dir;
2843 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
2847 my ($id, $orig_ref) = ($_, $_);
2848 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
2849 next unless -f
"$git_dir/$id/info/url";
2850 my $new_ref = "refs/remotes/$id";
2851 if (::verify_ref
("$new_ref^0")) {
2852 print STDERR
"W: $orig_ref is probably an old ",
2853 "branch used by an ancient version of ",
2855 "However, $new_ref also exists.\n",
2856 "We will not be able ",
2857 "to use this branch until this ",
2858 "ambiguity is resolved.\n";
2861 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
2862 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
2863 command_noisy
('update-ref', $new_ref, $orig_ref);
2864 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
2867 command_close_pipe
($fh, $ctx);
2868 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
2872 sub migrate_from_v1
{
2873 my $git_dir = $ENV{GIT_DIR
};
2875 return $migrated unless -d
$git_dir;
2876 my $svn_dir = "$git_dir/svn";
2878 # just in case somebody used 'svn' as their $id at some point...
2879 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
2881 print STDERR
"Migrating from a git-svn v1 layout...\n";
2883 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
2884 "$svn_dir\n\t(required for this version ",
2885 "($::VERSION) of git-svn) does not. exist\n";
2886 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
2889 next unless $x =~ s
#^refs/remotes/##;
2891 next unless -f
"$git_dir/$x/info/url";
2892 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
2894 my $dn = dirname
("$git_dir/svn/$x");
2895 mkpath
([$dn]) unless -d
$dn;
2896 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
2897 mkpath
(["$git_dir/svn/svn"]);
2898 print STDERR
" - $git_dir/$x/info => ",
2899 "$git_dir/svn/$x/info\n";
2900 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
2902 # don't worry too much about these, they probably
2903 # don't exist with repos this old (save for index,
2904 # and we can easily regenerate that)
2905 foreach my $f (qw
/unhandled.log index .rev_db/) {
2906 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
2909 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
2910 rename "$git_dir/$x", "$git_dir/svn/$x" or
2915 command_close_pipe
($fh, $ctx);
2916 print STDERR
"Done migrating from a git-svn v1 layout\n";
2921 my ($l_map, $pfx, $path) = @_;
2923 foreach (<$path/*>) {
2924 if (-r
"$_/info/url") {
2925 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
2926 my $ref_id = $pfx . basename
$_;
2927 my $url = ::file_to_s
("$_/info/url");
2928 $l_map->{$ref_id} = $url;
2935 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
2936 read_old_urls
($l_map, $x, $_);
2940 sub migrate_from_v2
{
2941 my @cfg = command
(qw
/config -l/);
2942 return if grep /^svn-remote\..+\.url=/, @cfg;
2944 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
2947 foreach my $ref_id (sort keys %l_map) {
2948 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
2954 sub minimize_connections
{
2955 my $r = Git
::SVN
::read_all_remotes
();
2957 my $root_repos = {};
2958 foreach my $repo_id (keys %$r) {
2959 my $url = $r->{$repo_id}->{url
} or next;
2960 my $fetch = $r->{$repo_id}->{fetch
} or next;
2961 my $ra = Git
::SVN
::Ra
->new($url);
2963 # skip existing cases where we already connect to the root
2964 if (($ra->{url
} eq $ra->{repos_root
}) ||
2965 (Git
::SVN
::sanitize_remote_name
($ra->{repos_root
}) eq
2967 $root_repos->{$ra->{url
}} = $repo_id;
2971 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
2972 my $root_path = $ra->{url
};
2973 $root_path =~ s
#^\Q$ra->{repos_root}\E/*##;
2974 foreach my $path (keys %$fetch) {
2975 my $ref_id = $fetch->{$path};
2976 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
2978 # make sure we can read when connecting to
2979 # a higher level of a repository
2980 my ($last_rev, undef) = $gs->last_rev_commit;
2981 if (!defined $last_rev) {
2983 $root_ra->get_latest_revnum;
2987 my $new = $root_path;
2988 $new .= length $path ?
"/$path" : '';
2990 $root_ra->get_log([$new], $last_rev, $last_rev,
2994 $new_urls->{$ra->{repos_root
}}->{$new} =
2995 { ref_id
=> $ref_id,
2996 old_repo_id
=> $repo_id,
2997 old_path
=> $path };
3002 foreach my $url (keys %$new_urls) {
3003 # see if we can re-use an existing [svn-remote "repo_id"]
3004 # instead of creating a(n ugly) new section:
3005 my $repo_id = $root_repos->{$url} ||
3006 Git
::SVN
::sanitize_remote_name
($url);
3008 my $fetch = $new_urls->{$url};
3009 foreach my $path (keys %$fetch) {
3010 my $x = $fetch->{$path};
3011 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
3012 my $pfx = "svn-remote.$x->{old_repo_id}";
3014 my $old_fetch = quotemeta("$x->{old_path}:".
3015 "refs/remotes/$x->{ref_id}");
3016 command_noisy
(qw
/config --unset/,
3017 "$pfx.fetch", '^'. $old_fetch . '$');
3018 delete $r->{$x->{old_repo_id
}}->
3019 {fetch
}->{$x->{old_path
}};
3020 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
3021 command_noisy
(qw
/config --unset/,
3023 push @emptied, $x->{old_repo_id
}
3028 my $file = $ENV{GIT_CONFIG
} || $ENV{GIT_CONFIG_LOCAL
} ||
3029 "$ENV{GIT_DIR}/config";
3031 The following [svn-remote] sections in your config file ($file) are empty
3032 and can be safely removed:
3034 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
3038 sub migration_check
{
3042 minimize_connections
() if $_minimize;
3045 package Git
::IndexInfo
;
3048 use Git qw
/command_input_pipe command_close_pipe/;
3052 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
3053 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
3057 my ($self, $path) = @_;
3058 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
3059 return ++$self->{nr
};
3065 my ($self, $mode, $hash, $path) = @_;
3066 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
3067 return ++$self->{nr
};
3074 command_close_pipe
($self->{gui
}, $self->{ctx
});
3081 $log_entry hashref as returned by libsvn_log_entry
()
3083 log => 'whitespace-formatted log entry
3084 ', # trailing newline is preserved
3085 revision
=> '8', # integer
3086 date
=> '2004-02-24T17:01:44.108345Z', # commit date
3087 author
=> 'committer name'
3091 # this is generated by generate_diff();
3092 @mods = array of diff
-index line hashes
, each element represents one line
3093 of diff
-index output
3095 diff
-index line
($m hash
)
3097 mode_a
=> first column of diff
-index output
, no leading
':',
3098 mode_b
=> second column of diff
-index output
,
3099 sha1_b
=> sha1sum of the final blob
,
3100 chg
=> change type
[MCRADT
],
3101 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
3102 file_b
=> new
/current file name of a file
(any chg
)
3106 # retval of read_url_paths{,_all}();
3108 # repository root url
3109 'https://svn.musicpd.org' => {
3110 # repository path # GIT_SVN_ID
3111 'mpd/trunk' => 'trunk',
3112 'mpd/tags/0.11.5' => 'tags/0.11.5',
3117 I don
't trust the each() function on unless I created %hash myself
3118 because the internal iterator may not have started at base.