2 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
3 # License: GPL v2 or later
6 use vars qw
/ $AUTHOR $VERSION
8 $GIT_SVN_INDEX $GIT_SVN
9 $GIT_DIR $GIT_SVN_DIR $REVDB
10 $_follow_parent $sha1 $sha1_short $_revision
11 $_cp_remote $_upgrade $_q
13 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
14 $VERSION = '@@GIT_VERSION@@';
16 $ENV{GIT_DIR
} ||= '.git';
17 $Git::SVN
::default_repo_id
= 'git-svn';
18 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
20 my $LC_ALL = $ENV{LC_ALL
};
21 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
22 # make sure the svn binary gives consistent output between locales and TZs:
25 $| = 1; # unbuffer STDOUT
27 sub fatal
(@
) { print STDERR
@_; exit 1 }
28 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
31 if ($SVN::Core
::VERSION
lt '1.1.0') {
32 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n";
34 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
35 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
36 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
39 use File
::Basename qw
/dirname basename/;
40 use File
::Path qw
/mkpath/;
41 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
47 foreach (qw
/command command_oneline command_noisy command_output_pipe
48 command_input_pipe command_close_pipe
/) {
49 $s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ".
50 "*Git::SVN::Migration::$_ = ".
51 "*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; ";
58 my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS
};
59 $sha1 = qr/[a-f\d]{40}/;
60 $sha1_short = qr/[a-f\d]{4,40}/;
61 my ($_stdin, $_help, $_edit,
62 $_repack, $_repack_nr, $_repack_flags,
63 $_message, $_file, $_no_metadata,
66 $_merge, $_strategy, $_dry_run,
69 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
70 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
71 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
);
72 my %fc_opts = ( 'follow-parent|follow' => \
$_follow_parent,
73 'authors-file|A=s' => \
$_authors,
74 'repack:i' => \
$_repack,
75 'no-metadata' => \
$_no_metadata,
77 'repack-flags|repack-args|repack-opts=s' => \
$_repack_flags,
80 my ($_trunk, $_tags, $_branches);
81 my %multi_opts = ( 'trunk|T=s' => \
$_trunk,
82 'tags|t=s' => \
$_tags,
83 'branches|b=s' => \
$_branches );
84 my %init_opts = ( 'template=s' => \
$_template, 'shared' => \
$_shared );
85 my %cmt_opts = ( 'edit|e' => \
$_edit,
86 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
87 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
88 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
89 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
93 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
94 { 'revision|r=s' => \
$_revision, %fc_opts } ],
95 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
96 " (requires URL argument)",
98 dcommit
=> [ \
&cmd_dcommit
,
99 'Commit several diffs to merge with upstream',
100 { 'merge|m|M' => \
$_merge,
101 'strategy|s=s' => \
$_strategy,
102 'dry-run|n' => \
$_dry_run,
103 %cmt_opts, %fc_opts } ],
104 'set-tree' => [ \
&cmd_set_tree
,
105 "Set an SVN repository to a git tree-ish",
106 { 'stdin|' => \
$_stdin, %cmt_opts, %fc_opts, } ],
107 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
108 { 'revision|r=i' => \
$_revision } ],
109 rebuild
=> [ \
&cmd_rebuild
, "Rebuild git-svn metadata (after git clone)",
110 { 'copy-remote|remote=s' => \
$_cp_remote,
111 'upgrade' => \
$_upgrade } ],
112 'multi-init' => [ \
&cmd_multi_init
,
113 'Initialize multiple trees (like git-svnimport)',
114 { %multi_opts, %init_opts, %remote_opts,
115 'revision|r=i' => \
$_revision,
116 'prefix=s' => \
$_prefix,
118 'multi-fetch' => [ \
&cmd_multi_fetch
,
119 'Fetch multiple trees (like git-svnimport)',
121 'migrate' => [ sub { },
122 # no-op, we automatically run this anyways,
123 'Migrate configuration/metadata/layout from
124 previous versions of git-svn',
126 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
127 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
128 'revision|r=s' => \
$_revision,
129 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
130 'incremental' => \
$Git::SVN
::Log
::incremental
,
131 'oneline' => \
$Git::SVN
::Log
::oneline
,
132 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
133 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
134 'authors-file|A=s' => \
$_authors,
135 'color' => \
$Git::SVN
::Log
::color
,
136 'pager=s' => \
$Git::SVN
::Log
::pager
,
138 'commit-diff' => [ \
&cmd_commit_diff
,
139 'Commit a diff between two trees',
140 { 'message|m=s' => \
$_message,
141 'file|F=s' => \
$_file,
142 'revision|r=s' => \
$_revision,
147 for (my $i = 0; $i < @ARGV; $i++) {
148 if (defined $cmd{$ARGV[$i]}) {
155 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
157 read_repo_config
(\
%opts);
158 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help,
159 'version|V' => \
$_version,
160 'minimize-connections' =>
161 \
$Git::SVN
::Migration
::_minimize
,
162 'id|i=s' => \
$Git::SVN
::default_ref_id
);
163 exit 1 if (!$rv && $cmd ne 'log');
166 version
() if $_version;
167 usage
(1) unless defined $cmd;
168 load_authors
() if $_authors;
169 unless ($cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/) {
170 Git
::SVN
::Migration
::migration_check
();
173 Git
::SVN
::verify_remotes_sanity
();
174 $cmd{$cmd}->[0]->(@ARGV);
179 ####################### primary functions ######################
181 my $exit = shift || 0;
182 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
184 git
-svn
- bidirectional operations between a single Subversion tree
and git
185 Usage
: $0 <command
> [options
] [arguments
]\n
187 print $fd "Available commands:\n" unless $cmd;
189 foreach (sort keys %cmd) {
190 next if $cmd && $cmd ne $_;
191 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
192 foreach (keys %{$cmd{$_}->[2]}) {
193 # prints out arguments as they should be passed:
194 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
195 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
197 split /\|/,$_)," $x\n";
201 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
202 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
203 one git repository and want to keep them separate. See git-svn(1) for more
210 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
216 my $gs = $url ? Git::SVN->init($url)
217 : eval { Git::SVN->new };
218 $gs ||= Git::SVN->_new;
219 if (!verify_ref($gs->refname.'^0')) {
220 $gs->copy_remote_ref;
223 my ($rev_list, $ctx) = command_output_pipe("rev-list", $gs->refname);
226 while (<$rev_list>) {
229 fatal "Non-SHA1: $c\n" unless $c =~ /^$sha1$/o;
230 my ($url, $rev, $uuid) = cmt_metadata($c);
232 # ignore merges (from set-tree)
233 next if (!defined $rev || !$uuid);
235 # if we merged or otherwise started elsewhere, this is
236 # how we break out of it
237 if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
238 ($gs->{url} && $url && ($url ne $gs->{url}))) {
242 unless (defined $latest) {
243 if (!$gs->{url} && !$url) {
244 fatal "SVN repository location required\n";
246 $gs = Git::SVN->init($url);
249 $gs->rev_db_set($rev, $c);
250 print "r$rev = $c\n";
252 command_close_pipe($rev_list, $ctx);
256 unless (-d $ENV{GIT_DIR}) {
257 my @init_db = ('init
');
258 push @init_db, "--template=$_template" if defined $_template;
259 push @init_db, "--shared" if defined $_shared;
260 command_noisy(@init_db);
265 my $url = shift or die "SVN repository location required " .
266 "as a command-line argument\n";
267 if (my $repo_path = shift) {
268 unless (-d $repo_path) {
269 mkpath([$repo_path]);
271 chdir $repo_path or croak $!;
272 $ENV{GIT_DIR} = $repo_path . "/.git";
276 Git::SVN->init($url);
281 die "Additional fetch arguments are no longer supported.\n",
282 "Use --follow-parent if you have moved/copied directories
285 my $gs = Git::SVN->new;
286 $gs->fetch(parse_revision_argument());
287 if ($gs->{last_commit} && !verify_ref('refs
/heads/master
^0')) {
288 command_noisy(qw(update-ref refs/heads/master),
295 if ($_stdin || !@commits) {
296 print "Reading from stdin...\n";
299 if (/\b($sha1_short)\b/o) {
300 unshift @commits, $1;
305 foreach my $c (@commits) {
306 my @tmp = command
('rev-parse',$c);
307 if (scalar @tmp == 1) {
309 } elsif (scalar @tmp > 1) {
310 push @revs, reverse(command
('rev-list',@tmp));
312 fatal
"Failed to rev-parse $c\n";
315 my $gs = Git
::SVN
->new;
316 my ($r_last, $cmt_last) = $gs->last_rev_commit;
318 if (defined $gs->{last_rev
} && $r_last != $gs->{last_rev
}) {
319 fatal
"There are new revisions that were fetched ",
320 "and need to be merged (or acknowledged) ",
321 "before committing.\nlast rev: $r_last\n",
322 " current: $gs->{last_rev}\n";
324 $gs->set_tree($_) foreach @revs;
325 print "Done committing ",scalar @revs," revisions to SVN\n";
330 my $gs = Git
::SVN
->new;
332 my @refs = command
(qw
/rev-list --no-merges/, $gs->refname."..$head");
334 foreach my $d (reverse @refs) {
335 if (!verify_ref
("$d~1")) {
337 "has no parent commit, and therefore ",
338 "nothing to diff against.\n",
339 "You should be working from a repository ",
340 "originally created by git-svn\n";
342 unless (defined $last_rev) {
343 (undef, $last_rev, undef) = cmt_metadata
("$d~1");
344 unless (defined $last_rev) {
345 fatal
"Unable to extract revision information ",
346 "from commit $d~1\n";
350 print "diff-tree $d~1 $d\n";
352 my %ed_opts = ( r
=> $last_rev,
353 log => get_commit_entry
($d)->{log},
358 print "Committed r$_[0]\n";
359 $last_rev = $_[0]; },
360 svn_path
=> $gs->{path
} );
361 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
362 print "No changes\n$d~1 == $d\n";
368 # we always want to rebase against the current HEAD, not any
369 # head that was passed to us
370 my @diff = command
('diff-tree', 'HEAD', $gs->refname, '--');
373 @finish = qw
/rebase/;
374 push @finish, qw
/--merge/ if $_merge;
375 push @finish, "--strategy=$_strategy" if $_strategy;
376 print STDERR
"W: HEAD and ", $gs->refname, " differ, ",
377 "using @finish:\n", "@diff";
379 print "No changes between current HEAD and ",
380 $gs->refname, "\nResetting to the latest ",
382 @finish = qw
/reset --mixed/;
384 command_noisy
(@finish, $gs->refname);
387 sub cmd_show_ignore
{
388 my $gs = Git
::SVN
->new;
389 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
390 $gs->traverse_ignore(\
*STDOUT
, '', $r);
395 unless (defined $_trunk || defined $_branches || defined $_tags) {
399 $_prefix = '' unless defined $_prefix;
400 $url =~ s
#/+$## if defined $url;
401 if (defined $_trunk) {
402 my $trunk_ref = $_prefix . 'trunk';
403 # try both old-style and new-style lookups:
404 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
406 my ($trunk_url, $trunk_path) =
407 complete_svn_url
($url, $_trunk);
408 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
412 return unless defined $_branches || defined $_tags;
413 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
414 complete_url_ls_init
($ra, $_branches, '--branches/-b', $_prefix);
415 complete_url_ls_init
($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
418 sub cmd_multi_fetch
{
419 my $remotes = Git
::SVN
::read_all_remotes
();
420 foreach my $repo_id (sort keys %$remotes) {
421 my $url = $remotes->{$repo_id}->{url
} or next;
422 my $fetch = $remotes->{$repo_id}->{fetch
} or next;
423 Git
::SVN
::fetch_all
($repo_id, $url, $fetch);
427 # this command is special because it requires no metadata
428 sub cmd_commit_diff
{
429 my ($ta, $tb, $url) = @_;
430 my $usage = "Usage: $0 commit-diff -r<revision> ".
431 "<tree-ish> <tree-ish> [<URL>]\n";
432 fatal
($usage) if (!defined $ta || !defined $tb);
435 my $gs = eval { Git
::SVN
->new };
437 fatal
("Needed URL or usable git-svn --id in ",
438 "the command-line\n", $usage);
441 $svn_path = $gs->{path
};
443 unless (defined $_revision) {
444 fatal
("-r|--revision is a required argument\n", $usage);
446 if (defined $_message && defined $_file) {
447 fatal
("Both --message/-m and --file/-F specified ",
448 "for the commit message.\n",
449 "I have no idea what you mean\n");
451 if (defined $_file) {
452 $_message = file_to_s
($_file);
454 $_message ||= get_commit_entry
($tb)->{log};
456 my $ra ||= Git
::SVN
::Ra
->new($url);
457 $svn_path ||= $ra->{svn_path
};
460 $r = $ra->get_latest_revnum;
461 } elsif ($r !~ /^\d+$/) {
462 die "revision argument: $r not understood by git-svn\n";
464 my %ed_opts = ( r
=> $r,
469 editor_cb
=> sub { print "Committed r$_[0]\n" },
470 svn_path
=> $svn_path );
471 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
472 print "No changes\n$ta == $tb\n";
476 ########################### utility functions #########################
478 sub parse_revision_argument
{
479 if (!defined $_revision || $_revision eq 'BASE:HEAD') {
480 return (undef, undef);
482 return ($1, $2) if ($_revision =~ /^(\d+):(\d+)$/);
483 return ($_revision, $_revision) if ($_revision =~ /^\d+$/);
484 return (undef, $1) if ($_revision =~ /^BASE:(\d+)$/);
485 return ($1, undef) if ($_revision =~ /^(\d+):HEAD$/);
486 die "revision argument: $_revision not understood by git-svn\n",
487 "Try using the command-line svn client instead\n";
490 sub complete_svn_url
{
491 my ($url, $path) = @_;
493 if ($path !~ m
#^[a-z\+]+://#) {
494 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
495 fatal
("E: '$path' is not a complete URL ",
496 "and a separate URL is not specified\n");
498 return ($url, $path);
503 sub complete_url_ls_init
{
504 my ($ra, $repo_path, $switch, $pfx) = @_;
505 unless ($repo_path) {
506 print STDERR
"W: $switch not specified\n";
509 $repo_path =~ s
#/+$##;
510 if ($repo_path =~ m
#^[a-z\+]+://#) {
511 $ra = Git
::SVN
::Ra
->new($repo_path);
514 $repo_path =~ s
#^/+##;
516 fatal
("E: '$repo_path' is not a complete URL ",
517 "and a separate URL is not specified\n");
520 my $r = defined $_revision ?
$_revision : $ra->get_latest_revnum;
521 my ($dirent, undef, undef) = $ra->get_dir($repo_path, $r);
522 my $url = $ra->{url
};
523 foreach my $d (sort keys %$dirent) {
524 next if ($dirent->{$d}->kind != $SVN::Node
::dir
);
525 my $path = "$repo_path/$d";
527 my $gs = eval { Git
::SVN
->new($ref) };
528 # don't try to init already existing refs
530 print "init $url/$path => $ref\n";
531 Git
::SVN
->init($url, $path, undef, $ref);
538 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
542 sub get_tree_from_treeish
{
544 # $treeish can be a symbolic ref, too:
545 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
547 while ($type eq 'tag') {
548 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
550 if ($type eq 'commit') {
551 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
553 ($expected) = ($expected =~ /^tree ($sha1)$/o);
554 die "Unable to get tree from $treeish\n" unless $expected;
555 } elsif ($type eq 'tree') {
556 $expected = $treeish;
558 die "$treeish is a $type, expected tree, tag or commit\n";
563 sub get_commit_entry
{
564 my ($treeish) = shift;
565 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
566 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
567 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
568 open my $log_fh, '>', $commit_editmsg or croak
$!;
570 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
571 if ($type eq 'commit' || $type eq 'tag') {
572 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
577 $in_msg = 1 if (/^\s*$/);
578 } elsif (/^git-svn-id: /) {
579 # skip this for now, we regenerate the
580 # correct one on re-fetch anyways
581 # TODO: set *:merge properties or like...
583 print $log_fh $_ or croak
$!;
586 command_close_pipe
($msg_fh, $ctx);
588 close $log_fh or croak
$!;
590 if ($_edit || ($type eq 'tree')) {
591 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
592 # TODO: strip out spaces, comments, like git-commit.sh
593 system($editor, $commit_editmsg);
595 rename $commit_editmsg, $commit_msg or croak
$!;
596 open $log_fh, '<', $commit_msg or croak
$!;
597 { local $/; chomp($log_entry{log} = <$log_fh>); }
598 close $log_fh or croak
$!;
604 my ($str, $file, $mode) = @_;
605 open my $fd,'>',$file or croak
$!;
606 print $fd $str,"\n" or croak
$!;
607 close $fd or croak
$!;
608 chmod ($mode &~ umask, $file) if (defined $mode);
613 open my $fd,'<',$file or croak
"$!: file: $file\n";
616 close $fd or croak
$!;
621 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
623 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
624 my $log = $cmd eq 'log';
627 next unless /^(\S+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
628 my ($user, $name, $email) = ($1, $2, $3);
630 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
632 $users{$user} = [$name, $email];
635 close $authors or croak
$!;
638 # convert GetOpt::Long specs for use by git-config
639 sub read_repo_config
{
640 return unless -d
$ENV{GIT_DIR
};
642 foreach my $o (keys %$opts) {
644 my ($key) = ($o =~ /^([a-z\-]+)/);
646 my $arg = 'git-config';
647 $arg .= ' --int' if ($o =~ /[:=]i$/);
648 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
649 if (ref $v eq 'ARRAY') {
650 chomp(my @tmp = `$arg --get-all svn.$key`);
653 chomp(my $tmp = `$arg --get svn.$key`);
654 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
661 sub extract_metadata
{
662 my $id = shift or return (undef, undef, undef);
663 my ($url, $rev, $uuid) = ($id =~ /^git
-svn
-id
:\s
(\S
+?
)\@
(\d
+)
665 if (!defined $rev || !$uuid || !$url) {
666 # some of the original repositories I made had
667 # identifiers like this:
668 ($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
670 return ($url, $rev, $uuid);
674 return extract_metadata
((grep(/^git-svn-id: /,
675 command
(qw
/cat-file commit/, shift)))[-1]);
681 use vars qw
/$default_repo_id $default_ref_id/;
683 use File
::Path qw
/mkpath/;
686 # properties that we do not log:
689 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
690 svn
:special svn
:executable
691 svn
:entry
:committed
-rev
692 svn
:entry
:last-author
694 svn
:entry
:committed
-date
/;
698 my ($repo_id, $url, $fetch) = @_;
700 my $ra = Git
::SVN
::Ra
->new($url);
701 my $head = $ra->get_latest_revnum;
704 foreach my $p (sort keys %$fetch) {
705 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
706 my $lr = $gs->last_rev;
708 $base = $lr if ($lr < $base);
714 $base = 0 if $new_remote;
715 return if (++$base > $head);
716 $ra->gs_fetch_loop_common($base, $head, @gs);
719 sub read_all_remotes
{
721 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
722 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) {
723 $r->{$1}->{fetch
}->{$2} = $3;
724 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
725 $r->{$1}->{url
} = $2;
731 sub verify_remotes_sanity
{
732 return unless -d
$ENV{GIT_DIR
};
734 foreach (command
(qw
/config -l/)) {
735 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
737 die "Remote ref refs/remote/$1 is tracked by",
738 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
739 "Please resolve this ambiguity in ",
740 "your git configuration file before ",
748 # we allow more chars than remotes2config.sh...
749 sub sanitize_remote_name
{
751 $name =~ tr{A-Za-z0-9:,/+-}{.}c;
755 sub find_existing_remote
{
756 my ($url, $remotes) = @_;
758 foreach my $repo_id (keys %$remotes) {
759 my $u = $remotes->{$repo_id}->{url
} or next;
761 $existing = $repo_id;
767 sub init_remote_config
{
768 my ($self, $url) = @_;
769 $url =~ s!/+$!!; # strip trailing slash
770 my $r = read_all_remotes
();
771 my $existing = find_existing_remote
($url, $r);
773 print STDERR
"Using existing ",
774 "[svn-remote \"$existing\"]\n";
775 $self->{repo_id
} = $existing;
777 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
778 $existing = find_existing_remote
($min_url, $r);
780 print STDERR
"Using existing ",
781 "[svn-remote \"$existing\"]\n";
782 $self->{repo_id
} = $existing;
784 if ($min_url ne $url) {
785 print STDERR
"Using higher level of URL: ",
786 "$url => $min_url\n";
787 my $old_path = $self->{path
};
788 $self->{path
} = $url;
789 $self->{path
} =~ s!^\Q$min_url\E/*!!;
790 if (length $old_path) {
791 $self->{path
} .= "/$old_path";
798 # verify that we aren't overwriting anything:
800 command_oneline
('config', '--get',
801 "svn-remote.$self->{repo_id}.url")
803 if ($orig_url && ($orig_url ne $url)) {
804 die "svn-remote.$self->{repo_id}.url already set: ",
805 "$orig_url\nwanted to set to: $url\n";
808 my ($xrepo_id, $xpath) = find_ref
($self->refname);
809 if (defined $xpath) {
810 die "svn-remote.$xrepo_id.fetch already set to track ",
811 "$xpath:refs/remotes/", $self->refname, "\n";
813 command_noisy
('config',
814 "svn-remote.$self->{repo_id}.url", $url);
815 command_noisy
('config', '--add',
816 "svn-remote.$self->{repo_id}.fetch",
817 "$self->{path}:".$self->refname);
822 my ($class, $url, $path, $repo_id, $ref_id) = @_;
823 my $self = _new
($class, $repo_id, $ref_id, $path);
825 $self->init_remote_config($url);
832 foreach (command
(qw
/config -l/)) {
833 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
834 \s
*(.*)\s
*:\s
*refs
/remotes/(.+)\s
*$!x
;
835 my ($repo_id, $path, $ref) = ($1, $2, $3);
836 if ($ref eq $ref_id) {
837 $path = '' if ($path =~ m
#^\./?#);
838 return ($repo_id, $path);
841 (undef, undef, undef);
845 my ($class, $ref_id, $repo_id, $path) = @_;
846 if (defined $ref_id && !defined $repo_id && !defined $path) {
847 ($repo_id, $path) = find_ref
($ref_id);
848 if (!defined $repo_id) {
849 die "Could not find a \"svn-remote.*.fetch\" key ",
850 "in the repository configuration matching: ",
851 "refs/remotes/$ref_id\n";
854 my $self = _new
($class, $repo_id, $ref_id, $path);
855 if (!defined $self->{path
} || !length $self->{path
}) {
856 my $fetch = command_oneline
('config', '--get',
857 "svn-remote.$repo_id.fetch",
858 ":refs/remotes/$ref_id\$") or
859 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
860 "\":refs/remotes/$ref_id\$\" in config\n";
861 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
863 $self->{url
} = command_oneline
('config', '--get',
864 "svn-remote.$repo_id.url") or
865 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
869 sub refname
{ "refs/remotes/$_[0]->{ref_id}" }
873 Git
::SVN
::Ra
->new($self->{url
});
878 my $repos_root = $self->ra->{repos_root
};
879 return $self->{path
} if ($self->{url
} eq $repos_root);
880 my $url = $self->{url
} .
881 (length $self->{path
} ?
"/$self->{path}" : $self->{path
});
882 $url =~ s!^\Q$repos_root\E/*!!g;
886 sub copy_remote_ref
{
888 my $origin = $::_cp_remote ?
$::_cp_remote
: 'origin';
889 my $ref = $self->refname;
890 if (command
('ls-remote', $origin, $ref)) {
891 command_noisy
('fetch', $origin, "$ref:$ref");
892 } elsif ($::_cp_remote
&& !$::_upgrade
) {
893 die "Unable to find remote reference: $ref on $origin\n";
897 sub traverse_ignore
{
898 my ($self, $fh, $path, $r) = @_;
901 my ($dirent, undef, $props) = $ra->get_dir($path, $r);
903 $p =~ s
#^\Q$ra->{svn_path}\E/##;
904 print $fh length $p ?
"\n# $p\n" : "\n# /\n";
905 if (my $s = $props->{'svn:ignore'}) {
906 $s =~ s/[\r\n]+/\n/g;
908 if (length $p == 0) {
913 print $fh "/$p/$s\n";
916 foreach (sort keys %$dirent) {
917 next if $dirent->{$_}->kind != $SVN::Node
::dir
;
918 $self->traverse_ignore($fh, "$path/$_", $r);
922 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
923 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
925 # returns the newest SVN revision number and newest commit SHA1
926 sub last_rev_commit
{
928 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
929 return ($self->{last_rev
}, $self->{last_commit
});
931 my $c = ::verify_ref
($self->refname.'^0');
933 my $rev = (::cmt_metadata
($c))[1];
935 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
939 my $offset = -41; # from tail
941 open my $fh, '<', $self->{db_path
} or
942 croak
"$self->{db_path} not readable: $!\n";
943 seek $fh, $offset, 2;
945 defined $rl or return (undef, undef);
947 while ($c ne $rl && tell $fh != 0) {
949 seek $fh, $offset, 2;
951 defined $rl or return (undef, undef);
955 croak
$! if ($rev < 0);
956 $rev = ($rev - 41) / 41;
957 close $fh or croak
$!;
958 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
962 sub get_fetch_range
{
963 my ($self, $min, $max) = @_;
964 $max ||= $self->ra->get_latest_revnum;
965 $min ||= $self->last_rev || 0;
970 my ($self, $sub) = @_;
971 my $old_index = $ENV{GIT_INDEX_FILE
};
972 $ENV{GIT_INDEX_FILE
} = $self->{index};
975 $ENV{GIT_INDEX_FILE
} = $old_index;
977 delete $ENV{GIT_INDEX_FILE
};
979 wantarray ?
@ret : $ret[0];
982 sub assert_index_clean
{
983 my ($self, $treeish) = @_;
985 $self->tmp_index_do(sub {
986 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
987 my $x = command_oneline
('write-tree');
988 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
989 /^tree ($::sha1)/mo);
991 unlink $self->{index} or croak
$!;
992 command_noisy
('read-tree', $treeish);
994 $x = command_oneline
('write-tree');
996 ::fatal
"trees ($treeish) $y != $x\n",
997 "Something is seriously wrong...\n";
1002 sub get_commit_parents
{
1003 my ($self, $log_entry) = @_;
1004 my (%seen, @ret, @tmp);
1005 # legacy support for 'set-tree'; this is only used by set_tree_cb:
1006 if (my $ip = $self->{inject_parents
}) {
1007 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
1011 if (my $cur = ::verify_ref
($self->refname.'^0')) {
1014 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
1015 while (my $p = shift @tmp) {
1019 # MAXPARENT is defined to 16 in commit-tree.c:
1023 die "r$log_entry->{revision}: No room for parents:\n\t",
1024 join("\n\t", @tmp), "\n";
1031 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
1035 my ($self, $log_entry) = @_;
1036 if (my $c = $self->rev_db_get($log_entry->{revision
})) {
1037 croak
"$log_entry->{revision} = $c already exists! ",
1038 "Why are we refetching it?\n";
1040 my $author = $log_entry->{author
};
1041 my ($name, $email) = (defined $::users
{$author} ? @
{$::users
{$author}}
1042 : ($author, "$author\@".$self->ra->uuid));
1043 $ENV{GIT_AUTHOR_NAME
} = $ENV{GIT_COMMITTER_NAME
} = $name;
1044 $ENV{GIT_AUTHOR_EMAIL
} = $ENV{GIT_COMMITTER_EMAIL
} = $email;
1045 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
1047 my $tree = $log_entry->{tree
};
1048 if (!defined $tree) {
1049 $tree = $self->tmp_index_do(sub {
1050 command_oneline
('write-tree') });
1052 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
1054 my @exec = ('git-commit-tree', $tree);
1055 foreach ($self->get_commit_parents($log_entry)) {
1056 push @exec, '-p', $_;
1058 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1060 print $msg_fh $log_entry->{log} or croak
$!;
1061 print $msg_fh "\ngit-svn-id: ", $self->full_url, '@',
1062 $log_entry->{revision
}, ' ',
1063 $self->ra->uuid, "\n" or croak
$!;
1064 $msg_fh->flush == 0 or croak
$!;
1065 close $msg_fh or croak
$!;
1066 chomp(my $commit = do { local $/; <$out_fh> });
1067 close $out_fh or croak
$!;
1070 if ($commit !~ /^$::sha1$/o) {
1071 die "Failed to commit, invalid sha1: $commit\n";
1074 command_noisy
('update-ref',$self->refname, $commit);
1075 $self->rev_db_set($log_entry->{revision
}, $commit);
1077 $self->{last_rev
} = $log_entry->{revision
};
1078 $self->{last_commit
} = $commit;
1079 print "r$log_entry->{revision} = $commit\n";
1084 my ($self, $r0, $r1) = @_;
1085 return 1 if $r0 == $r1;
1087 $self->ra->get_log([$self->{path
}], $r0, $r1,
1088 0, 0, 1, sub { $nr++ });
1089 return 0 if ($nr > 1);
1093 sub find_parent_branch
{
1094 my ($self, $paths, $rev) = @_;
1095 return undef unless $::_follow_parent
;
1096 unless (defined $paths) {
1097 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
1098 sub { $paths = dup_changed_paths
($_[0]) });
1100 return undef unless defined $paths;
1102 # look for a parent from another branch:
1103 my @b_path_components = split m
#/#, $self->rel_path;
1104 my @a_path_components;
1106 while (@b_path_components) {
1107 $i = $paths->{'/'.join('/', @b_path_components)};
1109 unshift(@a_path_components, pop(@b_path_components));
1111 goto not_found
unless defined $i;
1112 my $branch_from = $i->{copyfrom_path
} or goto not_found
;
1113 if (@a_path_components) {
1114 print STDERR
"branch_from: $branch_from => ";
1115 $branch_from .= '/'.join('/', @a_path_components);
1116 print STDERR
$branch_from, "\n";
1118 my $r = $i->{copyfrom_rev
};
1119 my $repos_root = $self->ra->{repos_root
};
1120 my $url = $self->ra->{url
};
1121 my $new_url = $repos_root . $branch_from;
1122 print STDERR
"Found possible branch point: ",
1123 "$new_url => ", $self->full_url, ", $r\n";
1124 $branch_from =~ s
#^/##;
1125 my $remotes = read_all_remotes
();
1127 foreach my $repo_id (keys %$remotes) {
1128 my $u = $remotes->{$repo_id}->{url
} or next;
1130 my $fetch = $remotes->{$repo_id}->{fetch
};
1131 foreach my $f (keys %$fetch) {
1132 next if $f ne $branch_from;
1133 $gs = Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
1139 my $ref_id = $self->{ref_id
};
1140 $ref_id =~ s/\@\d+$//;
1142 # just grow a tail if we're not unique enough :x
1143 $ref_id .= '-' while find_ref
($ref_id);
1144 print STDERR
"Initializing parent: $ref_id\n";
1145 $gs = Git
::SVN
->init($new_url, '', $ref_id, $ref_id);
1147 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1148 if ($::_follow_parent
&& (!defined $r0 || !defined $parent)) {
1150 ($r0, $parent) = $gs->last_rev_commit;
1152 if (defined $r0 && defined $parent && $gs->revisions_eq($r0, $r)) {
1153 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n";
1154 $self->assert_index_clean($parent);
1156 if ($self->ra->can_do_switch) {
1157 print STDERR
"Following parent with do_switch\n";
1158 # do_switch works with svn/trunk >= r22312, but that
1159 # is not included with SVN 1.4.3 (the latest version
1160 # at the moment), so we can't rely on it
1161 $self->{last_commit
} = $parent;
1162 $ed = SVN
::Git
::Fetcher
->new($self);
1163 $gs->ra->gs_do_switch($r0, $rev, $gs->{path
}, 1,
1164 $self->full_url, $ed)
1165 or die "SVN connection failed somewhere...\n";
1167 print STDERR
"Following parent with do_update\n";
1168 $ed = SVN
::Git
::Fetcher
->new($self);
1169 $self->ra->gs_do_update($rev, $rev, $self->{path
},
1171 or die "SVN connection failed somewhere...\n";
1173 print STDERR
"Successfully followed parent\n";
1174 $ed->{new_fetch
} = 1;
1175 return $self->make_log_entry($rev, [$parent], $ed);
1178 print STDERR
"Branch parent for path: '/",
1179 $self->rel_path, "' @ r$rev not found:\n";
1180 return undef unless $paths;
1181 print STDERR
"Changed paths:\n";
1182 foreach my $x (sort keys %$paths) {
1183 my $p = $paths->{$x};
1184 print STDERR
"\t$p->{action}\t$x";
1185 if ($p->{copyfrom_path
}) {
1186 print STDERR
"(from $p->{copyfrom_path}: ",
1187 "$p->{copyfrom_rev})";
1191 print STDERR
'-'x72
, "\n";
1196 my ($self, $paths, $rev) = @_;
1198 my ($last_rev, @parents);
1199 if ($self->{last_commit
}) {
1200 $ed = SVN
::Git
::Fetcher
->new($self);
1201 $last_rev = $self->{last_rev
};
1202 $ed->{c
} = $self->{last_commit
};
1203 @parents = ($self->{last_commit
});
1206 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1209 $ed = SVN
::Git
::Fetcher
->new($self);
1210 $ed->{new_fetch
} = 1;
1212 unless ($self->ra->gs_do_update($last_rev, $rev,
1213 $self->{path
}, 1, $ed)) {
1214 die "SVN connection failed somewhere...\n";
1216 $self->make_log_entry($rev, \
@parents, $ed);
1220 my ($self, $ed) = @_;
1222 my $h = $ed->{empty
};
1223 foreach (sort keys %$h) {
1224 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
1225 push @out, " $act: " . uri_encode
($_);
1226 warn "W: $act: $_\n";
1228 foreach my $t (qw
/dir_prop file_prop/) {
1229 $h = $ed->{$t} or next;
1230 foreach my $path (sort keys %$h) {
1231 my $ppath = $path eq '' ?
'.' : $path;
1232 foreach my $prop (sort keys %{$h->{$path}}) {
1233 next if $SKIP_PROP{$prop};
1234 my $v = $h->{$path}->{$prop};
1235 my $t_ppath_prop = "$t: " .
1236 uri_encode
($ppath) . ' ' .
1239 push @out, " +$t_ppath_prop " .
1242 push @out, " -$t_ppath_prop";
1247 foreach my $t (qw
/absent_file absent_directory/) {
1248 $h = $ed->{$t} or next;
1249 foreach my $parent (sort keys %$h) {
1250 foreach my $path (sort @
{$h->{$parent}}) {
1251 push @out, " $t: " .
1252 uri_encode
("$parent/$path");
1253 warn "W: $t: $parent/$path ",
1254 "Insufficient permissions?\n";
1261 sub parse_svn_date
{
1262 my $date = shift || return '+0000 1970-01-01 00:00:00';
1263 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
1264 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
) or
1265 croak
"Unable to parse date: $date\n";
1266 "+0000 $Y-$m-$d $H:$M:$S";
1271 if (!defined $author || length $author == 0) {
1272 $author = '(no author)';
1274 if (defined $::_authors
&& ! defined $::users
{$author}) {
1275 die "Author: $author not defined in $::_authors file\n";
1280 sub make_log_entry
{
1281 my ($self, $rev, $parents, $ed) = @_;
1282 my $untracked = $self->get_untracked($ed);
1284 return undef if (! $ed->{new_fetch
} && ! $ed->{nr
} && ! @
$untracked);
1286 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
1287 print $un "r$rev\n" or croak
$!;
1288 print $un $_, "\n" foreach @
$untracked;
1289 my %log_entry = ( parents
=> $parents || [], revision
=> $rev,
1291 my $rp = $self->ra->rev_proplist($rev);
1292 foreach (sort keys %$rp) {
1294 if (/^svn:(author|date|log)$/) {
1295 $log_entry{$1} = $v;
1297 print $un " rev_prop: ", uri_encode
($_), ' ',
1298 uri_encode
($v), "\n";
1301 close $un or croak
$!;
1303 $log_entry{date
} = parse_svn_date
($log_entry{date
});
1304 $log_entry{author
} = check_author
($log_entry{author
});
1305 $log_entry{log} .= "\n";
1310 my ($self, $min_rev, $max_rev, @parents) = @_;
1311 my ($last_rev, $last_commit) = $self->last_rev_commit;
1312 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
1313 return if ($base > $head);
1314 $self->ra->gs_fetch_loop_common($base, $head, $self);
1318 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
1319 # TODO: enable and test optimized commits:
1320 if (0 && $rev == ($self->{last_rev
} + 1)) {
1321 $log_entry->{revision
} = $rev;
1322 $log_entry->{author
} = $author;
1323 $self->do_git_commit($log_entry, "$rev=$tree");
1325 $self->{inject_parents
} = { $rev => $tree };
1326 $self->fetch(undef, undef);
1331 my ($self, $tree) = (shift, shift);
1332 my $log_entry = ::get_commit_entry
($tree);
1333 unless ($self->{last_rev
}) {
1334 fatal
("Must have an existing revision to commit\n");
1336 my %ed_opts = ( r
=> $self->{last_rev
},
1337 log => $log_entry->{log},
1339 tree_a
=> $self->{last_commit
},
1342 $self->set_tree_cb($log_entry, $tree, @_) },
1343 svn_path
=> $self->{path
} );
1344 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1345 print "No changes\nr$self->{last_rev} = $tree\n";
1350 # Tie::File seems to be prone to offset errors if revisions get sparse,
1351 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
1352 # one of my favorite modules is out :< Next up would be one of the DBM
1353 # modules, but I'm not sure which is most portable... So I'll just
1354 # go with something that's plain-text, but still capable of
1355 # being randomly accessed. So here's my ultra-simple fixed-width
1356 # database. All records are 40 characters + "\n", so it's easy to seek
1357 # to a revision: (41 * rev) is the byte offset.
1358 # A record of 40 0s denotes an empty revision.
1359 # And yes, it's still pretty fast (faster than Tie::File).
1362 my ($self, $rev, $commit) = @_;
1363 length $commit == 40 or croak
"arg3 must be a full SHA1 hexsum\n";
1364 open my $fh, '+<', $self->{db_path
} or croak
$!;
1365 my $offset = $rev * 41;
1366 # assume that append is the common case:
1367 seek $fh, 0, 2 or croak
$!;
1369 if ($pos < $offset) {
1370 print $fh (('0' x
40),"\n") x
(($offset - $pos) / 41)
1373 seek $fh, $offset, 0 or croak
$!;
1374 print $fh $commit,"\n" or croak
$!;
1375 close $fh or croak
$!;
1379 my ($self, $rev) = @_;
1381 my $offset = $rev * 41;
1382 open my $fh, '<', $self->{db_path
} or croak
$!;
1383 if (seek $fh, $offset, 0) {
1384 $ret = readline $fh;
1387 $ret = undef if ($ret =~ /^0{40}$/);
1390 close $fh or croak
$!;
1394 sub find_rev_before
{
1395 my ($self, $rev, $eq_ok) = @_;
1396 --$rev unless $eq_ok;
1398 if (my $c = $self->rev_db_get($rev)) {
1403 return (undef, undef);
1407 my ($class, $repo_id, $ref_id, $path) = @_;
1408 unless (defined $repo_id && length $repo_id) {
1409 $repo_id = $Git::SVN
::default_repo_id
;
1411 unless (defined $ref_id && length $ref_id) {
1412 $_[2] = $ref_id = $Git::SVN
::default_ref_id
;
1414 $_[1] = $repo_id = sanitize_remote_name
($repo_id);
1415 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
1416 $_[3] = $path = '' unless (defined $path);
1418 unless (-f
"$dir/.rev_db") {
1419 open my $fh, '>>', "$dir/.rev_db" or croak
$!;
1420 close $fh or croak
$!;
1422 bless { ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
1424 db_path
=> "$dir/.rev_db", repo_id
=> $repo_id }, $class;
1429 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
1433 package Git
::SVN
::Prompt
;
1437 use vars qw
/$_no_auth_cache $_username/;
1440 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
1441 $may_save = undef if $_no_auth_cache;
1442 $default_username = $_username if defined $_username;
1443 if (defined $default_username && length $default_username) {
1444 if (defined $realm && length $realm) {
1445 print STDERR
"Authentication realm: $realm\n";
1448 $cred->username($default_username);
1450 username
($cred, $realm, $may_save, $pool);
1452 $cred->password(_read_password
("Password for '" .
1453 $cred->username . "': ", $realm));
1454 $cred->may_save($may_save);
1455 $SVN::_Core
::SVN_NO_ERROR
;
1458 sub ssl_server_trust
{
1459 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
1460 $may_save = undef if $_no_auth_cache;
1461 print STDERR
"Error validating server certificate for '$realm':\n";
1462 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
1463 print STDERR
" - The certificate is not issued by a trusted ",
1464 "authority. Use the\n",
1465 " fingerprint to validate the certificate manually!\n";
1467 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
1468 print STDERR
" - The certificate hostname does not match.\n";
1470 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
1471 print STDERR
" - The certificate is not yet valid.\n";
1473 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
1474 print STDERR
" - The certificate has expired.\n";
1476 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
1477 print STDERR
" - The certificate has an unknown error.\n";
1480 "Certificate information:\n".
1481 " - Hostname: %s\n".
1482 " - Valid: from %s until %s\n".
1484 " - Fingerprint: %s\n",
1485 map $cert_info->$_, qw(hostname valid_from valid_until
1486 issuer_dname fingerprint);
1489 print STDERR
$may_save ?
1490 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
1491 "(R)eject or accept (t)emporarily? ";
1493 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
1494 if ($choice =~ /^t$/i) {
1495 $cred->may_save(undef);
1496 } elsif ($choice =~ /^r$/i) {
1498 } elsif ($may_save && $choice =~ /^p$/i) {
1499 $cred->may_save($may_save);
1503 $cred->accepted_failures($failures);
1504 $SVN::_Core
::SVN_NO_ERROR
;
1507 sub ssl_client_cert
{
1508 my ($cred, $realm, $may_save, $pool) = @_;
1509 $may_save = undef if $_no_auth_cache;
1510 print STDERR
"Client certificate filename: ";
1512 chomp(my $filename = <STDIN
>);
1513 $cred->cert_file($filename);
1514 $cred->may_save($may_save);
1515 $SVN::_Core
::SVN_NO_ERROR
;
1518 sub ssl_client_cert_pw
{
1519 my ($cred, $realm, $may_save, $pool) = @_;
1520 $may_save = undef if $_no_auth_cache;
1521 $cred->password(_read_password
("Password: ", $realm));
1522 $cred->may_save($may_save);
1523 $SVN::_Core
::SVN_NO_ERROR
;
1527 my ($cred, $realm, $may_save, $pool) = @_;
1528 $may_save = undef if $_no_auth_cache;
1529 if (defined $realm && length $realm) {
1530 print STDERR
"Authentication realm: $realm\n";
1533 if (defined $_username) {
1534 $username = $_username;
1536 print STDERR
"Username: ";
1538 chomp($username = <STDIN
>);
1540 $cred->username($username);
1541 $cred->may_save($may_save);
1542 $SVN::_Core
::SVN_NO_ERROR
;
1545 sub _read_password
{
1546 my ($prompt, $realm) = @_;
1547 print STDERR
$prompt;
1549 require Term
::ReadKey
;
1550 Term
::ReadKey
::ReadMode
('noecho');
1552 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
1553 last if $key =~ /[\012\015]/; # \n\r
1556 Term
::ReadKey
::ReadMode
('restore');
1565 my $kill_stupid_warnings = $SVN::Node
::none
.$SVN::Node
::file
.
1566 $SVN::Node
::dir
.$SVN::Node
::unknown
.
1567 $SVN::Node
::none
.$SVN::Node
::file
.
1568 $SVN::Node
::dir
.$SVN::Node
::unknown
.
1569 $SVN::Auth
::SSL
::CNMISMATCH
.
1570 $SVN::Auth
::SSL
::NOTYETVALID
.
1571 $SVN::Auth
::SSL
::EXPIRED
.
1572 $SVN::Auth
::SSL
::UNKNOWNCA
.
1573 $SVN::Auth
::SSL
::OTHER
;
1576 package SVN
::Git
::Fetcher
;
1584 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
1586 my ($class, $git_svn) = @_;
1587 my $self = SVN
::Delta
::Editor
->new;
1588 bless $self, $class;
1589 $self->{c
} = $git_svn->{last_commit
} if exists $git_svn->{last_commit
};
1590 $self->{empty
} = {};
1591 $self->{dir_prop
} = {};
1592 $self->{file_prop
} = {};
1593 $self->{absent_dir
} = {};
1594 $self->{absent_file
} = {};
1595 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
1599 sub set_path_strip
{
1600 my ($self, $path) = @_;
1601 $self->{path_strip
} = qr/^\Q$path\E\/?
/;
1608 sub open_directory
{
1609 my ($self, $path, $pb, $rev) = @_;
1614 my ($self, $path) = @_;
1615 if ($self->{path_strip
}) {
1616 $path =~ s!$self->{path_strip}!! or
1617 die "Failed to strip path '$path' ($self->{path_strip})\n";
1623 my ($self, $path, $rev, $pb) = @_;
1625 my $gpath = $self->git_path($path);
1626 # remove entire directories.
1627 if (command
('ls-tree', $self->{c
}, '--', $gpath) =~ /^040000 tree/) {
1628 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
1630 $self->{c
}, '--', $gpath);
1634 $self->{gii
}->remove($_);
1635 print "\tD\t$_\n" unless $self->{q
};
1637 print "\tD\t$gpath/\n" unless $self->{q
};
1638 command_close_pipe
($ls, $ctx);
1639 $self->{empty
}->{$path} = 0
1641 $self->{gii
}->remove($gpath);
1642 print "\tD\t$gpath\n" unless $self->{q
};
1648 my ($self, $path, $pb, $rev) = @_;
1649 my $gpath = $self->git_path($path);
1650 my ($mode, $blob) = (command
('ls-tree', $self->{c
}, '--', $gpath)
1651 =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
1652 unless (defined $mode && defined $blob) {
1653 die "$path was not found in commit $self->{c} (r$rev)\n";
1655 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
1656 pool
=> SVN
::Pool
->new, action
=> 'M' };
1660 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
1661 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
1662 delete $self->{empty
}->{$dir};
1663 { path
=> $path, mode_a
=> 100644, mode_b
=> 100644,
1664 pool
=> SVN
::Pool
->new, action
=> 'A' };
1668 my ($self, $path, $cp_path, $cp_rev) = @_;
1669 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
1670 delete $self->{empty
}->{$dir};
1671 $self->{empty
}->{$path} = 1;
1675 sub change_dir_prop
{
1676 my ($self, $db, $prop, $value) = @_;
1677 $self->{dir_prop
}->{$db->{path
}} ||= {};
1678 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
1682 sub absent_directory
{
1683 my ($self, $path, $pb) = @_;
1684 $self->{absent_dir
}->{$pb->{path
}} ||= [];
1685 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
1690 my ($self, $path, $pb) = @_;
1691 $self->{absent_file
}->{$pb->{path
}} ||= [];
1692 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
1696 sub change_file_prop
{
1697 my ($self, $fb, $prop, $value) = @_;
1698 if ($prop eq 'svn:executable') {
1699 if ($fb->{mode_b
} != 120000) {
1700 $fb->{mode_b
} = defined $value ?
100755 : 100644;
1702 } elsif ($prop eq 'svn:special') {
1703 $fb->{mode_b
} = defined $value ?
120000 : 100644;
1705 $self->{file_prop
}->{$fb->{path
}} ||= {};
1706 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
1711 sub apply_textdelta
{
1712 my ($self, $fb, $exp) = @_;
1713 my $fh = IO
::File
->new_tmpfile;
1715 # $fh gets auto-closed() by SVN::TxDelta::apply(),
1716 # (but $base does not,) so dup() it for reading in close_file
1717 open my $dup, '<&', $fh or croak
$!;
1718 my $base = IO
::File
->new_tmpfile;
1719 $base->autoflush(1);
1721 defined (my $pid = fork) or croak
$!;
1723 open STDOUT
, '>&', $base or croak
$!;
1724 print STDOUT
'link ' if ($fb->{mode_a
} == 120000);
1725 exec qw
/git-cat-file blob/, $fb->{blob
} or croak
$!;
1731 seek $base, 0, 0 or croak
$!;
1732 my $md5 = Digest
::MD5
->new;
1733 $md5->addfile($base);
1734 my $got = $md5->hexdigest;
1735 die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
1737 " got: $got\n" if ($got ne $exp);
1740 seek $base, 0, 0 or croak
$!;
1742 $fb->{base
} = $base;
1743 [ SVN
::TxDelta
::apply
($base, $fh, undef, $fb->{path
}, $fb->{pool
}) ];
1747 my ($self, $fb, $exp) = @_;
1749 my $path = $self->git_path($fb->{path
});
1750 if (my $fh = $fb->{fh
}) {
1751 seek($fh, 0, 0) or croak
$!;
1752 my $md5 = Digest
::MD5
->new;
1754 my $got = $md5->hexdigest;
1755 die "Checksum mismatch: $path\n",
1756 "expected: $exp\n got: $got\n" if ($got ne $exp);
1757 seek($fh, 0, 0) or croak
$!;
1758 if ($fb->{mode_b
} == 120000) {
1759 read($fh, my $buf, 5) == 5 or croak
$!;
1760 $buf eq 'link ' or die "$path has mode 120000",
1761 "but is not a link\n";
1763 defined(my $pid = open my $out,'-|') or die "Can't fork: $!\n";
1765 open STDIN
, '<&', $fh or croak
$!;
1766 exec qw
/git-hash-object -w --stdin/ or croak
$!;
1768 chomp($hash = do { local $/; <$out> });
1769 close $out or croak
$!;
1770 close $fh or croak
$!;
1771 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
1772 close $fb->{base
} or croak
$!;
1774 $hash = $fb->{blob
} or die "no blob information\n";
1777 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
1778 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $self->{q
};
1784 $self->{nr
} = $self->{gii
}->{nr
};
1785 delete $self->{gii
};
1786 $self->SUPER::abort_edit
(@_);
1791 $self->{git_commit_ok
} = 1;
1792 $self->{nr
} = $self->{gii
}->{nr
};
1793 delete $self->{gii
};
1794 $self->SUPER::close_edit
(@_);
1797 package SVN
::Git
::Editor
;
1798 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
1806 my ($class, $opts) = @_;
1807 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
1808 die "$_ required!\n" unless (defined $opts->{$_});
1811 my $pool = SVN
::Pool
->new;
1812 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
1813 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
1816 # $opts->{ra} functions should not be used after this:
1817 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
1818 $opts->{editor_cb
}, $pool);
1819 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
1820 bless $self, $class;
1821 foreach (qw
/svn_path r tree_a tree_b/) {
1822 $self->{$_} = $opts->{$_};
1824 $self->{url
} = $opts->{ra
}->{url
};
1825 $self->{mods
} = $mods;
1826 $self->{types
} = $types;
1827 $self->{pool
} = $pool;
1828 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
1830 $self->{path_prefix
} = length $self->{svn_path
} ?
1831 "$self->{svn_path}/" : '';
1836 my ($tree_a, $tree_b) = @_;
1837 my @diff_tree = qw(diff-tree -z -r);
1838 if ($_cp_similarity) {
1839 push @diff_tree, "-C$_cp_similarity";
1841 push @diff_tree, '-C';
1843 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
1844 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
1845 push @diff_tree, $tree_a, $tree_b;
1846 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
1850 while (<$diff_fh>) {
1851 chomp $_; # this gets rid of the trailing "\0"
1852 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
1853 $::sha1\s
($::sha1
)\s
1854 ([MTCRAD
])\d
*$/xo
) {
1855 push @mods, { mode_a
=> $1, mode_b
=> $2,
1856 sha1_b
=> $3, chg
=> $4 };
1857 if ($4 =~ /^(?:C|R)$/) {
1862 } elsif ($state eq 'file_a') {
1863 my $x = $mods[$#mods] or croak
"Empty array\n";
1864 if ($x->{chg
} !~ /^(?:C|R)$/) {
1865 croak
"Error parsing $_, $x->{chg}\n";
1869 } elsif ($state eq 'file_b') {
1870 my $x = $mods[$#mods] or croak
"Empty array\n";
1871 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
1872 croak
"Error parsing $_, $x->{chg}\n";
1874 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
1875 croak
"Error parsing $_, $x->{chg}\n";
1880 croak
"Error parsing $_\n";
1883 command_close_pipe
($diff_fh, $ctx);
1887 sub check_diff_paths
{
1888 my ($ra, $pfx, $rev, $mods) = @_;
1890 $pfx .= '/' if length $pfx;
1892 sub type_diff_paths
{
1893 my ($ra, $types, $path, $rev) = @_;
1894 my @p = split m
#/+#, $path;
1896 unless (defined $types->{$c}) {
1897 $types->{$c} = $ra->check_path($c, $rev);
1900 $c .= '/' . shift @p;
1901 next if defined $types->{$c};
1902 $types->{$c} = $ra->check_path($c, $rev);
1906 foreach my $m (@
$mods) {
1907 foreach my $f (qw
/file_a file_b/) {
1908 next unless defined $m->{$f};
1909 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
1910 if (length $pfx.$dir && ! defined $types{$dir}) {
1911 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
1919 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
1923 my ($self, $path) = @_;
1924 $self->{path_prefix
}.(defined $path ?
$path : '');
1928 my ($self, $path) = @_;
1929 $self->{url
} . '/' . $self->repo_path($path);
1934 my $rm = $self->{rm
};
1935 delete $rm->{''}; # we never delete the url we're tracking
1938 foreach (keys %$rm) {
1939 my @d = split m
#/#, $_;
1943 $c .= '/' . shift @d;
1947 delete $rm->{$self->{svn_path
}};
1948 delete $rm->{''}; # we never delete the url we're tracking
1951 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
1956 my @dn = split m
#/#, $_;
1958 delete $rm->{join '/', @dn};
1965 command_close_pipe
($fh, $ctx);
1967 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
1968 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
1969 $self->close_directory($bat->{$d}, $p);
1970 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
1971 print "\tD+\t$d/\n" unless $::_q
;
1972 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
1977 sub open_or_add_dir
{
1978 my ($self, $full_path, $baton) = @_;
1979 my $t = $self->{types
}->{$full_path};
1981 die "$full_path not known in r$self->{r} or we have a bug!\n";
1983 if ($t == $SVN::Node
::none
) {
1984 return $self->add_directory($full_path, $baton,
1985 undef, -1, $self->{pool
});
1986 } elsif ($t == $SVN::Node
::dir
) {
1987 return $self->open_directory($full_path, $baton,
1988 $self->{r
}, $self->{pool
});
1990 print STDERR
"$full_path already exists in repository at ",
1991 "r$self->{r} and it is not a directory (",
1992 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
1997 my ($self, $path) = @_;
1998 my $bat = $self->{bat
};
1999 my $repo_path = $self->repo_path($path);
2000 return $bat->{''} unless (length $repo_path);
2001 my @p = split m
#/+#, $repo_path;
2003 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
2006 $c .= '/' . shift @p;
2007 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
2013 my ($self, $m) = @_;
2014 my ($dir, $file) = split_path
($m->{file_b
});
2015 my $pbat = $self->ensure_path($dir);
2016 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2018 print "\tA\t$m->{file_b}\n" unless $::_q
;
2019 $self->chg_file($fbat, $m);
2020 $self->close_file($fbat,undef,$self->{pool
});
2024 my ($self, $m) = @_;
2025 my ($dir, $file) = split_path
($m->{file_b
});
2026 my $pbat = $self->ensure_path($dir);
2027 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2028 $self->url_path($m->{file_a
}), $self->{r
});
2029 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2030 $self->chg_file($fbat, $m);
2031 $self->close_file($fbat,undef,$self->{pool
});
2035 my ($self, $path, $pbat) = @_;
2036 my $rpath = $self->repo_path($path);
2037 my ($dir, $file) = split_path
($rpath);
2038 $self->{rm
}->{$dir} = 1;
2039 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
2043 my ($self, $m) = @_;
2044 my ($dir, $file) = split_path
($m->{file_b
});
2045 my $pbat = $self->ensure_path($dir);
2046 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2047 $self->url_path($m->{file_a
}), $self->{r
});
2048 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2049 $self->chg_file($fbat, $m);
2050 $self->close_file($fbat,undef,$self->{pool
});
2052 ($dir, $file) = split_path
($m->{file_a
});
2053 $pbat = $self->ensure_path($dir);
2054 $self->delete_entry($m->{file_a
}, $pbat);
2058 my ($self, $m) = @_;
2059 my ($dir, $file) = split_path
($m->{file_b
});
2060 my $pbat = $self->ensure_path($dir);
2061 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
2062 $pbat,$self->{r
},$self->{pool
});
2063 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
2064 $self->chg_file($fbat, $m);
2065 $self->close_file($fbat,undef,$self->{pool
});
2068 sub T
{ shift->M(@_) }
2070 sub change_file_prop
{
2071 my ($self, $fbat, $pname, $pval) = @_;
2072 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
2076 my ($self, $fbat, $m) = @_;
2077 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
2078 $self->change_file_prop($fbat,'svn:executable','*');
2079 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
2080 $self->change_file_prop($fbat,'svn:executable',undef);
2082 my $fh = IO
::File
->new_tmpfile or croak
$!;
2083 if ($m->{mode_b
} =~ /^120/) {
2084 print $fh 'link ' or croak
$!;
2085 $self->change_file_prop($fbat,'svn:special','*');
2086 } elsif ($m->{mode_a
} =~ /^120/ && $m->{mode_b
} !~ /^120/) {
2087 $self->change_file_prop($fbat,'svn:special',undef);
2089 defined(my $pid = fork) or croak
$!;
2091 open STDOUT
, '>&', $fh or croak
$!;
2092 exec qw
/git-cat-file blob/, $m->{sha1_b
} or croak
$!;
2096 $fh->flush == 0 or croak
$!;
2097 seek $fh, 0, 0 or croak
$!;
2099 my $md5 = Digest
::MD5
->new;
2100 $md5->addfile($fh) or croak
$!;
2101 seek $fh, 0, 0 or croak
$!;
2103 my $exp = $md5->hexdigest;
2104 my $pool = SVN
::Pool
->new;
2105 my $atd = $self->apply_textdelta($fbat, undef, $pool);
2106 my $got = SVN
::TxDelta
::send_stream
($fh, @
$atd, $pool);
2107 die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
2110 close $fh or croak
$!;
2114 my ($self, $m) = @_;
2115 my ($dir, $file) = split_path
($m->{file_b
});
2116 my $pbat = $self->ensure_path($dir);
2117 print "\tD\t$m->{file_b}\n" unless $::_q
;
2118 $self->delete_entry($m->{file_b
}, $pbat);
2123 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
2124 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
2125 $self->close_directory($bat->{$_}, $p);
2127 $self->SUPER::close_edit
($p);
2133 $self->SUPER::abort_edit
($self->{pool
});
2138 $self->SUPER::DESTROY
(@_);
2139 $self->{pool
}->clear;
2142 # this drives the editor
2145 my $mods = $self->{mods
};
2146 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
2147 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
2149 if (defined $o{$f}) {
2152 fatal
("Invalid change type: $f\n");
2155 $self->rmdirs if $_rmdir;
2161 return scalar @
$mods;
2164 package Git
::SVN
::Ra
;
2165 use vars qw
/@ISA $config_dir/;
2168 my ($can_do_switch);
2172 # enforce temporary pool usage for some simple functions
2174 foreach (qw
/get_latest_revnum rev_proplist get_file
2175 check_path get_dir get_uuid get_repos_root
/) {
2178 my \$pool = SVN::Pool->new;
2179 my \@ret = \$self->SUPER::$_(\@_,\$pool);
2181 wantarray ? \@ret : \$ret[0]; }\n";
2187 my ($class, $url) = @_;
2189 return $RA if ($RA && $RA->{url
} eq $url);
2191 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
2192 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
([
2193 SVN
::Client
::get_simple_provider
(),
2194 SVN
::Client
::get_ssl_server_trust_file_provider
(),
2195 SVN
::Client
::get_simple_prompt_provider
(
2196 \
&Git
::SVN
::Prompt
::simple
, 2),
2197 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
2198 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
2199 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
2200 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
2201 SVN
::Client
::get_username_provider
(),
2202 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
2203 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
2204 SVN
::Client
::get_username_prompt_provider
(
2205 \
&Git
::SVN
::Prompt
::username
, 2),
2207 my $config = SVN
::Core
::config_get_config
($config_dir);
2208 my $self = SVN
::Ra
->new(url
=> $url, auth
=> $baton,
2210 pool
=> SVN
::Pool
->new,
2211 auth_provider_callbacks
=> $callbacks);
2212 $self->{svn_path
} = $url;
2213 $self->{repos_root
} = $self->get_repos_root;
2214 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E/*##;
2215 $RA = bless $self, $class;
2219 # do not call the real DESTROY since we store ourselves in $RA
2223 my ($self, @args) = @_;
2224 my $pool = SVN
::Pool
->new;
2225 splice(@args, 3, 1) if ($SVN::Core
::VERSION
le '1.2.0');
2226 my $ret = $self->SUPER::get_log
(@args, $pool);
2231 sub get_commit_editor
{
2232 my ($self, $log, $cb, $pool) = @_;
2233 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
2234 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
2239 $self->{uuid
} ||= $self->get_uuid;
2243 my ($self, $rev_a, $rev_b, $path, $recurse, $editor) = @_;
2244 my $pool = SVN
::Pool
->new;
2245 $editor->set_path_strip($path);
2246 my (@pc) = split m
#/#, $path;
2247 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
2248 $recurse, $editor, $pool);
2249 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2251 # Since we can't rely on svn_ra_reparent being available, we'll
2252 # just have to do some magic with set_path to make it so
2253 # we only want a partial path.
2255 my $final = join('/', @pc);
2257 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
2258 $sp .= '/' if length $sp;
2261 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
2263 my $new = ($rev_a == $rev_b);
2264 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
2266 $reporter->finish_report($pool);
2268 $editor->{git_commit_ok
};
2271 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
2272 # svn_ra_reparent didn't work before 1.4)
2274 my ($self, $rev_a, $rev_b, $path, $recurse, $url_b, $editor) = @_;
2275 my $pool = SVN
::Pool
->new;
2277 my $full_url = $self->{url
};
2278 my $old_url = $full_url;
2279 $full_url .= "/$path" if length $path;
2280 my ($ra, $reparented);
2281 if ($old_url ne $full_url) {
2282 if ($old_url !~ m
#^svn(\+ssh)?://#) {
2283 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url,
2285 $self->{url
} = $full_url;
2288 $ra = Git
::SVN
::Ra
->new($full_url);
2292 my $reporter = $ra->do_switch($rev_b, '',
2293 $recurse, $url_b, $editor, $pool);
2294 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2295 $reporter->set_path('', $rev_a, 0, @lock, $pool);
2296 $reporter->finish_report($pool);
2299 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
2300 $self->{url
} = $old_url;
2304 $editor->{git_commit_ok
};
2307 sub gs_fetch_loop_common
{
2308 my ($self, $base, $head, @gs) = @_;
2310 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
2311 my @paths = @gs == 1 ?
($gs[0]->{path
}) : ('');
2312 foreach my $gs (@gs) {
2313 if (my $last_commit = $gs->last_commit) {
2314 $gs->assert_index_clean($last_commit);
2316 $gs->{path_regex
} = qr/^\/\Q
$gs->{path
}\E\
/?/;
2321 my $err_handler = $SVN::Error
::handler
;
2322 $SVN::Error
::handler
= sub {
2324 skip_unknown_revs
($err);
2326 $self->get_log(\
@paths, $min, $max, 0, 1, 1,
2327 sub { push @revs, [ dup_changed_paths
($_[0]), $_[1] ]; });
2328 $SVN::Error
::handler
= $err_handler;
2330 if (! @revs && $err && $max >= $head) {
2331 print STDERR
"Branch probably deleted:\n ",
2332 $err->expanded_message,
2333 "\nWill attempt to follow revisions ",
2335 "committed before the deletion\n";
2336 @revs = map { [ undef, $_ ] } ($min .. $max);
2339 my ($paths, $r) = @
$_;
2340 foreach my $gs (@gs) {
2342 grep /$gs->{path_regex}/, keys %$paths
2345 next if defined $gs->rev_db_get($r);
2346 if (my $log_entry = $gs->do_fetch($paths, $r)) {
2347 $gs->do_git_commit($log_entry);
2351 last if $max >= $head;
2354 $max = $head if ($max > $head);
2360 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
2361 my $url = $self->{repos_root
};
2362 my @components = split(m!/!, $self->{svn_path
});
2365 $url .= "/$c" if length $c;
2366 eval { (ref $self)->new($url)->get_latest_revnum };
2367 } while ($@
&& ($c = shift @components));
2373 unless (defined $can_do_switch) {
2374 my $pool = SVN
::Pool
->new;
2376 $self->do_switch(1, '', 0, $self->{url
},
2377 SVN
::Delta
::Editor
->new, $pool);
2382 $rep->abort_report($pool);
2390 sub skip_unknown_revs
{
2392 my $errno = $err->apr_err();
2393 # Maybe the branch we're tracking didn't
2394 # exist when the repo started, so it's
2395 # not an error if it doesn't, just continue
2397 # Wonderfully consistent library, eh?
2398 # 160013 - svn:// and file://
2399 # 175002 - http(s)://
2400 # 175007 - http(s):// (this repo required authorization, too...)
2401 # More codes may be discovered later...
2402 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
2405 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
2408 # svn_log_changed_path_t objects passed to get_log are likely to be
2409 # overwritten even if only the refs are copied to an external variable,
2410 # so we should dup the structures in their entirety. Using an externally
2411 # passed pool (instead of our temporary and quickly cleared pool in
2412 # Git::SVN::Ra) does not help matters at all...
2413 sub dup_changed_paths
{
2415 return undef unless $paths;
2417 foreach my $p (keys %$paths) {
2418 my $i = $paths->{$p};
2419 my %s = map { $_ => $i->$_ }
2420 qw
/copyfrom_path copyfrom_rev action/;
2426 package Git
::SVN
::Log
;
2429 use POSIX qw
/strftime/;
2430 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
2431 %rusers $show_commit $incremental/;
2436 return 1 if defined $c->{r
};
2437 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
2438 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
2439 my @log = command
(qw
/cat-file commit/, $c->{c
});
2440 shift @log while ($log[0] ne "\n");
2442 @
{$c->{l
}} = grep !/^git-svn-id: /, @log;
2444 (undef, $c->{r
}, undef) = ::extract_metadata
(
2445 (grep(/^git-svn-id: /, @log))[-1]);
2447 return defined $c->{r
};
2453 $dcvar = 'color.diff';
2454 $dc = `git-config --get $dcvar`;
2456 # nothing at all; fallback to "diff.color"
2457 $dcvar = 'diff.color';
2458 $dc = `git-config --get $dcvar`;
2461 if ($dc eq 'auto') {
2463 $pc = `git-config --get color.pager`;
2465 # does not have it -- fallback to pager.color
2466 $pc = `git-config --bool --get pager.color`;
2469 $pc = `git-config --bool --get color.pager`;
2475 if (-t
*STDOUT
|| (defined $pager && $pc eq 'true')) {
2476 return ($ENV{TERM
} && $ENV{TERM
} ne 'dumb');
2480 return 0 if $dc eq 'never';
2481 return 1 if $dc eq 'always';
2482 chomp($dc = `git-config --bool --get $dcvar`);
2483 return ($dc eq 'true');
2486 sub git_svn_log_cmd
{
2487 my ($r_min, $r_max) = @_;
2488 my $gs = Git
::SVN
->_new;
2489 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
2491 push @cmd, '-r' unless $non_recursive;
2492 push @cmd, qw
/--raw --name-status/ if $verbose;
2493 push @cmd, '--color' if log_use_color
();
2494 return @cmd unless defined $r_max;
2495 if ($r_max == $r_min) {
2496 push @cmd, '--max-count=1';
2497 if (my $c = $gs->rev_db_get($r_max)) {
2501 my ($c_min, $c_max);
2502 $c_max = $gs->rev_db_get($r_max);
2503 $c_min = $gs->rev_db_get($r_min);
2504 if (defined $c_min && defined $c_max) {
2505 if ($r_max > $r_max) {
2506 push @cmd, "$c_min..$c_max";
2508 push @cmd, "$c_max..$c_min";
2510 } elsif ($r_max > $r_min) {
2519 # adapted from pager.c
2521 $pager ||= $ENV{GIT_PAGER
} || $ENV{PAGER
};
2522 if (!defined $pager) {
2524 } elsif (length $pager == 0 || $pager eq 'cat') {
2530 return unless -t
*STDOUT
;
2531 pipe my $rfd, my $wfd or return;
2532 defined(my $pid = fork) or ::fatal
"Can't fork: $!\n";
2534 open STDOUT
, '>&', $wfd or
2535 ::fatal
"Can't redirect to stdout: $!\n";
2538 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!\n";
2539 $ENV{LESS
} ||= 'FRSX';
2540 exec $pager or ::fatal
"Can't run pager: $! ($pager)\n";
2543 sub tz_to_s_offset
{
2546 return ($1 * 60) + ($tz * 3600);
2549 sub get_author_info
{
2550 my ($dest, $author, $t, $tz) = @_;
2551 $author =~ s/(?:^\s*|\s*$)//g;
2552 $dest->{a_raw
} = $author;
2555 $au = $rusers{$author} || undef;
2558 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
2563 # Date::Parse isn't in the standard Perl distro :(
2564 if ($tz =~ s/^\+//) {
2565 $t += tz_to_s_offset
($tz);
2566 } elsif ($tz =~ s/^\-//) {
2567 $t -= tz_to_s_offset
($tz);
2569 $dest->{t_utc
} = $t;
2572 sub process_commit
{
2573 my ($c, $r_min, $r_max, $defer) = @_;
2574 if (defined $r_min && defined $r_max) {
2575 if ($r_min == $c->{r
} && $r_min == $r_max) {
2579 return 1 if $r_min == $r_max;
2580 if ($r_min < $r_max) {
2581 # we need to reverse the print order
2582 return 0 if (defined $limit && --$limit < 0);
2586 if ($r_min != $r_max) {
2587 return 1 if ($r_min < $c->{r
});
2588 return 1 if ($r_max > $c->{r
});
2591 return 0 if (defined $limit && --$limit < 0);
2600 if (my $l = $c->{l
}) {
2601 while ($l->[0] =~ /^\s*$/) { shift @
$l }
2604 $l_fmt ||= 'A' . length($c->{r
});
2605 print 'r',pack($l_fmt, $c->{r
}),' | ';
2606 print "$c->{c} | " if $show_commit;
2609 show_commit_normal
($c);
2613 sub show_commit_changed_paths
{
2615 return unless $c->{changed
};
2616 print "Changed paths:\n", @
{$c->{changed
}};
2619 sub show_commit_normal
{
2621 print '-' x72
, "\nr$c->{r} | ";
2622 print "$c->{c} | " if $show_commit;
2623 print "$c->{a} | ", strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
2624 localtime($c->{t_utc
})), ' | ';
2627 if (my $l = $c->{l
}) {
2628 while ($l->[$#$l] eq "\n" && $#$l > 0
2629 && $l->[($#$l - 1)] eq "\n") {
2632 $nr_line = scalar @
$l;
2634 print "1 line\n\n\n";
2636 if ($nr_line == 1) {
2637 $nr_line = '1 line';
2639 $nr_line .= ' lines';
2641 print $nr_line, "\n";
2642 show_commit_changed_paths
($c);
2644 print $_ foreach @
$l;
2648 show_commit_changed_paths
($c);
2652 foreach my $x (qw
/raw diff/) {
2655 print $_ foreach @
{$c->{$x}}
2662 my ($r_min, $r_max);
2663 my $r_last = -1; # prevent dupes
2669 if (defined $::_revision
) {
2670 if ($::_revision
=~ /^(\d+):(\d+)$/) {
2671 ($r_min, $r_max) = ($1, $2);
2672 } elsif ($::_revision
=~ /^\d+$/) {
2673 $r_min = $r_max = $::_revision
;
2675 ::fatal
"-r$::_revision is not supported, use ",
2676 "standard \'git log\' arguments instead\n";
2681 @args = (git_svn_log_cmd
($r_min, $r_max), @args);
2682 my $log = command_output_pipe
(@args);
2685 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
2687 if (/^${esc_color}commit ($::sha1_short)/o) {
2689 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
2691 process_commit
($c, $r_min, $r_max, \
@k) or
2696 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
2697 get_author_info
($c, $1, $2, $3);
2698 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
2700 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
2701 push @
{$c->{raw
}}, $_;
2702 } elsif (/^${esc_color}[ACRMDT]\t/) {
2703 # we could add $SVN->{svn_path} here, but that requires
2704 # remote access at the moment (repo_path_split)...
2705 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
2706 push @
{$c->{changed
}}, $_;
2707 } elsif (/^${esc_color}diff /o) {
2709 push @
{$c->{diff
}}, $_;
2711 push @
{$c->{diff
}}, $_;
2712 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
2713 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
2714 } elsif (s/^${esc_color} //o) {
2715 push @
{$c->{l
}}, $_;
2718 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
2720 process_commit
($c, $r_min, $r_max, \
@k);
2726 process_commit
($_, $r_min, $r_max) foreach reverse @k;
2730 print '-' x72
,"\n" unless $incremental || $oneline;
2733 package Git
::SVN
::Migration
;
2734 # these version numbers do NOT correspond to actual version numbers
2735 # of git nor git-svn. They are just relative.
2737 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
2739 # v1 layout: .git/$id/info/url, refs/remotes/$id
2741 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
2743 # v3 layout: .git/svn/$id, refs/remotes/$id
2744 # - info/url may remain for backwards compatibility
2745 # - this is what we migrate up to this layout automatically,
2746 # - this will be used by git svn init on single branches
2748 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
2749 # - this is only created for newly multi-init-ed
2750 # repositories. Similar in spirit to the
2751 # --use-separate-remotes option in git-clone (now default)
2752 # - we do not automatically migrate to this (following
2753 # the example set by core git)
2757 use File
::Path qw
/mkpath/;
2758 use File
::Basename qw
/dirname basename/;
2759 use vars qw
/$_minimize/;
2761 sub migrate_from_v0
{
2762 my $git_dir = $ENV{GIT_DIR
};
2763 return undef unless -d
$git_dir;
2764 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
2768 my ($id, $orig_ref) = ($_, $_);
2769 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
2770 next unless -f
"$git_dir/$id/info/url";
2771 my $new_ref = "refs/remotes/$id";
2772 if (::verify_ref
("$new_ref^0")) {
2773 print STDERR
"W: $orig_ref is probably an old ",
2774 "branch used by an ancient version of ",
2776 "However, $new_ref also exists.\n",
2777 "We will not be able ",
2778 "to use this branch until this ",
2779 "ambiguity is resolved.\n";
2782 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
2783 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
2784 command_noisy
('update-ref', $new_ref, $orig_ref);
2785 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
2788 command_close_pipe
($fh, $ctx);
2789 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
2793 sub migrate_from_v1
{
2794 my $git_dir = $ENV{GIT_DIR
};
2796 return $migrated unless -d
$git_dir;
2797 my $svn_dir = "$git_dir/svn";
2799 # just in case somebody used 'svn' as their $id at some point...
2800 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
2802 print STDERR
"Migrating from a git-svn v1 layout...\n";
2804 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
2805 "$svn_dir\n\t(required for this version ",
2806 "($::VERSION) of git-svn) does not. exist\n";
2807 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
2810 next unless $x =~ s
#^refs/remotes/##;
2812 next unless -f
"$git_dir/$x/info/url";
2813 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
2815 my $dn = dirname
("$git_dir/svn/$x");
2816 mkpath
([$dn]) unless -d
$dn;
2817 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
2818 mkpath
(["$git_dir/svn/svn"]);
2819 print STDERR
" - $git_dir/$x/info => ",
2820 "$git_dir/svn/$x/info\n";
2821 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
2823 # don't worry too much about these, they probably
2824 # don't exist with repos this old (save for index,
2825 # and we can easily regenerate that)
2826 foreach my $f (qw
/unhandled.log index .rev_db/) {
2827 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
2830 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
2831 rename "$git_dir/$x", "$git_dir/svn/$x" or
2836 command_close_pipe
($fh, $ctx);
2837 print STDERR
"Done migrating from a git-svn v1 layout\n";
2842 my ($l_map, $pfx, $path) = @_;
2844 foreach (<$path/*>) {
2845 if (-r
"$_/info/url") {
2846 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
2847 my $ref_id = $pfx . basename
$_;
2848 my $url = ::file_to_s
("$_/info/url");
2849 $l_map->{$ref_id} = $url;
2856 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
2857 read_old_urls
($l_map, $x, $_);
2861 sub migrate_from_v2
{
2862 my @cfg = command
(qw
/config -l/);
2863 return if grep /^svn-remote\..+\.url=/, @cfg;
2865 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
2868 foreach my $ref_id (sort keys %l_map) {
2869 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
2875 sub minimize_connections
{
2876 my $r = Git
::SVN
::read_all_remotes
();
2878 my $root_repos = {};
2879 foreach my $repo_id (keys %$r) {
2880 my $url = $r->{$repo_id}->{url
} or next;
2881 my $fetch = $r->{$repo_id}->{fetch
} or next;
2882 my $ra = Git
::SVN
::Ra
->new($url);
2884 # skip existing cases where we already connect to the root
2885 if (($ra->{url
} eq $ra->{repos_root
}) ||
2886 (Git
::SVN
::sanitize_remote_name
($ra->{repos_root
}) eq
2888 $root_repos->{$ra->{url
}} = $repo_id;
2892 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
2893 my $root_path = $ra->{url
};
2894 $root_path =~ s
#^\Q$ra->{repos_root}\E/*##;
2895 foreach my $path (keys %$fetch) {
2896 my $ref_id = $fetch->{$path};
2897 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
2899 # make sure we can read when connecting to
2900 # a higher level of a repository
2901 my ($last_rev, undef) = $gs->last_rev_commit;
2902 if (!defined $last_rev) {
2904 $root_ra->get_latest_revnum;
2908 my $new = $root_path;
2909 $new .= length $path ?
"/$path" : '';
2911 $root_ra->get_log([$new], $last_rev, $last_rev,
2915 $new_urls->{$ra->{repos_root
}}->{$new} =
2916 { ref_id
=> $ref_id,
2917 old_repo_id
=> $repo_id,
2918 old_path
=> $path };
2923 foreach my $url (keys %$new_urls) {
2924 # see if we can re-use an existing [svn-remote "repo_id"]
2925 # instead of creating a(n ugly) new section:
2926 my $repo_id = $root_repos->{$url} ||
2927 Git
::SVN
::sanitize_remote_name
($url);
2929 my $fetch = $new_urls->{$url};
2930 foreach my $path (keys %$fetch) {
2931 my $x = $fetch->{$path};
2932 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
2933 my $pfx = "svn-remote.$x->{old_repo_id}";
2935 my $old_fetch = quotemeta("$x->{old_path}:".
2936 "refs/remotes/$x->{ref_id}");
2937 command_noisy
(qw
/config --unset/,
2938 "$pfx.fetch", '^'. $old_fetch . '$');
2939 delete $r->{$x->{old_repo_id
}}->
2940 {fetch
}->{$x->{old_path
}};
2941 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
2942 command_noisy
(qw
/config --unset/,
2944 push @emptied, $x->{old_repo_id
}
2949 my $file = $ENV{GIT_CONFIG
} || $ENV{GIT_CONFIG_LOCAL
} ||
2950 "$ENV{GIT_DIR}/config";
2952 The following [svn-remote] sections in your config file ($file) are empty
2953 and can be safely removed:
2955 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
2959 sub migration_check
{
2963 minimize_connections
() if $_minimize;
2966 package Git
::IndexInfo
;
2969 use Git qw
/command_input_pipe command_close_pipe/;
2973 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
2974 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
2978 my ($self, $path) = @_;
2979 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
2980 return ++$self->{nr
};
2986 my ($self, $mode, $hash, $path) = @_;
2987 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
2988 return ++$self->{nr
};
2995 command_close_pipe
($self->{gui
}, $self->{ctx
});
3002 $log_entry hashref as returned by libsvn_log_entry
()
3004 log => 'whitespace-formatted log entry
3005 ', # trailing newline is preserved
3006 revision
=> '8', # integer
3007 date
=> '2004-02-24T17:01:44.108345Z', # commit date
3008 author
=> 'committer name'
3012 # this is generated by generate_diff();
3013 @mods = array of diff
-index line hashes
, each element represents one line
3014 of diff
-index output
3016 diff
-index line
($m hash
)
3018 mode_a
=> first column of diff
-index output
, no leading
':',
3019 mode_b
=> second column of diff
-index output
,
3020 sha1_b
=> sha1sum of the final blob
,
3021 chg
=> change type
[MCRADT
],
3022 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
3023 file_b
=> new
/current file name of a file
(any chg
)
3027 # retval of read_url_paths{,_all}();
3029 # repository root url
3030 'https://svn.musicpd.org' => {
3031 # repository path # GIT_SVN_ID
3032 'mpd/trunk' => 'trunk',
3033 'mpd/tags/0.11.5' => 'tags/0.11.5',
3038 I don
't trust the each() function on unless I created %hash myself
3039 because the internal iterator may not have started at base.