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 $_repository
8 $_q $_authors $_authors_prog %users/;
9 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
10 $VERSION = '@@GIT_VERSION@@';
12 # From which subdir have we been invoked?
13 my $cmd_dir_prefix = eval {
14 command_oneline
([qw
/rev-parse --show-prefix/], STDERR
=> 0)
17 my $git_dir_user_set = 1 if defined $ENV{GIT_DIR
};
18 $ENV{GIT_DIR
} ||= '.git';
19 $Git::SVN
::default_repo_id
= 'svn';
20 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
21 $Git::SVN
::Ra
::_log_window_size
= 100;
22 $Git::SVN
::_minimize_url
= 'unset';
24 if (! exists $ENV{SVN_SSH
}) {
25 if (exists $ENV{GIT_SSH
}) {
26 $ENV{SVN_SSH
} = $ENV{GIT_SSH
};
28 $ENV{SVN_SSH
} =~ s/\\/\\\\/g;
33 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
35 $| = 1; # unbuffer STDOUT
37 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
38 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
41 if ($SVN::Core
::VERSION
lt '1.1.0') {
42 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
44 my $can_compress = eval { require Compress
::Zlib
; 1};
45 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
46 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
47 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
51 use File
::Basename qw
/dirname basename/;
52 use File
::Path qw
/mkpath/;
55 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev/;
60 # import functions from Git into our packages, en masse
62 foreach (qw
/command command_oneline command_noisy command_output_pipe
63 command_input_pipe command_close_pipe
64 command_bidi_pipe command_close_bidi_pipe
/) {
65 for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
66 Git::SVN::Migration Git::SVN::Log Git::SVN),
68 *{"${package}::$_"} = \
&{"Git::$_"};
75 $sha1 = qr/[a-f\d]{40}/;
76 $sha1_short = qr/[a-f\d]{4,40}/;
77 my ($_stdin, $_help, $_edit,
78 $_message, $_file, $_branch_dest,
80 $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
81 $_merge, $_strategy, $_dry_run, $_local,
82 $_prefix, $_no_checkout, $_url, $_verbose,
83 $_git_format, $_commit_url, $_tag);
84 $Git::SVN
::_follow_parent
= 1;
86 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
87 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
88 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
,
89 'ignore-paths=s' => \
$SVN::Git
::Fetcher
::_ignore_regex
);
90 my %fc_opts = ( 'follow-parent|follow!' => \
$Git::SVN
::_follow_parent
,
91 'authors-file|A=s' => \
$_authors,
92 'authors-prog=s' => \
$_authors_prog,
93 'repack:i' => \
$Git::SVN
::_repack
,
94 'noMetadata' => \
$Git::SVN
::_no_metadata
,
95 'useSvmProps' => \
$Git::SVN
::_use_svm_props
,
96 'useSvnsyncProps' => \
$Git::SVN
::_use_svnsync_props
,
97 'log-window-size=i' => \
$Git::SVN
::Ra
::_log_window_size
,
98 'no-checkout' => \
$_no_checkout,
100 'repack-flags|repack-args|repack-opts=s' =>
101 \
$Git::SVN
::_repack_flags
,
102 'use-log-author' => \
$Git::SVN
::_use_log_author
,
103 'add-author-from' => \
$Git::SVN
::_add_author_from
,
104 'localtime' => \
$Git::SVN
::_localtime
,
107 my ($_trunk, @_tags, @_branches, $_stdlayout);
109 my %init_opts = ( 'template=s' => \
$_template, 'shared:s' => \
$_shared,
110 'trunk|T=s' => \
$_trunk, 'tags|t=s@' => \
@_tags,
111 'branches|b=s@' => \
@_branches, 'prefix=s' => \
$_prefix,
112 'stdlayout|s' => \
$_stdlayout,
113 'minimize-url|m!' => \
$Git::SVN
::_minimize_url
,
114 'no-metadata' => sub { $icv{noMetadata
} = 1 },
115 'use-svm-props' => sub { $icv{useSvmProps
} = 1 },
116 'use-svnsync-props' => sub { $icv{useSvnsyncProps
} = 1 },
117 'rewrite-root=s' => sub { $icv{rewriteRoot
} = $_[1] },
119 my %cmt_opts = ( 'edit|e' => \
$_edit,
120 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
121 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
122 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
123 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
127 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
128 { 'revision|r=s' => \
$_revision,
129 'fetch-all|all' => \
$_fetch_all,
130 'parent|p' => \
$_fetch_parent,
132 clone
=> [ \
&cmd_clone
, "Initialize and fetch revisions",
133 { 'revision|r=s' => \
$_revision,
134 %fc_opts, %init_opts } ],
135 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
136 " (requires URL argument)",
138 'multi-init' => [ \
&cmd_multi_init
,
139 "Deprecated alias for ".
140 "'$0 init -T<trunk> -b<branches> -t<tags>'",
142 dcommit
=> [ \
&cmd_dcommit
,
143 'Commit several diffs to merge with upstream',
144 { 'merge|m|M' => \
$_merge,
145 'strategy|s=s' => \
$_strategy,
146 'verbose|v' => \
$_verbose,
147 'dry-run|n' => \
$_dry_run,
148 'fetch-all|all' => \
$_fetch_all,
149 'commit-url=s' => \
$_commit_url,
150 'revision|r=i' => \
$_revision,
151 'no-rebase' => \
$_no_rebase,
152 %cmt_opts, %fc_opts } ],
153 branch
=> [ \
&cmd_branch
,
154 'Create a branch in the SVN repository',
155 { 'message|m=s' => \
$_message,
156 'destination|d=s' => \
$_branch_dest,
157 'dry-run|n' => \
$_dry_run,
158 'tag|t' => \
$_tag } ],
159 tag
=> [ sub { $_tag = 1; cmd_branch
(@_) },
160 'Create a tag in the SVN repository',
161 { 'message|m=s' => \
$_message,
162 'destination|d=s' => \
$_branch_dest,
163 'dry-run|n' => \
$_dry_run } ],
164 'set-tree' => [ \
&cmd_set_tree
,
165 "Set an SVN repository to a git tree-ish",
166 { 'stdin' => \
$_stdin, %cmt_opts, %fc_opts, } ],
167 'create-ignore' => [ \
&cmd_create_ignore
,
168 'Create a .gitignore per svn:ignore',
169 { 'revision|r=i' => \
$_revision
171 'mkdirs' => [ \
&cmd_mkdirs
,
172 "recreate empty directories after a checkout",
173 { 'revision|r=i' => \
$_revision } ],
174 'propget' => [ \
&cmd_propget
,
175 'Print the value of a property on a file or directory',
176 { 'revision|r=i' => \
$_revision } ],
177 'proplist' => [ \
&cmd_proplist
,
178 'List all properties of a file or directory',
179 { 'revision|r=i' => \
$_revision } ],
180 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
181 { 'revision|r=i' => \
$_revision
183 'show-externals' => [ \
&cmd_show_externals
, "Show svn:externals listings",
184 { 'revision|r=i' => \
$_revision
186 'multi-fetch' => [ \
&cmd_multi_fetch
,
187 "Deprecated alias for $0 fetch --all",
188 { 'revision|r=s' => \
$_revision, %fc_opts } ],
189 'migrate' => [ sub { },
190 # no-op, we automatically run this anyways,
191 'Migrate configuration/metadata/layout from
192 previous versions of git-svn',
193 { 'minimize' => \
$Git::SVN
::Migration
::_minimize
,
195 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
196 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
197 'revision|r=s' => \
$_revision,
198 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
199 'incremental' => \
$Git::SVN
::Log
::incremental
,
200 'oneline' => \
$Git::SVN
::Log
::oneline
,
201 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
202 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
203 'authors-file|A=s' => \
$_authors,
204 'color' => \
$Git::SVN
::Log
::color
,
205 'pager=s' => \
$Git::SVN
::Log
::pager
207 'find-rev' => [ \
&cmd_find_rev
,
208 "Translate between SVN revision numbers and tree-ish",
210 'rebase' => [ \
&cmd_rebase
, "Fetch and rebase your working directory",
211 { 'merge|m|M' => \
$_merge,
212 'verbose|v' => \
$_verbose,
213 'strategy|s=s' => \
$_strategy,
214 'local|l' => \
$_local,
215 'fetch-all|all' => \
$_fetch_all,
216 'dry-run|n' => \
$_dry_run,
218 'commit-diff' => [ \
&cmd_commit_diff
,
219 'Commit a diff between two trees',
220 { 'message|m=s' => \
$_message,
221 'file|F=s' => \
$_file,
222 'revision|r=s' => \
$_revision,
224 'info' => [ \
&cmd_info
,
225 "Show info about the latest SVN revision
226 on the current branch",
227 { 'url' => \
$_url, } ],
228 'blame' => [ \
&Git
::SVN
::Log
::cmd_blame
,
229 "Show what revision and author last modified each line of a file",
230 { 'git-format' => \
$_git_format } ],
231 'reset' => [ \
&cmd_reset
,
232 "Undo fetches back to the specified SVN revision",
233 { 'revision|r=s' => \
$_revision,
234 'parent|p' => \
$_fetch_parent } ],
236 "Compress unhandled.log files in .git/svn and remove " .
237 "index files in .git/svn",
242 for (my $i = 0; $i < @ARGV; $i++) {
243 if (defined $cmd{$ARGV[$i]}) {
247 } elsif ($ARGV[$i] eq 'help') {
253 # make sure we're always running at the top-level working directory
254 unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
255 unless (-d
$ENV{GIT_DIR
}) {
256 if ($git_dir_user_set) {
257 die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
258 "but it is not a directory\n";
260 my $git_dir = delete $ENV{GIT_DIR
};
263 $cdup = command_oneline
(qw
/rev-parse --show-cdup/);
264 $git_dir = '.' unless ($cdup);
265 chomp $cdup if ($cdup);
266 $cdup = "." unless ($cdup && length $cdup);
267 } "Already at toplevel, but $git_dir not found\n";
268 chdir $cdup or die "Unable to chdir up to '$cdup'\n";
269 unless (-d
$git_dir) {
270 die "$git_dir still not found after going to ",
273 $ENV{GIT_DIR
} = $git_dir;
275 $_repository = Git
->repository(Repository
=> $ENV{GIT_DIR
});
278 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
280 read_git_config
(\
%opts);
281 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
282 Getopt
::Long
::Configure
('pass_through');
284 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help, 'version|V' => \
$_version,
285 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
286 'id|i=s' => \
$Git::SVN
::default_ref_id
,
287 'svn-remote|remote|R=s' => sub {
288 $Git::SVN
::no_reuse_existing
= 1;
289 $Git::SVN
::default_repo_id
= $_[1] });
290 exit 1 if (!$rv && $cmd && $cmd ne 'log');
293 version
() if $_version;
294 usage
(1) unless defined $cmd;
295 load_authors
() if $_authors;
296 if (defined $_authors_prog) {
297 $_authors_prog = "'" . File
::Spec
->rel2abs($_authors_prog) . "'";
300 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
301 Git
::SVN
::Migration
::migration_check
();
303 Git
::SVN
::init_vars
();
305 Git
::SVN
::verify_remotes_sanity
();
306 $cmd{$cmd}->[0]->(@ARGV);
309 post_fetch_checkout
();
312 ####################### primary functions ######################
314 my $exit = shift || 0;
315 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
317 git
-svn
- bidirectional operations between a single Subversion tree
and git
318 Usage
: git svn
<command
> [options
] [arguments
]\n
320 print $fd "Available commands:\n" unless $cmd;
322 foreach (sort keys %cmd) {
323 next if $cmd && $cmd ne $_;
324 next if /^multi-/; # don't show deprecated commands
325 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
326 foreach (sort keys %{$cmd{$_}->[2]}) {
327 # mixed-case options are for .git/config only
328 next if /[A-Z]/ && /^[a-z]+$/i;
329 # prints out arguments as they should be passed:
330 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
331 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
333 split /\|/,$_)," $x\n";
337 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
338 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
339 one git repository and want to keep them separate. See git-svn(1) for more
346 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
351 unless (-d $ENV{GIT_DIR}) {
352 my @init_db = ('init
');
353 push @init_db, "--template=$_template" if defined $_template;
354 if (defined $_shared) {
355 if ($_shared =~ /[a-z]/) {
356 push @init_db, "--shared=$_shared";
358 push @init_db, "--shared";
361 command_noisy(@init_db);
362 $_repository = Git->repository(Repository => ".git");
364 command_noisy('config
', 'core
.autocrlf
', 'false
');
366 my $pfx = "svn-remote.$Git::SVN::default_repo_id";
367 foreach my $i (keys %icv) {
368 die "'$set' and '$i' cannot both be set\n" if $set;
369 next unless defined $icv{$i};
370 command_noisy('config
', "$pfx.$i", $icv{$i});
373 my $ignore_regex = \$SVN::Git::Fetcher::_ignore_regex;
374 command_noisy('config
', "$pfx.ignore-paths", $$ignore_regex)
375 if defined $$ignore_regex;
379 my $repo_path = shift or return;
380 mkpath([$repo_path]) unless -d $repo_path;
381 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
382 $ENV{GIT_DIR} = '.git';
383 $_repository = Git->repository(Repository => $ENV{GIT_DIR});
387 my ($url, $path) = @_;
388 if (!defined $path &&
389 (defined $_trunk || @_branches || @_tags ||
390 defined $_stdlayout) &&
391 $url !~ m#^[a-z\+]+://#) {
394 $path = basename($url) if !defined $path || !length $path;
395 my $authors_absolute = $_authors ? File::Spec->rel2abs($_authors) : "";
396 cmd_init($url, $path);
397 command_oneline('config', 'svn.authorsfile', $authors_absolute)
399 Git::SVN::fetch_all($Git::SVN::default_repo_id);
403 if (defined $_stdlayout) {
404 $_trunk = 'trunk' if (!defined $_trunk);
405 @_tags = 'tags' if (! @_tags);
406 @_branches = 'branches' if (! @_branches);
408 if (defined $_trunk || @_branches || @_tags) {
409 return cmd_multi_init(@_);
411 my $url = shift or die "SVN repository location required
",
412 "as a command
-line argument
\n";
413 $url = canonicalize_url($url);
417 if ($Git::SVN::_minimize_url eq 'unset') {
418 $Git::SVN::_minimize_url = 0;
421 Git::SVN->init($url);
425 if (grep /^\d+=./, @_) {
426 die "'<rev>=<commit>' fetch arguments are
",
427 "no longer supported
.\n";
431 die "Usage
: $0 fetch
[--all
] [--parent
] [svn
-remote
]\n";
433 $Git::SVN::no_reuse_existing = undef;
434 if ($_fetch_parent) {
435 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
437 die "Unable to determine upstream SVN information from
",
438 "working tree history
\n";
440 # just fetch, don't checkout.
441 $_no_checkout = 'true';
442 $_fetch_all ? $gs->fetch_all : $gs->fetch;
443 } elsif ($_fetch_all) {
446 $remote ||= $Git::SVN::default_repo_id;
447 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
453 if ($_stdin || !@commits) {
454 print "Reading from stdin
...\n";
457 if (/\b($sha1_short)\b/o) {
458 unshift @commits, $1;
463 foreach my $c (@commits) {
464 my @tmp = command('rev-parse',$c);
465 if (scalar @tmp == 1) {
467 } elsif (scalar @tmp > 1) {
468 push @revs, reverse(command('rev-list',@tmp));
470 fatal "Failed to rev
-parse
$c";
473 my $gs = Git::SVN->new;
474 my ($r_last, $cmt_last) = $gs->last_rev_commit;
476 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
477 fatal "There are new revisions that were fetched
",
478 "and need to be merged
(or acknowledged
) ",
479 "before committing
.\nlast rev
: $r_last\n",
480 " current
: $gs->{last_rev
}";
482 $gs->set_tree($_) foreach @revs;
483 print "Done committing
",scalar @revs," revisions to SVN
\n";
489 git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) }
490 'Cannot dcommit with a dirty index. Commit your changes first, '
491 . "or stash them with
`git stash'.\n";
495 if ($head ne 'HEAD') {
497 command_oneline([qw/symbolic-ref -q HEAD/])
500 $old_head =~ s{^refs/heads/}{};
502 $old_head = eval { command_oneline(qw/rev-parse HEAD/) };
504 command(['checkout', $head], STDERR => 0);
508 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD', \@refs);
510 die "Unable to determine upstream SVN information from ",
511 "$head history.\nPerhaps the repository is empty.";
514 if (defined $_commit_url) {
517 $url = eval { command_oneline('config', '--get',
518 "svn-remote.$gs->{repo_id}.commiturl") };
524 my $last_rev = $_revision if defined $_revision;
526 print "Committing to $url ...\n";
528 my ($linear_refs, $parents) = linearize_history($gs, \@refs);
529 if ($_no_rebase && scalar(@$linear_refs) > 1) {
530 warn "Attempting to commit more than one change while ",
531 "--no-rebase is enabled.\n",
532 "If these changes depend on each other, re-running ",
533 "without --no-rebase may be required."
535 my $expect_url = $url;
536 Git::SVN::remove_username($expect_url);
538 my $d = shift @$linear_refs or last;
539 unless (defined $last_rev) {
540 (undef, $last_rev, undef) = cmt_metadata("$d~1");
541 unless (defined $last_rev) {
542 fatal "Unable to extract revision information ",
547 print "diff-tree $d~1 $d\n";
550 my %ed_opts = ( r => $last_rev,
551 log => get_commit_entry($d)->{log},
552 ra => Git::SVN::Ra->new($url),
553 config => SVN::Core::config_get_config(
554 $Git::SVN::Ra::config_dir
559 print "Committed r$_[0]\n";
563 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
564 print "No changes\n$d~1 == $d\n";
565 } elsif ($parents->{$d} && @{$parents->{$d}}) {
566 $gs->{inject_parents_dcommit}->{$cmt_rev} =
569 $_fetch_all ? $gs->fetch_all : $gs->fetch;
570 $last_rev = $cmt_rev;
573 # we always want to rebase against the current HEAD,
574 # not any head that was passed to us
575 my @diff = command('diff-tree', $d,
579 @finish = rebase_cmd();
580 print STDERR "W: $d and ", $gs->refname,
581 " differ, using @finish:\n",
582 join("\n", @diff), "\n";
584 print "No changes between current HEAD and ",
586 "\nResetting to the latest ",
588 @finish = qw/reset --mixed/;
590 command_noisy(@finish, $gs->refname);
593 my ($url_, $rev_, $uuid_, $gs_) =
594 working_head_info('HEAD', \@refs);
595 my ($linear_refs_, $parents_) =
596 linearize_history($gs_, \@refs);
597 if (scalar(@$linear_refs) !=
598 scalar(@$linear_refs_)) {
599 fatal "# of revisions changed ",
601 join("\n", @$linear_refs),
603 join("\n", @$linear_refs_), "\n",
604 'If you are attempting to commit ',
605 "merges, try running:\n\t",
606 'git rebase --interactive',
607 '--preserve-merges ',
609 "\nBefore dcommitting";
611 if ($url_ ne $expect_url) {
612 if ($url_ eq $gs->metadata_url) {
614 "Accepting rewritten URL:",
618 "URL mismatch after rebase:",
619 " $url_ != $expect_url";
622 if ($uuid_ ne $uuid) {
623 fatal "uuid mismatch after rebase: ",
628 for ($i = 0; $i < scalar @$linear_refs; $i++) {
629 my $new = $linear_refs_->[$i] or next;
631 $parents->{$linear_refs->[$i]};
641 my $new_head = command_oneline(qw/rev-parse HEAD/);
642 my $new_is_symbolic = eval {
643 command_oneline(qw/symbolic-ref -q HEAD/);
645 if ($new_is_symbolic) {
646 print "dcommitted the branch ", $head, "\n";
648 print "dcommitted on a detached HEAD because you gave ",
649 "a revision argument.\n",
650 "The rewritten commit is: ", $new_head, "\n";
652 command(['checkout', $old_head], STDERR => 0);
659 my ($branch_name, $head) = @_;
661 unless (defined $branch_name && length $branch_name) {
662 die(($_tag ? "tag" : "branch") . " name required\n");
666 my ($src, $rev, undef, $gs) = working_head_info($head);
668 my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
669 my $allglobs = $remote->{ $_tag ? 'tags' : 'branches' };
671 if ($#{$allglobs} == 0) {
672 $glob = $allglobs->[0];
674 unless(defined $_branch_dest) {
676 $_tag ? "tag" : "branch",
677 " paths defined for Subversion repository.\n",
678 "You must specify where you want to create the ",
679 $_tag ? "tag" : "branch",
680 " with the --destination argument.\n";
682 foreach my $g (@{$allglobs}) {
683 # SVN::Git::Editor could probably be moved to Git.pm..
684 my $re = SVN::Git::Editor::glob2pat($g->{path}->{left});
685 if ($_branch_dest =~ /$re/) {
690 unless (defined $glob) {
691 my $dest_re = qr/\b\Q$_branch_dest\E\b/;
692 foreach my $g (@{$allglobs}) {
693 $g->{path}->{left} =~ /$dest_re/ or next;
695 die "Ambiguous destination: ",
696 $_branch_dest, "\nmatches both '",
697 $glob->{path}->{left}, "' and '",
698 $g->{path}->{left}, "'\n";
702 unless (defined $glob) {
704 $_tag ? "tag" : "branch",
705 " destination $_branch_dest\n";
709 my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
710 my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());
712 my $ctx = SVN::Client->new(
713 auth => Git::SVN::Ra::_auth_providers(),
715 ${ $_[0] } = defined $_message
717 : 'Create ' . ($_tag ? 'tag ' : 'branch ' )
723 $ctx->ls($dst, 'HEAD', 0);
724 } and die "branch ${branch_name} already exists\n";
726 print "Copying ${src} at r${rev} to ${dst}...\n";
727 $ctx->copy($src, $rev, $dst)
734 my $revision_or_hash = shift or die "SVN or git revision required ",
735 "as a command-line argument\n";
737 if ($revision_or_hash =~ /^r\d+$/) {
741 my (undef, undef, $uuid, $gs) = working_head_info($head, \@refs);
743 die "Unable to determine upstream SVN information from ",
746 my $desired_revision = substr($revision_or_hash, 1);
747 $result = $gs->rev_map_get($desired_revision, $uuid);
749 my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
752 print "$result\n" if $result;
756 command_noisy(qw/update-index --refresh/);
757 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
759 die "Unable to determine upstream SVN information from ",
760 "working tree history\n";
763 print "Remote Branch: " . $gs->refname . "\n";
764 print "SVN URL: " . $url . "\n";
767 if (command(qw/diff-index HEAD --/)) {
768 print STDERR "Cannot rebase with uncommited changes:\n";
769 command_noisy('status');
773 # rebase will checkout for us, so no need to do it explicitly
774 $_no_checkout = 'true';
775 $_fetch_all ? $gs->fetch_all : $gs->fetch;
777 command_noisy(rebase_cmd(), $gs->refname);
781 sub cmd_show_ignore {
782 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
783 $gs ||= Git::SVN->new;
784 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
785 $gs->prop_walk($gs->{path}, $r, sub {
786 my ($gs, $path, $props) = @_;
787 print STDOUT "\n# $path\n";
788 my $s = $props->{'svn:ignore'} or return;
789 $s =~ s/[\r\n]+/\n/g;
797 sub cmd_show_externals {
798 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
799 $gs ||= Git::SVN->new;
800 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
801 $gs->prop_walk($gs->{path}, $r, sub {
802 my ($gs, $path, $props) = @_;
803 print STDOUT "\n# $path\n";
804 my $s = $props->{'svn:externals'} or return;
805 $s =~ s/[\r\n]+/\n/g;
812 sub cmd_create_ignore {
813 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
814 $gs ||= Git::SVN->new;
815 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
816 $gs->prop_walk($gs->{path}, $r, sub {
817 my ($gs, $path, $props) = @_;
818 # $path is of the form /path/to/dir/
820 # SVN can have attributes on empty directories,
821 # which git won't track
822 mkpath([$path]) unless -d $path;
823 my $ignore = $path . '.gitignore';
824 my $s = $props->{'svn:ignore'} or return;
825 open(GITIGNORE, '>', $ignore)
826 or fatal("Failed to open `$ignore' for writing: $!");
827 $s =~ s/[\r\n]+/\n/g;
830 # Prefix all patterns so that the ignore doesn't apply
831 # to sub-directories.
833 print GITIGNORE
"$s\n";
835 or fatal
("Failed to close `$ignore': $!");
836 command_noisy
('add', '-f', $ignore);
841 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
842 $gs ||= Git
::SVN
->new;
843 $gs->mkemptydirs($_revision);
846 sub canonicalize_path
{
848 my $dot_slash_added = 0;
849 if (substr($path, 0, 1) ne "/") {
850 $path = "./" . $path;
851 $dot_slash_added = 1;
853 # File::Spec->canonpath doesn't collapse x/../y into y (for a
854 # good reason), so let's do this manually.
856 $path =~ s
#/\.(?:/|$)#/#g;
857 $path =~ s
#/[^/]+/\.\.##g;
859 $path =~ s
#^\./## if $dot_slash_added;
865 sub canonicalize_url
{
867 $url =~ s
#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
873 # Helper for cmd_propget and cmd_proplist below.
876 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
877 $gs ||= Git
::SVN
->new;
879 # prefix THE PATH by the sub-directory from which the user
881 $path = $cmd_dir_prefix . $path;
882 fatal
("No such file or directory: $path") unless -e
$path;
883 my $is_dir = -d
$path ?
1 : 0;
884 $path = $gs->{path
} . '/' . $path;
886 # canonicalize the path (otherwise libsvn will abort or fail to
888 $path = canonicalize_path
($path);
890 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
893 (undef, undef, $props) = $gs->ra->get_dir($path, $r);
896 (undef, $props) = $gs->ra->get_file($path, $r, undef);
901 # cmd_propget (PROP, PATH)
902 # ------------------------
903 # Print the SVN property PROP for PATH.
905 my ($prop, $path) = @_;
906 $path = '.' if not defined $path;
907 usage
(1) if not defined $prop;
908 my $props = get_svnprops
($path);
909 if (not defined $props->{$prop}) {
910 fatal
("`$path' does not have a `$prop' SVN property.");
912 print $props->{$prop} . "\n";
915 # cmd_proplist (PATH)
916 # -------------------
917 # Print the list of SVN properties for PATH.
920 $path = '.' if not defined $path;
921 my $props = get_svnprops
($path);
922 print "Properties on '$path':\n";
923 foreach (sort keys %{$props}) {
930 unless (defined $_trunk || @_branches || @_tags) {
934 $_prefix = '' unless defined $_prefix;
936 $url = canonicalize_url
($url);
940 if (defined $_trunk) {
941 my $trunk_ref = 'refs/remotes/' . $_prefix . 'trunk';
942 # try both old-style and new-style lookups:
943 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
945 my ($trunk_url, $trunk_path) =
946 complete_svn_url
($url, $_trunk);
947 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
951 return unless @_branches || @_tags;
952 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
953 foreach my $path (@_branches) {
954 complete_url_ls_init
($ra, $path, '--branches/-b', $_prefix);
956 foreach my $path (@_tags) {
957 complete_url_ls_init
($ra, $path, '--tags/-t', $_prefix.'tags/');
961 sub cmd_multi_fetch
{
962 $Git::SVN
::no_reuse_existing
= undef;
963 my $remotes = Git
::SVN
::read_all_remotes
();
964 foreach my $repo_id (sort keys %$remotes) {
965 if ($remotes->{$repo_id}->{url
}) {
966 Git
::SVN
::fetch_all
($repo_id, $remotes);
971 # this command is special because it requires no metadata
972 sub cmd_commit_diff
{
973 my ($ta, $tb, $url) = @_;
974 my $usage = "Usage: $0 commit-diff -r<revision> ".
975 "<tree-ish> <tree-ish> [<URL>]";
976 fatal
($usage) if (!defined $ta || !defined $tb);
979 my $gs = eval { Git
::SVN
->new };
981 fatal
("Needed URL or usable git-svn --id in ",
982 "the command-line\n", $usage);
985 $svn_path = $gs->{path
};
987 unless (defined $_revision) {
988 fatal
("-r|--revision is a required argument\n", $usage);
990 if (defined $_message && defined $_file) {
991 fatal
("Both --message/-m and --file/-F specified ",
992 "for the commit message.\n",
993 "I have no idea what you mean");
995 if (defined $_file) {
996 $_message = file_to_s
($_file);
998 $_message ||= get_commit_entry
($tb)->{log};
1000 my $ra ||= Git
::SVN
::Ra
->new($url);
1003 $r = $ra->get_latest_revnum;
1004 } elsif ($r !~ /^\d+$/) {
1005 die "revision argument: $r not understood by git-svn\n";
1007 my %ed_opts = ( r
=> $r,
1012 editor_cb
=> sub { print "Committed r$_[0]\n" },
1013 svn_path
=> $svn_path );
1014 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1015 print "No changes\n$ta == $tb\n";
1019 sub escape_uri_only
{
1022 foreach (split m{/}, $uri) {
1023 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
1031 if ($url =~ m
#^([^:]+)://([^/]*)(.*)$#) {
1032 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
1033 $url = "$scheme://$domain$uri";
1039 my $path = canonicalize_path
(defined($_[0]) ?
$_[0] : ".");
1040 my $fullpath = canonicalize_path
($cmd_dir_prefix . $path);
1042 die "Too many arguments specified\n";
1045 my ($file_type, $diff_status) = find_file_type_and_diff_status
($path);
1047 if (!$file_type && !$diff_status) {
1048 print STDERR
"svn: '$path' is not under version control\n";
1052 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1054 die "Unable to determine upstream SVN information from ",
1055 "working tree history\n";
1058 # canonicalize_path() will return "" to make libsvn 1.5.x happy,
1059 $path = "." if $path eq "";
1061 my $full_url = $url . ($fullpath eq "" ?
"" : "/$fullpath");
1064 print escape_url
($full_url), "\n";
1068 my $result = "Path: $path\n";
1069 $result .= "Name: " . basename
($path) . "\n" if $file_type ne "dir";
1070 $result .= "URL: " . escape_url
($full_url) . "\n";
1073 my $repos_root = $gs->repos_root;
1074 Git
::SVN
::remove_username
($repos_root);
1075 $result .= "Repository Root: " . escape_url
($repos_root) . "\n";
1078 $result .= "Repository Root: (offline)\n";
1080 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
1081 ($SVN::Core
::VERSION
le '1.5.4' || $file_type ne "dir");
1082 $result .= "Revision: " . ($diff_status eq "A" ?
0 : $rev) . "\n";
1084 $result .= "Node Kind: " .
1085 ($file_type eq "dir" ?
"directory" : "file") . "\n";
1087 my $schedule = $diff_status eq "A"
1089 : ($diff_status eq "D" ?
"delete" : "normal");
1090 $result .= "Schedule: $schedule\n";
1092 if ($diff_status eq "A") {
1093 print $result, "\n";
1097 my ($lc_author, $lc_rev, $lc_date_utc);
1098 my @args = Git
::SVN
::Log
::git_svn_log_cmd
($rev, $rev, "--", $fullpath);
1099 my $log = command_output_pipe
(@args);
1100 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
1102 if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
1104 $lc_date_utc = Git
::SVN
::Log
::parse_git_date
($2, $3);
1105 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
1106 (undef, $lc_rev, undef) = ::extract_metadata
($1);
1111 Git
::SVN
::Log
::set_local_timezone
();
1113 $result .= "Last Changed Author: $lc_author\n";
1114 $result .= "Last Changed Rev: $lc_rev\n";
1115 $result .= "Last Changed Date: " .
1116 Git
::SVN
::Log
::format_svn_date
($lc_date_utc) . "\n";
1118 if ($file_type ne "dir") {
1119 my $text_last_updated_date =
1120 ($diff_status eq "D" ?
$lc_date_utc : (stat $path)[9]);
1122 "Text Last Updated: " .
1123 Git
::SVN
::Log
::format_svn_date
($text_last_updated_date) .
1126 if ($diff_status eq "D") {
1128 command_output_pipe
(qw(cat-file blob), "HEAD:$path");
1129 if ($file_type eq "link") {
1130 my $file_name = <$fh>;
1131 $checksum = md5sum
("link $file_name");
1133 $checksum = md5sum
($fh);
1135 command_close_pipe
($fh, $ctx);
1136 } elsif ($file_type eq "link") {
1138 command
(qw(cat-file blob), "HEAD:$path");
1140 md5sum
("link " . $file_name);
1142 open FILE
, "<", $path or die $!;
1143 $checksum = md5sum
(\
*FILE
);
1144 close FILE
or die $!;
1146 $result .= "Checksum: " . $checksum . "\n";
1149 print $result, "\n";
1153 my $target = shift || $_revision or die "SVN revision required\n";
1154 $target = $1 if $target =~ /^r(\d+)$/;
1155 $target =~ /^\d+$/ or die "Numeric SVN revision expected\n";
1156 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1158 die "Unable to determine upstream SVN information from ".
1161 my ($r, $c) = $gs->find_rev_before($target, not $_fetch_parent);
1162 $gs->rev_map_set($r, $c, 'reset', $uuid);
1163 print "r$r = $c ($gs->{ref_id})\n";
1167 if (!$can_compress) {
1168 warn "Compress::Zlib could not be found; unhandled.log " .
1169 "files will not be compressed.\n";
1171 find
({ wanted
=> \
&gc_directory
, no_chdir
=> 1}, "$ENV{GIT_DIR}/svn");
1174 ########################### utility functions #########################
1177 my @cmd = qw
/rebase/;
1178 push @cmd, '-v' if $_verbose;
1179 push @cmd, qw
/--merge/ if $_merge;
1180 push @cmd, "--strategy=$_strategy" if $_strategy;
1184 sub post_fetch_checkout
{
1185 return if $_no_checkout;
1186 my $gs = $Git::SVN
::_head
or return;
1187 return if verify_ref
('refs/heads/master^0');
1189 # look for "trunk" ref if it exists
1190 my $remote = Git
::SVN
::read_all_remotes
()->{$gs->{repo_id
}};
1191 my $fetch = $remote->{fetch
};
1193 foreach my $p (keys %$fetch) {
1194 basename
($fetch->{$p}) eq 'trunk' or next;
1195 $gs = Git
::SVN
->new($fetch->{$p}, $gs->{repo_id
}, $p);
1200 my $valid_head = verify_ref
('HEAD^0');
1201 command_noisy
(qw(update-ref refs/heads/master), $gs->refname);
1202 return if ($valid_head || !verify_ref
('HEAD^0'));
1204 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
1205 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
1206 return if -f
$index;
1208 return if command_oneline
(qw
/rev-parse --is-inside-work-tree/) eq 'false';
1209 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
1210 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
1211 print STDERR
"Checked out HEAD:\n ",
1212 $gs->full_url, " r", $gs->last_rev, "\n";
1213 $gs->mkemptydirs($gs->last_rev);
1216 sub complete_svn_url
{
1217 my ($url, $path) = @_;
1219 if ($path !~ m
#^[a-z\+]+://#) {
1220 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
1221 fatal
("E: '$path' is not a complete URL ",
1222 "and a separate URL is not specified");
1224 return ($url, $path);
1229 sub complete_url_ls_init
{
1230 my ($ra, $repo_path, $switch, $pfx) = @_;
1231 unless ($repo_path) {
1232 print STDERR
"W: $switch not specified\n";
1235 $repo_path =~ s
#/+$##;
1236 if ($repo_path =~ m
#^[a-z\+]+://#) {
1237 $ra = Git
::SVN
::Ra
->new($repo_path);
1240 $repo_path =~ s
#^/+##;
1242 fatal
("E: '$repo_path' is not a complete URL ",
1243 "and a separate URL is not specified");
1246 my $url = $ra->{url
};
1247 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
1248 my $k = "svn-remote.$gs->{repo_id}.url";
1249 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
1250 if ($orig_url && ($orig_url ne $gs->{url
})) {
1251 die "$k already set: $orig_url\n",
1252 "wanted to set to: $gs->{url}\n";
1254 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
1255 my $remote_path = "$gs->{path}/$repo_path";
1256 $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
1257 $remote_path =~ s
#/+#/#g;
1258 $remote_path =~ s
#^/##g;
1259 $remote_path .= "/*" if $remote_path !~ /\
*/;
1260 my ($n) = ($switch =~ /^--(\w+)/);
1261 if (length $pfx && $pfx !~ m
#/$#) {
1262 die "--prefix='$pfx' must have a trailing slash '/'\n";
1264 command_noisy
('config',
1266 "svn-remote.$gs->{repo_id}.$n",
1267 "$remote_path:refs/remotes/$pfx*" .
1268 ('/*' x
(($remote_path =~ tr
/*/*/) - 1)) );
1273 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
1274 { STDERR
=> 0 }); };
1277 sub get_tree_from_treeish
{
1279 # $treeish can be a symbolic ref, too:
1280 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1282 while ($type eq 'tag') {
1283 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
1285 if ($type eq 'commit') {
1286 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
1288 ($expected) = ($expected =~ /^tree ($sha1)$/o);
1289 die "Unable to get tree from $treeish\n" unless $expected;
1290 } elsif ($type eq 'tree') {
1291 $expected = $treeish;
1293 die "$treeish is a $type, expected tree, tag or commit\n";
1298 sub get_commit_entry
{
1299 my ($treeish) = shift;
1300 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
1301 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1302 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1303 open my $log_fh, '>', $commit_editmsg or croak
$!;
1305 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1306 if ($type eq 'commit' || $type eq 'tag') {
1307 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
1315 $in_msg = 1 if (/^\s*$/);
1316 $author = $1 if (/^author (.*>)/);
1317 } elsif (/^git-svn-id: /) {
1318 # skip this for now, we regenerate the
1319 # correct one on re-fetch anyways
1320 # TODO: set *:merge properties or like...
1322 if (/^From:/ || /^Signed-off-by:/) {
1328 $msgbuf =~ s/\s+$//s;
1329 if ($Git::SVN
::_add_author_from
&& defined($author)
1331 $msgbuf .= "\n\nFrom: $author";
1333 print $log_fh $msgbuf or croak
$!;
1334 command_close_pipe
($msg_fh, $ctx);
1336 close $log_fh or croak
$!;
1338 if ($_edit || ($type eq 'tree')) {
1339 chomp(my $editor = command_oneline
(qw(var GIT_EDITOR)));
1340 system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
1342 rename $commit_editmsg, $commit_msg or croak
$!;
1345 # SVN requires messages to be UTF-8 when entering the repo
1347 open $log_fh, '<', $commit_msg or croak
$!;
1349 chomp($log_entry{log} = <$log_fh>);
1351 my $enc = Git
::config
('i18n.commitencoding') || 'UTF-8';
1352 my $msg = $log_entry{log};
1354 eval { $msg = Encode
::decode
($enc, $msg, 1) };
1356 die "Could not decode as $enc:\n", $msg,
1357 "\nPerhaps you need to set i18n.commitencoding\n";
1360 eval { $msg = Encode
::encode
('UTF-8', $msg, 1) };
1361 die "Could not encode as UTF-8:\n$msg\n" if $@
;
1363 $log_entry{log} = $msg;
1365 close $log_fh or croak
$!;
1372 my ($str, $file, $mode) = @_;
1373 open my $fd,'>',$file or croak
$!;
1374 print $fd $str,"\n" or croak
$!;
1375 close $fd or croak
$!;
1376 chmod ($mode &~ umask, $file) if (defined $mode);
1381 open my $fd,'<',$file or croak
"$!: file: $file\n";
1384 close $fd or croak
$!;
1389 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
1391 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1392 my $log = $cmd eq 'log';
1393 while (<$authors>) {
1395 next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1396 my ($user, $name, $email) = ($1, $2, $3);
1398 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
1400 $users{$user} = [$name, $email];
1403 close $authors or croak
$!;
1406 # convert GetOpt::Long specs for use by git-config
1407 sub read_git_config
{
1410 foreach my $o (keys %$opts) {
1411 # if we have mixedCase and a long option-only, then
1412 # it's a config-only variable that we don't need for
1414 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
1415 my $v = $opts->{$o};
1416 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
1418 my $arg = 'git config';
1419 $arg .= ' --int' if ($o =~ /[:=]i$/);
1420 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
1421 if (ref $v eq 'ARRAY') {
1422 chomp(my @tmp = `$arg --get-all svn.$key`);
1425 chomp(my $tmp = `$arg --get svn.$key`);
1426 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
1431 delete @
$opts{@config_only} if @config_only;
1434 sub extract_metadata
{
1435 my $id = shift or return (undef, undef, undef);
1436 my ($url, $rev, $uuid) = ($id =~ /^\s
*git
-svn
-id
:\s
+(.*)\@
(\d
+)
1437 \s
([a
-f\d\
-]+)$/ix
);
1438 if (!defined $rev || !$uuid || !$url) {
1439 # some of the original repositories I made had
1440 # identifiers like this:
1441 ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/i);
1443 return ($url, $rev, $uuid);
1447 return extract_metadata
((grep(/^git-svn-id: /,
1448 command
(qw
/cat-file commit/, shift)))[-1]);
1451 sub cmt_sha2rev_batch
{
1453 my ($pid, $in, $out, $ctx) = command_bidi_pipe
(qw
/cat-file --batch/);
1456 foreach my $sha (@
{$list}) {
1459 print $out $sha, "\n";
1461 while (my $line = <$in>) {
1462 if ($first && $line =~ /^[[:xdigit:]]{40}\smissing$/) {
1465 $line =~ /^[[:xdigit:]]{40}\scommit\s(\d+)$/) {
1469 } elsif ($line =~ /^(git-svn-id: )/) {
1470 my (undef, $rev, undef) =
1471 extract_metadata
($line);
1475 $size -= length($line);
1476 last if ($size == 0);
1480 command_close_bidi_pipe
($pid, $in, $out, $ctx);
1485 sub working_head_info
{
1486 my ($head, $refs) = @_;
1487 my @args = ('log', '--no-color', '--first-parent', '--pretty=medium');
1488 my ($fh, $ctx) = command_output_pipe
(@args, $head);
1492 if ( m{^commit ($::sha1)$} ) {
1493 unshift @
$refs, $hash if $hash and $refs;
1497 next unless s{^\s*(git-svn-id:)}{$1};
1498 my ($url, $rev, $uuid) = extract_metadata
($_);
1499 if (defined $url && defined $rev) {
1500 next if $max{$url} and $max{$url} < $rev;
1501 if (my $gs = Git
::SVN
->find_by_url($url)) {
1502 my $c = $gs->rev_map_get($rev, $uuid);
1503 if ($c && $c eq $hash) {
1504 close $fh; # break the pipe
1505 return ($url, $rev, $uuid, $gs);
1507 $max{$url} ||= $gs->rev_map_max;
1512 command_close_pipe
($fh, $ctx);
1513 (undef, undef, undef, undef);
1516 sub read_commit_parents
{
1517 my ($parents, $c) = @_;
1518 chomp(my $p = command_oneline
(qw
/rev-list --parents -1/, $c));
1519 $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
1520 @
{$parents->{$c}} = split(/ /, $p);
1523 sub linearize_history
{
1524 my ($gs, $refs) = @_;
1526 foreach my $c (@
$refs) {
1527 read_commit_parents
(\
%parents, $c);
1532 my $last_svn_commit = $gs->last_commit;
1533 foreach my $c (reverse @
$refs) {
1534 next if $c eq $last_svn_commit;
1537 unshift @linear_refs, $c;
1540 # we only want the first parent to diff against for linear
1541 # history, we save the rest to inject when we finalize the
1543 my $fp_a = verify_ref
("$c~1");
1544 my $fp_b = shift @
{$parents{$c}} if $parents{$c};
1545 if (!$fp_a || !$fp_b) {
1547 "has no parent commit, and therefore ",
1548 "nothing to diff against.\n",
1549 "You should be working from a repository ",
1550 "originally created by git-svn\n";
1552 if ($fp_a ne $fp_b) {
1553 die "$c~1 = $fp_a, however parsing commit $c ",
1554 "revealed that:\n$c~1 = $fp_b\nBUG!\n";
1557 foreach my $p (@
{$parents{$c}}) {
1561 (\
@linear_refs, \
%parents);
1564 sub find_file_type_and_diff_status
{
1566 return ('dir', '') if $path eq '';
1569 command_oneline
(qw(diff --cached --name-status --), $path) || "";
1570 my $diff_status = (split(' ', $diff_output))[0] || "";
1572 my $ls_tree = command_oneline
(qw(ls-tree HEAD), $path) || "";
1574 return (undef, undef) if !$diff_status && !$ls_tree;
1576 if ($diff_status eq "A") {
1577 return ("link", $diff_status) if -l
$path;
1578 return ("dir", $diff_status) if -d
$path;
1579 return ("file", $diff_status);
1582 my $mode = (split(' ', $ls_tree))[0] || "";
1584 return ("link", $diff_status) if $mode eq "120000";
1585 return ("dir", $diff_status) if $mode eq "040000";
1586 return ("file", $diff_status);
1592 my $md5 = Digest
::MD5
->new();
1593 if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
1594 $md5->addfile($arg) or croak
$!;
1595 } elsif ($ref eq 'SCALAR') {
1596 $md5->add($$arg) or croak
$!;
1598 $md5->add($arg) or croak
$!;
1600 ::fatal
"Can't provide MD5 hash for unknown ref type: '", $ref, "'";
1602 return $md5->hexdigest();
1606 if ($can_compress && -f
$_ && basename
($_) eq "unhandled.log") {
1607 my $out_filename = $_ . ".gz";
1608 open my $in_fh, "<", $_ or die "Unable to open $_: $!\n";
1610 my $gz = Compress
::Zlib
::gzopen
($out_filename, "ab") or
1611 die "Unable to open $out_filename: $!\n";
1614 while ($res = sysread($in_fh, my $str, 1024)) {
1615 $gz->gzwrite($str) or
1616 die "Unable to write: ".$gz->gzerror()."!\n";
1618 unlink $_ or die "unlink $File::Find::name: $!\n";
1619 } elsif (-f
$_ && basename
($_) eq "index") {
1620 unlink $_ or die "unlink $_: $!\n";
1627 use Fcntl qw
/:DEFAULT :seek/;
1628 use constant rev_map_fmt
=> 'NH40';
1629 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1630 $_repack $_repack_flags $_use_svm_props $_head
1631 $_use_svnsync_props $no_reuse_existing $_minimize_url
1632 $_use_log_author $_add_author_from $_localtime/;
1634 use File
::Path qw
/mkpath/;
1635 use File
::Copy qw
/copy/;
1638 my ($_gc_nr, $_gc_period);
1640 # properties that we do not log:
1643 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
1644 svn
:special svn
:executable
1645 svn
:entry
:committed
-rev
1646 svn
:entry
:last-author
1648 svn
:entry
:committed
-date
/;
1650 # some options are read globally, but can be overridden locally
1651 # per [svn-remote "..."] section. Command-line options will *NOT*
1652 # override options set in an [svn-remote "..."] section
1654 for my $option (qw
/follow_parent no_metadata use_svm_props
1655 use_svnsync_props
/) {
1658 my $prop = "-$option";
1661 return $self->{$prop} if exists $self->{$prop};
1662 my $k = "svn-remote.$self->{repo_id}.$key";
1663 eval { command_oneline
(qw
/config --get/, $k) };
1665 $self->{$prop} = ${"Git::SVN::_$option"};
1667 my $v = command_oneline
(qw
/config --bool/,$k);
1668 $self->{$prop} = $v eq 'false' ?
0 : 1;
1670 return $self->{$prop};
1676 my (%LOCKFILES, %INDEX_FILES);
1678 unlink keys %LOCKFILES if %LOCKFILES;
1679 unlink keys %INDEX_FILES if %INDEX_FILES;
1682 sub resolve_local_globs
{
1683 my ($url, $fetch, $glob_spec) = @_;
1684 return unless defined $glob_spec;
1685 my $ref = $glob_spec->{ref};
1686 my $path = $glob_spec->{path
};
1687 foreach (command
(qw
#for-each-ref --format=%(refname) refs/#)) {
1688 next unless m
#^$ref->{regex}$#;
1690 my $pathname = desanitize_refname
($path->full_path($p));
1691 my $refname = desanitize_refname
($ref->full_path($p));
1692 if (my $existing = $fetch->{$pathname}) {
1693 if ($existing ne $refname) {
1694 die "Refspec conflict:\n",
1695 "existing: $existing\n",
1696 " globbed: $refname\n";
1698 my $u = (::cmt_metadata
("$refname"))[0];
1699 $u =~ s!^\Q$url\E(/|$)!! or die
1700 "$refname: '$url' not found in '$u'\n";
1701 if ($pathname ne $u) {
1702 warn "W: Refspec glob conflict ",
1703 "(ref: $refname):\n",
1704 "expected path: $pathname\n",
1706 "Continuing ahead with $u\n";
1710 $fetch->{$pathname} = $refname;
1715 sub parse_revision_argument
{
1716 my ($base, $head) = @_;
1717 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
1718 return ($base, $head);
1720 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
1721 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
1722 return ($head, $head) if ($::_revision
eq 'HEAD');
1723 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
1724 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
1725 die "revision argument: $::_revision not understood by git-svn\n";
1729 my ($repo_id, $remotes) = @_;
1733 $repo_id = $gs->{repo_id
};
1735 $remotes ||= read_all_remotes
();
1736 my $remote = $remotes->{$repo_id} or
1737 die "[svn-remote \"$repo_id\"] unknown\n";
1738 my $fetch = $remote->{fetch
};
1739 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
1741 my $ra = Git
::SVN
::Ra
->new($url);
1742 my $uuid = $ra->get_uuid;
1743 my $head = $ra->get_latest_revnum;
1745 # ignore errors, $head revision may not even exist anymore
1746 eval { $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }) };
1747 warn "W: $@\n" if $@
;
1749 my $base = defined $fetch ?
$head : 0;
1751 # read the max revs for wildcard expansion (branches/*, tags/*)
1752 foreach my $t (qw
/branches tags/) {
1753 defined $remote->{$t} or next;
1754 push @globs, @
{$remote->{$t}};
1756 my $max_rev = eval { tmp_config
(qw
/--int --get/,
1757 "svn-remote.$repo_id.${t}-maxRev") };
1758 if (defined $max_rev && ($max_rev < $base)) {
1760 } elsif (!defined $max_rev) {
1766 foreach my $p (sort keys %$fetch) {
1767 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
1768 my $lr = $gs->rev_map_max;
1770 $base = $lr if ($lr < $base);
1776 ($base, $head) = parse_revision_argument
($base, $head);
1777 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
1780 sub read_all_remotes
{
1782 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
1783 svn
.useSvmProps
/) };
1784 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
1785 my $svn_refspec = qr{\s*(.*?)\s*:\s*(.+?)\s*};
1786 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
1787 if (m!^(.+)\.fetch=$svn_refspec$!) {
1788 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
1789 die("svn-remote.$remote: remote ref '$remote_ref' "
1790 . "must start with 'refs/'\n")
1791 unless $remote_ref =~ m{^refs/};
1792 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
1793 $r->{$remote}->{svm
} = {} if $use_svm_props;
1794 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
1795 $r->{$1}->{svm
} = {};
1796 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
1797 $r->{$1}->{url
} = $2;
1798 } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
1799 my ($remote, $t, $local_ref, $remote_ref) =
1801 die("svn-remote.$remote: remote ref '$remote_ref' ($t) "
1802 . "must start with 'refs/'\n")
1803 unless $remote_ref =~ m{^refs/};
1807 path
=> Git
::SVN
::GlobSpec
->new($local_ref),
1808 ref => Git
::SVN
::GlobSpec
->new($remote_ref) };
1809 if (length($rs->{ref}->{right
}) != 0) {
1810 die "The '*' glob character must be the last ",
1811 "character of '$remote_ref'\n";
1813 push @
{ $r->{$remote}->{$t} }, $rs;
1818 if (defined $r->{$_}->{svm
}) {
1821 my $section = "svn-remote.$_";
1823 source
=> tmp_config
('--get',
1824 "$section.svm-source"),
1825 replace
=> tmp_config
('--get',
1826 "$section.svm-replace"),
1829 $r->{$_}->{svm
} = $svm;
1837 $_gc_nr = $_gc_period = 1000;
1838 if (defined $_repack || defined $_repack_flags) {
1839 warn "Repack options are obsolete; they have no effect.\n";
1843 sub verify_remotes_sanity
{
1844 return unless -d
$ENV{GIT_DIR
};
1846 foreach (command
(qw
/config -l/)) {
1847 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
1849 die "Remote ref refs/remote/$1 is tracked by",
1850 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
1851 "Please resolve this ambiguity in ",
1852 "your git configuration file before ",
1860 sub find_existing_remote
{
1861 my ($url, $remotes) = @_;
1862 return undef if $no_reuse_existing;
1864 foreach my $repo_id (keys %$remotes) {
1865 my $u = $remotes->{$repo_id}->{url
} or next;
1867 $existing = $repo_id;
1873 sub init_remote_config
{
1874 my ($self, $url, $no_write) = @_;
1875 $url =~ s!/+$!!; # strip trailing slash
1876 my $r = read_all_remotes
();
1877 my $existing = find_existing_remote
($url, $r);
1879 unless ($no_write) {
1880 print STDERR
"Using existing ",
1881 "[svn-remote \"$existing\"]\n";
1883 $self->{repo_id
} = $existing;
1884 } elsif ($_minimize_url) {
1885 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
1886 $existing = find_existing_remote
($min_url, $r);
1888 unless ($no_write) {
1889 print STDERR
"Using existing ",
1890 "[svn-remote \"$existing\"]\n";
1892 $self->{repo_id
} = $existing;
1894 if ($min_url ne $url) {
1895 unless ($no_write) {
1896 print STDERR
"Using higher level of URL: ",
1897 "$url => $min_url\n";
1899 my $old_path = $self->{path
};
1900 $self->{path
} = $url;
1901 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
1902 if (length $old_path) {
1903 $self->{path
} .= "/$old_path";
1910 # verify that we aren't overwriting anything:
1912 command_oneline
('config', '--get',
1913 "svn-remote.$self->{repo_id}.url")
1915 if ($orig_url && ($orig_url ne $url)) {
1916 die "svn-remote.$self->{repo_id}.url already set: ",
1917 "$orig_url\nwanted to set to: $url\n";
1920 my ($xrepo_id, $xpath) = find_ref
($self->refname);
1921 if (!$no_write && defined $xpath) {
1922 die "svn-remote.$xrepo_id.fetch already set to track ",
1923 "$xpath:", $self->refname, "\n";
1925 unless ($no_write) {
1926 command_noisy
('config',
1927 "svn-remote.$self->{repo_id}.url", $url);
1928 $self->{path
} =~ s{^/}{};
1929 $self->{path
} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
1930 command_noisy
('config', '--add',
1931 "svn-remote.$self->{repo_id}.fetch",
1932 "$self->{path}:".$self->refname);
1934 $self->{url
} = $url;
1937 sub find_by_url
{ # repos_root and, path are optional
1938 my ($class, $full_url, $repos_root, $path) = @_;
1940 return undef unless defined $full_url;
1941 remove_username
($full_url);
1942 remove_username
($repos_root) if defined $repos_root;
1943 my $remotes = read_all_remotes
();
1944 if (defined $full_url && defined $repos_root && !defined $path) {
1946 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
1948 foreach my $repo_id (keys %$remotes) {
1949 my $u = $remotes->{$repo_id}->{url
} or next;
1950 remove_username
($u);
1951 next if defined $repos_root && $repos_root ne $u;
1953 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
1954 foreach my $t (qw
/branches tags/) {
1955 foreach my $globspec (@
{$remotes->{$repo_id}->{$t}}) {
1956 resolve_local_globs
($u, $fetch, $globspec);
1960 my $rwr = rewrite_root
({repo_id
=> $repo_id});
1961 my $svm = $remotes->{$repo_id}->{svm
}
1962 if defined $remotes->{$repo_id}->{svm
};
1963 unless (defined $p) {
1969 remove_username
($z);
1970 } elsif (defined $svm) {
1971 $z = $svm->{source
};
1972 $prefix = $svm->{replace
};
1973 $prefix =~ s
#^\Q$u\E(?:/|$)##;
1976 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
1978 foreach my $f (keys %$fetch) {
1980 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
1987 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
1988 my $self = _new
($class, $repo_id, $ref_id, $path);
1990 $self->init_remote_config($url, $no_write);
1997 foreach (command
(qw
/config -l/)) {
1998 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
1999 \s
*(.*?
)\s
*:\s
*(.+?
)\s
*$!x
;
2000 my ($repo_id, $path, $ref) = ($1, $2, $3);
2001 if ($ref eq $ref_id) {
2002 $path = '' if ($path =~ m
#^\./?#);
2003 return ($repo_id, $path);
2006 (undef, undef, undef);
2010 my ($class, $ref_id, $repo_id, $path) = @_;
2011 if (defined $ref_id && !defined $repo_id && !defined $path) {
2012 ($repo_id, $path) = find_ref
($ref_id);
2013 if (!defined $repo_id) {
2014 die "Could not find a \"svn-remote.*.fetch\" key ",
2015 "in the repository configuration matching: ",
2019 my $self = _new
($class, $repo_id, $ref_id, $path);
2020 if (!defined $self->{path
} || !length $self->{path
}) {
2021 my $fetch = command_oneline
('config', '--get',
2022 "svn-remote.$repo_id.fetch",
2024 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
2025 "\":$ref_id\$\" in config\n";
2026 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
2028 $self->{url
} = command_oneline
('config', '--get',
2029 "svn-remote.$repo_id.url") or
2030 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
2036 my ($refname) = $_[0]->{ref_id
} ;
2038 # It cannot end with a slash /, we'll throw up on this because
2039 # SVN can't have directories with a slash in their name, either:
2040 if ($refname =~ m{/$}) {
2041 die "ref: '$refname' ends with a trailing slash, this is ",
2042 "not permitted by git nor Subversion\n";
2045 # It cannot have ASCII control character space, tilde ~, caret ^,
2046 # colon :, question-mark ?, asterisk *, space, or open bracket [
2049 # Additionally, % must be escaped because it is used for escaping
2050 # and we want our escaped refname to be reversible
2051 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
2053 # no slash-separated component can begin with a dot .
2055 $refname =~ s{/\.}{/%2E}g;
2057 # It cannot have two consecutive dots .. anywhere
2059 $refname =~ s{\.\.}{%2E%2E}g;
2064 sub desanitize_refname
{
2066 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
2072 return $self->{svm
}->{uuid
} if $self->svm;
2074 unless ($self->{svm
}) {
2075 die "SVM UUID not cached, and reading remotely failed\n";
2077 $self->{svm
}->{uuid
};
2082 return $self->{svm
} if $self->{svm
};
2084 # see if we have it in our config, first:
2086 my $section = "svn-remote.$self->{repo_id}";
2088 source
=> tmp_config
('--get', "$section.svm-source"),
2089 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
2090 replace
=> tmp_config
('--get', "$section.svm-replace"),
2093 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
2094 $self->{svm
} = $svm;
2100 my ($self, $ra) = @_;
2101 return $ra if $self->svm;
2103 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
2104 "(svm:source, svm:uuid) ",
2105 "from the following URLs:\n" );
2106 sub read_svm_props
{
2107 my ($self, $ra, $path, $r) = @_;
2108 my $props = ($ra->get_dir($path, $r))[2];
2109 my $src = $props->{'svm:source'};
2110 my $uuid = $props->{'svm:uuid'};
2111 return undef if (!$src || !$uuid);
2115 $uuid =~ m{^[0-9a-f\-]{30,}$}i
2116 or die "doesn't look right - svm:uuid is '$uuid'\n";
2118 # the '!' is used to mark the repos_root!/relative/path
2119 $src =~ s{/?!/?}{/};
2120 $src =~ s{/+$}{}; # no trailing slashes please
2121 # username is of no interest
2122 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
2124 my $replace = $ra->{url
};
2125 $replace .= "/$path" if length $path;
2127 my $section = "svn-remote.$self->{repo_id}";
2128 tmp_config
("$section.svm-source", $src);
2129 tmp_config
("$section.svm-replace", $replace);
2130 tmp_config
("$section.svm-uuid", $uuid);
2138 my $r = $ra->get_latest_revnum;
2139 my $path = $self->{path
};
2141 while (length $path) {
2142 unless ($tried{"$self->{url}/$path"}) {
2143 return $ra if $self->read_svm_props($ra, $path, $r);
2144 $tried{"$self->{url}/$path"} = 1;
2146 $path =~ s
#/?[^/]+$##;
2148 die "Path: '$path' should be ''\n" if $path ne '';
2149 return $ra if $self->read_svm_props($ra, $path, $r);
2150 $tried{"$self->{url}/$path"} = 1;
2152 if ($ra->{repos_root
} eq $self->{url
}) {
2153 die @err, (map { " $_\n" } keys %tried), "\n";
2156 # nope, make sure we're connected to the repository root:
2159 $path = $ra->{svn_path
};
2160 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
2161 while (length $path) {
2162 unless ($tried{"$ra->{url}/$path"}) {
2163 $ok = $self->read_svm_props($ra, $path, $r);
2165 $tried{"$ra->{url}/$path"} = 1;
2167 $path =~ s
#/?[^/]+$##;
2169 die "Path: '$path' should be ''\n" if $path ne '';
2170 $ok ||= $self->read_svm_props($ra, $path, $r);
2171 $tried{"$ra->{url}/$path"} = 1;
2173 die @err, (map { " $_\n" } keys %tried), "\n";
2175 Git
::SVN
::Ra
->new($self->{url
});
2180 return $self->{svnsync
} if $self->{svnsync
};
2182 if ($self->no_metadata) {
2183 die "Can't have both 'noMetadata' and ",
2184 "'useSvnsyncProps' options set!\n";
2186 if ($self->rewrite_root) {
2187 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
2192 # see if we have it in our config, first:
2194 my $section = "svn-remote.$self->{repo_id}";
2196 my $url = tmp_config
('--get', "$section.svnsync-url");
2197 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2198 die "doesn't look right - svn:sync-from-url is '$url'\n";
2200 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
2201 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2202 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2204 $svnsync = { url
=> $url, uuid
=> $uuid }
2206 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
2207 return $self->{svnsync
} = $svnsync;
2210 my $err = "useSvnsyncProps set, but failed to read " .
2211 "svnsync property: svn:sync-from-";
2212 my $rp = $self->ra->rev_proplist(0);
2214 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
2215 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2216 die "doesn't look right - svn:sync-from-url is '$url'\n";
2218 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
2219 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2220 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2222 my $section = "svn-remote.$self->{repo_id}";
2223 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
2224 tmp_config
('--add', "$section.svnsync-url", $url);
2225 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
2228 # this allows us to memoize our SVN::Ra UUID locally and avoid a
2229 # remote lookup (useful for 'git svn log').
2232 unless ($self->{ra_uuid
}) {
2233 my $key = "svn-remote.$self->{repo_id}.uuid";
2234 my $uuid = eval { tmp_config
('--get', $key) };
2235 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) {
2236 $self->{ra_uuid
} = $uuid;
2238 die "ra_uuid called without URL\n" unless $self->{url
};
2239 $self->{ra_uuid
} = $self->ra->get_uuid;
2240 tmp_config
('--add', $key, $self->{ra_uuid
});
2246 sub _set_repos_root
{
2247 my ($self, $repos_root) = @_;
2248 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2249 $repos_root ||= $self->ra->{repos_root
};
2250 tmp_config
($k, $repos_root);
2256 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2257 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
2262 my $ra = Git
::SVN
::Ra
->new($self->{url
});
2263 $self->_set_repos_root($ra->{repos_root
});
2264 if ($self->use_svm_props && !$self->{svm
}) {
2265 if ($self->no_metadata) {
2266 die "Can't have both 'noMetadata' and ",
2267 "'useSvmProps' options set!\n";
2268 } elsif ($self->use_svnsync_props) {
2269 die "Can't have both 'useSvnsyncProps' and ",
2270 "'useSvmProps' options set!\n";
2272 $ra = $self->_set_svm_vars($ra);
2273 $self->{-want_revprops
} = 1;
2278 # prop_walk(PATH, REV, SUB)
2279 # -------------------------
2280 # Recursively traverse PATH at revision REV and invoke SUB for each
2281 # directory that contains a SVN property. SUB will be invoked as
2282 # follows: &SUB(gs, path, props); where `gs' is this instance of
2283 # Git::SVN, `path' the path to the directory where the properties
2284 # `props' were found. The `path' will be relative to point of checkout,
2285 # that is, if url://repo/trunk is the current Git branch, and that
2286 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
2287 # as `path' (note the trailing `/').
2289 my ($self, $path, $rev, $sub) = @_;
2292 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
2295 # Strip the irrelevant part of the path.
2296 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
2297 # Ensure the path is terminated by a `/'.
2300 # The properties contain all the internal SVN stuff nobody
2301 # (usually) cares about.
2302 my $interesting_props = 0;
2303 foreach (keys %{$props}) {
2304 # If it doesn't start with `svn:', it must be a
2305 # user-defined property.
2306 ++$interesting_props and next if $_ !~ /^svn:/;
2307 # FIXME: Fragile, if SVN adds new public properties,
2308 # this needs to be updated.
2309 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
2310 |eol
-style
|mime
-type
2311 |externals
|needs
-lock)$/x
;
2313 &$sub($self, $p, $props) if $interesting_props;
2315 foreach (sort keys %$dirent) {
2316 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
2317 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
2321 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
2322 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
2324 # returns the newest SVN revision number and newest commit SHA1
2325 sub last_rev_commit
{
2327 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
2328 return ($self->{last_rev
}, $self->{last_commit
});
2330 my $c = ::verify_ref
($self->refname.'^0');
2331 if ($c && !$self->use_svm_props && !$self->no_metadata) {
2332 my $rev = (::cmt_metadata
($c))[1];
2334 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
2338 my $map_path = $self->map_path;
2339 unless (-e
$map_path) {
2340 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
2341 return (undef, undef);
2343 my ($rev, $commit) = $self->rev_map_max(1);
2344 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
2345 return ($rev, $commit);
2348 sub get_fetch_range
{
2349 my ($self, $min, $max) = @_;
2350 $max ||= $self->ra->get_latest_revnum;
2351 $min ||= $self->rev_map_max;
2357 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
2358 my $config = "$ENV{GIT_DIR}/svn/.metadata";
2359 if (! -f
$config && -f
$old_def_config) {
2360 rename $old_def_config, $config or
2361 die "Failed rename $old_def_config => $config: $!\n";
2363 my $old_config = $ENV{GIT_CONFIG
};
2364 $ENV{GIT_CONFIG
} = $config;
2367 unless (-f
$config) {
2369 open my $fh, '>', $config or
2370 die "Can't open $config: $!\n";
2371 print $fh "; This file is used internally by ",
2373 "Couldn't write to $config: $!\n";
2374 print $fh "; You should not have to edit it\n" or
2375 die "Couldn't write to $config: $!\n";
2376 close $fh or die "Couldn't close $config: $!\n";
2378 command
('config', @args);
2381 if (defined $old_config) {
2382 $ENV{GIT_CONFIG
} = $old_config;
2384 delete $ENV{GIT_CONFIG
};
2387 wantarray ?
@ret : $ret[0];
2391 my ($self, $sub) = @_;
2392 my $old_index = $ENV{GIT_INDEX_FILE
};
2393 $ENV{GIT_INDEX_FILE
} = $self->{index};
2396 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
2397 mkpath
([$dir]) unless -d
$dir;
2401 if (defined $old_index) {
2402 $ENV{GIT_INDEX_FILE
} = $old_index;
2404 delete $ENV{GIT_INDEX_FILE
};
2407 wantarray ?
@ret : $ret[0];
2410 sub assert_index_clean
{
2411 my ($self, $treeish) = @_;
2413 $self->tmp_index_do(sub {
2414 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
2415 my $x = command_oneline
('write-tree');
2416 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
2417 /^tree ($::sha1)/mo);
2420 warn "Index mismatch: $y != $x\nrereading $treeish\n";
2421 unlink $self->{index} or die "unlink $self->{index}: $!\n";
2422 command_noisy
('read-tree', $treeish);
2423 $x = command_oneline
('write-tree');
2425 ::fatal
"trees ($treeish) $y != $x\n",
2426 "Something is seriously wrong...";
2431 sub get_commit_parents
{
2432 my ($self, $log_entry) = @_;
2433 my (%seen, @ret, @tmp);
2434 # legacy support for 'set-tree'; this is only used by set_tree_cb:
2435 if (my $ip = $self->{inject_parents
}) {
2436 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
2440 if (my $cur = ::verify_ref
($self->refname.'^0')) {
2443 if (my $ipd = $self->{inject_parents_dcommit
}) {
2444 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
2445 push @tmp, @
$commit;
2448 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
2449 while (my $p = shift @tmp) {
2453 # MAXPARENT is defined to 16 in commit-tree.c:
2457 die "r$log_entry->{revision}: No room for parents:\n\t",
2458 join("\n\t", @tmp), "\n";
2465 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
2466 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
2467 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
2470 if ($rwr !~ m
#^[a-z\+]+://#) {
2471 die "$rwr is not a valid URL (key: $k)\n";
2474 $self->{-rewrite_root
} = $rwr;
2479 ($self->rewrite_root || $self->{url
}) .
2480 (length $self->{path
} ?
'/' . $self->{path
} : '');
2485 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
2489 sub set_commit_header_env
{
2490 my ($log_entry) = @_;
2492 foreach my $ned (qw
/NAME EMAIL DATE/) {
2493 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2494 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2498 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
2499 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
2500 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
2502 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
2503 ?
$log_entry->{commit_name
}
2504 : $log_entry->{name
};
2505 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
2506 ?
$log_entry->{commit_email
}
2507 : $log_entry->{email
};
2511 sub restore_commit_header_env
{
2513 foreach my $ned (qw
/NAME EMAIL DATE/) {
2514 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2515 my $k = "GIT_${ac}_${ned}";
2516 if (defined $env->{$k}) {
2517 $ENV{$k} = $env->{$k};
2526 command_noisy
('gc', '--auto');
2530 my ($self, $log_entry) = @_;
2531 my $lr = $self->last_rev;
2532 if (defined $lr && $lr >= $log_entry->{revision
}) {
2533 die "Last fetched revision of ", $self->refname,
2534 " was r$lr, but we are about to fetch: ",
2535 "r$log_entry->{revision}!\n";
2537 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
2538 croak
"$log_entry->{revision} = $c already exists! ",
2539 "Why are we refetching it?\n";
2541 my $old_env = set_commit_header_env
($log_entry);
2542 my $tree = $log_entry->{tree
};
2543 if (!defined $tree) {
2544 $tree = $self->tmp_index_do(sub {
2545 command_oneline
('write-tree') });
2547 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
2549 my @exec = ('git', 'commit-tree', $tree);
2550 foreach ($self->get_commit_parents($log_entry)) {
2551 push @exec, '-p', $_;
2553 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
2557 # we always get UTF-8 from SVN, but we may want our commits in
2558 # a different encoding.
2559 if (my $enc = Git
::config
('i18n.commitencoding')) {
2561 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
2563 print $msg_fh $log_entry->{log} or croak
$!;
2564 restore_commit_header_env
($old_env);
2565 unless ($self->no_metadata) {
2566 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
2569 $msg_fh->flush == 0 or croak
$!;
2570 close $msg_fh or croak
$!;
2571 chomp(my $commit = do { local $/; <$out_fh> });
2572 close $out_fh or croak
$!;
2575 if ($commit !~ /^$::sha1$/o) {
2576 die "Failed to commit, invalid sha1: $commit\n";
2579 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
2581 $self->{last_rev
} = $log_entry->{revision
};
2582 $self->{last_commit
} = $commit;
2583 print "r$log_entry->{revision}" unless $::_q
> 1;
2584 if (defined $log_entry->{svm_revision
}) {
2585 print " (\@$log_entry->{svm_revision})" unless $::_q
> 1;
2586 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
2587 0, $self->svm_uuid);
2589 print " = $commit ($self->{ref_id})\n" unless $::_q
> 1;
2590 if (--$_gc_nr == 0) {
2591 $_gc_nr = $_gc_period;
2598 my ($self, $paths, $r) = @_;
2599 return 1 if $self->{path
} eq '';
2600 if (my $path = $paths->{"/$self->{path}"}) {
2601 return ($path->{action
} eq 'D') ?
0 : 1;
2603 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
2604 if (grep /$self->{path_regex}/, keys %$paths) {
2608 foreach (split m
#/#, $self->{path}) {
2610 next unless ($paths->{$c} &&
2611 ($paths->{$c}->{action
} =~ /^[AR]$/));
2612 if ($self->ra->check_path($self->{path
}, $r) ==
2620 sub find_parent_branch
{
2621 my ($self, $paths, $rev) = @_;
2622 return undef unless $self->follow_parent;
2623 unless (defined $paths) {
2624 my $err_handler = $SVN::Error
::handler
;
2625 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
2626 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
2627 sub { $paths = $_[0] });
2628 $SVN::Error
::handler
= $err_handler;
2630 return undef unless defined $paths;
2632 # look for a parent from another branch:
2633 my @b_path_components = split m
#/#, $self->{path};
2634 my @a_path_components;
2636 while (@b_path_components) {
2637 $i = $paths->{'/'.join('/', @b_path_components)};
2638 last if $i && defined $i->{copyfrom_path
};
2639 unshift(@a_path_components, pop(@b_path_components));
2641 return undef unless defined $i && defined $i->{copyfrom_path
};
2642 my $branch_from = $i->{copyfrom_path
};
2643 if (@a_path_components) {
2644 print STDERR
"branch_from: $branch_from => ";
2645 $branch_from .= '/'.join('/', @a_path_components);
2646 print STDERR
$branch_from, "\n";
2648 my $r = $i->{copyfrom_rev
};
2649 my $repos_root = $self->ra->{repos_root
};
2650 my $url = $self->ra->{url
};
2651 my $new_url = $url . $branch_from;
2652 print STDERR
"Found possible branch point: ",
2653 "$new_url => ", $self->full_url, ", $r\n"
2655 $branch_from =~ s
#^/##;
2656 my $gs = $self->other_gs($new_url, $url,
2657 $branch_from, $r, $self->{ref_id
});
2658 my ($r0, $parent) = $gs->find_rev_before($r, 1);
2661 if (!defined $r0 || !defined $parent) {
2662 ($base, $head) = parse_revision_argument
(0, $r);
2665 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
2666 0, 1, sub { $base = $_[1] - 1 });
2669 if (defined $base && $base <= $r) {
2670 $gs->fetch($base, $r);
2672 ($r0, $parent) = $gs->find_rev_before($r, 1);
2674 if (defined $r0 && defined $parent) {
2675 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n"
2678 if ($self->ra->can_do_switch) {
2679 $self->assert_index_clean($parent);
2680 print STDERR
"Following parent with do_switch\n"
2682 # do_switch works with svn/trunk >= r22312, but that
2683 # is not included with SVN 1.4.3 (the latest version
2684 # at the moment), so we can't rely on it
2685 $self->{last_rev
} = $r0;
2686 $self->{last_commit
} = $parent;
2687 $ed = SVN
::Git
::Fetcher
->new($self, $gs->{path
});
2688 $gs->ra->gs_do_switch($r0, $rev, $gs,
2689 $self->full_url, $ed)
2690 or die "SVN connection failed somewhere...\n";
2691 } elsif ($self->ra->trees_match($new_url, $r0,
2692 $self->full_url, $rev)) {
2693 print STDERR
"Trees match:\n",
2695 " ${\$self->full_url}\@$rev\n",
2696 "Following parent with no changes\n"
2698 $self->tmp_index_do(sub {
2699 command_noisy
('read-tree', $parent);
2701 $self->{last_commit
} = $parent;
2703 print STDERR
"Following parent with do_update\n"
2705 $ed = SVN
::Git
::Fetcher
->new($self);
2706 $self->ra->gs_do_update($rev, $rev, $self, $ed)
2707 or die "SVN connection failed somewhere...\n";
2709 print STDERR
"Successfully followed parent\n" unless $::_q
> 1;
2710 return $self->make_log_entry($rev, [$parent], $ed);
2716 my ($self, $paths, $rev) = @_;
2718 my ($last_rev, @parents);
2719 if (my $lc = $self->last_commit) {
2720 # we can have a branch that was deleted, then re-added
2721 # under the same name but copied from another path, in
2722 # which case we'll have multiple parents (we don't
2723 # want to break the original ref, nor lose copypath info):
2724 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2725 push @
{$log_entry->{parents
}}, $lc;
2728 $ed = SVN
::Git
::Fetcher
->new($self);
2729 $last_rev = $self->{last_rev
};
2734 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2737 $ed = SVN
::Git
::Fetcher
->new($self);
2739 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
2740 die "SVN connection failed somewhere...\n";
2742 $self->make_log_entry($rev, \
@parents, $ed);
2746 my ($self, $r) = @_;
2749 my ($r, $empty_dirs, $line) = @_;
2750 if (defined $r && $line =~ /^r(\d+)$/) {
2751 return 0 if $1 > $r;
2752 } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
2753 $empty_dirs->{$1} = 1;
2754 } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
2755 my @d = grep {m
[^\Q
$1\E
(/|$)]} (keys %$empty_dirs);
2756 delete @
$empty_dirs{@d};
2761 my %empty_dirs = ();
2762 my $gz_file = "$self->{dir}/unhandled.log.gz";
2764 if (!$can_compress) {
2765 warn "Compress::Zlib could not be found; ",
2766 "empty directories in $gz_file will not be read\n";
2768 my $gz = Compress
::Zlib
::gzopen
($gz_file, "rb") or
2769 die "Unable to open $gz_file: $!\n";
2771 while ($gz->gzreadline($line) > 0) {
2772 scan
($r, \
%empty_dirs, $line) or last;
2778 if (open my $fh, '<', "$self->{dir}/unhandled.log") {
2779 binmode $fh or croak
"binmode: $!";
2781 scan
($r, \
%empty_dirs, $_) or last;
2786 my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
2787 foreach my $d (sort keys %empty_dirs) {
2788 $d = uri_decode
($d);
2792 warn "$d exists but is not a directory\n";
2794 print "creating empty directory: $d\n";
2801 my ($self, $ed) = @_;
2803 my $h = $ed->{empty
};
2804 foreach (sort keys %$h) {
2805 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
2806 push @out, " $act: " . uri_encode
($_);
2807 warn "W: $act: $_\n";
2809 foreach my $t (qw
/dir_prop file_prop/) {
2810 $h = $ed->{$t} or next;
2811 foreach my $path (sort keys %$h) {
2812 my $ppath = $path eq '' ?
'.' : $path;
2813 foreach my $prop (sort keys %{$h->{$path}}) {
2814 next if $SKIP_PROP{$prop};
2815 my $v = $h->{$path}->{$prop};
2816 my $t_ppath_prop = "$t: " .
2817 uri_encode
($ppath) . ' ' .
2820 push @out, " +$t_ppath_prop " .
2823 push @out, " -$t_ppath_prop";
2828 foreach my $t (qw
/absent_file absent_directory/) {
2829 $h = $ed->{$t} or next;
2830 foreach my $parent (sort keys %$h) {
2831 foreach my $path (sort @
{$h->{$parent}}) {
2832 push @out, " $t: " .
2833 uri_encode
("$parent/$path");
2834 warn "W: $t: $parent/$path ",
2835 "Insufficient permissions?\n";
2842 # parse_svn_date(DATE)
2843 # --------------------
2844 # Given a date (in UTC) from Subversion, return a string in the format
2845 # "<TZ Offset> <local date/time>" that Git will use.
2847 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
2848 # is true we'll convert it to the local timezone instead.
2849 sub parse_svn_date
{
2850 my $date = shift || return '+0000 1970-01-01 00:00:00';
2851 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
2852 (\d\d
)\
:(\d\d
)\
:(\d\d
)\
.\d
*Z
$/x
) or
2853 croak
"Unable to parse date: $date\n";
2854 my $parsed_date; # Set next.
2856 if ($Git::SVN
::_localtime
) {
2857 # Translate the Subversion datetime to an epoch time.
2858 # Begin by switching ourselves to $date's timezone, UTC.
2859 my $old_env_TZ = $ENV{TZ
};
2863 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
2865 # Determine our local timezone (including DST) at the
2866 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
2867 # value of TZ, if any, at the time we were run.
2868 if (defined $Git::SVN
::Log
::TZ
) {
2869 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
2875 POSIX
::strftime
('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
2877 # This converts $epoch_in_UTC into our local timezone.
2878 my ($sec, $min, $hour, $mday, $mon, $year,
2879 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
2881 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
2882 $our_TZ, $year + 1900, $mon + 1,
2883 $mday, $hour, $min, $sec);
2885 # Reset us to the timezone in effect when we entered
2887 if (defined $old_env_TZ) {
2888 $ENV{TZ
} = $old_env_TZ;
2893 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
2896 return $parsed_date;
2900 my ($self, $new_url, $url,
2901 $branch_from, $r, $old_ref_id) = @_;
2902 my $gs = Git
::SVN
->find_by_url($new_url, $url, $branch_from);
2904 my $ref_id = $old_ref_id;
2905 $ref_id =~ s/\@\d+$//;
2907 # just grow a tail if we're not unique enough :x
2908 $ref_id .= '-' while find_ref
($ref_id);
2909 print STDERR
"Initializing parent: $ref_id\n" unless $::_q
> 1;
2910 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
2911 if ($u =~ s
#^\Q$url\E(/|$)##) {
2914 $repo_id = $self->{repo_id
};
2916 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
2921 sub call_authors_prog
{
2922 my ($orig_author) = @_;
2923 $orig_author = command_oneline
('rev-parse', '--sq-quote', $orig_author);
2924 my $author = `$::_authors_prog $orig_author`;
2926 die "$::_authors_prog failed with exit code $?\n"
2928 if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
2929 my ($name, $email) = ($1, $2);
2930 $email = undef if length $2 == 0;
2931 return [$name, $email];
2933 die "Author: $orig_author: $::_authors_prog returned "
2934 . "invalid author format: $author\n";
2940 if (!defined $author || length $author == 0) {
2941 $author = '(no author)';
2943 if (!defined $::users
{$author}) {
2944 if (defined $::_authors_prog
) {
2945 $::users
{$author} = call_authors_prog
($author);
2946 } elsif (defined $::_authors
) {
2947 die "Author: $author not defined in $::_authors file\n";
2953 sub find_extra_svk_parents
{
2954 my ($self, $ed, $tickets, $parents) = @_;
2955 # aha! svk:merge property changed...
2956 my @tickets = split "\n", $tickets;
2958 for my $ticket ( @tickets ) {
2959 my ($uuid, $path, $rev) = split /:/, $ticket;
2960 if ( $uuid eq $self->ra_uuid ) {
2961 my $url = $self->rewrite_root || $self->{url
};
2962 my $repos_root = $url;
2963 my $branch_from = $path;
2964 $branch_from =~ s{^/}{};
2965 my $gs = $self->other_gs($repos_root."/".$branch_from,
2970 if ( my $commit = $gs->rev_map_get($rev, $uuid) ) {
2971 # wahey! we found it, but it might be
2973 push @known_parents, [ $rev, $commit ];
2977 # Ordering matters; highest-numbered commit merge tickets
2978 # first, as they may account for later merge ticket additions
2980 @known_parents = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @known_parents;
2981 for my $parent ( @known_parents ) {
2982 my @cmd = ('rev-list', $parent, map { "^$_" } @
$parents );
2983 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
2985 while ( <$msg_fh> ) {
2988 command_close_pipe
($msg_fh, $ctx);
2991 "Found merge parent (svk:merge ticket): $parent\n";
2992 push @
$parents, $parent;
2997 # note: this function should only be called if the various dirprops
2998 # have actually changed
2999 sub find_extra_svn_parents
{
3000 my ($self, $ed, $mergeinfo, $parents) = @_;
3001 # aha! svk:merge property changed...
3003 # We first search for merged tips which are not in our
3004 # history. Then, we figure out which git revisions are in
3005 # that tip, but not this revision. If all of those revisions
3006 # are now marked as merge, we can add the tip as a parent.
3007 my @merges = split "\n", $mergeinfo;
3009 my @merged_commit_ranges;
3010 my $url = $self->rewrite_root || $self->{url
};
3011 for my $merge ( @merges ) {
3012 my ($source, $revs) = split ":", $merge;
3015 my $gs = Git
::SVN
->find_by_url($url.$source, $url, $path);
3017 warn "Couldn't find revmap for $url$source\n";
3020 my @ranges = split ",", $revs;
3021 my ($tip, $tip_commit);
3023 for my $range ( @ranges ) {
3024 my ($bottom, $top) = split "-", $range;
3027 $gs->rev_map_get($bottom, $self->ra_uuid) ||
3028 $gs->rev_map_get($bottom+1, $self->ra_uuid);
3030 for (; !$top_commit && $top >= $bottom; --$top) {
3032 $gs->rev_map_get($top, $self->ra_uuid);
3035 unless ($top_commit and $bottom_commit) {
3036 warn "W:unknown path/rev in svn:mergeinfo "
3037 ."dirprop: $source:$range\n";
3041 push @merged_commit_ranges,
3042 "$bottom_commit..$top_commit";
3044 if ( !defined $tip or $top > $tip ) {
3046 $tip_commit = $top_commit;
3049 unless (!$tip_commit or
3050 grep { $_ eq $tip_commit } @
$parents ) {
3051 push @merge_tips, $tip_commit;
3053 push @merge_tips, undef;
3056 for my $merge_tip ( @merge_tips ) {
3057 my $spec = shift @merges;
3058 next unless $merge_tip;
3059 my @cmd = ('rev-list', "-1", $merge_tip,
3060 "--not", @
$parents );
3061 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
3063 while ( <$msg_fh> ) {
3066 command_close_pipe
($msg_fh, $ctx);
3068 push @cmd, @merged_commit_ranges;
3069 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
3071 while ( <$msg_fh> ) {
3074 command_close_pipe
($msg_fh, $ctx);
3076 warn "W:svn cherry-pick ignored ($spec)\n";
3079 "Found merge parent (svn:mergeinfo prop): ",
3081 push @
$parents, $merge_tip;
3087 sub make_log_entry
{
3088 my ($self, $rev, $parents, $ed) = @_;
3089 my $untracked = $self->get_untracked($ed);
3091 my @parents = @
$parents;
3092 my $ps = $ed->{path_strip
} || "";
3093 for my $path ( grep { m/$ps/ } %{$ed->{dir_prop
}} ) {
3094 my $props = $ed->{dir_prop
}{$path};
3095 if ( $props->{"svk:merge"} ) {
3096 $self->find_extra_svk_parents
3097 ($ed, $props->{"svk:merge"}, \
@parents);
3099 if ( $props->{"svn:mergeinfo"} ) {
3100 $self->find_extra_svn_parents
3102 $props->{"svn:mergeinfo"},
3107 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
3108 print $un "r$rev\n" or croak
$!;
3109 print $un $_, "\n" foreach @
$untracked;
3110 my %log_entry = ( parents
=> \
@parents, revision
=> $rev,
3114 my $logged = delete $self->{logged_rev_props
};
3115 if (!$logged || $self->{-want_revprops
}) {
3116 my $rp = $self->ra->rev_proplist($rev);
3117 foreach (sort keys %$rp) {
3119 if (/^svn:(author|date|log)$/) {
3120 $log_entry{$1} = $v;
3121 } elsif ($_ eq 'svm:headrev') {
3124 print $un " rev_prop: ", uri_encode
($_), ' ',
3125 uri_encode
($v), "\n";
3129 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
3131 close $un or croak
$!;
3133 $log_entry{date
} = parse_svn_date
($log_entry{date
});
3134 $log_entry{log} .= "\n";
3135 my $author = $log_entry{author
} = check_author
($log_entry{author
});
3136 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
3139 my ($commit_name, $commit_email) = ($name, $email);
3140 if ($_use_log_author) {
3142 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
3144 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
3147 if (!defined $name_field) {
3148 if (!defined $email) {
3151 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
3152 ($name, $email) = ($1, $2);
3153 } elsif ($name_field =~ /(.*)@/) {
3154 ($name, $email) = ($1, $name_field);
3156 ($name, $email) = ($name_field, $name_field);
3159 if (defined $headrev && $self->use_svm_props) {
3160 if ($self->rewrite_root) {
3161 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
3164 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$}i
;
3165 # we don't want "SVM: initializing mirror for junk" ...
3166 return undef if $r == 0;
3167 my $svm = $self->svm;
3168 if ($uuid ne $svm->{uuid
}) {
3169 die "UUID mismatch on SVM path:\n",
3170 "expected: $svm->{uuid}\n",
3173 my $full_url = $self->full_url;
3174 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
3175 die "Failed to replace '$svm->{replace}' with ",
3176 "'$svm->{source}' in $full_url\n";
3177 # throw away username for storing in records
3178 remove_username
($full_url);
3179 $log_entry{metadata
} = "$full_url\@$r $uuid";
3180 $log_entry{svm_revision
} = $r;
3181 $email ||= "$author\@$uuid";
3182 $commit_email ||= "$author\@$uuid";
3183 } elsif ($self->use_svnsync_props) {
3184 my $full_url = $self->svnsync->{url
};
3185 $full_url .= "/$self->{path}" if length $self->{path
};
3186 remove_username
($full_url);
3187 my $uuid = $self->svnsync->{uuid
};
3188 $log_entry{metadata
} = "$full_url\@$rev $uuid";
3189 $email ||= "$author\@$uuid";
3190 $commit_email ||= "$author\@$uuid";
3192 my $url = $self->metadata_url;
3193 remove_username
($url);
3194 $log_entry{metadata
} = "$url\@$rev " .
3195 $self->ra->get_uuid;
3196 $email ||= "$author\@" . $self->ra->get_uuid;
3197 $commit_email ||= "$author\@" . $self->ra->get_uuid;
3199 $log_entry{name
} = $name;
3200 $log_entry{email
} = $email;
3201 $log_entry{commit_name
} = $commit_name;
3202 $log_entry{commit_email
} = $commit_email;
3207 my ($self, $min_rev, $max_rev, @parents) = @_;
3208 my ($last_rev, $last_commit) = $self->last_rev_commit;
3209 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
3210 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
3214 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
3215 $self->{inject_parents
} = { $rev => $tree };
3216 $self->fetch(undef, undef);
3220 my ($self, $tree) = (shift, shift);
3221 my $log_entry = ::get_commit_entry
($tree);
3222 unless ($self->{last_rev
}) {
3223 ::fatal
("Must have an existing revision to commit");
3225 my %ed_opts = ( r
=> $self->{last_rev
},
3226 log => $log_entry->{log},
3228 tree_a
=> $self->{last_commit
},
3231 $self->set_tree_cb($log_entry, $tree, @_) },
3232 svn_path
=> $self->{path
} );
3233 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
3234 print "No changes\nr$self->{last_rev} = $tree\n";
3238 sub rebuild_from_rev_db
{
3239 my ($self, $path) = @_;
3241 open my $fh, '<', $path or croak
"open: $!";
3242 binmode $fh or croak
"binmode: $!";
3244 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
3247 next if $_ eq ('0' x
40);
3248 $self->rev_map_set($r, $_);
3251 close $fh or croak
"close: $!";
3252 unlink $path or croak
"unlink: $!";
3257 my $map_path = $self->map_path;
3258 my $partial = (-e
$map_path && ! -z
$map_path);
3259 return unless ::verify_ref
($self->refname.'^0');
3260 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
3261 my $rev_db = $self->rev_db_path;
3262 $self->rebuild_from_rev_db($rev_db);
3263 if ($self->use_svm_props) {
3264 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
3265 $self->rebuild_from_rev_db($svm_rev_db);
3267 $self->unlink_rev_db_symlink;
3270 print "Rebuilding $map_path ...\n" if (!$partial);
3271 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
3274 command_output_pipe
(qw
/rev-list --pretty=raw --no-color --reverse/,
3275 ($head ?
"$head.." : "") . $self->refname,
3277 my $metadata_url = $self->metadata_url;
3278 remove_username
($metadata_url);
3279 my $svn_uuid = $self->ra_uuid;
3282 if ( m{^commit ($::sha1)$} ) {
3286 next unless s{^\s*(git-svn-id:)}{$1};
3287 my ($url, $rev, $uuid) = ::extract_metadata
($_);
3288 remove_username
($url);
3290 # ignore merges (from set-tree)
3291 next if (!defined $rev || !$uuid);
3293 # if we merged or otherwise started elsewhere, this is
3294 # how we break out of it
3295 if (($uuid ne $svn_uuid) ||
3296 ($metadata_url && $url && ($url ne $metadata_url))) {
3299 if ($partial && $head) {
3300 print "Partial-rebuilding $map_path ...\n";
3301 print "Currently at $base_rev = $head\n";
3305 $self->rev_map_set($rev, $c);
3306 print "r$rev = $c\n";
3308 command_close_pipe
($log, $ctx);
3309 print "Done rebuilding $map_path\n" if (!$partial || !$head);
3310 my $rev_db_path = $self->rev_db_path;
3311 if (-f
$self->rev_db_path) {
3312 unlink $self->rev_db_path or croak
"unlink: $!";
3314 $self->unlink_rev_db_symlink;
3318 # Tie::File seems to be prone to offset errors if revisions get sparse,
3319 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
3320 # one of my favorite modules is out :< Next up would be one of the DBM
3321 # modules, but I'm not sure which is most portable...
3323 # This is the replacement for the rev_db format, which was too big
3324 # and inefficient for large repositories with a lot of sparse history
3327 # The format is this:
3328 # - 24 bytes for every record,
3329 # * 4 bytes for the integer representing an SVN revision number
3330 # * 20 bytes representing the sha1 of a git commit
3331 # - No empty padding records like the old format
3332 # (except the last record, which can be overwritten)
3333 # - new records are written append-only since SVN revision numbers
3334 # increase monotonically
3335 # - lookups on SVN revision number are done via a binary search
3336 # - Piping the file to xxd -c24 is a good way of dumping it for
3337 # viewing or editing (piped back through xxd -r), should the need
3339 # - The last record can be padding revision with an all-zero sha1
3340 # This is used to optimize fetch performance when using multiple
3341 # "fetch" directives in .git/config
3343 # These files are disposable unless noMetadata or useSvmProps is set
3346 my ($fh, $rev, $commit) = @_;
3348 binmode $fh or croak
"binmode: $!";
3349 my $size = (stat($fh))[7];
3350 ($size % 24) == 0 or croak
"inconsistent size: $size";
3354 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
3355 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
3356 $read == 24 or croak
"read only $read bytes (!= 24)";
3357 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
3358 if ($last_commit eq ('0' x40
)) {
3360 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
3361 $read = sysread($fh, $buf, 24) or
3364 croak
"read only $read bytes (!= 24)";
3365 ($last_rev, $last_commit) =
3366 unpack(rev_map_fmt
, $buf);
3367 if ($last_commit eq ('0' x40
)) {
3368 croak
"inconsistent .rev_map\n";
3371 if ($last_rev >= $rev) {
3372 croak
"last_rev is higher!: $last_rev >= $rev";
3377 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
3378 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
3382 sub _rev_map_reset
{
3383 my ($fh, $rev, $commit) = @_;
3384 my $c = _rev_map_get
($fh, $rev);
3385 $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n";
3386 my $offset = sysseek($fh, 0, SEEK_CUR
) or croak
"seek: $!";
3387 truncate $fh, $offset or croak
"truncate: $!";
3393 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3394 mkpath
([$dir]) unless -d
$dir;
3395 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
3396 close $fh or die "Couldn't close (create) $path: $!\n";
3401 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
3402 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
3403 my $db = $self->map_path($uuid);
3404 my $db_lock = "$db.lock";
3408 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
3409 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
3413 $LOCKFILES{$db_lock} = 1;
3415 # both of these options make our .rev_db file very, very important
3416 # and we can't afford to lose it because rebuild() won't work
3417 if ($self->use_svm_props || $self->no_metadata) {
3419 copy
($db, $db_lock) or die "rev_map_set(@_): ",
3421 "$db => $db_lock ($!)\n";
3423 rename $db, $db_lock or die "rev_map_set(@_): ",
3424 "Failed to rename: ",
3425 "$db => $db_lock ($!)\n";
3428 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
3429 or croak
"Couldn't open $db_lock: $!\n";
3430 $update_ref eq 'reset' ? _rev_map_reset
($fh, $rev, $commit) :
3431 _rev_map_set
($fh, $rev, $commit);
3433 $fh->flush or die "Couldn't flush $db_lock: $!\n";
3434 $fh->sync or die "Couldn't sync $db_lock: $!\n";
3436 close $fh or croak
$!;
3440 $note = " ($update_ref)" if ($update_ref !~ /^\d*$/);
3441 command_noisy
('update-ref', '-m', "r$rev$note",
3442 $self->refname, $commit);
3444 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
3445 "$db_lock => $db ($!)\n";
3446 delete $LOCKFILES{$db_lock};
3448 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
3449 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
3450 kill $sig, $$ if defined $sig;
3454 # If want_commit, this will return an array of (rev, commit) where
3455 # commit _must_ be a valid commit in the archive.
3456 # Otherwise, it'll return the max revision (whether or not the
3457 # commit is valid or just a 0x40 placeholder).
3459 my ($self, $want_commit) = @_;
3461 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
3462 $want_commit ?
($r, $c) : $r;
3465 sub rev_map_max_norebuild
{
3466 my ($self, $want_commit) = @_;
3467 my $map_path = $self->map_path;
3468 stat $map_path or return $want_commit ?
(0, undef) : 0;
3469 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
3470 binmode $fh or croak
"binmode: $!";
3471 my $size = (stat($fh))[7];
3472 ($size % 24) == 0 or croak
"inconsistent size: $size";
3475 close $fh or croak
"close: $!";
3476 return $want_commit ?
(0, undef) : 0;
3479 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
3480 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
3481 my ($r, $c) = unpack(rev_map_fmt
, $buf);
3482 if ($want_commit && $c eq ('0' x40
)) {
3484 return $want_commit ?
(0, undef) : 0;
3486 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
3487 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
3488 ($r, $c) = unpack(rev_map_fmt
, $buf);
3489 if ($c eq ('0'x40
)) {
3490 croak
"Penultimate record is all-zeroes in $map_path";
3493 close $fh or croak
"close: $!";
3494 $want_commit ?
($r, $c) : $r;
3498 my ($self, $rev, $uuid) = @_;
3499 my $map_path = $self->map_path($uuid);
3500 return undef unless -e
$map_path;
3502 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
3503 my $c = _rev_map_get
($fh, $rev);
3504 close($fh) or croak
"close: $!";
3509 my ($fh, $rev) = @_;
3511 binmode $fh or croak
"binmode: $!";
3512 my $size = (stat($fh))[7];
3513 ($size % 24) == 0 or croak
"inconsistent size: $size";
3519 my ($l, $u) = (0, $size - 24);
3523 my $i = int(($l/24 + $u/24) / 2) * 24;
3524 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
3525 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
3526 my ($r, $c) = unpack(rev_map_fmt
, $buf);
3530 } elsif ($r > $rev) {
3532 } else { # $r == $rev
3533 return $c eq ('0' x
40) ?
undef : $c;
3539 # Finds the first svn revision that exists on (if $eq_ok is true) or
3540 # before $rev for the current branch. It will not search any lower
3541 # than $min_rev. Returns the git commit hash and svn revision number
3542 # if found, else (undef, undef).
3543 sub find_rev_before
{
3544 my ($self, $rev, $eq_ok, $min_rev) = @_;
3545 --$rev unless $eq_ok;
3547 my $max_rev = $self->rev_map_max;
3548 $rev = $max_rev if ($rev > $max_rev);
3549 while ($rev >= $min_rev) {
3550 if (my $c = $self->rev_map_get($rev)) {
3555 return (undef, undef);
3558 # Finds the first svn revision that exists on (if $eq_ok is true) or
3559 # after $rev for the current branch. It will not search any higher
3560 # than $max_rev. Returns the git commit hash and svn revision number
3561 # if found, else (undef, undef).
3562 sub find_rev_after
{
3563 my ($self, $rev, $eq_ok, $max_rev) = @_;
3564 ++$rev unless $eq_ok;
3565 $max_rev ||= $self->rev_map_max;
3566 while ($rev <= $max_rev) {
3567 if (my $c = $self->rev_map_get($rev)) {
3572 return (undef, undef);
3576 my ($class, $repo_id, $ref_id, $path) = @_;
3577 unless (defined $repo_id && length $repo_id) {
3578 $repo_id = $Git::SVN
::default_repo_id
;
3580 unless (defined $ref_id && length $ref_id) {
3581 $_prefix = '' unless defined($_prefix);
3583 "refs/remotes/$_prefix$Git::SVN::default_ref_id";
3586 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
3588 # Older repos imported by us used $GIT_DIR/svn/foo instead of
3589 # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
3590 if ($ref_id =~ m{^refs/remotes/(.*)}) {
3591 my $old_dir = "$ENV{GIT_DIR}/svn/$1";
3592 if (-d
$old_dir && ! -d
$dir) {
3597 $_[3] = $path = '' unless (defined $path);
3600 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
3601 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
3602 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
3605 # for read-only access of old .rev_db formats
3606 sub unlink_rev_db_symlink
{
3608 my $link = $self->rev_db_path;
3609 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
3611 unlink $link or croak
"unlink: $link failed!";
3616 my ($self, $uuid) = @_;
3617 my $db_path = $self->map_path($uuid);
3618 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
3619 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
3623 # the new replacement for .rev_db
3625 my ($self, $uuid) = @_;
3626 $uuid ||= $self->ra_uuid;
3627 "$self->{map_root}.$uuid";
3632 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
3638 $f =~ s
#%([0-9a-fA-F]{2})#chr(hex($1))#eg;
3642 sub remove_username
{
3643 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};
3646 package Git
::SVN
::Prompt
;
3650 use vars qw
/$_no_auth_cache $_username/;
3653 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
3654 $may_save = undef if $_no_auth_cache;
3655 $default_username = $_username if defined $_username;
3656 if (defined $default_username && length $default_username) {
3657 if (defined $realm && length $realm) {
3658 print STDERR
"Authentication realm: $realm\n";
3661 $cred->username($default_username);
3663 username
($cred, $realm, $may_save, $pool);
3665 $cred->password(_read_password
("Password for '" .
3666 $cred->username . "': ", $realm));
3667 $cred->may_save($may_save);
3668 $SVN::_Core
::SVN_NO_ERROR
;
3671 sub ssl_server_trust
{
3672 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
3673 $may_save = undef if $_no_auth_cache;
3674 print STDERR
"Error validating server certificate for '$realm':\n";
3677 # All variables SVN::Auth::SSL::* are used only once,
3678 # so we're shutting up Perl warnings about this.
3679 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
3680 print STDERR
" - The certificate is not issued ",
3681 "by a trusted authority. Use the\n",
3682 " fingerprint to validate ",
3683 "the certificate manually!\n";
3685 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
3686 print STDERR
" - The certificate hostname ",
3687 "does not match.\n";
3689 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
3690 print STDERR
" - The certificate is not yet valid.\n";
3692 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
3693 print STDERR
" - The certificate has expired.\n";
3695 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
3696 print STDERR
" - The certificate has ",
3697 "an unknown error.\n";
3699 } # no warnings 'once'
3701 "Certificate information:\n".
3702 " - Hostname: %s\n".
3703 " - Valid: from %s until %s\n".
3705 " - Fingerprint: %s\n",
3706 map $cert_info->$_, qw(hostname valid_from valid_until
3707 issuer_dname fingerprint);
3710 print STDERR
$may_save ?
3711 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
3712 "(R)eject or accept (t)emporarily? ";
3714 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
3715 if ($choice =~ /^t$/i) {
3716 $cred->may_save(undef);
3717 } elsif ($choice =~ /^r$/i) {
3719 } elsif ($may_save && $choice =~ /^p$/i) {
3720 $cred->may_save($may_save);
3724 $cred->accepted_failures($failures);
3725 $SVN::_Core
::SVN_NO_ERROR
;
3728 sub ssl_client_cert
{
3729 my ($cred, $realm, $may_save, $pool) = @_;
3730 $may_save = undef if $_no_auth_cache;
3731 print STDERR
"Client certificate filename: ";
3733 chomp(my $filename = <STDIN
>);
3734 $cred->cert_file($filename);
3735 $cred->may_save($may_save);
3736 $SVN::_Core
::SVN_NO_ERROR
;
3739 sub ssl_client_cert_pw
{
3740 my ($cred, $realm, $may_save, $pool) = @_;
3741 $may_save = undef if $_no_auth_cache;
3742 $cred->password(_read_password
("Password: ", $realm));
3743 $cred->may_save($may_save);
3744 $SVN::_Core
::SVN_NO_ERROR
;
3748 my ($cred, $realm, $may_save, $pool) = @_;
3749 $may_save = undef if $_no_auth_cache;
3750 if (defined $realm && length $realm) {
3751 print STDERR
"Authentication realm: $realm\n";
3754 if (defined $_username) {
3755 $username = $_username;
3757 print STDERR
"Username: ";
3759 chomp($username = <STDIN
>);
3761 $cred->username($username);
3762 $cred->may_save($may_save);
3763 $SVN::_Core
::SVN_NO_ERROR
;
3766 sub _read_password
{
3767 my ($prompt, $realm) = @_;
3768 print STDERR
$prompt;
3770 require Term
::ReadKey
;
3771 Term
::ReadKey
::ReadMode
('noecho');
3773 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
3774 last if $key =~ /[\012\015]/; # \n\r
3777 Term
::ReadKey
::ReadMode
('restore');
3783 package SVN
::Git
::Fetcher
;
3788 use File
::Temp qw
/tempfile/;
3790 use vars qw
/$_ignore_regex/;
3792 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
3794 my ($class, $git_svn, $switch_path) = @_;
3795 my $self = SVN
::Delta
::Editor
->new;
3796 bless $self, $class;
3797 if (exists $git_svn->{last_commit
}) {
3798 $self->{c
} = $git_svn->{last_commit
};
3799 $self->{empty_symlinks
} =
3800 _mark_empty_symlinks
($git_svn, $switch_path);
3802 $self->{ignore_regex
} = eval { command_oneline
('config', '--get',
3803 "svn-remote.$git_svn->{repo_id}.ignore-paths") };
3804 $self->{empty
} = {};
3805 $self->{dir_prop
} = {};
3806 $self->{file_prop
} = {};
3807 $self->{absent_dir
} = {};
3808 $self->{absent_file
} = {};
3809 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
3813 # this uses the Ra object, so it must be called before do_{switch,update},
3814 # not inside them (when the Git::SVN::Fetcher object is passed) to
3815 # do_{switch,update}
3816 sub _mark_empty_symlinks
{
3817 my ($git_svn, $switch_path) = @_;
3818 my $bool = Git
::config_bool
('svn.brokenSymlinkWorkaround');
3819 return {} if (!defined($bool)) || (defined($bool) && ! $bool);
3822 my ($rev, $cmt) = $git_svn->last_rev_commit;
3823 return {} unless ($rev && $cmt);
3825 # allow the warning to be printed for each revision we fetch to
3826 # ensure the user sees it. The user can also disable the workaround
3827 # on the repository even while git svn is running and the next
3828 # revision fetched will skip this expensive function.
3829 my $printed_warning;
3830 chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
3831 my ($ls, $ctx) = command_output_pipe
(qw
/ls-tree -r -z/, $cmt);
3833 my $pfx = defined($switch_path) ?
$switch_path : $git_svn->{path
};
3834 $pfx .= '/' if length($pfx);
3837 s/\A100644 blob $empty_blob\t//o or next;
3838 unless ($printed_warning) {
3839 print STDERR
"Scanning for empty symlinks, ",
3840 "this may take a while if you have ",
3841 "many empty files\n",
3842 "You may disable this with `",
3843 "git config svn.brokenSymlinkWorkaround ",
3845 "This may be done in a different ",
3846 "terminal without restarting ",
3848 $printed_warning = 1;
3851 my (undef, $props) =
3852 $git_svn->ra->get_file($pfx.$path, $rev, undef);
3853 if ($props->{'svn:special'}) {
3857 command_close_pipe
($ls, $ctx);
3861 # returns true if a given path is inside a ".git" directory
3863 $_[0] =~ m{(?:^|/)\.git(?:/|$)};
3866 # return value: 0 -- don't ignore, 1 -- ignore
3867 sub is_path_ignored
{
3868 my ($self, $path) = @_;
3869 return 1 if in_dot_git
($path);
3870 return 1 if defined($self->{ignore_regex
}) &&
3871 $path =~ m!$self->{ignore_regex}!;
3872 return 0 unless defined($_ignore_regex);
3873 return 1 if $path =~ m!$_ignore_regex!o;
3877 sub set_path_strip
{
3878 my ($self, $path) = @_;
3879 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
3886 sub open_directory
{
3887 my ($self, $path, $pb, $rev) = @_;
3892 my ($self, $path) = @_;
3893 if ($self->{path_strip
}) {
3894 $path =~ s!$self->{path_strip}!! or
3895 die "Failed to strip path '$path' ($self->{path_strip})\n";
3901 my ($self, $path, $rev, $pb) = @_;
3902 return undef if $self->is_path_ignored($path);
3904 my $gpath = $self->git_path($path);
3905 return undef if ($gpath eq '');
3907 # remove entire directories.
3908 my ($tree) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
3909 =~ /\A040000 tree ([a-f\d]{40})\t\Q$gpath\E\0/);
3911 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3917 my $rmpath = "$gpath/$_";
3918 $self->{gii
}->remove($rmpath);
3919 print "\tD\t$rmpath\n" unless $::_q
;
3921 print "\tD\t$gpath/\n" unless $::_q
;
3922 command_close_pipe
($ls, $ctx);
3924 $self->{gii
}->remove($gpath);
3925 print "\tD\t$gpath\n" unless $::_q
;
3927 $self->{empty
}->{$path} = 0;
3932 my ($self, $path, $pb, $rev) = @_;
3935 goto out
if $self->is_path_ignored($path);
3937 my $gpath = $self->git_path($path);
3938 ($mode, $blob) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
3939 =~ /\A(\d{6}) blob ([a-f\d]{40})\t\Q$gpath\E\0/);
3940 unless (defined $mode && defined $blob) {
3941 die "$path was not found in commit $self->{c} (r$rev)\n";
3943 if ($mode eq '100644' && $self->{empty_symlinks
}->{$path}) {
3947 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
3948 pool
=> SVN
::Pool
->new, action
=> 'M' };
3952 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
3955 if (!$self->is_path_ignored($path)) {
3956 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3957 delete $self->{empty
}->{$dir};
3960 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode,
3961 pool
=> SVN
::Pool
->new, action
=> 'A' };
3965 my ($self, $path, $cp_path, $cp_rev) = @_;
3966 goto out
if $self->is_path_ignored($path);
3967 my $gpath = $self->git_path($path);
3969 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3975 $self->{gii
}->remove($_);
3976 print "\tD\t$_\n" unless $::_q
;
3978 command_close_pipe
($ls, $ctx);
3979 $self->{empty
}->{$path} = 0;
3981 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3982 delete $self->{empty
}->{$dir};
3983 $self->{empty
}->{$path} = 1;
3988 sub change_dir_prop
{
3989 my ($self, $db, $prop, $value) = @_;
3990 return undef if $self->is_path_ignored($db->{path
});
3991 $self->{dir_prop
}->{$db->{path
}} ||= {};
3992 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
3996 sub absent_directory
{
3997 my ($self, $path, $pb) = @_;
3998 return undef if $self->is_path_ignored($path);
3999 $self->{absent_dir
}->{$pb->{path
}} ||= [];
4000 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
4005 my ($self, $path, $pb) = @_;
4006 return undef if $self->is_path_ignored($path);
4007 $self->{absent_file
}->{$pb->{path
}} ||= [];
4008 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
4012 sub change_file_prop
{
4013 my ($self, $fb, $prop, $value) = @_;
4014 return undef if $self->is_path_ignored($fb->{path
});
4015 if ($prop eq 'svn:executable') {
4016 if ($fb->{mode_b
} != 120000) {
4017 $fb->{mode_b
} = defined $value ?
100755 : 100644;
4019 } elsif ($prop eq 'svn:special') {
4020 $fb->{mode_b
} = defined $value ?
120000 : 100644;
4022 $self->{file_prop
}->{$fb->{path
}} ||= {};
4023 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
4028 sub apply_textdelta
{
4029 my ($self, $fb, $exp) = @_;
4030 return undef if $self->is_path_ignored($fb->{path
});
4031 my $fh = $::_repository
->temp_acquire('svn_delta');
4032 # $fh gets auto-closed() by SVN::TxDelta::apply(),
4033 # (but $base does not,) so dup() it for reading in close_file
4034 open my $dup, '<&', $fh or croak
$!;
4035 my $base = $::_repository
->temp_acquire('git_blob');
4038 my ($base_is_link, $size);
4040 if ($fb->{mode_a
} eq '120000' &&
4041 ! $self->{empty_symlinks
}->{$fb->{path
}}) {
4042 print $base 'link ' or die "print $!\n";
4046 $size = $::_repository
->cat_blob($fb->{blob
}, $base);
4047 die "Failed to read object $fb->{blob}" if ($size < 0);
4050 seek $base, 0, 0 or croak
$!;
4051 my $got = ::md5sum
($base);
4053 my $err = "Checksum mismatch: ".
4054 "$fb->{path} $fb->{blob}\n" .
4055 "expected: $exp\n" .
4057 if ($base_is_link) {
4059 "Retrying... (possibly ",
4060 "a bad symlink from SVN)\n";
4061 $::_repository
->temp_reset($base);
4069 seek $base, 0, 0 or croak
$!;
4071 $fb->{base
} = $base;
4072 [ SVN
::TxDelta
::apply
($base, $dup, undef, $fb->{path
}, $fb->{pool
}) ];
4076 my ($self, $fb, $exp) = @_;
4077 return undef if $self->is_path_ignored($fb->{path
});
4080 my $path = $self->git_path($fb->{path
});
4081 if (my $fh = $fb->{fh
}) {
4083 seek($fh, 0, 0) or croak
$!;
4084 my $got = ::md5sum
($fh);
4086 die "Checksum mismatch: $path\n",
4087 "expected: $exp\n got: $got\n";
4090 if ($fb->{mode_b
} == 120000) {
4091 sysseek($fh, 0, 0) or croak
$!;
4092 my $rd = sysread($fh, my $buf, 5);
4095 croak
"sysread: $!\n";
4096 } elsif ($rd == 0) {
4097 warn "$path has mode 120000",
4098 " but it points to nothing\n",
4099 "converting to an empty file with mode",
4101 $fb->{mode_b
} = '100644';
4102 } elsif ($buf ne 'link ') {
4103 warn "$path has mode 120000",
4104 " but is not a link\n";
4106 my $tmp_fh = $::_repository
->temp_acquire(
4109 while ($res = sysread($fh, my $str, 1024)) {
4110 my $out = syswrite($tmp_fh, $str, $res);
4111 defined($out) && $out == $res
4113 Git
::temp_path
($tmp_fh),
4116 defined $res or croak
$!;
4118 ($fh, $tmp_fh) = ($tmp_fh, $fh);
4119 Git
::temp_release
($tmp_fh, 1);
4123 $hash = $::_repository
->hash_and_insert_object(
4124 Git
::temp_path
($fh));
4125 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
4127 Git
::temp_release
($fb->{base
}, 1);
4128 Git
::temp_release
($fh, 1);
4130 $hash = $fb->{blob
} or die "no blob information\n";
4133 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
4134 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
4140 $self->{nr
} = $self->{gii
}->{nr
};
4141 delete $self->{gii
};
4142 $self->SUPER::abort_edit
(@_);
4147 $self->{git_commit_ok
} = 1;
4148 $self->{nr
} = $self->{gii
}->{nr
};
4149 delete $self->{gii
};
4150 $self->SUPER::close_edit
(@_);
4153 package SVN
::Git
::Editor
;
4154 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
4161 my ($class, $opts) = @_;
4162 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
4163 die "$_ required!\n" unless (defined $opts->{$_});
4166 my $pool = SVN
::Pool
->new;
4167 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
4168 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
4171 # $opts->{ra} functions should not be used after this:
4172 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
4173 $opts->{editor_cb
}, $pool);
4174 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
4175 bless $self, $class;
4176 foreach (qw
/svn_path r tree_a tree_b/) {
4177 $self->{$_} = $opts->{$_};
4179 $self->{url
} = $opts->{ra
}->{url
};
4180 $self->{mods
} = $mods;
4181 $self->{types
} = $types;
4182 $self->{pool
} = $pool;
4183 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
4185 $self->{path_prefix
} = length $self->{svn_path
} ?
4186 "$self->{svn_path}/" : '';
4187 $self->{config
} = $opts->{config
};
4192 my ($tree_a, $tree_b) = @_;
4193 my @diff_tree = qw(diff-tree -z -r);
4194 if ($_cp_similarity) {
4195 push @diff_tree, "-C$_cp_similarity";
4197 push @diff_tree, '-C';
4199 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
4200 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
4201 push @diff_tree, $tree_a, $tree_b;
4202 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
4206 while (<$diff_fh>) {
4207 chomp $_; # this gets rid of the trailing "\0"
4208 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
4209 ($::sha1
)\s
($::sha1
)\s
4210 ([MTCRAD
])\d
*$/xo
) {
4211 push @mods, { mode_a
=> $1, mode_b
=> $2,
4212 sha1_a
=> $3, sha1_b
=> $4,
4214 if ($5 =~ /^(?:C|R)$/) {
4219 } elsif ($state eq 'file_a') {
4220 my $x = $mods[$#mods] or croak
"Empty array\n";
4221 if ($x->{chg
} !~ /^(?:C|R)$/) {
4222 croak
"Error parsing $_, $x->{chg}\n";
4226 } elsif ($state eq 'file_b') {
4227 my $x = $mods[$#mods] or croak
"Empty array\n";
4228 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
4229 croak
"Error parsing $_, $x->{chg}\n";
4231 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
4232 croak
"Error parsing $_, $x->{chg}\n";
4237 croak
"Error parsing $_\n";
4240 command_close_pipe
($diff_fh, $ctx);
4244 sub check_diff_paths
{
4245 my ($ra, $pfx, $rev, $mods) = @_;
4247 $pfx .= '/' if length $pfx;
4249 sub type_diff_paths
{
4250 my ($ra, $types, $path, $rev) = @_;
4251 my @p = split m
#/+#, $path;
4253 unless (defined $types->{$c}) {
4254 $types->{$c} = $ra->check_path($c, $rev);
4257 $c .= '/' . shift @p;
4258 next if defined $types->{$c};
4259 $types->{$c} = $ra->check_path($c, $rev);
4263 foreach my $m (@
$mods) {
4264 foreach my $f (qw
/file_a file_b/) {
4265 next unless defined $m->{$f};
4266 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
4267 if (length $pfx.$dir && ! defined $types{$dir}) {
4268 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
4276 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
4280 my ($self, $path) = @_;
4281 $self->{path_prefix
}.(defined $path ?
$path : '');
4285 my ($self, $path) = @_;
4286 if ($self->{url
} =~ m
#^https?://#) {
4287 $path =~ s!([^~a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg;
4289 $self->{url
} . '/' . $self->repo_path($path);
4294 my $rm = $self->{rm
};
4295 delete $rm->{''}; # we never delete the url we're tracking
4298 foreach (keys %$rm) {
4299 my @d = split m
#/#, $_;
4303 $c .= '/' . shift @d;
4307 delete $rm->{$self->{svn_path
}};
4308 delete $rm->{''}; # we never delete the url we're tracking
4311 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
4316 my @dn = split m
#/#, $_;
4318 delete $rm->{join '/', @dn};
4325 command_close_pipe
($fh, $ctx);
4327 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
4328 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
4329 $self->close_directory($bat->{$d}, $p);
4330 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
4331 print "\tD+\t$d/\n" unless $::_q
;
4332 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
4337 sub open_or_add_dir
{
4338 my ($self, $full_path, $baton) = @_;
4339 my $t = $self->{types
}->{$full_path};
4341 die "$full_path not known in r$self->{r} or we have a bug!\n";
4345 # SVN::Node::none and SVN::Node::file are used only once,
4346 # so we're shutting up Perl's warnings about them.
4347 if ($t == $SVN::Node
::none
) {
4348 return $self->add_directory($full_path, $baton,
4349 undef, -1, $self->{pool
});
4350 } elsif ($t == $SVN::Node
::dir
) {
4351 return $self->open_directory($full_path, $baton,
4352 $self->{r
}, $self->{pool
});
4353 } # no warnings 'once'
4354 print STDERR
"$full_path already exists in repository at ",
4355 "r$self->{r} and it is not a directory (",
4356 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
4357 } # no warnings 'once'
4362 my ($self, $path) = @_;
4363 my $bat = $self->{bat
};
4364 my $repo_path = $self->repo_path($path);
4365 return $bat->{''} unless (length $repo_path);
4366 my @p = split m
#/+#, $repo_path;
4368 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
4371 $c .= '/' . shift @p;
4372 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
4377 # Subroutine to convert a globbing pattern to a regular expression.
4378 # From perl cookbook.
4380 my $globstr = shift;
4381 my %patmap = ('*' => '.*', '?' => '.', '[' => '[', ']' => ']');
4382 $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
4383 return '^' . $globstr . '$';
4386 sub check_autoprop
{
4387 my ($self, $pattern, $properties, $file, $fbat) = @_;
4388 # Convert the globbing pattern to a regular expression.
4389 my $regex = glob2pat
($pattern);
4390 # Check if the pattern matches the file name.
4391 if($file =~ m/($regex)/) {
4392 # Parse the list of properties to set.
4393 my @props = split(/;/, $properties);
4394 foreach my $prop (@props) {
4395 # Parse 'name=value' syntax and set the property.
4396 if ($prop =~ /([^=]+)=(.*)/) {
4397 my ($n,$v) = ($1,$2);
4401 $self->change_file_prop($fbat, $n, $v);
4407 sub apply_autoprops
{
4408 my ($self, $file, $fbat) = @_;
4409 my $conf_t = ${$self->{config
}}{'config'};
4411 # Check [miscellany]/enable-auto-props in svn configuration.
4412 if (SVN
::_Core
::svn_config_get_bool
(
4414 $SVN::_Core
::SVN_CONFIG_SECTION_MISCELLANY
,
4415 $SVN::_Core
::SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS
,
4417 # Auto-props are enabled. Enumerate them to look for matches.
4418 my $callback = sub {
4419 $self->check_autoprop($_[0], $_[1], $file, $fbat);
4421 SVN
::_Core
::svn_config_enumerate
(
4423 $SVN::_Core
::SVN_CONFIG_SECTION_AUTO_PROPS
,
4429 my ($self, $m) = @_;
4430 my ($dir, $file) = split_path
($m->{file_b
});
4431 my $pbat = $self->ensure_path($dir);
4432 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
4434 print "\tA\t$m->{file_b}\n" unless $::_q
;
4435 $self->apply_autoprops($file, $fbat);
4436 $self->chg_file($fbat, $m);
4437 $self->close_file($fbat,undef,$self->{pool
});
4441 my ($self, $m) = @_;
4442 my ($dir, $file) = split_path
($m->{file_b
});
4443 my $pbat = $self->ensure_path($dir);
4444 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
4445 $self->url_path($m->{file_a
}), $self->{r
});
4446 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
4447 $self->chg_file($fbat, $m);
4448 $self->close_file($fbat,undef,$self->{pool
});
4452 my ($self, $path, $pbat) = @_;
4453 my $rpath = $self->repo_path($path);
4454 my ($dir, $file) = split_path
($rpath);
4455 $self->{rm
}->{$dir} = 1;
4456 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
4460 my ($self, $m) = @_;
4461 my ($dir, $file) = split_path
($m->{file_b
});
4462 my $pbat = $self->ensure_path($dir);
4463 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
4464 $self->url_path($m->{file_a
}), $self->{r
});
4465 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
4466 $self->apply_autoprops($file, $fbat);
4467 $self->chg_file($fbat, $m);
4468 $self->close_file($fbat,undef,$self->{pool
});
4470 ($dir, $file) = split_path
($m->{file_a
});
4471 $pbat = $self->ensure_path($dir);
4472 $self->delete_entry($m->{file_a
}, $pbat);
4476 my ($self, $m) = @_;
4477 my ($dir, $file) = split_path
($m->{file_b
});
4478 my $pbat = $self->ensure_path($dir);
4479 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
4480 $pbat,$self->{r
},$self->{pool
});
4481 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
4482 $self->chg_file($fbat, $m);
4483 $self->close_file($fbat,undef,$self->{pool
});
4486 sub T
{ shift->M(@_) }
4488 sub change_file_prop
{
4489 my ($self, $fbat, $pname, $pval) = @_;
4490 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
4493 sub _chg_file_get_blob
($$$$) {
4494 my ($self, $fbat, $m, $which) = @_;
4495 my $fh = $::_repository
->temp_acquire("git_blob_$which");
4496 if ($m->{"mode_$which"} =~ /^120/) {
4497 print $fh 'link ' or croak
$!;
4498 $self->change_file_prop($fbat,'svn:special','*');
4499 } elsif ($m->{mode_a
} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
4500 $self->change_file_prop($fbat,'svn:special',undef);
4502 my $blob = $m->{"sha1_$which"};
4503 return ($fh,) if ($blob =~ /^0{40}$/);
4504 my $size = $::_repository
->cat_blob($blob, $fh);
4505 croak
"Failed to read object $blob" if ($size < 0);
4506 $fh->flush == 0 or croak
$!;
4507 seek $fh, 0, 0 or croak
$!;
4509 my $exp = ::md5sum
($fh);
4510 seek $fh, 0, 0 or croak
$!;
4515 my ($self, $fbat, $m) = @_;
4516 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
4517 $self->change_file_prop($fbat,'svn:executable','*');
4518 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
4519 $self->change_file_prop($fbat,'svn:executable',undef);
4521 my ($fh_a, $exp_a) = _chg_file_get_blob
$self, $fbat, $m, 'a';
4522 my ($fh_b, $exp_b) = _chg_file_get_blob
$self, $fbat, $m, 'b';
4523 my $pool = SVN
::Pool
->new;
4524 my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
4526 my $txstream = SVN
::TxDelta
::new
($fh_a, $fh_b, $pool);
4527 my $res = SVN
::TxDelta
::send_txstream
($txstream, @
$atd, $pool);
4529 die "Unexpected result from send_txstream: $res\n",
4530 "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
4533 my $got = SVN
::TxDelta
::send_stream
($fh_b, @
$atd, $pool);
4534 die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
4535 if ($got ne $exp_b);
4537 Git
::temp_release
($fh_b, 1);
4538 Git
::temp_release
($fh_a, 1);
4543 my ($self, $m) = @_;
4544 my ($dir, $file) = split_path
($m->{file_b
});
4545 my $pbat = $self->ensure_path($dir);
4546 print "\tD\t$m->{file_b}\n" unless $::_q
;
4547 $self->delete_entry($m->{file_b
}, $pbat);
4552 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
4553 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
4555 $self->close_directory($bat->{$_}, $p);
4557 $self->close_directory($bat->{''}, $p);
4558 $self->SUPER::close_edit
($p);
4564 $self->SUPER::abort_edit
($self->{pool
});
4569 $self->SUPER::DESTROY
(@_);
4570 $self->{pool
}->clear;
4573 # this drives the editor
4576 my $mods = $self->{mods
};
4577 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
4578 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
4580 if (defined $o{$f}) {
4583 fatal
("Invalid change type: $f");
4586 $self->rmdirs if $_rmdir;
4592 return scalar @
$mods;
4595 package Git
::SVN
::Ra
;
4596 use vars qw
/@ISA $config_dir $_log_window_size/;
4599 my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
4602 # enforce temporary pool usage for some simple functions
4604 for my $f (qw
/rev_proplist get_latest_revnum get_uuid get_repos_root
4606 my $SUPER = "SUPER::$f";
4609 my $pool = SVN
::Pool
->new;
4610 my @ret = $self->$SUPER(@_,$pool);
4612 wantarray ?
@ret : $ret[0];
4617 sub _auth_providers
() {
4619 SVN
::Client
::get_simple_provider
(),
4620 SVN
::Client
::get_ssl_server_trust_file_provider
(),
4621 SVN
::Client
::get_simple_prompt_provider
(
4622 \
&Git
::SVN
::Prompt
::simple
, 2),
4623 SVN
::Client
::get_ssl_client_cert_file_provider
(),
4624 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
4625 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
4626 SVN
::Client
::get_ssl_client_cert_pw_file_provider
(),
4627 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
4628 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
4629 SVN
::Client
::get_username_provider
(),
4630 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
4631 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
4632 SVN
::Client
::get_username_prompt_provider
(
4633 \
&Git
::SVN
::Prompt
::username
, 2)
4637 sub escape_uri_only
{
4640 foreach (split m{/}, $uri) {
4641 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
4649 if ($url =~ m
#^(https?)://([^/]+)(.*)$#) {
4650 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
4651 $url = "$scheme://$domain$uri";
4657 my ($class, $url) = @_;
4659 return $RA if ($RA && $RA->{url
} eq $url);
4661 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
4662 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
(_auth_providers
);
4663 my $config = SVN
::Core
::config_get_config
($config_dir);
4665 my $dont_store_passwords = 1;
4666 my $conf_t = ${$config}{'config'};
4669 # The usage of $SVN::_Core::SVN_CONFIG_* variables
4670 # produces warnings that variables are used only once.
4671 # I had not found the better way to shut them up, so
4672 # the warnings of type 'once' are disabled in this block.
4673 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
4674 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
4675 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_PASSWORDS
,
4677 SVN
::_Core
::svn_auth_set_parameter
($baton,
4678 $SVN::_Core
::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS
,
4679 bless (\
$dont_store_passwords, "_p_void"));
4681 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
4682 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
4683 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_AUTH_CREDS
,
4685 $Git::SVN
::Prompt
::_no_auth_cache
= 1;
4687 } # no warnings 'once'
4688 my $self = SVN
::Ra
->new(url
=> escape_url
($url), auth
=> $baton,
4690 pool
=> SVN
::Pool
->new,
4691 auth_provider_callbacks
=> $callbacks);
4692 $self->{url
} = $url;
4693 $self->{svn_path
} = $url;
4694 $self->{repos_root
} = $self->get_repos_root;
4695 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
4696 $self->{cache
} = { check_path
=> { r
=> 0, data
=> {} },
4697 get_dir
=> { r
=> 0, data
=> {} } };
4698 $RA = bless $self, $class;
4702 my ($self, $path, $r) = @_;
4703 my $cache = $self->{cache
}->{check_path
};
4704 if ($r == $cache->{r
} && exists $cache->{data
}->{$path}) {
4705 return $cache->{data
}->{$path};
4707 my $pool = SVN
::Pool
->new;
4708 my $t = $self->SUPER::check_path
($path, $r, $pool);
4710 if ($r != $cache->{r
}) {
4711 %{$cache->{data
}} = ();
4714 $cache->{data
}->{$path} = $t;
4718 my ($self, $dir, $r) = @_;
4719 my $cache = $self->{cache
}->{get_dir
};
4720 if ($r == $cache->{r
}) {
4721 if (my $x = $cache->{data
}->{$dir}) {
4722 return wantarray ? @
$x : $x->[0];
4725 my $pool = SVN
::Pool
->new;
4726 my ($d, undef, $props) = $self->SUPER::get_dir
($dir, $r, $pool);
4727 my %dirents = map { $_ => { kind
=> $d->{$_}->kind } } keys %$d;
4729 if ($r != $cache->{r
}) {
4730 %{$cache->{data
}} = ();
4733 $cache->{data
}->{$dir} = [ \
%dirents, $r, $props ];
4734 wantarray ?
(\
%dirents, $r, $props) : \
%dirents;
4738 # do not call the real DESTROY since we store ourselves in $RA
4741 # get_log(paths, start, end, limit,
4742 # discover_changed_paths, strict_node_history, receiver)
4744 my ($self, @args) = @_;
4745 my $pool = SVN
::Pool
->new;
4747 # svn_log_changed_path_t objects passed to get_log are likely to be
4748 # overwritten even if only the refs are copied to an external variable,
4749 # so we should dup the structures in their entirety. Using an
4750 # externally passed pool (instead of our temporary and quickly cleared
4751 # pool in Git::SVN::Ra) does not help matters at all...
4752 my $receiver = pop @args;
4753 my $prefix = "/".$self->{svn_path
};
4754 $prefix =~ s
#/+($)##;
4755 my $prefix_regex = qr
#^\Q$prefix\E#;
4757 my ($paths) = $_[0];
4758 return &$receiver(@_) unless $paths;
4760 foreach my $p (keys %$paths) {
4761 my $i = $paths->{$p};
4762 # Make path relative to our url, not repos_root
4763 $p =~ s/$prefix_regex//;
4764 my %s = map { $_ => $i->$_; }
4765 qw
/copyfrom_path copyfrom_rev action/;
4766 if ($s{'copyfrom_path'}) {
4767 $s{'copyfrom_path'} =~ s/$prefix_regex//;
4775 # the limit parameter was not supported in SVN 1.1.x, so we
4776 # drop it. Therefore, the receiver callback passed to it
4777 # is made aware of this limitation by being wrapped if
4778 # the limit passed to is being wrapped.
4779 if ($SVN::Core
::VERSION
le '1.2.0') {
4780 my $limit = splice(@args, 3, 1);
4782 my $receiver = pop @args;
4783 push(@args, sub { &$receiver(@_) if (--$limit >= 0) });
4786 my $ret = $self->SUPER::get_log
(@args, $pool);
4792 my ($self, $url1, $rev1, $url2, $rev2) = @_;
4793 my $ctx = SVN
::Client
->new(auth
=> _auth_providers
);
4794 my $out = IO
::File
->new_tmpfile;
4796 # older SVN (1.1.x) doesn't take $pool as the last parameter for
4797 # $ctx->diff(), so we'll create a default one
4798 my $pool = SVN
::Pool
->new_default_sub;
4800 $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
4801 $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
4803 my $ret = (($out->stat)[7] == 0);
4804 close $out or croak
$!;
4809 sub get_commit_editor
{
4810 my ($self, $log, $cb, $pool) = @_;
4811 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
4812 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
4816 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
4817 my $new = ($rev_a == $rev_b);
4818 my $path = $gs->{path
};
4820 if ($new && -e
$gs->{index}) {
4821 unlink $gs->{index} or die
4822 "Couldn't unlink index: $gs->{index}: $!\n";
4824 my $pool = SVN
::Pool
->new;
4825 $editor->set_path_strip($path);
4826 my (@pc) = split m
#/#, $path;
4827 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
4829 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4831 # Since we can't rely on svn_ra_reparent being available, we'll
4832 # just have to do some magic with set_path to make it so
4833 # we only want a partial path.
4835 my $final = join('/', @pc);
4837 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
4838 $sp .= '/' if length $sp;
4841 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
4843 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
4845 $reporter->finish_report($pool);
4847 $editor->{git_commit_ok
};
4850 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
4851 # svn_ra_reparent didn't work before 1.4)
4853 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
4854 my $path = $gs->{path
};
4855 my $pool = SVN
::Pool
->new;
4857 my $full_url = $self->{url
};
4858 my $old_url = $full_url;
4859 $full_url .= '/' . $path if length $path;
4860 my ($ra, $reparented);
4862 if ($old_url =~ m
#^svn(\+ssh)?://# ||
4863 ($full_url =~ m
#^https?://# &&
4864 escape_url
($full_url) ne $full_url)) {
4868 $ra = Git
::SVN
::Ra
->new($full_url);
4870 } elsif ($old_url ne $full_url) {
4871 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url, $pool);
4872 $self->{url
} = $full_url;
4877 $url_b = escape_url
($url_b);
4878 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
4879 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4880 $reporter->set_path('', $rev_a, 0, @lock, $pool);
4881 $reporter->finish_report($pool);
4884 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
4885 $self->{url
} = $old_url;
4889 $editor->{git_commit_ok
};
4892 sub longest_common_path
{
4893 my ($gsv, $globs) = @_;
4895 my $common_max = scalar @
$gsv;
4897 foreach my $gs (@
$gsv) {
4898 my @tmp = split m
#/#, $gs->{path};
4901 $p .= length($p) ?
"/$_" : $_;
4907 $common_max += scalar @
$globs;
4908 foreach my $glob (@
$globs) {
4909 my @tmp = split m
#/#, $glob->{path}->{left};
4912 $p .= length($p) ?
"/$_" : $_;
4918 my $longest_path = '';
4919 foreach (sort {length $b <=> length $a} keys %common) {
4920 if ($common{$_} == $common_max) {
4928 sub gs_fetch_loop_common
{
4929 my ($self, $base, $head, $gsv, $globs) = @_;
4930 return if ($base > $head);
4931 my $inc = $_log_window_size;
4932 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
4933 my $longest_path = longest_common_path
($gsv, $globs);
4934 my $ra_url = $self->{url
};
4935 my $find_trailing_edge;
4939 my $err_handler = $SVN::Error
::handler
;
4940 $SVN::Error
::handler
= sub {
4942 skip_unknown_revs
($err);
4945 my ($paths, $r, $author, $date, $log) = @_;
4947 { author
=> $author, date
=> $date, log => $log } ];
4949 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
4950 sub { $revs{$_[1]} = _cb
(@_) });
4952 print "Checked through r$max\r";
4954 $find_trailing_edge = 1;
4956 if ($err and $find_trailing_edge) {
4957 print STDERR
"Path '$longest_path' ",
4958 "was probably deleted:\n",
4959 $err->expanded_message,
4960 "\nWill attempt to follow ",
4961 "revisions r$min .. r$max ",
4962 "committed before the deletion\n";
4964 while (--$hi >= $min) {
4966 $self->get_log([$longest_path], $min, $hi,
4969 $revs{$_[1]} = _cb
(@_) });
4971 print STDERR
"r$min .. r$ok OK\n";
4975 $find_trailing_edge = 0;
4977 $SVN::Error
::handler
= $err_handler;
4979 my %exists = map { $_->{path
} => $_ } @
$gsv;
4980 foreach my $r (sort {$a <=> $b} keys %revs) {
4981 my ($paths, $logged) = @
{$revs{$r}};
4983 foreach my $gs ($self->match_globs(\
%exists, $paths,
4985 if ($gs->rev_map_max >= $r) {
4988 next unless $gs->match_paths($paths, $r);
4989 $gs->{logged_rev_props
} = $logged;
4990 if (my $last_commit = $gs->last_commit) {
4991 $gs->assert_index_clean($last_commit);
4993 my $log_entry = $gs->do_fetch($paths, $r);
4995 $gs->do_git_commit($log_entry);
4997 $INDEX_FILES{$gs->{index}} = 1;
4999 foreach my $g (@
$globs) {
5000 my $k = "svn-remote.$g->{remote}." .
5002 Git
::SVN
::tmp_config
($k, $r);
5008 $self = Git
::SVN
::Ra
->new($ra_url);
5009 $ra_invalid = undef;
5012 # pre-fill the .rev_db since it'll eventually get filled in
5013 # with '0' x40 if something new gets committed
5014 foreach my $gs (@
$gsv) {
5015 next if $gs->rev_map_max >= $max;
5016 next if defined $gs->rev_map_get($max);
5017 $gs->rev_map_set($max, 0 x40
);
5019 foreach my $g (@
$globs) {
5020 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
5021 Git
::SVN
::tmp_config
($k, $max);
5023 last if $max >= $head;
5026 $max = $head if ($max > $head);
5031 sub get_dir_globbed
{
5032 my ($self, $left, $depth, $r) = @_;
5034 my @x = eval { $self->get_dir($left, $r) };
5035 return unless scalar @x == 3;
5036 my $dirents = $x[0];
5038 foreach my $de (keys %$dirents) {
5039 next if $dirents->{$de}->{kind
} != $SVN::Node
::dir
;
5041 my @args = ("$left/$de", $depth - 1, $r);
5042 foreach my $dir ($self->get_dir_globbed(@args)) {
5043 push @finalents, "$de/$dir";
5046 push @finalents, $de;
5053 my ($self, $exists, $paths, $globs, $r) = @_;
5056 my ($self, $exists, $g, $r) = @_;
5058 my @dirs = $self->get_dir_globbed($g->{path
}->{left
},
5059 $g->{path
}->{depth
},
5062 foreach my $de (@dirs) {
5063 my $p = $g->{path
}->full_path($de);
5064 next if $exists->{$p};
5065 next if (length $g->{path
}->{right
} &&
5066 ($self->check_path($p, $r) !=
5068 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
5069 $g->{ref}->full_path($de), 1);
5072 foreach my $g (@
$globs) {
5073 if (my $path = $paths->{"/$g->{path}->{left}"}) {
5074 if ($path->{action
} =~ /^[AR]$/) {
5075 get_dir_check
($self, $exists, $g, $r);
5078 foreach (keys %$paths) {
5079 if (/$g->{path}->{left_regex}/ &&
5080 !/$g->{path}->{regex}/) {
5081 next if $paths->{$_}->{action
} !~ /^[AR]$/;
5082 get_dir_check
($self, $exists, $g, $r);
5084 next unless /$g->{path}->{regex}/;
5086 my $pathname = $g->{path
}->full_path($p);
5087 next if $exists->{$pathname};
5088 next if ($self->check_path($pathname, $r) !=
5090 $exists->{$pathname} = Git
::SVN
->init(
5091 $self->{url
}, $pathname, undef,
5092 $g->{ref}->full_path($p), 1);
5095 foreach (split m
#/#, $g->{path}->{left}) {
5097 next unless ($paths->{$c} &&
5098 ($paths->{$c}->{action
} =~ /^[AR]$/));
5099 get_dir_check
($self, $exists, $g, $r);
5107 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
5108 my $url = $self->{repos_root
};
5109 my @components = split(m!/!, $self->{svn_path
});
5112 $url .= "/$c" if length $c;
5114 my $ra = (ref $self)->new($url);
5115 my $latest = $ra->get_latest_revnum;
5116 $ra->get_log("", $latest, 0, 1, 0, 1, sub {});
5118 } while ($@
&& ($c = shift @components));
5124 unless (defined $can_do_switch) {
5125 my $pool = SVN
::Pool
->new;
5127 $self->do_switch(1, '', 0, $self->{url
},
5128 SVN
::Delta
::Editor
->new, $pool);
5133 $rep->abort_report($pool);
5141 sub skip_unknown_revs
{
5143 my $errno = $err->apr_err();
5144 # Maybe the branch we're tracking didn't
5145 # exist when the repo started, so it's
5146 # not an error if it doesn't, just continue
5148 # Wonderfully consistent library, eh?
5149 # 160013 - svn:// and file://
5150 # 175002 - http(s)://
5151 # 175007 - http(s):// (this repo required authorization, too...)
5152 # More codes may be discovered later...
5153 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
5154 my $err_key = $err->expanded_message;
5155 # revision numbers change every time, filter them out
5156 $err_key =~ s/\d+/\0/g;
5157 $err_key = "$errno\0$err_key";
5158 unless ($ignored_err{$err_key}) {
5159 warn "W: Ignoring error from SVN, path probably ",
5160 "does not exist: ($errno): ",
5161 $err->expanded_message,"\n";
5162 warn "W: Do not be alarmed at the above message ",
5163 "git-svn is just searching aggressively for ",
5165 "This may take a while on large repositories\n";
5166 $ignored_err{$err_key} = 1;
5170 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
5173 package Git
::SVN
::Log
;
5176 use POSIX qw
/strftime/;
5178 use constant commit_log_separator
=> ('-' x
72) . "\n";
5179 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
5180 %rusers $show_commit $incremental/;
5185 return 1 if defined $c->{r
};
5187 # big commit message got truncated by the 16k pretty buffer in rev-list
5188 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
5189 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
5191 my @log = command
(qw
/cat-file commit/, $c->{c
});
5193 # shift off the headers
5194 shift @log while ($log[0] ne '');
5197 # TODO: make $c->{l} not have a trailing newline in the future
5198 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
5200 (undef, $c->{r
}, undef) = ::extract_metadata
(
5201 (grep(/^git-svn-id: /, @log))[-1]);
5203 return defined $c->{r
};
5207 return $color || Git
->repository->get_colorbool('color.diff');
5210 sub git_svn_log_cmd
{
5211 my ($r_min, $r_max, @args) = @_;
5213 my (@files, @log_opts);
5214 foreach my $x (@args) {
5215 if ($x eq '--' || @files) {
5218 if (::verify_ref
("$x^0")) {
5226 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
5227 $gs ||= Git
::SVN
->_new;
5228 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
5230 push @cmd, '-r' unless $non_recursive;
5231 push @cmd, qw
/--raw --name-status/ if $verbose;
5232 push @cmd, '--color' if log_use_color
();
5233 push @cmd, @log_opts;
5234 if (defined $r_max && $r_max == $r_min) {
5235 push @cmd, '--max-count=1';
5236 if (my $c = $gs->rev_map_get($r_max)) {
5239 } elsif (defined $r_max) {
5240 if ($r_max < $r_min) {
5241 ($r_min, $r_max) = ($r_max, $r_min);
5243 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
5244 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
5245 # If there are no commits in the range, both $c_max and $c_min
5246 # will be undefined. If there is at least 1 commit in the
5247 # range, both will be defined.
5248 return () if !defined $c_min || !defined $c_max;
5249 if ($c_min eq $c_max) {
5250 push @cmd, '--max-count=1', $c_min;
5252 push @cmd, '--boundary', "$c_min..$c_max";
5255 return (@cmd, @files);
5258 # adapted from pager.c
5260 chomp(my $pager = command_oneline
(qw(var GIT_PAGER)));
5261 if ($pager eq 'cat') {
5264 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
5268 return unless -t
*STDOUT
&& defined $pager;
5269 pipe my ($rfd, $wfd) or return;
5270 defined(my $pid = fork) or ::fatal
"Can't fork: $!";
5272 open STDOUT
, '>&', $wfd or
5273 ::fatal
"Can't redirect to stdout: $!";
5276 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!";
5277 $ENV{LESS
} ||= 'FRSX';
5278 exec $pager or ::fatal
"Can't run pager: $! ($pager)";
5281 sub format_svn_date
{
5282 # some systmes don't handle or mishandle %z, so be creative.
5283 my $t = shift || time;
5284 my $gm = timelocal
(gmtime($t));
5285 my $sign = qw( + + - )[ $t <=> $gm ];
5286 my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
5287 return strftime
("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
5290 sub parse_git_date
{
5292 # Date::Parse isn't in the standard Perl distro :(
5293 if ($tz =~ s/^\+//) {
5294 $t += tz_to_s_offset
($tz);
5295 } elsif ($tz =~ s/^\-//) {
5296 $t -= tz_to_s_offset
($tz);
5301 sub set_local_timezone
{
5309 sub tz_to_s_offset
{
5312 return ($1 * 60) + ($tz * 3600);
5315 sub get_author_info
{
5316 my ($dest, $author, $t, $tz) = @_;
5317 $author =~ s/(?:^\s*|\s*$)//g;
5318 $dest->{a_raw
} = $author;
5321 $au = $rusers{$author} || undef;
5324 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
5329 $dest->{t_utc
} = parse_git_date
($t, $tz);
5332 sub process_commit
{
5333 my ($c, $r_min, $r_max, $defer) = @_;
5334 if (defined $r_min && defined $r_max) {
5335 if ($r_min == $c->{r
} && $r_min == $r_max) {
5339 return 1 if $r_min == $r_max;
5340 if ($r_min < $r_max) {
5341 # we need to reverse the print order
5342 return 0 if (defined $limit && --$limit < 0);
5346 if ($r_min != $r_max) {
5347 return 1 if ($r_min < $c->{r
});
5348 return 1 if ($r_max > $c->{r
});
5351 return 0 if (defined $limit && --$limit < 0);
5360 if (my $l = $c->{l
}) {
5361 while ($l->[0] =~ /^\s*$/) { shift @
$l }
5364 $l_fmt ||= 'A' . length($c->{r
});
5365 print 'r',pack($l_fmt, $c->{r
}),' | ';
5366 print "$c->{c} | " if $show_commit;
5369 show_commit_normal
($c);
5373 sub show_commit_changed_paths
{
5375 return unless $c->{changed
};
5376 print "Changed paths:\n", @
{$c->{changed
}};
5379 sub show_commit_normal
{
5381 print commit_log_separator
, "r$c->{r} | ";
5382 print "$c->{c} | " if $show_commit;
5383 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
5386 if (my $l = $c->{l
}) {
5387 while ($l->[$#$l] eq "\n" && $#$l > 0
5388 && $l->[($#$l - 1)] eq "\n") {
5391 $nr_line = scalar @
$l;
5393 print "1 line\n\n\n";
5395 if ($nr_line == 1) {
5396 $nr_line = '1 line';
5398 $nr_line .= ' lines';
5400 print $nr_line, "\n";
5401 show_commit_changed_paths
($c);
5403 print $_ foreach @
$l;
5407 show_commit_changed_paths
($c);
5411 foreach my $x (qw
/raw stat diff/) {
5414 print $_ foreach @
{$c->{$x}}
5421 my ($r_min, $r_max);
5422 my $r_last = -1; # prevent dupes
5423 set_local_timezone
();
5424 if (defined $::_revision
) {
5425 if ($::_revision
=~ /^(\d+):(\d+)$/) {
5426 ($r_min, $r_max) = ($1, $2);
5427 } elsif ($::_revision
=~ /^\d+$/) {
5428 $r_min = $r_max = $::_revision
;
5430 ::fatal
"-r$::_revision is not supported, use ",
5431 "standard 'git log' arguments instead";
5436 @args = git_svn_log_cmd
($r_min, $r_max, @args);
5438 print commit_log_separator
unless $incremental || $oneline;
5441 my $log = command_output_pipe
(@args);
5443 my (@k, $c, $d, $stat);
5444 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
5446 if (/^${esc_color}commit -?($::sha1_short)/o) {
5448 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
5450 process_commit
($c, $r_min, $r_max, \
@k) or
5455 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
5456 get_author_info
($c, $1, $2, $3);
5457 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
5459 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
5460 push @
{$c->{raw
}}, $_;
5461 } elsif (/^${esc_color}[ACRMDT]\t/) {
5462 # we could add $SVN->{svn_path} here, but that requires
5463 # remote access at the moment (repo_path_split)...
5464 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
5465 push @
{$c->{changed
}}, $_;
5466 } elsif (/^${esc_color}diff /o) {
5468 push @
{$c->{diff
}}, $_;
5470 push @
{$c->{diff
}}, $_;
5471 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
5472 $esc_color*[\
+\
-]*$esc_color$/x
) {
5474 push @
{$c->{stat}}, $_;
5475 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
5476 push @
{$c->{stat}}, $_;
5478 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
5479 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
5480 } elsif (s/^${esc_color} //o) {
5481 push @
{$c->{l
}}, $_;
5484 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
5486 process_commit
($c, $r_min, $r_max, \
@k);
5489 ($r_min, $r_max) = ($r_max, $r_min);
5490 process_commit
($_, $r_min, $r_max) foreach reverse @k;
5494 print commit_log_separator
unless $incremental || $oneline;
5503 my ($fh, $ctx, $rev);
5506 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
5507 while (my $line = <$fh>) {
5508 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
5509 # Uncommitted edits show up as a rev ID of
5510 # all zeros, which we can't look up with
5513 (undef, $rev, undef) =
5515 $rev = '0' if (!$rev);
5519 $rev = sprintf('%-10s', $rev);
5520 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
5525 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
5530 my %dsha; #distinct sha keys
5532 while (my $line = <$fh>) {
5533 push @buffer, $line;
5534 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
5539 my $s2r = ::cmt_sha2rev_batch
([keys %dsha]);
5541 foreach my $line (@buffer) {
5542 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
5544 $rev = '0' if (!$rev)
5546 elsif ($line =~ /^author (.*)/) {
5547 $authors{$rev} = $1;
5548 $authors{$rev} =~ s/\s/_/g;
5550 elsif ($line =~ /^\t(.*)$/) {
5551 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
5555 command_close_pipe
($fh, $ctx);
5558 package Git
::SVN
::Migration
;
5559 # these version numbers do NOT correspond to actual version numbers
5560 # of git nor git-svn. They are just relative.
5562 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
5564 # v1 layout: .git/$id/info/url, refs/remotes/$id
5566 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
5568 # v3 layout: .git/svn/$id, refs/remotes/$id
5569 # - info/url may remain for backwards compatibility
5570 # - this is what we migrate up to this layout automatically,
5571 # - this will be used by git svn init on single branches
5572 # v3.1 layout (auto migrated):
5573 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
5574 # for backwards compatibility
5576 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
5577 # - this is only created for newly multi-init-ed
5578 # repositories. Similar in spirit to the
5579 # --use-separate-remotes option in git-clone (now default)
5580 # - we do not automatically migrate to this (following
5581 # the example set by core git)
5583 # v5 layout: .rev_db.$UUID => .rev_map.$UUID
5584 # - newer, more-efficient format that uses 24-bytes per record
5585 # with no filler space.
5586 # - use xxd -c24 < .rev_map.$UUID to view and debug
5587 # - This is a one-way migration, repositories updated to the
5588 # new format will not be able to use old git-svn without
5589 # rebuilding the .rev_db. Rebuilding the rev_db is not
5590 # possible if noMetadata or useSvmProps are set; but should
5591 # be no problem for users that use the (sensible) defaults.
5595 use File
::Path qw
/mkpath/;
5596 use File
::Basename qw
/dirname basename/;
5597 use vars qw
/$_minimize/;
5599 sub migrate_from_v0
{
5600 my $git_dir = $ENV{GIT_DIR
};
5601 return undef unless -d
$git_dir;
5602 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
5606 my ($id, $orig_ref) = ($_, $_);
5607 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
5608 next unless -f
"$git_dir/$id/info/url";
5609 my $new_ref = "refs/remotes/$id";
5610 if (::verify_ref
("$new_ref^0")) {
5611 print STDERR
"W: $orig_ref is probably an old ",
5612 "branch used by an ancient version of ",
5614 "However, $new_ref also exists.\n",
5615 "We will not be able ",
5616 "to use this branch until this ",
5617 "ambiguity is resolved.\n";
5620 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
5621 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
5622 command_noisy
('update-ref', $new_ref, $orig_ref);
5623 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
5626 command_close_pipe
($fh, $ctx);
5627 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
5631 sub migrate_from_v1
{
5632 my $git_dir = $ENV{GIT_DIR
};
5634 return $migrated unless -d
$git_dir;
5635 my $svn_dir = "$git_dir/svn";
5637 # just in case somebody used 'svn' as their $id at some point...
5638 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
5640 print STDERR
"Migrating from a git-svn v1 layout...\n";
5642 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
5643 "$svn_dir\n\t(required for this version ",
5644 "($::VERSION) of git-svn) does not exist.\n";
5645 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
5648 next unless $x =~ s
#^refs/remotes/##;
5650 next unless -f
"$git_dir/$x/info/url";
5651 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
5653 my $dn = dirname
("$git_dir/svn/$x");
5654 mkpath
([$dn]) unless -d
$dn;
5655 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
5656 mkpath
(["$git_dir/svn/svn"]);
5657 print STDERR
" - $git_dir/$x/info => ",
5658 "$git_dir/svn/$x/info\n";
5659 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
5661 # don't worry too much about these, they probably
5662 # don't exist with repos this old (save for index,
5663 # and we can easily regenerate that)
5664 foreach my $f (qw
/unhandled.log index .rev_db/) {
5665 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
5668 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
5669 rename "$git_dir/$x", "$git_dir/svn/$x" or
5674 command_close_pipe
($fh, $ctx);
5675 print STDERR
"Done migrating from a git-svn v1 layout\n";
5680 my ($l_map, $pfx, $path) = @_;
5682 foreach (<$path/*>) {
5683 if (-r
"$_/info/url") {
5684 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
5685 my $ref_id = $pfx . basename
$_;
5686 my $url = ::file_to_s
("$_/info/url");
5687 $l_map->{$ref_id} = $url;
5694 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
5695 read_old_urls
($l_map, $x, $_);
5699 sub migrate_from_v2
{
5700 my @cfg = command
(qw
/config -l/);
5701 return if grep /^svn-remote\..+\.url=/, @cfg;
5703 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
5706 foreach my $ref_id (sort keys %l_map) {
5707 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
5709 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
5716 sub minimize_connections
{
5717 my $r = Git
::SVN
::read_all_remotes
();
5719 my $root_repos = {};
5720 foreach my $repo_id (keys %$r) {
5721 my $url = $r->{$repo_id}->{url
} or next;
5722 my $fetch = $r->{$repo_id}->{fetch
} or next;
5723 my $ra = Git
::SVN
::Ra
->new($url);
5725 # skip existing cases where we already connect to the root
5726 if (($ra->{url
} eq $ra->{repos_root
}) ||
5727 ($ra->{repos_root
} eq $repo_id)) {
5728 $root_repos->{$ra->{url
}} = $repo_id;
5732 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
5733 my $root_path = $ra->{url
};
5734 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
5735 foreach my $path (keys %$fetch) {
5736 my $ref_id = $fetch->{$path};
5737 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
5739 # make sure we can read when connecting to
5740 # a higher level of a repository
5741 my ($last_rev, undef) = $gs->last_rev_commit;
5742 if (!defined $last_rev) {
5744 $root_ra->get_latest_revnum;
5748 my $new = $root_path;
5749 $new .= length $path ?
"/$path" : '';
5751 $root_ra->get_log([$new], $last_rev, $last_rev,
5755 $new_urls->{$ra->{repos_root
}}->{$new} =
5756 { ref_id
=> $ref_id,
5757 old_repo_id
=> $repo_id,
5758 old_path
=> $path };
5763 foreach my $url (keys %$new_urls) {
5764 # see if we can re-use an existing [svn-remote "repo_id"]
5765 # instead of creating a(n ugly) new section:
5766 my $repo_id = $root_repos->{$url} || $url;
5768 my $fetch = $new_urls->{$url};
5769 foreach my $path (keys %$fetch) {
5770 my $x = $fetch->{$path};
5771 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
5772 my $pfx = "svn-remote.$x->{old_repo_id}";
5774 my $old_fetch = quotemeta("$x->{old_path}:".
5776 command_noisy
(qw
/config --unset/,
5777 "$pfx.fetch", '^'. $old_fetch . '$');
5778 delete $r->{$x->{old_repo_id
}}->
5779 {fetch
}->{$x->{old_path
}};
5780 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
5781 command_noisy
(qw
/config --unset/,
5783 push @emptied, $x->{old_repo_id
}
5788 my $file = $ENV{GIT_CONFIG
} || "$ENV{GIT_DIR}/config";
5790 The following [svn-remote] sections in your config file ($file) are empty
5791 and can be safely removed:
5793 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
5797 sub migration_check
{
5801 minimize_connections
() if $_minimize;
5804 package Git
::IndexInfo
;
5807 use Git qw
/command_input_pipe command_close_pipe/;
5811 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
5812 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
5816 my ($self, $path) = @_;
5817 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
5818 return ++$self->{nr
};
5824 my ($self, $mode, $hash, $path) = @_;
5825 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
5826 return ++$self->{nr
};
5833 command_close_pipe
($self->{gui
}, $self->{ctx
});
5836 package Git
::SVN
::GlobSpec
;
5841 my ($class, $glob) = @_;
5843 $re =~ s!/+$!!g; # no need for trailing slashes
5844 $re =~ m!^([^*]*)(\*(?:/\*)*)(.*)$!;
5846 my ($left, $right) = ($1, $3);
5848 my $depth = $re =~ tr/*/*/;
5849 if ($depth != $temp =~ tr/*/*/) {
5850 die "Only one set of wildcard directories " .
5851 "(e.g. '*' or '*/*/*') is supported: '$glob'\n";
5854 die "One '*' is needed for glob: '$glob'\n";
5856 $re =~ s!\*!\[^/\]*!g;
5857 $re = quotemeta($left) . "($re)" . quotemeta($right);
5858 if (length $left && !($left =~ s!/+$!!g)) {
5859 die "Missing trailing '/' on left side of: '$glob' ($left)\n";
5861 if (length $right && !($right =~ s!^/+!!g)) {
5862 die "Missing leading '/' on right side of: '$glob' ($right)\n";
5864 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
5865 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
5866 regex
=> qr/$re/, glob => $glob, depth
=> $depth }, $class;
5870 my ($self, $path) = @_;
5871 return (length $self->{left
} ?
"$self->{left}/" : '') .
5872 $path . (length $self->{right
} ?
"/$self->{right}" : '');
5880 $remotes = { # returned by read_all_remotes()
5882 # svn-remote.svn.url=https://svn.musicpd.org
5883 url
=> 'https://svn.musicpd.org',
5884 # svn-remote.svn.fetch=mpd/trunk:trunk
5886 'mpd/trunk' => 'trunk',
5888 # svn-remote.svn.tags=mpd/tags/*:tags/*
5893 regex
=> qr!mpd/tags/([^/]+)$!,
5899 regex
=> qr!tags/([^/]+)$!,
5906 $log_entry hashref as returned by libsvn_log_entry
()
5908 log => 'whitespace-formatted log entry
5909 ', # trailing newline is preserved
5910 revision
=> '8', # integer
5911 date
=> '2004-02-24T17:01:44.108345Z', # commit date
5912 author
=> 'committer name'
5916 # this is generated by generate_diff();
5917 @mods = array of diff
-index line hashes
, each element represents one line
5918 of diff
-index output
5920 diff
-index line
($m hash
)
5922 mode_a
=> first column of diff
-index output
, no leading
':',
5923 mode_b
=> second column of diff
-index output
,
5924 sha1_b
=> sha1sum of the final blob
,
5925 chg
=> change type
[MCRADT
],
5926 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
5927 file_b
=> new
/current file name of a file
(any chg
)
5931 # retval of read_url_paths{,_all}();
5933 # repository root url
5934 'https://svn.musicpd.org' => {
5935 # repository path # GIT_SVN_ID
5936 'mpd/trunk' => 'trunk',
5937 'mpd/tags/0.11.5' => 'tags/0.11.5',
5942 I don
't trust the each() function on unless I created %hash myself
5943 because the internal iterator may not have started at base.