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
= 'svn';
14 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
15 $Git::SVN
::Ra
::_log_window_size
= 100;
17 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
19 $| = 1; # unbuffer STDOUT
21 sub fatal
(@
) { print STDERR
@_; exit 1 }
22 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
25 if ($SVN::Core
::VERSION
lt '1.1.0') {
26 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n";
28 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
29 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
30 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
33 use File
::Basename qw
/dirname basename/;
34 use File
::Path qw
/mkpath/;
35 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
41 foreach (qw
/command command_oneline command_noisy command_output_pipe
42 command_input_pipe command_close_pipe
/) {
43 $s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ".
44 "*Git::SVN::Migration::$_ = ".
45 "*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; ";
52 $sha1 = qr/[a-f\d]{40}/;
53 $sha1_short = qr/[a-f\d]{4,40}/;
54 my ($_stdin, $_help, $_edit,
57 $_version, $_fetch_all,
58 $_merge, $_strategy, $_dry_run,
59 $_prefix, $_no_checkout);
60 $Git::SVN
::_follow_parent
= 1;
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 'noMetadata' => \
$Git::SVN
::_no_metadata
,
68 'useSvmProps' => \
$Git::SVN
::_use_svm_props
,
69 'log-window-size=i' => \
$Git::SVN
::Ra
::_log_window_size
,
70 'no-checkout' => \
$_no_checkout,
72 'repack-flags|repack-args|repack-opts=s' =>
73 \
$Git::SVN
::_repack_flags
,
76 my ($_trunk, $_tags, $_branches);
77 my %init_opts = ( 'template=s' => \
$_template, 'shared:s' => \
$_shared,
78 'trunk|T=s' => \
$_trunk, 'tags|t=s' => \
$_tags,
79 'branches|b=s' => \
$_branches, 'prefix=s' => \
$_prefix,
81 my %cmt_opts = ( 'edit|e' => \
$_edit,
82 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
83 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
84 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
85 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
89 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
90 { 'revision|r=s' => \
$_revision,
91 'all|a' => \
$_fetch_all,
93 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
94 " (requires URL argument)",
96 'multi-init' => [ \
&cmd_multi_init
,
97 "Deprecated alias for ".
98 "'$0 init -T<trunk> -b<branches> -t<tags>'",
100 dcommit
=> [ \
&cmd_dcommit
,
101 'Commit several diffs to merge with upstream',
102 { 'merge|m|M' => \
$_merge,
103 'strategy|s=s' => \
$_strategy,
104 'dry-run|n' => \
$_dry_run,
105 %cmt_opts, %fc_opts } ],
106 'set-tree' => [ \
&cmd_set_tree
,
107 "Set an SVN repository to a git tree-ish",
108 { 'stdin|' => \
$_stdin, %cmt_opts, %fc_opts, } ],
109 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
110 { 'revision|r=i' => \
$_revision } ],
111 'multi-fetch' => [ \
&cmd_multi_fetch
,
112 "Deprecated alias for $0 fetch --all",
113 { 'revision|r=s' => \
$_revision, %fc_opts } ],
114 'migrate' => [ sub { },
115 # no-op, we automatically run this anyways,
116 'Migrate configuration/metadata/layout from
117 previous versions of git-svn',
118 { 'minimize' => \
$Git::SVN
::Migration
::_minimize
,
120 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
121 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
122 'revision|r=s' => \
$_revision,
123 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
124 'incremental' => \
$Git::SVN
::Log
::incremental
,
125 'oneline' => \
$Git::SVN
::Log
::oneline
,
126 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
127 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
128 'authors-file|A=s' => \
$_authors,
129 'color' => \
$Git::SVN
::Log
::color
,
130 'pager=s' => \
$Git::SVN
::Log
::pager
,
132 'commit-diff' => [ \
&cmd_commit_diff
,
133 'Commit a diff between two trees',
134 { 'message|m=s' => \
$_message,
135 'file|F=s' => \
$_file,
136 'revision|r=s' => \
$_revision,
141 for (my $i = 0; $i < @ARGV; $i++) {
142 if (defined $cmd{$ARGV[$i]}) {
149 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
151 read_repo_config
(\
%opts);
152 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help, 'version|V' => \
$_version,
153 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
154 'id|i=s' => \
$Git::SVN
::default_ref_id
,
155 'svn-remote|remote|R=s' => \
$Git::SVN
::default_repo_id
);
156 exit 1 if (!$rv && $cmd ne 'log');
159 version
() if $_version;
160 usage
(1) unless defined $cmd;
161 load_authors
() if $_authors;
162 unless ($cmd =~ /^(?:init|multi-init|commit-diff)$/) {
163 Git
::SVN
::Migration
::migration_check
();
165 Git
::SVN
::init_vars
();
167 Git
::SVN
::verify_remotes_sanity
();
168 $cmd{$cmd}->[0]->(@ARGV);
171 post_fetch_checkout
();
174 ####################### primary functions ######################
176 my $exit = shift || 0;
177 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
179 git
-svn
- bidirectional operations between a single Subversion tree
and git
180 Usage
: $0 <command
> [options
] [arguments
]\n
182 print $fd "Available commands:\n" unless $cmd;
184 foreach (sort keys %cmd) {
185 next if $cmd && $cmd ne $_;
186 next if /^multi-/; # don't show deprecated commands
187 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
188 foreach (keys %{$cmd{$_}->[2]}) {
189 # prints out arguments as they should be passed:
190 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
191 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
193 split /\|/,$_)," $x\n";
197 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
198 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
199 one git repository and want to keep them separate. See git-svn(1) for more
206 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
211 unless (-d $ENV{GIT_DIR}) {
212 my @init_db = ('init
');
213 push @init_db, "--template=$_template" if defined $_template;
214 if (defined $_shared) {
215 if ($_shared =~ /[a-z]/) {
216 push @init_db, "--shared=$_shared";
218 push @init_db, "--shared";
221 command_noisy(@init_db);
226 my $repo_path = shift or return;
227 mkpath([$repo_path]) unless -d $repo_path;
228 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
229 $ENV{GIT_DIR} = $repo_path . "/.git
";
233 if (defined $_trunk || defined $_branches || defined $_tags) {
234 return cmd_multi_init(@_);
236 my $url = shift or die "SVN repository location required
",
237 "as a command
-line argument
\n";
241 Git::SVN->init($url);
245 if (grep /^\d+=./, @_) {
246 die "'<rev>=<commit>' fetch arguments are
",
247 "no longer supported
.\n";
251 die "Usage
: $0 fetch
[--all
|-a
] [svn
-remote
]\n";
253 $remote ||= $Git::SVN::default_repo_id;
257 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
263 if ($_stdin || !@commits) {
264 print "Reading from stdin
...\n";
267 if (/\b($sha1_short)\b/o) {
268 unshift @commits, $1;
273 foreach my $c (@commits) {
274 my @tmp = command('rev-parse',$c);
275 if (scalar @tmp == 1) {
277 } elsif (scalar @tmp > 1) {
278 push @revs, reverse(command('rev-list',@tmp));
280 fatal "Failed to rev
-parse
$c\n";
283 my $gs = Git::SVN->new;
284 my ($r_last, $cmt_last) = $gs->last_rev_commit;
286 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
287 fatal "There are new revisions that were fetched
",
288 "and need to be merged
(or acknowledged
) ",
289 "before committing
.\nlast rev
: $r_last\n",
290 " current
: $gs->{last_rev
}\n";
292 $gs->set_tree($_) foreach @revs;
293 print "Done committing
",scalar @revs," revisions to SVN
\n";
299 my ($url, $rev, $uuid);
300 my ($fh, $ctx) = command_output_pipe('rev-list', $head);
306 ($url, $rev, $uuid) = cmt_metadata($c);
307 last if (defined $url && defined $rev && defined $uuid);
310 close $fh; # most likely breaking the pipe
311 unless (defined $url && defined $rev && defined $uuid) {
312 die "Unable to determine upstream SVN information from
",
313 "$head history
:\n $ctx\n";
315 my $gs = Git::SVN->find_by_url($url);
317 foreach my $d (@refs) {
318 if (!verify_ref("$d~1")) {
320 "has
no parent commit
, and therefore
",
321 "nothing to diff against
.\n",
322 "You should be working from a repository
",
323 "originally created by git
-svn
\n";
325 unless (defined $last_rev) {
326 (undef, $last_rev, undef) = cmt_metadata("$d~1");
327 unless (defined $last_rev) {
328 fatal "Unable to extract revision information
",
329 "from commit
$d~1\n";
333 print "diff
-tree
$d~1 $d\n";
335 my %ed_opts = ( r => $last_rev,
336 log => get_commit_entry($d)->{log},
337 ra => Git::SVN::Ra->new($url),
341 print "Committed r
$_[0]\n";
342 $last_rev = $_[0]; },
344 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
345 print "No changes
\n$d~1 == $d\n";
351 warn "Could
not determine fetch information
for $url\n",
352 "Will
not attempt to fetch
and rebase commits
.\n",
353 "This probably means you have useSvmProps
and should
\n",
354 "now resync your SVN
::Mirror repository
.\n";
358 # we always want to rebase against the current HEAD, not any
359 # head that was passed to us
360 my @diff = command('diff-tree', 'HEAD', $gs->refname, '--');
363 @finish = qw/rebase/;
364 push @finish, qw/--merge/ if $_merge;
365 push @finish, "--strategy
=$_strategy" if $_strategy;
366 print STDERR "W
: HEAD
and ", $gs->refname, " differ
, ",
367 "using
@finish:\n", "@diff";
369 print "No changes between current HEAD
and ",
370 $gs->refname, "\nResetting to the latest
",
372 @finish = qw/reset --mixed/;
374 command_noisy(@finish, $gs->refname);
377 sub cmd_show_ignore {
378 my $gs = Git::SVN->new;
379 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
380 $gs->traverse_ignore(\*STDOUT, '', $r);
385 unless (defined $_trunk || defined $_branches || defined $_tags) {
389 $_prefix = '' unless defined $_prefix;
394 if (defined $_trunk) {
395 my $trunk_ref = $_prefix . 'trunk';
396 # try both old-style and new-style lookups:
397 my $gs_trunk = eval { Git::SVN->new($trunk_ref) };
399 my ($trunk_url, $trunk_path) =
400 complete_svn_url($url, $_trunk);
401 $gs_trunk = Git::SVN->init($trunk_url, $trunk_path,
405 return unless defined $_branches || defined $_tags;
406 my $ra = $url ? Git::SVN::Ra->new($url) : undef;
407 complete_url_ls_init($ra, $_branches, '--branches/-b', $_prefix);
408 complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
411 sub cmd_multi_fetch {
412 my $remotes = Git::SVN::read_all_remotes();
413 foreach my $repo_id (sort keys %$remotes) {
414 if ($remotes->{$repo_id}->{url}) {
415 Git::SVN::fetch_all($repo_id, $remotes);
420 # this command is special because it requires no metadata
421 sub cmd_commit_diff {
422 my ($ta, $tb, $url) = @_;
423 my $usage = "Usage
: $0 commit
-diff
-r
<revision
> ".
424 "<tree
-ish
> <tree
-ish
> [<URL
>]\n";
425 fatal($usage) if (!defined $ta || !defined $tb);
428 my $gs = eval { Git::SVN->new };
430 fatal("Needed URL
or usable git
-svn
--id
in ",
431 "the command
-line
\n", $usage);
434 $svn_path = $gs->{path};
436 unless (defined $_revision) {
437 fatal("-r
|--revision is a required argument
\n", $usage);
439 if (defined $_message && defined $_file) {
440 fatal("Both
--message
/-m and --file/-F specified
",
441 "for the commit message
.\n",
442 "I have
no idea what you mean
\n");
444 if (defined $_file) {
445 $_message = file_to_s($_file);
447 $_message ||= get_commit_entry($tb)->{log};
449 my $ra ||= Git::SVN::Ra->new($url);
450 $svn_path ||= $ra->{svn_path};
453 $r = $ra->get_latest_revnum;
454 } elsif ($r !~ /^\d+$/) {
455 die "revision argument
: $r not understood by git
-svn
\n";
457 my %ed_opts = ( r => $r,
462 editor_cb => sub { print "Committed r
$_[0]\n" },
463 svn_path => $svn_path );
464 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
465 print "No changes
\n$ta == $tb\n";
469 ########################### utility functions #########################
471 sub post_fetch_checkout {
472 return if $_no_checkout;
473 my $gs = $Git::SVN::_head or return;
474 return if verify_ref('refs/heads/master^0');
476 my $valid_head = verify_ref('HEAD^0');
477 command_noisy(qw(update-ref refs/heads/master), $gs->refname);
478 return if ($valid_head || !verify_ref
('HEAD^0'));
480 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
481 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
484 chomp(my $bare = `git config --bool --get core.bare`);
485 return if $bare eq 'true';
486 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
487 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
488 print STDERR
"Checked out HEAD:\n ",
489 $gs->full_url, " r", $gs->last_rev, "\n";
492 sub complete_svn_url
{
493 my ($url, $path) = @_;
495 if ($path !~ m
#^[a-z\+]+://#) {
496 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
497 fatal
("E: '$path' is not a complete URL ",
498 "and a separate URL is not specified\n");
500 return ($url, $path);
505 sub complete_url_ls_init
{
506 my ($ra, $repo_path, $switch, $pfx) = @_;
507 unless ($repo_path) {
508 print STDERR
"W: $switch not specified\n";
511 $repo_path =~ s
#/+$##;
512 if ($repo_path =~ m
#^[a-z\+]+://#) {
513 $ra = Git
::SVN
::Ra
->new($repo_path);
516 $repo_path =~ s
#^/+##;
518 fatal
("E: '$repo_path' is not a complete URL ",
519 "and a separate URL is not specified\n");
522 my $url = $ra->{url
};
523 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
524 my $k = "svn-remote.$gs->{repo_id}.url";
525 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
526 if ($orig_url && ($orig_url ne $gs->{url
})) {
527 die "$k already set: $orig_url\n",
528 "wanted to set to: $gs->{url}\n";
530 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
531 my $remote_path = "$ra->{svn_path}/$repo_path/*";
532 $remote_path =~ s
#/+#/#g;
533 $remote_path =~ s
#^/##g;
534 my ($n) = ($switch =~ /^--(\w+)/);
535 if (length $pfx && $pfx !~ m
#/$#) {
536 die "--prefix='$pfx' must have a trailing slash '/'\n";
538 command_noisy
('config', "svn-remote.$gs->{repo_id}.$n",
539 "$remote_path:refs/remotes/$pfx*");
544 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
548 sub get_tree_from_treeish
{
550 # $treeish can be a symbolic ref, too:
551 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
553 while ($type eq 'tag') {
554 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
556 if ($type eq 'commit') {
557 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
559 ($expected) = ($expected =~ /^tree ($sha1)$/o);
560 die "Unable to get tree from $treeish\n" unless $expected;
561 } elsif ($type eq 'tree') {
562 $expected = $treeish;
564 die "$treeish is a $type, expected tree, tag or commit\n";
569 sub get_commit_entry
{
570 my ($treeish) = shift;
571 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
572 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
573 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
574 open my $log_fh, '>', $commit_editmsg or croak
$!;
576 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
577 if ($type eq 'commit' || $type eq 'tag') {
578 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
583 $in_msg = 1 if (/^\s*$/);
584 } elsif (/^git-svn-id: /) {
585 # skip this for now, we regenerate the
586 # correct one on re-fetch anyways
587 # TODO: set *:merge properties or like...
589 print $log_fh $_ or croak
$!;
592 command_close_pipe
($msg_fh, $ctx);
594 close $log_fh or croak
$!;
596 if ($_edit || ($type eq 'tree')) {
597 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
598 # TODO: strip out spaces, comments, like git-commit.sh
599 system($editor, $commit_editmsg);
601 rename $commit_editmsg, $commit_msg or croak
$!;
602 open $log_fh, '<', $commit_msg or croak
$!;
603 { local $/; chomp($log_entry{log} = <$log_fh>); }
604 close $log_fh or croak
$!;
610 my ($str, $file, $mode) = @_;
611 open my $fd,'>',$file or croak
$!;
612 print $fd $str,"\n" or croak
$!;
613 close $fd or croak
$!;
614 chmod ($mode &~ umask, $file) if (defined $mode);
619 open my $fd,'<',$file or croak
"$!: file: $file\n";
622 close $fd or croak
$!;
627 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
629 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
630 my $log = $cmd eq 'log';
633 next unless /^(\S+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
634 my ($user, $name, $email) = ($1, $2, $3);
636 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
638 $users{$user} = [$name, $email];
641 close $authors or croak
$!;
644 # convert GetOpt::Long specs for use by git-config
645 sub read_repo_config
{
646 return unless -d
$ENV{GIT_DIR
};
649 foreach my $o (keys %$opts) {
650 # if we have mixedCase and a long option-only, then
651 # it's a config-only variable that we don't need for
653 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
655 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
657 my $arg = 'git-config';
658 $arg .= ' --int' if ($o =~ /[:=]i$/);
659 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
660 if (ref $v eq 'ARRAY') {
661 chomp(my @tmp = `$arg --get-all svn.$key`);
664 chomp(my $tmp = `$arg --get svn.$key`);
665 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
670 delete @
$opts{@config_only} if @config_only;
673 sub extract_metadata
{
674 my $id = shift or return (undef, undef, undef);
675 my ($url, $rev, $uuid) = ($id =~ /^git
-svn
-id
:\s
(\S
+?
)\@
(\d
+)
677 if (!defined $rev || !$uuid || !$url) {
678 # some of the original repositories I made had
679 # identifiers like this:
680 ($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
682 return ($url, $rev, $uuid);
686 return extract_metadata
((grep(/^git-svn-id: /,
687 command
(qw
/cat-file commit/, shift)))[-1]);
693 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
694 $_repack $_repack_flags $_use_svm_props $_head/;
696 use File
::Path qw
/mkpath/;
697 use File
::Copy qw
/copy/;
701 # properties that we do not log:
704 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
705 svn
:special svn
:executable
706 svn
:entry
:committed
-rev
707 svn
:entry
:last-author
709 svn
:entry
:committed
-date
/;
711 # some options are read globally, but can be overridden locally
712 # per [svn-remote "..."] section. Command-line options will *NOT*
713 # override options set in an [svn-remote "..."] section
715 foreach (qw
/follow_parent no_metadata use_svm_props/) {
720 return \$self->{-$_} if exists \$self->{-$_};
721 my \$k = \"svn-remote.\$self->{repo_id}\.$key\";
722 eval { command_oneline(qw/config --get/, \$k) };
724 \$self->{-$_} = \$Git::SVN::_$_;
726 my \$v = command_oneline(qw/config --bool/,\$k);
727 \$self->{-$_} = \$v eq 'false' ? 0 : 1;
729 return \$self->{-$_} }\n";
736 END { unlink keys %LOCKFILES if %LOCKFILES }
738 sub resolve_local_globs
{
739 my ($url, $fetch, $glob_spec) = @_;
740 return unless defined $glob_spec;
741 my $ref = $glob_spec->{ref};
742 my $path = $glob_spec->{path
};
743 foreach (command
(qw
#for-each-ref --format=%(refname) refs/remotes#)) {
744 next unless m
#^refs/remotes/$ref->{regex}$#;
746 my $pathname = $path->full_path($p);
747 my $refname = $ref->full_path($p);
748 if (my $existing = $fetch->{$pathname}) {
749 if ($existing ne $refname) {
750 die "Refspec conflict:\n",
751 "existing: refs/remotes/$existing\n",
752 " globbed: refs/remotes/$refname\n";
754 my $u = (::cmt_metadata
("refs/remotes/$refname"))[0];
755 $u =~ s!^\Q$url\E(/|$)!! or die
756 "refs/remotes/$refname: '$url' not found in '$u'\n";
757 if ($pathname ne $u) {
758 warn "W: Refspec glob conflict ",
759 "(ref: refs/remotes/$refname):\n",
760 "expected path: $pathname\n",
762 "Continuing ahead with $u\n";
766 $fetch->{$pathname} = $refname;
771 sub parse_revision_argument
{
772 my ($base, $head) = @_;
773 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
774 return ($base, $head);
776 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
777 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
778 return ($head, $head) if ($::_revision
eq 'HEAD');
779 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
780 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
781 die "revision argument: $::_revision not understood by git-svn\n";
785 my ($repo_id, $remotes) = @_;
786 my $remote = $remotes->{$repo_id} or
787 die "[svn-remote \"$repo_id\"] unknown\n";
788 my $fetch = $remote->{fetch
};
789 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
791 my $ra = Git
::SVN
::Ra
->new($url);
792 my $uuid = $ra->get_uuid;
793 my $head = $ra->get_latest_revnum;
794 my $base = defined $fetch ?
$head : 0;
796 # read the max revs for wildcard expansion (branches/*, tags/*)
797 foreach my $t (qw
/branches tags/) {
798 defined $remote->{$t} or next;
799 push @globs, $remote->{$t};
800 my $max_rev = eval { tmp_config
(qw
/--int --get/,
801 "svn-remote.$repo_id.${t}-maxRev") };
802 if (defined $max_rev && ($max_rev < $base)) {
808 foreach my $p (sort keys %$fetch) {
809 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
810 my $lr = $gs->rev_db_max;
812 $base = $lr if ($lr < $base);
818 ($base, $head) = parse_revision_argument
($base, $head);
819 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
822 sub read_all_remotes
{
824 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
825 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) {
826 $r->{$1}->{fetch
}->{$2} = $3;
827 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
828 $r->{$1}->{url
} = $2;
829 } elsif (m
!^(.+)\
.(branches
|tags
)=
830 (.*):refs
/remotes
/(.+)\s
*$/!x
) {
831 my ($p, $g) = ($3, $4);
832 my $rs = $r->{$1}->{$2} = {
835 path
=> Git
::SVN
::GlobSpec
->new($p),
836 ref => Git
::SVN
::GlobSpec
->new($g) };
837 if (length($rs->{ref}->{right
}) != 0) {
838 die "The '*' glob character must be the last ",
839 "character of '$g'\n";
847 if (defined $_repack) {
848 $_repack = 1000 if ($_repack <= 0);
849 $_repack_nr = $_repack;
850 $_repack_flags ||= '-d';
854 sub verify_remotes_sanity
{
855 return unless -d
$ENV{GIT_DIR
};
857 foreach (command
(qw
/config -l/)) {
858 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
860 die "Remote ref refs/remote/$1 is tracked by",
861 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
862 "Please resolve this ambiguity in ",
863 "your git configuration file before ",
871 # we allow more chars than remotes2config.sh...
872 sub sanitize_remote_name
{
874 $name =~ tr{A-Za-z0-9:,/+-}{.}c;
878 sub find_existing_remote
{
879 my ($url, $remotes) = @_;
881 foreach my $repo_id (keys %$remotes) {
882 my $u = $remotes->{$repo_id}->{url
} or next;
884 $existing = $repo_id;
890 sub init_remote_config
{
891 my ($self, $url, $no_write) = @_;
892 $url =~ s!/+$!!; # strip trailing slash
893 my $r = read_all_remotes
();
894 my $existing = find_existing_remote
($url, $r);
897 print STDERR
"Using existing ",
898 "[svn-remote \"$existing\"]\n";
900 $self->{repo_id
} = $existing;
902 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
903 $existing = find_existing_remote
($min_url, $r);
906 print STDERR
"Using existing ",
907 "[svn-remote \"$existing\"]\n";
909 $self->{repo_id
} = $existing;
911 if ($min_url ne $url) {
913 print STDERR
"Using higher level of URL: ",
914 "$url => $min_url\n";
916 my $old_path = $self->{path
};
917 $self->{path
} = $url;
918 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
919 if (length $old_path) {
920 $self->{path
} .= "/$old_path";
927 # verify that we aren't overwriting anything:
929 command_oneline
('config', '--get',
930 "svn-remote.$self->{repo_id}.url")
932 if ($orig_url && ($orig_url ne $url)) {
933 die "svn-remote.$self->{repo_id}.url already set: ",
934 "$orig_url\nwanted to set to: $url\n";
937 my ($xrepo_id, $xpath) = find_ref
($self->refname);
938 if (defined $xpath) {
939 die "svn-remote.$xrepo_id.fetch already set to track ",
940 "$xpath:refs/remotes/", $self->refname, "\n";
943 command_noisy
('config',
944 "svn-remote.$self->{repo_id}.url", $url);
945 command_noisy
('config', '--add',
946 "svn-remote.$self->{repo_id}.fetch",
947 "$self->{path}:".$self->refname);
952 sub find_by_url
{ # repos_root and, path are optional
953 my ($class, $full_url, $repos_root, $path) = @_;
954 my $remotes = read_all_remotes
();
955 if (defined $full_url && defined $repos_root && !defined $path) {
957 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
959 foreach my $repo_id (keys %$remotes) {
960 my $u = $remotes->{$repo_id}->{url
} or next;
961 next if defined $repos_root && $repos_root ne $u;
963 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
964 foreach (qw
/branches tags/) {
965 resolve_local_globs
($u, $fetch,
966 $remotes->{$repo_id}->{$_});
969 unless (defined $p) {
971 $p =~ s
#^\Q$u\E(?:/|$)## or next;
973 foreach my $f (keys %$fetch) {
975 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
982 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
983 my $self = _new
($class, $repo_id, $ref_id, $path);
985 $self->init_remote_config($url, $no_write);
992 foreach (command
(qw
/config -l/)) {
993 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
994 \s
*(.*)\s
*:\s
*refs
/remotes/(.+)\s
*$!x
;
995 my ($repo_id, $path, $ref) = ($1, $2, $3);
996 if ($ref eq $ref_id) {
997 $path = '' if ($path =~ m
#^\./?#);
998 return ($repo_id, $path);
1001 (undef, undef, undef);
1005 my ($class, $ref_id, $repo_id, $path) = @_;
1006 if (defined $ref_id && !defined $repo_id && !defined $path) {
1007 ($repo_id, $path) = find_ref
($ref_id);
1008 if (!defined $repo_id) {
1009 die "Could not find a \"svn-remote.*.fetch\" key ",
1010 "in the repository configuration matching: ",
1011 "refs/remotes/$ref_id\n";
1014 my $self = _new
($class, $repo_id, $ref_id, $path);
1015 if (!defined $self->{path
} || !length $self->{path
}) {
1016 my $fetch = command_oneline
('config', '--get',
1017 "svn-remote.$repo_id.fetch",
1018 ":refs/remotes/$ref_id\$") or
1019 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
1020 "\":refs/remotes/$ref_id\$\" in config\n";
1021 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
1023 $self->{url
} = command_oneline
('config', '--get',
1024 "svn-remote.$repo_id.url") or
1025 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
1026 if ((-z
$self->db_path || ! -e
$self->db_path) &&
1027 ::verify_ref
($self->refname.'^0')) {
1033 sub refname
{ "refs/remotes/$_[0]->{ref_id}" }
1037 return $self->{svm
}->{uuid
} if $self->svm;
1039 unless ($self->{svm
}) {
1040 die "SVM UUID not cached, and reading remotely failed\n";
1042 $self->{svm
}->{uuid
};
1047 return $self->{svm
} if $self->{svm
};
1049 # see if we have it in our config, first:
1051 my $section = "svn-remote.$self->{repo_id}";
1053 source
=> tmp_config
('--get', "$section.svm-source"),
1054 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
1057 $self->{svm
} = $svm if ($svm && $svm->{source
} && $svm->{uuid
});
1062 my ($self, $ra) = @_;
1063 return $ra if $self->svm;
1065 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
1066 "(svm:source, svm:mirror, svm:mirror) ",
1067 "from the following URLs:\n" );
1068 sub read_svm_props
{
1069 my ($self, $props) = @_;
1070 my $src = $props->{'svm:source'};
1071 my $mirror = $props->{'svm:mirror'};
1072 my $uuid = $props->{'svm:uuid'};
1073 return undef if (!$src || !$mirror || !$uuid);
1075 chomp($src, $mirror, $uuid);
1077 $uuid =~ m{^[0-9a-f\-]{30,}$}
1078 or die "doesn't look right - svm:uuid is '$uuid'\n";
1079 # don't know what a '!' is there for, also the
1080 # username is of no interest
1081 $src =~ s{/?!$}{$mirror};
1082 $src =~ s{/+$}{}; # no trailing slashes please
1083 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
1085 my $section = "svn-remote.$self->{repo_id}";
1086 tmp_config
('--add', "$section.svm-source", $src);
1087 tmp_config
('--add', "$section.svm-uuid", $uuid);
1088 $self->{svm
} = { source
=> $src , uuid
=> $uuid };
1092 my $r = $ra->get_latest_revnum;
1093 my $path = $self->{path
};
1094 my @tried_a = ($path);
1095 while (length $path) {
1096 if ($self->read_svm_props(($ra->get_dir($path, $r))[2])) {
1099 $path =~ s
#/?[^/]+$## && push @tried_a, $path;
1101 if ($self->read_svm_props(($ra->get_dir('', $r))[2])) {
1105 if ($ra->{repos_root
} eq $self->{url
}) {
1106 die @err, map { " $self->{url}/$_\n" } @tried_a, "\n";
1109 # nope, make sure we're connected to the repository root:
1112 $path = $ra->{svn_path
};
1113 $path =~ s
#/?[^/]+$##; # we already tried this one above
1114 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
1115 while (length $path) {
1116 $ok = $self->read_svm_props(($ra->get_dir($path, $r))[2]);
1118 $path =~ s
#/?[^/]+$## && push @tried_b, $path;
1120 $ok = $self->read_svm_props(($ra->get_dir('', $r))[2]) unless $ok;
1122 die @err, map { " $self->{url}/$_\n" } @tried_a, "\n",
1123 map { " $ra->{url}/$_\n" } @tried_b, "\n"
1125 Git
::SVN
::Ra
->new($self->{url
});
1128 # this allows us to memoize our SVN::Ra UUID locally and avoid a
1129 # remote lookup (useful for 'git svn log').
1132 unless ($self->{ra_uuid
}) {
1133 my $key = "svn-remote.$self->{repo_id}.uuid";
1134 my $uuid = eval { tmp_config
('--get', $key) };
1135 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/) {
1136 $self->{ra_uuid
} = $uuid;
1138 die "ra_uuid called without URL\n" unless $self->{url
};
1139 $self->{ra_uuid
} = $self->ra->get_uuid;
1140 tmp_config
('--add', $key, $self->{ra_uuid
});
1148 my $ra = Git
::SVN
::Ra
->new($self->{url
});
1149 if ($self->use_svm_props && !$self->{svm
}) {
1150 if ($self->no_metadata) {
1151 die "Can't have both 'noMetadata' and ",
1152 "'useSvmProps' options set!\n";
1154 $ra = $self->_set_svm_vars($ra);
1155 $self->{-want_revprops
} = 1;
1162 my $repos_root = $self->ra->{repos_root
};
1163 return $self->{path
} if ($self->{url
} eq $repos_root);
1164 die "BUG: rel_path failed! repos_root: $repos_root, Ra URL: ",
1165 $self->ra->{url
}, " path: $self->{path}, URL: $self->{url}\n";
1168 sub traverse_ignore
{
1169 my ($self, $fh, $path, $r) = @_;
1172 my ($dirent, undef, $props) = $ra->get_dir($path, $r);
1174 $p =~ s
#^\Q$ra->{svn_path}\E/##;
1175 print $fh length $p ?
"\n# $p\n" : "\n# /\n";
1176 if (my $s = $props->{'svn:ignore'}) {
1177 $s =~ s/[\r\n]+/\n/g;
1179 if (length $p == 0) {
1183 $s =~ s
#\n#\n/$p/#g;
1184 print $fh "/$p/$s\n";
1187 foreach (sort keys %$dirent) {
1188 next if $dirent->{$_}->kind != $SVN::Node
::dir
;
1189 $self->traverse_ignore($fh, "$path/$_", $r);
1193 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
1194 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
1196 # returns the newest SVN revision number and newest commit SHA1
1197 sub last_rev_commit
{
1199 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
1200 return ($self->{last_rev
}, $self->{last_commit
});
1202 my $c = ::verify_ref
($self->refname.'^0');
1203 if ($c && !$self->use_svm_props && !$self->no_metadata) {
1204 my $rev = (::cmt_metadata
($c))[1];
1206 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
1210 my $db_path = $self->db_path;
1211 unless (-e
$db_path) {
1212 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
1213 return (undef, undef);
1215 my $offset = -41; # from tail
1217 open my $fh, '<', $db_path or croak
"$db_path not readable: $!\n";
1218 sysseek($fh, $offset, 2); # don't care for errors
1219 sysread($fh, $rl, 41) == 41 or return (undef, undef);
1221 while (('0' x40
) eq $rl && sysseek($fh, 0, 1) != 0) {
1223 sysseek($fh, $offset, 2); # don't care for errors
1224 sysread($fh, $rl, 41) == 41 or return (undef, undef);
1227 if ($c && $c ne $rl) {
1228 die "$db_path and ", $self->refname,
1229 " inconsistent!:\n$c != $rl\n";
1231 my $rev = sysseek($fh, 0, 1) or croak
$!;
1232 $rev = ($rev - 41) / 41;
1233 close $fh or croak
$!;
1234 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
1238 sub get_fetch_range
{
1239 my ($self, $min, $max) = @_;
1240 $max ||= $self->ra->get_latest_revnum;
1241 $min ||= $self->rev_db_max;
1247 my $config = "$ENV{GIT_DIR}/svn/config";
1248 my $old_config = $ENV{GIT_CONFIG
};
1249 $ENV{GIT_CONFIG
} = $config;
1252 unless (-f
$config) {
1254 open my $fh, '>', $config or
1255 die "Can't open $config: $!\n";
1256 print $fh "; This file is used internally by ",
1258 "Couldn't write to $config: $!\n";
1259 print $fh "; You should not have to edit it\n" or
1260 die "Couldn't write to $config: $!\n";
1261 close $fh or die "Couldn't close $config: $!\n";
1263 command
('config', @args);
1266 if (defined $old_config) {
1267 $ENV{GIT_CONFIG
} = $old_config;
1269 delete $ENV{GIT_CONFIG
};
1272 wantarray ?
@ret : $ret[0];
1276 my ($self, $sub) = @_;
1277 my $old_index = $ENV{GIT_INDEX_FILE
};
1278 $ENV{GIT_INDEX_FILE
} = $self->{index};
1281 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
1282 mkpath
([$dir]) unless -d
$dir;
1286 if (defined $old_index) {
1287 $ENV{GIT_INDEX_FILE
} = $old_index;
1289 delete $ENV{GIT_INDEX_FILE
};
1292 wantarray ?
@ret : $ret[0];
1295 sub assert_index_clean
{
1296 my ($self, $treeish) = @_;
1298 $self->tmp_index_do(sub {
1299 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
1300 my $x = command_oneline
('write-tree');
1301 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
1302 /^tree ($::sha1)/mo);
1305 warn "Index mismatch: $y != $x\nrereading $treeish\n";
1306 unlink $self->{index} or die "unlink $self->{index}: $!\n";
1307 command_noisy
('read-tree', $treeish);
1308 $x = command_oneline
('write-tree');
1310 ::fatal
"trees ($treeish) $y != $x\n",
1311 "Something is seriously wrong...\n";
1316 sub get_commit_parents
{
1317 my ($self, $log_entry) = @_;
1318 my (%seen, @ret, @tmp);
1319 # legacy support for 'set-tree'; this is only used by set_tree_cb:
1320 if (my $ip = $self->{inject_parents
}) {
1321 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
1325 if (my $cur = ::verify_ref
($self->refname.'^0')) {
1328 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
1329 while (my $p = shift @tmp) {
1333 # MAXPARENT is defined to 16 in commit-tree.c:
1337 die "r$log_entry->{revision}: No room for parents:\n\t",
1338 join("\n\t", @tmp), "\n";
1345 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
1349 my ($self, $log_entry) = @_;
1350 my $lr = $self->last_rev;
1351 if (defined $lr && $lr >= $log_entry->{revision
}) {
1352 die "Last fetched revision of ", $self->refname,
1353 " was r$lr, but we are about to fetch: ",
1354 "r$log_entry->{revision}!\n";
1356 if (my $c = $self->rev_db_get($log_entry->{revision
})) {
1357 croak
"$log_entry->{revision} = $c already exists! ",
1358 "Why are we refetching it?\n";
1360 $ENV{GIT_AUTHOR_NAME
} = $ENV{GIT_COMMITTER_NAME
} = $log_entry->{name
};
1361 $ENV{GIT_AUTHOR_EMAIL
} = $ENV{GIT_COMMITTER_EMAIL
} =
1362 $log_entry->{email
};
1363 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
1365 my $tree = $log_entry->{tree
};
1366 if (!defined $tree) {
1367 $tree = $self->tmp_index_do(sub {
1368 command_oneline
('write-tree') });
1370 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
1372 my @exec = ('git-commit-tree', $tree);
1373 foreach ($self->get_commit_parents($log_entry)) {
1374 push @exec, '-p', $_;
1376 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1378 print $msg_fh $log_entry->{log} or croak
$!;
1379 unless ($self->no_metadata) {
1380 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
1383 $msg_fh->flush == 0 or croak
$!;
1384 close $msg_fh or croak
$!;
1385 chomp(my $commit = do { local $/; <$out_fh> });
1386 close $out_fh or croak
$!;
1389 if ($commit !~ /^$::sha1$/o) {
1390 die "Failed to commit, invalid sha1: $commit\n";
1393 $self->rev_db_set($log_entry->{revision
}, $commit, 1);
1395 $self->{last_rev
} = $log_entry->{revision
};
1396 $self->{last_commit
} = $commit;
1397 print "r$log_entry->{revision}";
1398 if (defined $log_entry->{svm_revision
}) {
1399 print " (\@$log_entry->{svm_revision})";
1400 $self->rev_db_set($log_entry->{svm_revision
}, $commit,
1401 0, $self->svm_uuid);
1403 print " = $commit ($self->{ref_id})\n";
1404 if (defined $_repack && (--$_repack_nr == 0)) {
1405 $_repack_nr = $_repack;
1406 # repack doesn't use any arguments with spaces in them, does it?
1407 print "Running git repack $_repack_flags ...\n";
1408 command_noisy
('repack', split(/\s+/, $_repack_flags));
1409 print "Done repacking\n";
1415 my ($self, $paths, $r) = @_;
1416 return 1 if $self->{path
} eq '';
1417 if (my $path = $paths->{"/$self->{path}"}) {
1418 return ($path->{action
} eq 'D') ?
0 : 1;
1420 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
1421 if (grep /$self->{path_regex}/, keys %$paths) {
1425 foreach (split m
#/#, $self->{path}) {
1427 next unless ($paths->{$c} &&
1428 ($paths->{$c}->{action
} =~ /^[AR]$/));
1429 if ($self->ra->check_path($self->{path
}, $r) ==
1437 sub find_parent_branch
{
1438 my ($self, $paths, $rev) = @_;
1439 return undef unless $self->follow_parent;
1440 unless (defined $paths) {
1441 my $err_handler = $SVN::Error
::handler
;
1442 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
1443 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1, sub {
1445 Git
::SVN
::Ra
::dup_changed_paths
($_[0]) });
1446 $SVN::Error
::handler
= $err_handler;
1448 return undef unless defined $paths;
1450 # look for a parent from another branch:
1451 my @b_path_components = split m
#/#, $self->rel_path;
1452 my @a_path_components;
1454 while (@b_path_components) {
1455 $i = $paths->{'/'.join('/', @b_path_components)};
1456 last if $i && defined $i->{copyfrom_path
};
1457 unshift(@a_path_components, pop(@b_path_components));
1459 return undef unless defined $i && defined $i->{copyfrom_path
};
1460 my $branch_from = $i->{copyfrom_path
};
1461 if (@a_path_components) {
1462 print STDERR
"branch_from: $branch_from => ";
1463 $branch_from .= '/'.join('/', @a_path_components);
1464 print STDERR
$branch_from, "\n";
1466 my $r = $i->{copyfrom_rev
};
1467 my $repos_root = $self->ra->{repos_root
};
1468 my $url = $self->ra->{url
};
1469 my $new_url = $repos_root . $branch_from;
1470 print STDERR
"Found possible branch point: ",
1471 "$new_url => ", $self->full_url, ", $r\n";
1472 $branch_from =~ s
#^/##;
1473 my $gs = Git
::SVN
->find_by_url($new_url, $repos_root, $branch_from);
1475 my $ref_id = $self->{ref_id
};
1476 $ref_id =~ s/\@\d+$//;
1478 # just grow a tail if we're not unique enough :x
1479 $ref_id .= '-' while find_ref
($ref_id);
1480 print STDERR
"Initializing parent: $ref_id\n";
1481 $gs = Git
::SVN
->init($new_url, '', $ref_id, $ref_id, 1);
1483 my ($r0, $parent) = $gs->find_rev_before($r, 1);
1484 if (!defined $r0 || !defined $parent) {
1486 ($r0, $parent) = $gs->last_rev_commit;
1488 if (defined $r0 && defined $parent) {
1489 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n";
1490 $self->assert_index_clean($parent);
1492 if ($self->ra->can_do_switch) {
1493 print STDERR
"Following parent with do_switch\n";
1494 # do_switch works with svn/trunk >= r22312, but that
1495 # is not included with SVN 1.4.3 (the latest version
1496 # at the moment), so we can't rely on it
1497 $self->{last_commit
} = $parent;
1498 $ed = SVN
::Git
::Fetcher
->new($self);
1499 $gs->ra->gs_do_switch($r0, $rev, $gs,
1500 $self->full_url, $ed)
1501 or die "SVN connection failed somewhere...\n";
1503 print STDERR
"Following parent with do_update\n";
1504 $ed = SVN
::Git
::Fetcher
->new($self);
1505 $self->ra->gs_do_update($rev, $rev, $self, $ed)
1506 or die "SVN connection failed somewhere...\n";
1508 print STDERR
"Successfully followed parent\n";
1509 return $self->make_log_entry($rev, [$parent], $ed);
1515 my ($self, $paths, $rev) = @_;
1517 my ($last_rev, @parents);
1518 if (my $lc = $self->last_commit) {
1519 # we can have a branch that was deleted, then re-added
1520 # under the same name but copied from another path, in
1521 # which case we'll have multiple parents (we don't
1522 # want to break the original ref, nor lose copypath info):
1523 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1524 push @
{$log_entry->{parents
}}, $lc;
1527 $ed = SVN
::Git
::Fetcher
->new($self);
1528 $last_rev = $self->{last_rev
};
1533 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
1536 $ed = SVN
::Git
::Fetcher
->new($self);
1538 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1539 die "SVN connection failed somewhere...\n";
1541 $self->make_log_entry($rev, \
@parents, $ed);
1545 my ($self, $ed) = @_;
1547 my $h = $ed->{empty
};
1548 foreach (sort keys %$h) {
1549 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
1550 push @out, " $act: " . uri_encode
($_);
1551 warn "W: $act: $_\n";
1553 foreach my $t (qw
/dir_prop file_prop/) {
1554 $h = $ed->{$t} or next;
1555 foreach my $path (sort keys %$h) {
1556 my $ppath = $path eq '' ?
'.' : $path;
1557 foreach my $prop (sort keys %{$h->{$path}}) {
1558 next if $SKIP_PROP{$prop};
1559 my $v = $h->{$path}->{$prop};
1560 my $t_ppath_prop = "$t: " .
1561 uri_encode
($ppath) . ' ' .
1564 push @out, " +$t_ppath_prop " .
1567 push @out, " -$t_ppath_prop";
1572 foreach my $t (qw
/absent_file absent_directory/) {
1573 $h = $ed->{$t} or next;
1574 foreach my $parent (sort keys %$h) {
1575 foreach my $path (sort @
{$h->{$parent}}) {
1576 push @out, " $t: " .
1577 uri_encode
("$parent/$path");
1578 warn "W: $t: $parent/$path ",
1579 "Insufficient permissions?\n";
1586 sub parse_svn_date
{
1587 my $date = shift || return '+0000 1970-01-01 00:00:00';
1588 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
1589 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
) or
1590 croak
"Unable to parse date: $date\n";
1591 "+0000 $Y-$m-$d $H:$M:$S";
1596 if (!defined $author || length $author == 0) {
1597 $author = '(no author)';
1599 if (defined $::_authors
&& ! defined $::users
{$author}) {
1600 die "Author: $author not defined in $::_authors file\n";
1605 sub make_log_entry
{
1606 my ($self, $rev, $parents, $ed) = @_;
1607 my $untracked = $self->get_untracked($ed);
1609 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
1610 print $un "r$rev\n" or croak
$!;
1611 print $un $_, "\n" foreach @
$untracked;
1612 my %log_entry = ( parents
=> $parents || [], revision
=> $rev,
1616 my $logged = delete $self->{logged_rev_props
};
1617 if (!$logged || $self->{-want_revprops
}) {
1618 my $rp = $self->ra->rev_proplist($rev);
1619 foreach (sort keys %$rp) {
1621 if (/^svn:(author|date|log)$/) {
1622 $log_entry{$1} = $v;
1623 } elsif ($_ eq 'svm:headrev') {
1626 print $un " rev_prop: ", uri_encode
($_), ' ',
1627 uri_encode
($v), "\n";
1631 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
1633 close $un or croak
$!;
1635 $log_entry{date
} = parse_svn_date
($log_entry{date
});
1636 $log_entry{log} .= "\n";
1637 my $author = $log_entry{author
} = check_author
($log_entry{author
});
1638 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
1640 if (defined $headrev && $self->use_svm_props) {
1641 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$};
1642 if ($uuid ne $self->{svm
}->{uuid
}) {
1643 die "UUID mismatch on SVM path:\n",
1644 "expected: $self->{svm}->{uuid}\n",
1647 my $full_url = $self->{svm
}->{source
};
1648 $full_url .= "/$self->{path}" if length $self->{path
};
1649 $log_entry{metadata
} = "$full_url\@$r $uuid";
1650 $log_entry{svm_revision
} = $r;
1651 $email ||= "$author\@$uuid"
1653 $log_entry{metadata
} = $self->full_url . "\@$rev " .
1654 $self->ra->get_uuid;
1655 $email ||= "$author\@" . $self->ra->get_uuid;
1657 $log_entry{name
} = $name;
1658 $log_entry{email
} = $email;
1663 my ($self, $min_rev, $max_rev, @parents) = @_;
1664 my ($last_rev, $last_commit) = $self->last_rev_commit;
1665 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
1666 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
1670 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
1671 $self->{inject_parents
} = { $rev => $tree };
1672 $self->fetch(undef, undef);
1676 my ($self, $tree) = (shift, shift);
1677 my $log_entry = ::get_commit_entry
($tree);
1678 unless ($self->{last_rev
}) {
1679 fatal
("Must have an existing revision to commit\n");
1681 my %ed_opts = ( r
=> $self->{last_rev
},
1682 log => $log_entry->{log},
1684 tree_a
=> $self->{last_commit
},
1687 $self->set_tree_cb($log_entry, $tree, @_) },
1688 svn_path
=> $self->{path
} );
1689 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1690 print "No changes\nr$self->{last_rev} = $tree\n";
1696 my $db_path = $self->db_path;
1697 if (-f
$self->{db_root
}) {
1698 rename $self->{db_root
}, $db_path or die
1699 "rename $self->{db_root} => $db_path failed: $!\n";
1700 my ($dir, $base) = ($db_path =~ m
#^(.*?)/?([^/]+)$#);
1701 symlink $base, $self->{db_root
} or die
1702 "symlink $base => $self->{db_root} failed: $!\n";
1705 print "Rebuilding $db_path ...\n";
1706 my ($rev_list, $ctx) = command_output_pipe
("rev-list", $self->refname);
1708 my $full_url = $self->full_url;
1710 while (<$rev_list>) {
1713 die "Non-SHA1: $c\n" unless $c =~ /^$::sha1$/o;
1714 my ($url, $rev, $uuid) = ::cmt_metadata
($c);
1716 # ignore merges (from set-tree)
1717 next if (!defined $rev || !$uuid);
1719 # if we merged or otherwise started elsewhere, this is
1720 # how we break out of it
1721 if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
1722 ($full_url && $url && ($url ne $full_url))) {
1726 $svn_uuid ||= $uuid;
1728 $self->rev_db_set($rev, $c);
1729 print "r$rev = $c\n";
1731 command_close_pipe
($rev_list, $ctx);
1732 print "Done rebuilding $db_path\n";
1736 # Tie::File seems to be prone to offset errors if revisions get sparse,
1737 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
1738 # one of my favorite modules is out :< Next up would be one of the DBM
1739 # modules, but I'm not sure which is most portable... So I'll just
1740 # go with something that's plain-text, but still capable of
1741 # being randomly accessed. So here's my ultra-simple fixed-width
1742 # database. All records are 40 characters + "\n", so it's easy to seek
1743 # to a revision: (41 * rev) is the byte offset.
1744 # A record of 40 0s denotes an empty revision.
1745 # And yes, it's still pretty fast (faster than Tie::File).
1746 # These files are disposable unless noMetadata or useSvmProps is set
1749 my ($fh, $rev, $commit) = @_;
1750 my $offset = $rev * 41;
1751 # assume that append is the common case:
1752 seek $fh, 0, 2 or croak
$!;
1754 if ($pos < $offset) {
1755 for (1 .. (($offset - $pos) / 41)) {
1756 print $fh (('0' x
40),"\n") or croak
$!;
1759 seek $fh, $offset, 0 or croak
$!;
1760 print $fh $commit,"\n" or croak
$!;
1766 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
1767 mkpath
([$dir]) unless -d
$dir;
1768 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
1769 close $fh or die "Couldn't close (create) $path: $!\n";
1774 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
1775 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
1776 my $db = $self->db_path($uuid);
1777 my $db_lock = "$db.lock";
1780 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
1781 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
1785 $LOCKFILES{$db_lock} = 1;
1787 # both of these options make our .rev_db file very, very important
1788 # and we can't afford to lose it because rebuild() won't work
1789 if ($self->use_svm_props || $self->no_metadata) {
1791 copy
($db, $db_lock) or die "rev_db_set(@_): ",
1793 "$db => $db_lock ($!)\n";
1795 rename $db, $db_lock or die "rev_db_set(@_): ",
1796 "Failed to rename: ",
1797 "$db => $db_lock ($!)\n";
1799 open my $fh, '+<', $db_lock or die "Couldn't open $db_lock: $!\n";
1800 _rev_db_set
($fh, $rev, $commit);
1802 $fh->flush or die "Couldn't flush $db_lock: $!\n";
1803 $fh->sync or die "Couldn't sync $db_lock: $!\n";
1805 close $fh or croak
$!;
1808 command_noisy
('update-ref', '-m', "r$rev",
1809 $self->refname, $commit);
1811 rename $db_lock, $db or die "rev_db_set(@_): ", "Failed to rename: ",
1812 "$db_lock => $db ($!)\n";
1813 delete $LOCKFILES{$db_lock};
1815 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
1816 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
1817 kill $sig, $$ if defined $sig;
1823 my $db_path = $self->db_path;
1824 my @stat = stat $db_path or return 0;
1825 ($stat[7] % 41) == 0 or die "$db_path inconsistent size: $stat[7]\n";
1826 my $max = $stat[7] / 41;
1827 (($max > 0) ?
$max - 1 : 0);
1831 my ($self, $rev, $uuid) = @_;
1833 my $offset = $rev * 41;
1834 my $db_path = $self->db_path($uuid);
1835 return undef unless -e
$db_path;
1836 open my $fh, '<', $db_path or croak
$!;
1837 if (sysseek($fh, $offset, 0) == $offset) {
1838 my $read = sysread($fh, $ret, 40);
1839 $ret = undef if ($read != 40 || $ret eq ('0'x40
));
1841 close $fh or croak
$!;
1845 sub find_rev_before
{
1846 my ($self, $rev, $eq_ok) = @_;
1847 --$rev unless $eq_ok;
1849 if (my $c = $self->rev_db_get($rev)) {
1854 return (undef, undef);
1858 my ($class, $repo_id, $ref_id, $path) = @_;
1859 unless (defined $repo_id && length $repo_id) {
1860 $repo_id = $Git::SVN
::default_repo_id
;
1862 unless (defined $ref_id && length $ref_id) {
1863 $_[2] = $ref_id = $Git::SVN
::default_ref_id
;
1865 $_[1] = $repo_id = sanitize_remote_name
($repo_id);
1866 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
1867 $_[3] = $path = '' unless (defined $path);
1868 mkpath
(["$ENV{GIT_DIR}/svn"]);
1870 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
1871 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
1872 db_root
=> "$dir/.rev_db", repo_id
=> $repo_id }, $class;
1876 my ($self, $uuid) = @_;
1877 $uuid ||= $self->ra_uuid;
1878 "$self->{db_root}.$uuid";
1883 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
1887 package Git
::SVN
::Prompt
;
1891 use vars qw
/$_no_auth_cache $_username/;
1894 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
1895 $may_save = undef if $_no_auth_cache;
1896 $default_username = $_username if defined $_username;
1897 if (defined $default_username && length $default_username) {
1898 if (defined $realm && length $realm) {
1899 print STDERR
"Authentication realm: $realm\n";
1902 $cred->username($default_username);
1904 username
($cred, $realm, $may_save, $pool);
1906 $cred->password(_read_password
("Password for '" .
1907 $cred->username . "': ", $realm));
1908 $cred->may_save($may_save);
1909 $SVN::_Core
::SVN_NO_ERROR
;
1912 sub ssl_server_trust
{
1913 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
1914 $may_save = undef if $_no_auth_cache;
1915 print STDERR
"Error validating server certificate for '$realm':\n";
1916 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
1917 print STDERR
" - The certificate is not issued by a trusted ",
1918 "authority. Use the\n",
1919 " fingerprint to validate the certificate manually!\n";
1921 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
1922 print STDERR
" - The certificate hostname does not match.\n";
1924 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
1925 print STDERR
" - The certificate is not yet valid.\n";
1927 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
1928 print STDERR
" - The certificate has expired.\n";
1930 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
1931 print STDERR
" - The certificate has an unknown error.\n";
1934 "Certificate information:\n".
1935 " - Hostname: %s\n".
1936 " - Valid: from %s until %s\n".
1938 " - Fingerprint: %s\n",
1939 map $cert_info->$_, qw(hostname valid_from valid_until
1940 issuer_dname fingerprint);
1943 print STDERR
$may_save ?
1944 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
1945 "(R)eject or accept (t)emporarily? ";
1947 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
1948 if ($choice =~ /^t$/i) {
1949 $cred->may_save(undef);
1950 } elsif ($choice =~ /^r$/i) {
1952 } elsif ($may_save && $choice =~ /^p$/i) {
1953 $cred->may_save($may_save);
1957 $cred->accepted_failures($failures);
1958 $SVN::_Core
::SVN_NO_ERROR
;
1961 sub ssl_client_cert
{
1962 my ($cred, $realm, $may_save, $pool) = @_;
1963 $may_save = undef if $_no_auth_cache;
1964 print STDERR
"Client certificate filename: ";
1966 chomp(my $filename = <STDIN
>);
1967 $cred->cert_file($filename);
1968 $cred->may_save($may_save);
1969 $SVN::_Core
::SVN_NO_ERROR
;
1972 sub ssl_client_cert_pw
{
1973 my ($cred, $realm, $may_save, $pool) = @_;
1974 $may_save = undef if $_no_auth_cache;
1975 $cred->password(_read_password
("Password: ", $realm));
1976 $cred->may_save($may_save);
1977 $SVN::_Core
::SVN_NO_ERROR
;
1981 my ($cred, $realm, $may_save, $pool) = @_;
1982 $may_save = undef if $_no_auth_cache;
1983 if (defined $realm && length $realm) {
1984 print STDERR
"Authentication realm: $realm\n";
1987 if (defined $_username) {
1988 $username = $_username;
1990 print STDERR
"Username: ";
1992 chomp($username = <STDIN
>);
1994 $cred->username($username);
1995 $cred->may_save($may_save);
1996 $SVN::_Core
::SVN_NO_ERROR
;
1999 sub _read_password
{
2000 my ($prompt, $realm) = @_;
2001 print STDERR
$prompt;
2003 require Term
::ReadKey
;
2004 Term
::ReadKey
::ReadMode
('noecho');
2006 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
2007 last if $key =~ /[\012\015]/; # \n\r
2010 Term
::ReadKey
::ReadMode
('restore');
2019 my $kill_stupid_warnings = $SVN::Node
::none
.$SVN::Node
::file
.
2020 $SVN::Node
::dir
.$SVN::Node
::unknown
.
2021 $SVN::Node
::none
.$SVN::Node
::file
.
2022 $SVN::Node
::dir
.$SVN::Node
::unknown
.
2023 $SVN::Auth
::SSL
::CNMISMATCH
.
2024 $SVN::Auth
::SSL
::NOTYETVALID
.
2025 $SVN::Auth
::SSL
::EXPIRED
.
2026 $SVN::Auth
::SSL
::UNKNOWNCA
.
2027 $SVN::Auth
::SSL
::OTHER
;
2030 package SVN
::Git
::Fetcher
;
2038 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
2040 my ($class, $git_svn) = @_;
2041 my $self = SVN
::Delta
::Editor
->new;
2042 bless $self, $class;
2043 $self->{c
} = $git_svn->{last_commit
} if exists $git_svn->{last_commit
};
2044 $self->{empty
} = {};
2045 $self->{dir_prop
} = {};
2046 $self->{file_prop
} = {};
2047 $self->{absent_dir
} = {};
2048 $self->{absent_file
} = {};
2049 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
2053 sub set_path_strip
{
2054 my ($self, $path) = @_;
2055 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
2062 sub open_directory
{
2063 my ($self, $path, $pb, $rev) = @_;
2068 my ($self, $path) = @_;
2069 if ($self->{path_strip
}) {
2070 $path =~ s!$self->{path_strip}!! or
2071 die "Failed to strip path '$path' ($self->{path_strip})\n";
2077 my ($self, $path, $rev, $pb) = @_;
2079 my $gpath = $self->git_path($path);
2080 return undef if ($gpath eq '');
2082 # remove entire directories.
2083 if (command
('ls-tree', $self->{c
}, '--', $gpath) =~ /^040000 tree/) {
2084 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
2086 $self->{c
}, '--', $gpath);
2090 $self->{gii
}->remove($_);
2091 print "\tD\t$_\n" unless $::_q
;
2093 print "\tD\t$gpath/\n" unless $::_q
;
2094 command_close_pipe
($ls, $ctx);
2095 $self->{empty
}->{$path} = 0
2097 $self->{gii
}->remove($gpath);
2098 print "\tD\t$gpath\n" unless $::_q
;
2104 my ($self, $path, $pb, $rev) = @_;
2105 my $gpath = $self->git_path($path);
2106 my ($mode, $blob) = (command
('ls-tree', $self->{c
}, '--', $gpath)
2107 =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
2108 unless (defined $mode && defined $blob) {
2109 die "$path was not found in commit $self->{c} (r$rev)\n";
2111 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
2112 pool
=> SVN
::Pool
->new, action
=> 'M' };
2116 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
2117 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2118 delete $self->{empty
}->{$dir};
2119 { path
=> $path, mode_a
=> 100644, mode_b
=> 100644,
2120 pool
=> SVN
::Pool
->new, action
=> 'A' };
2124 my ($self, $path, $cp_path, $cp_rev) = @_;
2125 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2126 delete $self->{empty
}->{$dir};
2127 $self->{empty
}->{$path} = 1;
2131 sub change_dir_prop
{
2132 my ($self, $db, $prop, $value) = @_;
2133 $self->{dir_prop
}->{$db->{path
}} ||= {};
2134 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
2138 sub absent_directory
{
2139 my ($self, $path, $pb) = @_;
2140 $self->{absent_dir
}->{$pb->{path
}} ||= [];
2141 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
2146 my ($self, $path, $pb) = @_;
2147 $self->{absent_file
}->{$pb->{path
}} ||= [];
2148 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
2152 sub change_file_prop
{
2153 my ($self, $fb, $prop, $value) = @_;
2154 if ($prop eq 'svn:executable') {
2155 if ($fb->{mode_b
} != 120000) {
2156 $fb->{mode_b
} = defined $value ?
100755 : 100644;
2158 } elsif ($prop eq 'svn:special') {
2159 $fb->{mode_b
} = defined $value ?
120000 : 100644;
2161 $self->{file_prop
}->{$fb->{path
}} ||= {};
2162 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
2167 sub apply_textdelta
{
2168 my ($self, $fb, $exp) = @_;
2169 my $fh = IO
::File
->new_tmpfile;
2171 # $fh gets auto-closed() by SVN::TxDelta::apply(),
2172 # (but $base does not,) so dup() it for reading in close_file
2173 open my $dup, '<&', $fh or croak
$!;
2174 my $base = IO
::File
->new_tmpfile;
2175 $base->autoflush(1);
2177 defined (my $pid = fork) or croak
$!;
2179 open STDOUT
, '>&', $base or croak
$!;
2180 print STDOUT
'link ' if ($fb->{mode_a
} == 120000);
2181 exec qw
/git-cat-file blob/, $fb->{blob
} or croak
$!;
2187 seek $base, 0, 0 or croak
$!;
2188 my $md5 = Digest
::MD5
->new;
2189 $md5->addfile($base);
2190 my $got = $md5->hexdigest;
2191 die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
2193 " got: $got\n" if ($got ne $exp);
2196 seek $base, 0, 0 or croak
$!;
2198 $fb->{base
} = $base;
2199 [ SVN
::TxDelta
::apply
($base, $fh, undef, $fb->{path
}, $fb->{pool
}) ];
2203 my ($self, $fb, $exp) = @_;
2205 my $path = $self->git_path($fb->{path
});
2206 if (my $fh = $fb->{fh
}) {
2207 seek($fh, 0, 0) or croak
$!;
2208 my $md5 = Digest
::MD5
->new;
2210 my $got = $md5->hexdigest;
2211 die "Checksum mismatch: $path\n",
2212 "expected: $exp\n got: $got\n" if ($got ne $exp);
2213 seek($fh, 0, 0) or croak
$!;
2214 if ($fb->{mode_b
} == 120000) {
2215 read($fh, my $buf, 5) == 5 or croak
$!;
2216 $buf eq 'link ' or die "$path has mode 120000",
2217 "but is not a link\n";
2219 defined(my $pid = open my $out,'-|') or die "Can't fork: $!\n";
2221 open STDIN
, '<&', $fh or croak
$!;
2222 exec qw
/git-hash-object -w --stdin/ or croak
$!;
2224 chomp($hash = do { local $/; <$out> });
2225 close $out or croak
$!;
2226 close $fh or croak
$!;
2227 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
2228 close $fb->{base
} or croak
$!;
2230 $hash = $fb->{blob
} or die "no blob information\n";
2233 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
2234 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
2240 $self->{nr
} = $self->{gii
}->{nr
};
2241 delete $self->{gii
};
2242 $self->SUPER::abort_edit
(@_);
2247 $self->{git_commit_ok
} = 1;
2248 $self->{nr
} = $self->{gii
}->{nr
};
2249 delete $self->{gii
};
2250 $self->SUPER::close_edit
(@_);
2253 package SVN
::Git
::Editor
;
2254 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
2262 my ($class, $opts) = @_;
2263 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
2264 die "$_ required!\n" unless (defined $opts->{$_});
2267 my $pool = SVN
::Pool
->new;
2268 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
2269 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
2272 # $opts->{ra} functions should not be used after this:
2273 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
2274 $opts->{editor_cb
}, $pool);
2275 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
2276 bless $self, $class;
2277 foreach (qw
/svn_path r tree_a tree_b/) {
2278 $self->{$_} = $opts->{$_};
2280 $self->{url
} = $opts->{ra
}->{url
};
2281 $self->{mods
} = $mods;
2282 $self->{types
} = $types;
2283 $self->{pool
} = $pool;
2284 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
2286 $self->{path_prefix
} = length $self->{svn_path
} ?
2287 "$self->{svn_path}/" : '';
2292 my ($tree_a, $tree_b) = @_;
2293 my @diff_tree = qw(diff-tree -z -r);
2294 if ($_cp_similarity) {
2295 push @diff_tree, "-C$_cp_similarity";
2297 push @diff_tree, '-C';
2299 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
2300 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
2301 push @diff_tree, $tree_a, $tree_b;
2302 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
2306 while (<$diff_fh>) {
2307 chomp $_; # this gets rid of the trailing "\0"
2308 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
2309 $::sha1\s
($::sha1
)\s
2310 ([MTCRAD
])\d
*$/xo
) {
2311 push @mods, { mode_a
=> $1, mode_b
=> $2,
2312 sha1_b
=> $3, chg
=> $4 };
2313 if ($4 =~ /^(?:C|R)$/) {
2318 } elsif ($state eq 'file_a') {
2319 my $x = $mods[$#mods] or croak
"Empty array\n";
2320 if ($x->{chg
} !~ /^(?:C|R)$/) {
2321 croak
"Error parsing $_, $x->{chg}\n";
2325 } elsif ($state eq 'file_b') {
2326 my $x = $mods[$#mods] or croak
"Empty array\n";
2327 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
2328 croak
"Error parsing $_, $x->{chg}\n";
2330 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
2331 croak
"Error parsing $_, $x->{chg}\n";
2336 croak
"Error parsing $_\n";
2339 command_close_pipe
($diff_fh, $ctx);
2343 sub check_diff_paths
{
2344 my ($ra, $pfx, $rev, $mods) = @_;
2346 $pfx .= '/' if length $pfx;
2348 sub type_diff_paths
{
2349 my ($ra, $types, $path, $rev) = @_;
2350 my @p = split m
#/+#, $path;
2352 unless (defined $types->{$c}) {
2353 $types->{$c} = $ra->check_path($c, $rev);
2356 $c .= '/' . shift @p;
2357 next if defined $types->{$c};
2358 $types->{$c} = $ra->check_path($c, $rev);
2362 foreach my $m (@
$mods) {
2363 foreach my $f (qw
/file_a file_b/) {
2364 next unless defined $m->{$f};
2365 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
2366 if (length $pfx.$dir && ! defined $types{$dir}) {
2367 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
2375 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
2379 my ($self, $path) = @_;
2380 $self->{path_prefix
}.(defined $path ?
$path : '');
2384 my ($self, $path) = @_;
2385 $self->{url
} . '/' . $self->repo_path($path);
2390 my $rm = $self->{rm
};
2391 delete $rm->{''}; # we never delete the url we're tracking
2394 foreach (keys %$rm) {
2395 my @d = split m
#/#, $_;
2399 $c .= '/' . shift @d;
2403 delete $rm->{$self->{svn_path
}};
2404 delete $rm->{''}; # we never delete the url we're tracking
2407 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
2412 my @dn = split m
#/#, $_;
2414 delete $rm->{join '/', @dn};
2421 command_close_pipe
($fh, $ctx);
2423 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
2424 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
2425 $self->close_directory($bat->{$d}, $p);
2426 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
2427 print "\tD+\t$d/\n" unless $::_q
;
2428 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
2433 sub open_or_add_dir
{
2434 my ($self, $full_path, $baton) = @_;
2435 my $t = $self->{types
}->{$full_path};
2437 die "$full_path not known in r$self->{r} or we have a bug!\n";
2439 if ($t == $SVN::Node
::none
) {
2440 return $self->add_directory($full_path, $baton,
2441 undef, -1, $self->{pool
});
2442 } elsif ($t == $SVN::Node
::dir
) {
2443 return $self->open_directory($full_path, $baton,
2444 $self->{r
}, $self->{pool
});
2446 print STDERR
"$full_path already exists in repository at ",
2447 "r$self->{r} and it is not a directory (",
2448 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
2453 my ($self, $path) = @_;
2454 my $bat = $self->{bat
};
2455 my $repo_path = $self->repo_path($path);
2456 return $bat->{''} unless (length $repo_path);
2457 my @p = split m
#/+#, $repo_path;
2459 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
2462 $c .= '/' . shift @p;
2463 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
2469 my ($self, $m) = @_;
2470 my ($dir, $file) = split_path
($m->{file_b
});
2471 my $pbat = $self->ensure_path($dir);
2472 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2474 print "\tA\t$m->{file_b}\n" unless $::_q
;
2475 $self->chg_file($fbat, $m);
2476 $self->close_file($fbat,undef,$self->{pool
});
2480 my ($self, $m) = @_;
2481 my ($dir, $file) = split_path
($m->{file_b
});
2482 my $pbat = $self->ensure_path($dir);
2483 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2484 $self->url_path($m->{file_a
}), $self->{r
});
2485 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2486 $self->chg_file($fbat, $m);
2487 $self->close_file($fbat,undef,$self->{pool
});
2491 my ($self, $path, $pbat) = @_;
2492 my $rpath = $self->repo_path($path);
2493 my ($dir, $file) = split_path
($rpath);
2494 $self->{rm
}->{$dir} = 1;
2495 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
2499 my ($self, $m) = @_;
2500 my ($dir, $file) = split_path
($m->{file_b
});
2501 my $pbat = $self->ensure_path($dir);
2502 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
2503 $self->url_path($m->{file_a
}), $self->{r
});
2504 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
2505 $self->chg_file($fbat, $m);
2506 $self->close_file($fbat,undef,$self->{pool
});
2508 ($dir, $file) = split_path
($m->{file_a
});
2509 $pbat = $self->ensure_path($dir);
2510 $self->delete_entry($m->{file_a
}, $pbat);
2514 my ($self, $m) = @_;
2515 my ($dir, $file) = split_path
($m->{file_b
});
2516 my $pbat = $self->ensure_path($dir);
2517 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
2518 $pbat,$self->{r
},$self->{pool
});
2519 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
2520 $self->chg_file($fbat, $m);
2521 $self->close_file($fbat,undef,$self->{pool
});
2524 sub T
{ shift->M(@_) }
2526 sub change_file_prop
{
2527 my ($self, $fbat, $pname, $pval) = @_;
2528 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
2532 my ($self, $fbat, $m) = @_;
2533 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
2534 $self->change_file_prop($fbat,'svn:executable','*');
2535 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
2536 $self->change_file_prop($fbat,'svn:executable',undef);
2538 my $fh = IO
::File
->new_tmpfile or croak
$!;
2539 if ($m->{mode_b
} =~ /^120/) {
2540 print $fh 'link ' or croak
$!;
2541 $self->change_file_prop($fbat,'svn:special','*');
2542 } elsif ($m->{mode_a
} =~ /^120/ && $m->{mode_b
} !~ /^120/) {
2543 $self->change_file_prop($fbat,'svn:special',undef);
2545 defined(my $pid = fork) or croak
$!;
2547 open STDOUT
, '>&', $fh or croak
$!;
2548 exec qw
/git-cat-file blob/, $m->{sha1_b
} or croak
$!;
2552 $fh->flush == 0 or croak
$!;
2553 seek $fh, 0, 0 or croak
$!;
2555 my $md5 = Digest
::MD5
->new;
2556 $md5->addfile($fh) or croak
$!;
2557 seek $fh, 0, 0 or croak
$!;
2559 my $exp = $md5->hexdigest;
2560 my $pool = SVN
::Pool
->new;
2561 my $atd = $self->apply_textdelta($fbat, undef, $pool);
2562 my $got = SVN
::TxDelta
::send_stream
($fh, @
$atd, $pool);
2563 die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
2566 close $fh or croak
$!;
2570 my ($self, $m) = @_;
2571 my ($dir, $file) = split_path
($m->{file_b
});
2572 my $pbat = $self->ensure_path($dir);
2573 print "\tD\t$m->{file_b}\n" unless $::_q
;
2574 $self->delete_entry($m->{file_b
}, $pbat);
2579 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
2580 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
2581 $self->close_directory($bat->{$_}, $p);
2583 $self->SUPER::close_edit
($p);
2589 $self->SUPER::abort_edit
($self->{pool
});
2594 $self->SUPER::DESTROY
(@_);
2595 $self->{pool
}->clear;
2598 # this drives the editor
2601 my $mods = $self->{mods
};
2602 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
2603 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
2605 if (defined $o{$f}) {
2608 fatal
("Invalid change type: $f\n");
2611 $self->rmdirs if $_rmdir;
2617 return scalar @
$mods;
2620 package Git
::SVN
::Ra
;
2621 use vars qw
/@ISA $config_dir $_log_window_size/;
2624 my ($can_do_switch);
2628 # enforce temporary pool usage for some simple functions
2630 foreach (qw
/get_latest_revnum get_uuid get_repos_root/) {
2633 my \$pool = SVN::Pool->new;
2634 my \@ret = \$self->SUPER::$_(\@_,\$pool);
2636 wantarray ? \@ret : \$ret[0]; }\n";
2639 # get_dir needs $pool held in cache for dirents to work,
2640 # check_path is cacheable and rev_proplist is close enough
2642 foreach (qw
/check_path get_dir rev_proplist/) {
2643 $e .= "my \%${_}_cache; my \$${_}_rev = 0; sub $_ {
2646 my \$k = join(\"\\0\", \@_);
2647 if (my \$x = \$${_}_cache{\$r}->{\$k}) {
2648 return wantarray ? \@\$x : \$x->[0];
2650 my \$pool = SVN::Pool->new;
2651 my \@ret = \$self->SUPER::$_(\@_, \$r, \$pool);
2652 if (\$r != \$${_}_rev) {
2653 \%${_}_cache = ( pool => [] );
2656 \$${_}_cache{\$r}->{\$k} = \\\@ret;
2657 push \@{\$${_}_cache{pool}}, \$pool;
2658 wantarray ? \@ret : \$ret[0]; }\n";
2665 my ($class, $url) = @_;
2667 return $RA if ($RA && $RA->{url
} eq $url);
2669 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
2670 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
([
2671 SVN
::Client
::get_simple_provider
(),
2672 SVN
::Client
::get_ssl_server_trust_file_provider
(),
2673 SVN
::Client
::get_simple_prompt_provider
(
2674 \
&Git
::SVN
::Prompt
::simple
, 2),
2675 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
2676 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
2677 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
2678 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
2679 SVN
::Client
::get_username_provider
(),
2680 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
2681 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
2682 SVN
::Client
::get_username_prompt_provider
(
2683 \
&Git
::SVN
::Prompt
::username
, 2),
2685 my $config = SVN
::Core
::config_get_config
($config_dir);
2686 my $self = SVN
::Ra
->new(url
=> $url, auth
=> $baton,
2688 pool
=> SVN
::Pool
->new,
2689 auth_provider_callbacks
=> $callbacks);
2690 $self->{svn_path
} = $url;
2691 $self->{repos_root
} = $self->get_repos_root;
2692 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
2693 $RA = bless $self, $class;
2697 # do not call the real DESTROY since we store ourselves in $RA
2701 my ($self, @args) = @_;
2702 my $pool = SVN
::Pool
->new;
2703 splice(@args, 3, 1) if ($SVN::Core
::VERSION
le '1.2.0');
2704 my $ret = $self->SUPER::get_log
(@args, $pool);
2709 sub get_commit_editor
{
2710 my ($self, $log, $cb, $pool) = @_;
2711 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
2712 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
2716 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
2717 my $new = ($rev_a == $rev_b);
2718 my $path = $gs->{path
};
2720 my $pool = SVN
::Pool
->new;
2721 $editor->set_path_strip($path);
2722 my (@pc) = split m
#/#, $path;
2723 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
2725 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2727 # Since we can't rely on svn_ra_reparent being available, we'll
2728 # just have to do some magic with set_path to make it so
2729 # we only want a partial path.
2731 my $final = join('/', @pc);
2733 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
2734 $sp .= '/' if length $sp;
2737 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
2739 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
2741 $reporter->finish_report($pool);
2743 $editor->{git_commit_ok
};
2746 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
2747 # svn_ra_reparent didn't work before 1.4)
2749 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
2750 my $path = $gs->{path
};
2751 my $pool = SVN
::Pool
->new;
2753 my $full_url = $self->{url
};
2754 my $old_url = $full_url;
2755 $full_url .= "/$path" if length $path;
2756 my ($ra, $reparented);
2757 if ($old_url ne $full_url) {
2758 if ($old_url !~ m
#^svn(\+ssh)?://#) {
2759 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url,
2761 $self->{url
} = $full_url;
2764 $ra = Git
::SVN
::Ra
->new($full_url);
2768 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
2769 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
2770 $reporter->set_path('', $rev_a, 0, @lock, $pool);
2771 $reporter->finish_report($pool);
2774 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
2775 $self->{url
} = $old_url;
2779 $editor->{git_commit_ok
};
2782 sub gs_fetch_loop_common
{
2783 my ($self, $base, $head, $gsv, $globs) = @_;
2784 return if ($base > $head);
2785 my $inc = $_log_window_size;
2786 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
2788 my $common_max = scalar @
$gsv;
2790 foreach my $gs (@
$gsv) {
2791 my @tmp = split m
#/#, $gs->{path};
2794 $p .= length($p) ?
"/$_" : $_;
2800 $common_max += scalar @
$globs;
2801 foreach my $glob (@
$globs) {
2802 my @tmp = split m
#/#, $glob->{path}->{left};
2805 $p .= length($p) ?
"/$_" : $_;
2811 my $longest_path = '';
2812 foreach (sort {length $b <=> length $a} keys %common) {
2813 if ($common{$_} == $common_max) {
2821 my $err_handler = $SVN::Error
::handler
;
2822 $SVN::Error
::handler
= sub {
2824 skip_unknown_revs
($err);
2827 my ($paths, $r, $author, $date, $log) = @_;
2828 [ dup_changed_paths
($paths),
2829 { author
=> $author, date
=> $date, log => $log } ];
2831 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
2832 sub { $revs{$_[1]} = _cb
(@_) });
2833 if ($err && $max >= $head) {
2834 print STDERR
"Path '$longest_path' ",
2835 "was probably deleted:\n",
2836 $err->expanded_message,
2837 "\nWill attempt to follow ",
2838 "revisions r$min .. r$max ",
2839 "committed before the deletion\n";
2841 while (--$hi >= $min) {
2843 $self->get_log([$longest_path], $min, $hi,
2846 $revs{$_[1]} = _cb
(@_) });
2848 print STDERR
"r$min .. r$ok OK\n";
2853 $SVN::Error
::handler
= $err_handler;
2855 my %exists = map { $_->{path
} => $_ } @
$gsv;
2856 foreach my $r (sort {$a <=> $b} keys %revs) {
2857 my ($paths, $logged) = @
{$revs{$r}};
2859 foreach my $gs ($self->match_globs(\
%exists, $paths,
2861 if ($gs->rev_db_max >= $r) {
2864 next unless $gs->match_paths($paths, $r);
2865 $gs->{logged_rev_props
} = $logged;
2866 if (my $last_commit = $gs->last_commit) {
2867 $gs->assert_index_clean($last_commit);
2869 my $log_entry = $gs->do_fetch($paths, $r);
2871 $gs->do_git_commit($log_entry);
2874 foreach my $g (@
$globs) {
2875 my $k = "svn-remote.$g->{remote}." .
2877 Git
::SVN
::tmp_config
($k, $r);
2880 # pre-fill the .rev_db since it'll eventually get filled in
2881 # with '0' x40 if something new gets committed
2882 foreach my $gs (@
$gsv) {
2883 next if defined $gs->rev_db_get($max);
2884 $gs->rev_db_set($max, 0 x40
);
2886 foreach my $g (@
$globs) {
2887 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
2888 Git
::SVN
::tmp_config
($k, $max);
2890 last if $max >= $head;
2893 $max = $head if ($max > $head);
2898 my ($self, $exists, $paths, $globs, $r) = @_;
2901 my ($self, $exists, $g, $r) = @_;
2902 my @x = eval { $self->get_dir($g->{path
}->{left
}, $r) };
2903 return unless scalar @x == 3;
2904 my $dirents = $x[0];
2905 foreach my $de (keys %$dirents) {
2906 next if $dirents->{$de}->kind != $SVN::Node
::dir
;
2907 my $p = $g->{path
}->full_path($de);
2908 next if $exists->{$p};
2909 next if (length $g->{path
}->{right
} &&
2910 ($self->check_path($p, $r) !=
2912 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
2913 $g->{ref}->full_path($de), 1);
2916 foreach my $g (@
$globs) {
2917 if (my $path = $paths->{"/$g->{path}->{left}"}) {
2918 if ($path->{action
} =~ /^[AR]$/) {
2919 get_dir_check
($self, $exists, $g, $r);
2922 foreach (keys %$paths) {
2923 if (/$g->{path}->{left_regex}/ &&
2924 !/$g->{path}->{regex}/) {
2925 next if $paths->{$_}->{action
} !~ /^[AR]$/;
2926 get_dir_check
($self, $exists, $g, $r);
2928 next unless /$g->{path}->{regex}/;
2930 my $pathname = $g->{path
}->full_path($p);
2931 next if $exists->{$pathname};
2932 $exists->{$pathname} = Git
::SVN
->init(
2933 $self->{url
}, $pathname, undef,
2934 $g->{ref}->full_path($p), 1);
2937 foreach (split m
#/#, $g->{path}->{left}) {
2939 next unless ($paths->{$c} &&
2940 ($paths->{$c}->{action
} =~ /^[AR]$/));
2941 get_dir_check
($self, $exists, $g, $r);
2949 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
2950 my $url = $self->{repos_root
};
2951 my @components = split(m!/!, $self->{svn_path
});
2954 $url .= "/$c" if length $c;
2955 eval { (ref $self)->new($url)->get_latest_revnum };
2956 } while ($@
&& ($c = shift @components));
2962 unless (defined $can_do_switch) {
2963 my $pool = SVN
::Pool
->new;
2965 $self->do_switch(1, '', 0, $self->{url
},
2966 SVN
::Delta
::Editor
->new, $pool);
2971 $rep->abort_report($pool);
2979 sub skip_unknown_revs
{
2981 my $errno = $err->apr_err();
2982 # Maybe the branch we're tracking didn't
2983 # exist when the repo started, so it's
2984 # not an error if it doesn't, just continue
2986 # Wonderfully consistent library, eh?
2987 # 160013 - svn:// and file://
2988 # 175002 - http(s)://
2989 # 175007 - http(s):// (this repo required authorization, too...)
2990 # More codes may be discovered later...
2991 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
2992 warn "W: Ignoring error from SVN, path probably ",
2993 "does not exist: ($errno): ",
2994 $err->expanded_message,"\n";
2997 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
3000 # svn_log_changed_path_t objects passed to get_log are likely to be
3001 # overwritten even if only the refs are copied to an external variable,
3002 # so we should dup the structures in their entirety. Using an externally
3003 # passed pool (instead of our temporary and quickly cleared pool in
3004 # Git::SVN::Ra) does not help matters at all...
3005 sub dup_changed_paths
{
3007 return undef unless $paths;
3009 foreach my $p (keys %$paths) {
3010 my $i = $paths->{$p};
3011 my %s = map { $_ => $i->$_ }
3012 qw
/copyfrom_path copyfrom_rev action/;
3018 package Git
::SVN
::Log
;
3021 use POSIX qw
/strftime/;
3022 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
3023 %rusers $show_commit $incremental/;
3028 return 1 if defined $c->{r
};
3029 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
3030 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
3031 my @log = command
(qw
/cat-file commit/, $c->{c
});
3032 shift @log while ($log[0] ne "\n");
3034 @
{$c->{l
}} = grep !/^git-svn-id: /, @log;
3036 (undef, $c->{r
}, undef) = ::extract_metadata
(
3037 (grep(/^git-svn-id: /, @log))[-1]);
3039 return defined $c->{r
};
3045 $dcvar = 'color.diff';
3046 $dc = `git-config --get $dcvar`;
3048 # nothing at all; fallback to "diff.color"
3049 $dcvar = 'diff.color';
3050 $dc = `git-config --get $dcvar`;
3053 if ($dc eq 'auto') {
3055 $pc = `git-config --get color.pager`;
3057 # does not have it -- fallback to pager.color
3058 $pc = `git-config --bool --get pager.color`;
3061 $pc = `git-config --bool --get color.pager`;
3067 if (-t
*STDOUT
|| (defined $pager && $pc eq 'true')) {
3068 return ($ENV{TERM
} && $ENV{TERM
} ne 'dumb');
3072 return 0 if $dc eq 'never';
3073 return 1 if $dc eq 'always';
3074 chomp($dc = `git-config --bool --get $dcvar`);
3075 return ($dc eq 'true');
3078 sub git_svn_log_cmd
{
3079 my ($r_min, $r_max, @args) = @_;
3081 foreach my $x (@args) {
3083 next unless ::verify_ref
("$x^0");
3089 my ($fh, $ctx) = command_output_pipe
('rev-list', $head);
3092 $url = (::cmt_metadata
($_))[0];
3093 last if defined $url;
3095 close $fh; # break the pipe
3097 my $gs = Git
::SVN
->find_by_url($url) || Git
::SVN
->_new;
3098 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
3100 push @cmd, '-r' unless $non_recursive;
3101 push @cmd, qw
/--raw --name-status/ if $verbose;
3102 push @cmd, '--color' if log_use_color
();
3103 return @cmd unless defined $r_max;
3104 if ($r_max == $r_min) {
3105 push @cmd, '--max-count=1';
3106 if (my $c = $gs->rev_db_get($r_max)) {
3110 my ($c_min, $c_max);
3111 $c_max = $gs->rev_db_get($r_max);
3112 $c_min = $gs->rev_db_get($r_min);
3113 if (defined $c_min && defined $c_max) {
3114 if ($r_max > $r_max) {
3115 push @cmd, "$c_min..$c_max";
3117 push @cmd, "$c_max..$c_min";
3119 } elsif ($r_max > $r_min) {
3128 # adapted from pager.c
3130 $pager ||= $ENV{GIT_PAGER
} || $ENV{PAGER
};
3131 if (!defined $pager) {
3133 } elsif (length $pager == 0 || $pager eq 'cat') {
3139 return unless -t
*STDOUT
;
3140 pipe my $rfd, my $wfd or return;
3141 defined(my $pid = fork) or ::fatal
"Can't fork: $!\n";
3143 open STDOUT
, '>&', $wfd or
3144 ::fatal
"Can't redirect to stdout: $!\n";
3147 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!\n";
3148 $ENV{LESS
} ||= 'FRSX';
3149 exec $pager or ::fatal
"Can't run pager: $! ($pager)\n";
3152 sub tz_to_s_offset
{
3155 return ($1 * 60) + ($tz * 3600);
3158 sub get_author_info
{
3159 my ($dest, $author, $t, $tz) = @_;
3160 $author =~ s/(?:^\s*|\s*$)//g;
3161 $dest->{a_raw
} = $author;
3164 $au = $rusers{$author} || undef;
3167 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
3172 # Date::Parse isn't in the standard Perl distro :(
3173 if ($tz =~ s/^\+//) {
3174 $t += tz_to_s_offset
($tz);
3175 } elsif ($tz =~ s/^\-//) {
3176 $t -= tz_to_s_offset
($tz);
3178 $dest->{t_utc
} = $t;
3181 sub process_commit
{
3182 my ($c, $r_min, $r_max, $defer) = @_;
3183 if (defined $r_min && defined $r_max) {
3184 if ($r_min == $c->{r
} && $r_min == $r_max) {
3188 return 1 if $r_min == $r_max;
3189 if ($r_min < $r_max) {
3190 # we need to reverse the print order
3191 return 0 if (defined $limit && --$limit < 0);
3195 if ($r_min != $r_max) {
3196 return 1 if ($r_min < $c->{r
});
3197 return 1 if ($r_max > $c->{r
});
3200 return 0 if (defined $limit && --$limit < 0);
3209 if (my $l = $c->{l
}) {
3210 while ($l->[0] =~ /^\s*$/) { shift @
$l }
3213 $l_fmt ||= 'A' . length($c->{r
});
3214 print 'r',pack($l_fmt, $c->{r
}),' | ';
3215 print "$c->{c} | " if $show_commit;
3218 show_commit_normal
($c);
3222 sub show_commit_changed_paths
{
3224 return unless $c->{changed
};
3225 print "Changed paths:\n", @
{$c->{changed
}};
3228 sub show_commit_normal
{
3230 print '-' x72
, "\nr$c->{r} | ";
3231 print "$c->{c} | " if $show_commit;
3232 print "$c->{a} | ", strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
3233 localtime($c->{t_utc
})), ' | ';
3236 if (my $l = $c->{l
}) {
3237 while ($l->[$#$l] eq "\n" && $#$l > 0
3238 && $l->[($#$l - 1)] eq "\n") {
3241 $nr_line = scalar @
$l;
3243 print "1 line\n\n\n";
3245 if ($nr_line == 1) {
3246 $nr_line = '1 line';
3248 $nr_line .= ' lines';
3250 print $nr_line, "\n";
3251 show_commit_changed_paths
($c);
3253 print $_ foreach @
$l;
3257 show_commit_changed_paths
($c);
3261 foreach my $x (qw
/raw stat diff/) {
3264 print $_ foreach @
{$c->{$x}}
3271 my ($r_min, $r_max);
3272 my $r_last = -1; # prevent dupes
3278 if (defined $::_revision
) {
3279 if ($::_revision
=~ /^(\d+):(\d+)$/) {
3280 ($r_min, $r_max) = ($1, $2);
3281 } elsif ($::_revision
=~ /^\d+$/) {
3282 $r_min = $r_max = $::_revision
;
3284 ::fatal
"-r$::_revision is not supported, use ",
3285 "standard \'git log\' arguments instead\n";
3290 @args = (git_svn_log_cmd
($r_min, $r_max, @args), @args);
3291 my $log = command_output_pipe
(@args);
3293 my (@k, $c, $d, $stat);
3294 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
3296 if (/^${esc_color}commit ($::sha1_short)/o) {
3298 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
3300 process_commit
($c, $r_min, $r_max, \
@k) or
3305 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
3306 get_author_info
($c, $1, $2, $3);
3307 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
3309 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
3310 push @
{$c->{raw
}}, $_;
3311 } elsif (/^${esc_color}[ACRMDT]\t/) {
3312 # we could add $SVN->{svn_path} here, but that requires
3313 # remote access at the moment (repo_path_split)...
3314 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
3315 push @
{$c->{changed
}}, $_;
3316 } elsif (/^${esc_color}diff /o) {
3318 push @
{$c->{diff
}}, $_;
3320 push @
{$c->{diff
}}, $_;
3321 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
3322 $esc_color*[\
+\
-]*$esc_color$/x
) {
3324 push @
{$c->{stat}}, $_;
3325 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
3326 push @
{$c->{stat}}, $_;
3328 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
3329 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
3330 } elsif (s/^${esc_color} //o) {
3331 push @
{$c->{l
}}, $_;
3334 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
3336 process_commit
($c, $r_min, $r_max, \
@k);
3342 process_commit
($_, $r_min, $r_max) foreach reverse @k;
3346 print '-' x72
,"\n" unless $incremental || $oneline;
3349 package Git
::SVN
::Migration
;
3350 # these version numbers do NOT correspond to actual version numbers
3351 # of git nor git-svn. They are just relative.
3353 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
3355 # v1 layout: .git/$id/info/url, refs/remotes/$id
3357 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
3359 # v3 layout: .git/svn/$id, refs/remotes/$id
3360 # - info/url may remain for backwards compatibility
3361 # - this is what we migrate up to this layout automatically,
3362 # - this will be used by git svn init on single branches
3363 # v3.1 layout (auto migrated):
3364 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
3365 # for backwards compatibility
3367 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
3368 # - this is only created for newly multi-init-ed
3369 # repositories. Similar in spirit to the
3370 # --use-separate-remotes option in git-clone (now default)
3371 # - we do not automatically migrate to this (following
3372 # the example set by core git)
3376 use File
::Path qw
/mkpath/;
3377 use File
::Basename qw
/dirname basename/;
3378 use vars qw
/$_minimize/;
3380 sub migrate_from_v0
{
3381 my $git_dir = $ENV{GIT_DIR
};
3382 return undef unless -d
$git_dir;
3383 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
3387 my ($id, $orig_ref) = ($_, $_);
3388 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
3389 next unless -f
"$git_dir/$id/info/url";
3390 my $new_ref = "refs/remotes/$id";
3391 if (::verify_ref
("$new_ref^0")) {
3392 print STDERR
"W: $orig_ref is probably an old ",
3393 "branch used by an ancient version of ",
3395 "However, $new_ref also exists.\n",
3396 "We will not be able ",
3397 "to use this branch until this ",
3398 "ambiguity is resolved.\n";
3401 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
3402 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
3403 command_noisy
('update-ref', $new_ref, $orig_ref);
3404 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
3407 command_close_pipe
($fh, $ctx);
3408 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
3412 sub migrate_from_v1
{
3413 my $git_dir = $ENV{GIT_DIR
};
3415 return $migrated unless -d
$git_dir;
3416 my $svn_dir = "$git_dir/svn";
3418 # just in case somebody used 'svn' as their $id at some point...
3419 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
3421 print STDERR
"Migrating from a git-svn v1 layout...\n";
3423 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
3424 "$svn_dir\n\t(required for this version ",
3425 "($::VERSION) of git-svn) does not. exist\n";
3426 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
3429 next unless $x =~ s
#^refs/remotes/##;
3431 next unless -f
"$git_dir/$x/info/url";
3432 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
3434 my $dn = dirname
("$git_dir/svn/$x");
3435 mkpath
([$dn]) unless -d
$dn;
3436 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
3437 mkpath
(["$git_dir/svn/svn"]);
3438 print STDERR
" - $git_dir/$x/info => ",
3439 "$git_dir/svn/$x/info\n";
3440 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
3442 # don't worry too much about these, they probably
3443 # don't exist with repos this old (save for index,
3444 # and we can easily regenerate that)
3445 foreach my $f (qw
/unhandled.log index .rev_db/) {
3446 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
3449 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
3450 rename "$git_dir/$x", "$git_dir/svn/$x" or
3455 command_close_pipe
($fh, $ctx);
3456 print STDERR
"Done migrating from a git-svn v1 layout\n";
3461 my ($l_map, $pfx, $path) = @_;
3463 foreach (<$path/*>) {
3464 if (-r
"$_/info/url") {
3465 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
3466 my $ref_id = $pfx . basename
$_;
3467 my $url = ::file_to_s
("$_/info/url");
3468 $l_map->{$ref_id} = $url;
3475 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
3476 read_old_urls
($l_map, $x, $_);
3480 sub migrate_from_v2
{
3481 my @cfg = command
(qw
/config -l/);
3482 return if grep /^svn-remote\..+\.url=/, @cfg;
3484 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
3487 foreach my $ref_id (sort keys %l_map) {
3488 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
3490 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
3497 sub minimize_connections
{
3498 my $r = Git
::SVN
::read_all_remotes
();
3500 my $root_repos = {};
3501 foreach my $repo_id (keys %$r) {
3502 my $url = $r->{$repo_id}->{url
} or next;
3503 my $fetch = $r->{$repo_id}->{fetch
} or next;
3504 my $ra = Git
::SVN
::Ra
->new($url);
3506 # skip existing cases where we already connect to the root
3507 if (($ra->{url
} eq $ra->{repos_root
}) ||
3508 (Git
::SVN
::sanitize_remote_name
($ra->{repos_root
}) eq
3510 $root_repos->{$ra->{url
}} = $repo_id;
3514 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
3515 my $root_path = $ra->{url
};
3516 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
3517 foreach my $path (keys %$fetch) {
3518 my $ref_id = $fetch->{$path};
3519 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
3521 # make sure we can read when connecting to
3522 # a higher level of a repository
3523 my ($last_rev, undef) = $gs->last_rev_commit;
3524 if (!defined $last_rev) {
3526 $root_ra->get_latest_revnum;
3530 my $new = $root_path;
3531 $new .= length $path ?
"/$path" : '';
3533 $root_ra->get_log([$new], $last_rev, $last_rev,
3537 $new_urls->{$ra->{repos_root
}}->{$new} =
3538 { ref_id
=> $ref_id,
3539 old_repo_id
=> $repo_id,
3540 old_path
=> $path };
3545 foreach my $url (keys %$new_urls) {
3546 # see if we can re-use an existing [svn-remote "repo_id"]
3547 # instead of creating a(n ugly) new section:
3548 my $repo_id = $root_repos->{$url} ||
3549 Git
::SVN
::sanitize_remote_name
($url);
3551 my $fetch = $new_urls->{$url};
3552 foreach my $path (keys %$fetch) {
3553 my $x = $fetch->{$path};
3554 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
3555 my $pfx = "svn-remote.$x->{old_repo_id}";
3557 my $old_fetch = quotemeta("$x->{old_path}:".
3558 "refs/remotes/$x->{ref_id}");
3559 command_noisy
(qw
/config --unset/,
3560 "$pfx.fetch", '^'. $old_fetch . '$');
3561 delete $r->{$x->{old_repo_id
}}->
3562 {fetch
}->{$x->{old_path
}};
3563 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
3564 command_noisy
(qw
/config --unset/,
3566 push @emptied, $x->{old_repo_id
}
3571 my $file = $ENV{GIT_CONFIG
} || $ENV{GIT_CONFIG_LOCAL
} ||
3572 "$ENV{GIT_DIR}/config";
3574 The following [svn-remote] sections in your config file ($file) are empty
3575 and can be safely removed:
3577 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
3581 sub migration_check
{
3585 minimize_connections
() if $_minimize;
3588 package Git
::IndexInfo
;
3591 use Git qw
/command_input_pipe command_close_pipe/;
3595 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
3596 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
3600 my ($self, $path) = @_;
3601 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
3602 return ++$self->{nr
};
3608 my ($self, $mode, $hash, $path) = @_;
3609 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
3610 return ++$self->{nr
};
3617 command_close_pipe
($self->{gui
}, $self->{ctx
});
3620 package Git
::SVN
::GlobSpec
;
3625 my ($class, $glob) = @_;
3627 $re =~ s!/+$!!g; # no need for trailing slashes
3628 my $nr = ($re =~ s!^(.*)\*(.*)$!\(\[^/\]+\)!g);
3629 my ($left, $right) = ($1, $2);
3631 die "Only one '*' wildcard expansion ",
3632 "is supported (got $nr): '$glob'\n";
3633 } elsif ($nr == 0) {
3634 die "One '*' is needed for glob: '$glob'\n";
3636 $re = quotemeta($left) . $re . quotemeta($right);
3637 if (length $left && !($left =~ s!/+$!!g)) {
3638 die "Missing trailing '/' on left side of: '$glob' ($left)\n";
3640 if (length $right && !($right =~ s!^/+!!g)) {
3641 die "Missing leading '/' on right side of: '$glob' ($right)\n";
3643 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
3644 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
3645 regex
=> qr/$re/, glob => $glob }, $class;
3649 my ($self, $path) = @_;
3650 return (length $self->{left
} ?
"$self->{left}/" : '') .
3651 $path . (length $self->{right
} ?
"/$self->{right}" : '');
3659 $remotes = { # returned by read_all_remotes()
3661 # svn-remote.svn.url=https://svn.musicpd.org
3662 url
=> 'https://svn.musicpd.org',
3663 # svn-remote.svn.fetch=mpd/trunk:trunk
3665 'mpd/trunk' => 'trunk',
3667 # svn-remote.svn.tags=mpd/tags/*:tags/*
3672 regex
=> qr!mpd/tags/([^/]+)$!,
3678 regex
=> qr!tags/([^/]+)$!,
3685 $log_entry hashref as returned by libsvn_log_entry
()
3687 log => 'whitespace-formatted log entry
3688 ', # trailing newline is preserved
3689 revision
=> '8', # integer
3690 date
=> '2004-02-24T17:01:44.108345Z', # commit date
3691 author
=> 'committer name'
3695 # this is generated by generate_diff();
3696 @mods = array of diff
-index line hashes
, each element represents one line
3697 of diff
-index output
3699 diff
-index line
($m hash
)
3701 mode_a
=> first column of diff
-index output
, no leading
':',
3702 mode_b
=> second column of diff
-index output
,
3703 sha1_b
=> sha1sum of the final blob
,
3704 chg
=> change type
[MCRADT
],
3705 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
3706 file_b
=> new
/current file name of a file
(any chg
)
3710 # retval of read_url_paths{,_all}();
3712 # repository root url
3713 'https://svn.musicpd.org' => {
3714 # repository path # GIT_SVN_ID
3715 'mpd/trunk' => 'trunk',
3716 'mpd/tags/0.11.5' => 'tags/0.11.5',
3721 I don
't trust the each() function on unless I created %hash myself
3722 because the internal iterator may not have started at base.