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
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;
23 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
25 $| = 1; # unbuffer STDOUT
27 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
28 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
31 if ($SVN::Core
::VERSION
lt '1.1.0') {
32 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
34 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
35 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
36 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
40 use File
::Basename qw
/dirname basename/;
41 use File
::Path qw
/mkpath/;
42 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev/;
47 # import functions from Git into our packages, en masse
49 foreach (qw
/command command_oneline command_noisy command_output_pipe
50 command_input_pipe command_close_pipe
/) {
51 for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
52 Git::SVN::Migration Git::SVN::Log Git::SVN),
54 *{"${package}::$_"} = \
&{"Git::$_"};
61 $sha1 = qr/[a-f\d]{40}/;
62 $sha1_short = qr/[a-f\d]{4,40}/;
63 my ($_stdin, $_help, $_edit,
66 $_version, $_fetch_all, $_no_rebase,
67 $_merge, $_strategy, $_dry_run, $_local,
68 $_prefix, $_no_checkout, $_url, $_verbose,
69 $_git_format, $_commit_url, $_tag);
70 $Git::SVN
::_follow_parent
= 1;
71 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
72 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
73 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
);
74 my %fc_opts = ( 'follow-parent|follow!' => \
$Git::SVN
::_follow_parent
,
75 'authors-file|A=s' => \
$_authors,
76 'repack:i' => \
$Git::SVN
::_repack
,
77 'noMetadata' => \
$Git::SVN
::_no_metadata
,
78 'useSvmProps' => \
$Git::SVN
::_use_svm_props
,
79 'useSvnsyncProps' => \
$Git::SVN
::_use_svnsync_props
,
80 'log-window-size=i' => \
$Git::SVN
::Ra
::_log_window_size
,
81 'no-checkout' => \
$_no_checkout,
83 'repack-flags|repack-args|repack-opts=s' =>
84 \
$Git::SVN
::_repack_flags
,
85 'use-log-author' => \
$Git::SVN
::_use_log_author
,
86 'add-author-from' => \
$Git::SVN
::_add_author_from
,
87 'localtime' => \
$Git::SVN
::_localtime
,
90 my ($_trunk, $_tags, $_branches, $_stdlayout);
92 my %init_opts = ( 'template=s' => \
$_template, 'shared:s' => \
$_shared,
93 'trunk|T=s' => \
$_trunk, 'tags|t=s' => \
$_tags,
94 'branches|b=s' => \
$_branches, 'prefix=s' => \
$_prefix,
95 'stdlayout|s' => \
$_stdlayout,
96 'minimize-url|m' => \
$Git::SVN
::_minimize_url
,
97 'no-metadata' => sub { $icv{noMetadata
} = 1 },
98 'use-svm-props' => sub { $icv{useSvmProps
} = 1 },
99 'use-svnsync-props' => sub { $icv{useSvnsyncProps
} = 1 },
100 'rewrite-root=s' => sub { $icv{rewriteRoot
} = $_[1] },
102 my %cmt_opts = ( 'edit|e' => \
$_edit,
103 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
104 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
105 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
106 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
110 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
111 { 'revision|r=s' => \
$_revision,
112 'fetch-all|all' => \
$_fetch_all,
114 clone
=> [ \
&cmd_clone
, "Initialize and fetch revisions",
115 { 'revision|r=s' => \
$_revision,
116 %fc_opts, %init_opts } ],
117 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
118 " (requires URL argument)",
120 'multi-init' => [ \
&cmd_multi_init
,
121 "Deprecated alias for ".
122 "'$0 init -T<trunk> -b<branches> -t<tags>'",
124 dcommit
=> [ \
&cmd_dcommit
,
125 'Commit several diffs to merge with upstream',
126 { 'merge|m|M' => \
$_merge,
127 'strategy|s=s' => \
$_strategy,
128 'verbose|v' => \
$_verbose,
129 'dry-run|n' => \
$_dry_run,
130 'fetch-all|all' => \
$_fetch_all,
131 'commit-url=s' => \
$_commit_url,
132 'revision|r=i' => \
$_revision,
133 'no-rebase' => \
$_no_rebase,
134 %cmt_opts, %fc_opts } ],
135 branch
=> [ \
&cmd_branch
,
136 'Create a branch in the SVN repository',
137 { 'message|m=s' => \
$_message,
138 'dry-run|n' => \
$_dry_run,
139 'tag|t' => \
$_tag } ],
140 tag
=> [ sub { $_tag = 1; cmd_branch
(@_) },
141 'Create a tag in the SVN repository',
142 { 'message|m=s' => \
$_message,
143 'dry-run|n' => \
$_dry_run } ],
144 'set-tree' => [ \
&cmd_set_tree
,
145 "Set an SVN repository to a git tree-ish",
146 { 'stdin|' => \
$_stdin, %cmt_opts, %fc_opts, } ],
147 'create-ignore' => [ \
&cmd_create_ignore
,
148 'Create a .gitignore per svn:ignore',
149 { 'revision|r=i' => \
$_revision
151 'propget' => [ \
&cmd_propget
,
152 'Print the value of a property on a file or directory',
153 { 'revision|r=i' => \
$_revision } ],
154 'proplist' => [ \
&cmd_proplist
,
155 'List all properties of a file or directory',
156 { 'revision|r=i' => \
$_revision } ],
157 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
158 { 'revision|r=i' => \
$_revision
160 'show-externals' => [ \
&cmd_show_externals
, "Show svn:externals listings",
161 { 'revision|r=i' => \
$_revision
163 'multi-fetch' => [ \
&cmd_multi_fetch
,
164 "Deprecated alias for $0 fetch --all",
165 { 'revision|r=s' => \
$_revision, %fc_opts } ],
166 'migrate' => [ sub { },
167 # no-op, we automatically run this anyways,
168 'Migrate configuration/metadata/layout from
169 previous versions of git-svn',
170 { 'minimize' => \
$Git::SVN
::Migration
::_minimize
,
172 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
173 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
174 'revision|r=s' => \
$_revision,
175 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
176 'incremental' => \
$Git::SVN
::Log
::incremental
,
177 'oneline' => \
$Git::SVN
::Log
::oneline
,
178 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
179 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
180 'authors-file|A=s' => \
$_authors,
181 'color' => \
$Git::SVN
::Log
::color
,
182 'pager=s' => \
$Git::SVN
::Log
::pager
184 'find-rev' => [ \
&cmd_find_rev
,
185 "Translate between SVN revision numbers and tree-ish",
187 'rebase' => [ \
&cmd_rebase
, "Fetch and rebase your working directory",
188 { 'merge|m|M' => \
$_merge,
189 'verbose|v' => \
$_verbose,
190 'strategy|s=s' => \
$_strategy,
191 'local|l' => \
$_local,
192 'fetch-all|all' => \
$_fetch_all,
193 'dry-run|n' => \
$_dry_run,
195 'commit-diff' => [ \
&cmd_commit_diff
,
196 'Commit a diff between two trees',
197 { 'message|m=s' => \
$_message,
198 'file|F=s' => \
$_file,
199 'revision|r=s' => \
$_revision,
201 'info' => [ \
&cmd_info
,
202 "Show info about the latest SVN revision
203 on the current branch",
204 { 'url' => \
$_url, } ],
205 'blame' => [ \
&Git
::SVN
::Log
::cmd_blame
,
206 "Show what revision and author last modified each line of a file",
207 { 'git-format' => \
$_git_format } ],
211 for (my $i = 0; $i < @ARGV; $i++) {
212 if (defined $cmd{$ARGV[$i]}) {
219 # make sure we're always running at the top-level working directory
220 unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
221 unless (-d
$ENV{GIT_DIR
}) {
222 if ($git_dir_user_set) {
223 die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
224 "but it is not a directory\n";
226 my $git_dir = delete $ENV{GIT_DIR
};
229 $cdup = command_oneline
(qw
/rev-parse --show-cdup/);
230 $git_dir = '.' unless ($cdup);
231 chomp $cdup if ($cdup);
232 $cdup = "." unless ($cdup && length $cdup);
233 } "Already at toplevel, but $git_dir not found\n";
234 chdir $cdup or die "Unable to chdir up to '$cdup'\n";
235 unless (-d
$git_dir) {
236 die "$git_dir still not found after going to ",
239 $ENV{GIT_DIR
} = $git_dir;
241 $_repository = Git
->repository(Repository
=> $ENV{GIT_DIR
});
244 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
246 read_repo_config
(\
%opts);
247 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
248 Getopt
::Long
::Configure
('pass_through');
250 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help, 'version|V' => \
$_version,
251 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
252 'id|i=s' => \
$Git::SVN
::default_ref_id
,
253 'svn-remote|remote|R=s' => sub {
254 $Git::SVN
::no_reuse_existing
= 1;
255 $Git::SVN
::default_repo_id
= $_[1] });
256 exit 1 if (!$rv && $cmd && $cmd ne 'log');
259 version
() if $_version;
260 usage
(1) unless defined $cmd;
261 load_authors
() if $_authors;
263 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
264 Git
::SVN
::Migration
::migration_check
();
266 Git
::SVN
::init_vars
();
268 Git
::SVN
::verify_remotes_sanity
();
269 $cmd{$cmd}->[0]->(@ARGV);
272 post_fetch_checkout
();
275 ####################### primary functions ######################
277 my $exit = shift || 0;
278 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
280 git
-svn
- bidirectional operations between a single Subversion tree
and git
281 Usage
: git svn
<command
> [options
] [arguments
]\n
283 print $fd "Available commands:\n" unless $cmd;
285 foreach (sort keys %cmd) {
286 next if $cmd && $cmd ne $_;
287 next if /^multi-/; # don't show deprecated commands
288 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
289 foreach (sort keys %{$cmd{$_}->[2]}) {
290 # mixed-case options are for .git/config only
291 next if /[A-Z]/ && /^[a-z]+$/i;
292 # prints out arguments as they should be passed:
293 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
294 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
296 split /\|/,$_)," $x\n";
300 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
301 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
302 one git repository and want to keep them separate. See git-svn(1) for more
309 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
314 unless (-d $ENV{GIT_DIR}) {
315 my @init_db = ('init
');
316 push @init_db, "--template=$_template" if defined $_template;
317 if (defined $_shared) {
318 if ($_shared =~ /[a-z]/) {
319 push @init_db, "--shared=$_shared";
321 push @init_db, "--shared";
324 command_noisy(@init_db);
325 $_repository = Git->repository(Repository => ".git");
328 my $pfx = "svn-remote.$Git::SVN::default_repo_id";
329 foreach my $i (keys %icv) {
330 die "'$set' and '$i' cannot both be set\n" if $set;
331 next unless defined $icv{$i};
332 command_noisy('config
', "$pfx.$i", $icv{$i});
338 my $repo_path = shift or return;
339 mkpath([$repo_path]) unless -d $repo_path;
340 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
341 $ENV{GIT_DIR} = '.git';
342 $_repository = Git->repository(Repository => $ENV{GIT_DIR});
346 my ($url, $path) = @_;
347 if (!defined $path &&
348 (defined $_trunk || defined $_branches || defined $_tags ||
349 defined $_stdlayout) &&
350 $url !~ m#^[a-z\+]+://#) {
353 $path = basename($url) if !defined $path || !length $path;
354 cmd_init($url, $path);
355 Git::SVN::fetch_all($Git::SVN::default_repo_id);
359 if (defined $_stdlayout) {
360 $_trunk = 'trunk' if (!defined $_trunk);
361 $_tags = 'tags' if (!defined $_tags);
362 $_branches = 'branches' if (!defined $_branches);
364 if (defined $_trunk || defined $_branches || defined $_tags) {
365 return cmd_multi_init(@_);
367 my $url = shift or die "SVN repository location required
",
368 "as a command
-line argument
\n";
372 Git::SVN->init($url);
376 if (grep /^\d+=./, @_) {
377 die "'<rev>=<commit>' fetch arguments are
",
378 "no longer supported
.\n";
382 die "Usage
: $0 fetch
[--all
] [svn
-remote
]\n";
384 $remote ||= $Git::SVN::default_repo_id;
388 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
394 if ($_stdin || !@commits) {
395 print "Reading from stdin
...\n";
398 if (/\b($sha1_short)\b/o) {
399 unshift @commits, $1;
404 foreach my $c (@commits) {
405 my @tmp = command('rev-parse',$c);
406 if (scalar @tmp == 1) {
408 } elsif (scalar @tmp > 1) {
409 push @revs, reverse(command('rev-list',@tmp));
411 fatal "Failed to rev
-parse
$c";
414 my $gs = Git::SVN->new;
415 my ($r_last, $cmt_last) = $gs->last_rev_commit;
417 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
418 fatal "There are new revisions that were fetched
",
419 "and need to be merged
(or acknowledged
) ",
420 "before committing
.\nlast rev
: $r_last\n",
421 " current
: $gs->{last_rev
}";
423 $gs->set_tree($_) foreach @revs;
424 print "Done committing
",scalar @revs," revisions to SVN
\n";
430 git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) }
431 'Cannot dcommit with a dirty index. Commit your changes first, '
432 . "or stash them with
`git stash'.\n";
435 my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
437 die "Unable to determine upstream SVN information from ",
438 "$head history.\nPerhaps the repository is empty.";
440 $url = defined $_commit_url ? $_commit_url : $gs->full_url;
441 my $last_rev = $_revision if defined $_revision;
443 print "Committing to $url ...\n";
445 my ($linear_refs, $parents) = linearize_history($gs, \@refs);
446 if ($_no_rebase && scalar(@$linear_refs) > 1) {
447 warn "Attempting to commit more than one change while ",
448 "--no-rebase is enabled.\n",
449 "If these changes depend on each other, re-running ",
450 "without --no-rebase may be required."
452 my $expect_url = $url;
453 Git::SVN::remove_username($expect_url);
455 my $d = shift @$linear_refs or last;
456 unless (defined $last_rev) {
457 (undef, $last_rev, undef) = cmt_metadata("$d~1");
458 unless (defined $last_rev) {
459 fatal "Unable to extract revision information ",
464 print "diff-tree $d~1 $d\n";
467 my %ed_opts = ( r => $last_rev,
468 log => get_commit_entry($d)->{log},
469 ra => Git::SVN::Ra->new($url),
470 config => SVN::Core::config_get_config(
471 $Git::SVN::Ra::config_dir
476 print "Committed r$_[0]\n";
480 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
481 print "No changes\n$d~1 == $d\n";
482 } elsif ($parents->{$d} && @{$parents->{$d}}) {
483 $gs->{inject_parents_dcommit}->{$cmt_rev} =
486 $_fetch_all ? $gs->fetch_all : $gs->fetch;
487 $last_rev = $cmt_rev;
490 # we always want to rebase against the current HEAD,
491 # not any head that was passed to us
492 my @diff = command('diff-tree', $d,
496 @finish = rebase_cmd();
497 print STDERR "W: $d and ", $gs->refname,
498 " differ, using @finish:\n",
499 join("\n", @diff), "\n";
501 print "No changes between current HEAD and ",
503 "\nResetting to the latest ",
505 @finish = qw/reset --mixed/;
507 command_noisy(@finish, $gs->refname);
510 my ($url_, $rev_, $uuid_, $gs_) =
511 working_head_info($head, \@refs);
512 my ($linear_refs_, $parents_) =
513 linearize_history($gs_, \@refs);
514 if (scalar(@$linear_refs) !=
515 scalar(@$linear_refs_)) {
516 fatal "# of revisions changed ",
518 join("\n", @$linear_refs),
520 join("\n", @$linear_refs_), "\n",
521 'If you are attempting to commit ',
522 "merges, try running:\n\t",
523 'git rebase --interactive',
524 '--preserve-merges ',
526 "\nBefore dcommitting";
528 if ($url_ ne $expect_url) {
529 fatal "URL mismatch after rebase: ",
530 "$url_ != $expect_url";
532 if ($uuid_ ne $uuid) {
533 fatal "uuid mismatch after rebase: ",
538 for ($i = 0; $i < scalar @$linear_refs; $i++) {
539 my $new = $linear_refs_->[$i] or next;
541 $parents->{$linear_refs->[$i]};
553 my ($branch_name, $head) = @_;
555 unless (defined $branch_name && length $branch_name) {
556 die(($_tag ? "tag" : "branch") . " name required\n");
560 my ($src, $rev, undef, $gs) = working_head_info($head);
562 my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
563 my $glob = $remote->{ $_tag ? 'tags' : 'branches' };
564 my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
565 my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());
567 my $ctx = SVN::Client->new(
568 auth => Git::SVN::Ra::_auth_providers(),
570 ${ $_[0] } = defined $_message
572 : 'Create ' . ($_tag ? 'tag ' : 'branch ' )
578 $ctx->ls($dst, 'HEAD', 0);
579 } and die "branch ${branch_name} already exists\n";
581 print "Copying ${src} at r${rev} to ${dst}...\n";
582 $ctx->copy($src, $rev, $dst)
589 my $revision_or_hash = shift or die "SVN or git revision required ",
590 "as a command-line argument\n";
592 if ($revision_or_hash =~ /^r\d+$/) {
596 my (undef, undef, $uuid, $gs) = working_head_info($head, \@refs);
598 die "Unable to determine upstream SVN information from ",
601 my $desired_revision = substr($revision_or_hash, 1);
602 $result = $gs->rev_map_get($desired_revision, $uuid);
604 my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
607 print "$result\n" if $result;
611 command_noisy(qw/update-index --refresh/);
612 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
614 die "Unable to determine upstream SVN information from ",
615 "working tree history\n";
618 print "Remote Branch: " . $gs->refname . "\n";
619 print "SVN URL: " . $url . "\n";
622 if (command(qw/diff-index HEAD --/)) {
623 print STDERR "Cannot rebase with uncommited changes:\n";
624 command_noisy('status');
628 # rebase will checkout for us, so no need to do it explicitly
629 $_no_checkout = 'true';
630 $_fetch_all ? $gs->fetch_all : $gs->fetch;
632 command_noisy(rebase_cmd(), $gs->refname);
635 sub cmd_show_ignore {
636 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
637 $gs ||= Git::SVN->new;
638 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
639 $gs->prop_walk($gs->{path}, $r, sub {
640 my ($gs, $path, $props) = @_;
641 print STDOUT "\n# $path\n";
642 my $s = $props->{'svn:ignore'} or return;
643 $s =~ s/[\r\n]+/\n/g;
650 sub cmd_show_externals {
651 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
652 $gs ||= Git::SVN->new;
653 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
654 $gs->prop_walk($gs->{path}, $r, sub {
655 my ($gs, $path, $props) = @_;
656 print STDOUT "\n# $path\n";
657 my $s = $props->{'svn:externals'} or return;
658 $s =~ s/[\r\n]+/\n/g;
665 sub cmd_create_ignore {
666 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
667 $gs ||= Git::SVN->new;
668 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
669 $gs->prop_walk($gs->{path}, $r, sub {
670 my ($gs, $path, $props) = @_;
671 # $path is of the form /path/to/dir/
672 my $ignore = '.' . $path . '.gitignore';
673 my $s = $props->{'svn:ignore'} or return;
674 open(GITIGNORE, '>', $ignore)
675 or fatal("Failed to open `$ignore' for writing: $!");
676 $s =~ s/[\r\n]+/\n/g;
678 # Prefix all patterns so that the ignore doesn't apply
679 # to sub-directories.
681 print GITIGNORE
"$s\n";
683 or fatal
("Failed to close `$ignore': $!");
684 command_noisy
('add', '-f', $ignore);
688 sub canonicalize_path
{
690 my $dot_slash_added = 0;
691 if (substr($path, 0, 1) ne "/") {
692 $path = "./" . $path;
693 $dot_slash_added = 1;
695 # File::Spec->canonpath doesn't collapse x/../y into y (for a
696 # good reason), so let's do this manually.
698 $path =~ s
#/\.(?:/|$)#/#g;
699 $path =~ s
#/[^/]+/\.\.##g;
701 $path =~ s
#^\./## if $dot_slash_added;
709 # Helper for cmd_propget and cmd_proplist below.
712 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
713 $gs ||= Git
::SVN
->new;
715 # prefix THE PATH by the sub-directory from which the user
717 $path = $cmd_dir_prefix . $path;
718 fatal
("No such file or directory: $path") unless -e
$path;
719 my $is_dir = -d
$path ?
1 : 0;
720 $path = $gs->{path
} . '/' . $path;
722 # canonicalize the path (otherwise libsvn will abort or fail to
724 $path = canonicalize_path
($path);
726 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
729 (undef, undef, $props) = $gs->ra->get_dir($path, $r);
732 (undef, $props) = $gs->ra->get_file($path, $r, undef);
737 # cmd_propget (PROP, PATH)
738 # ------------------------
739 # Print the SVN property PROP for PATH.
741 my ($prop, $path) = @_;
742 $path = '.' if not defined $path;
743 usage
(1) if not defined $prop;
744 my $props = get_svnprops
($path);
745 if (not defined $props->{$prop}) {
746 fatal
("`$path' does not have a `$prop' SVN property.");
748 print $props->{$prop} . "\n";
751 # cmd_proplist (PATH)
752 # -------------------
753 # Print the list of SVN properties for PATH.
756 $path = '.' if not defined $path;
757 my $props = get_svnprops
($path);
758 print "Properties on '$path':\n";
759 foreach (sort keys %{$props}) {
766 unless (defined $_trunk || defined $_branches || defined $_tags) {
770 # there are currently some bugs that prevent multi-init/multi-fetch
771 # setups from working well without this.
772 $Git::SVN
::_minimize_url
= 1;
774 $_prefix = '' unless defined $_prefix;
780 if (defined $_trunk) {
781 my $trunk_ref = $_prefix . 'trunk';
782 # try both old-style and new-style lookups:
783 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
785 my ($trunk_url, $trunk_path) =
786 complete_svn_url
($url, $_trunk);
787 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
791 return unless defined $_branches || defined $_tags;
792 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
793 complete_url_ls_init
($ra, $_branches, '--branches/-b', $_prefix);
794 complete_url_ls_init
($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
797 sub cmd_multi_fetch
{
798 my $remotes = Git
::SVN
::read_all_remotes
();
799 foreach my $repo_id (sort keys %$remotes) {
800 if ($remotes->{$repo_id}->{url
}) {
801 Git
::SVN
::fetch_all
($repo_id, $remotes);
806 # this command is special because it requires no metadata
807 sub cmd_commit_diff
{
808 my ($ta, $tb, $url) = @_;
809 my $usage = "Usage: $0 commit-diff -r<revision> ".
810 "<tree-ish> <tree-ish> [<URL>]";
811 fatal
($usage) if (!defined $ta || !defined $tb);
814 my $gs = eval { Git
::SVN
->new };
816 fatal
("Needed URL or usable git-svn --id in ",
817 "the command-line\n", $usage);
820 $svn_path = $gs->{path
};
822 unless (defined $_revision) {
823 fatal
("-r|--revision is a required argument\n", $usage);
825 if (defined $_message && defined $_file) {
826 fatal
("Both --message/-m and --file/-F specified ",
827 "for the commit message.\n",
828 "I have no idea what you mean");
830 if (defined $_file) {
831 $_message = file_to_s
($_file);
833 $_message ||= get_commit_entry
($tb)->{log};
835 my $ra ||= Git
::SVN
::Ra
->new($url);
838 $r = $ra->get_latest_revnum;
839 } elsif ($r !~ /^\d+$/) {
840 die "revision argument: $r not understood by git-svn\n";
842 my %ed_opts = ( r
=> $r,
847 editor_cb
=> sub { print "Committed r$_[0]\n" },
848 svn_path
=> $svn_path );
849 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
850 print "No changes\n$ta == $tb\n";
854 sub escape_uri_only
{
857 foreach (split m{/}, $uri) {
858 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
866 if ($url =~ m
#^([^:]+)://([^/]*)(.*)$#) {
867 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
868 $url = "$scheme://$domain$uri";
874 my $path = canonicalize_path
(defined($_[0]) ?
$_[0] : ".");
875 my $fullpath = canonicalize_path
($cmd_dir_prefix . $path);
877 die "Too many arguments specified\n";
880 my ($file_type, $diff_status) = find_file_type_and_diff_status
($path);
882 if (!$file_type && !$diff_status) {
883 print STDERR
"svn: '$path' is not under version control\n";
887 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
889 die "Unable to determine upstream SVN information from ",
890 "working tree history\n";
893 # canonicalize_path() will return "" to make libsvn 1.5.x happy,
894 $path = "." if $path eq "";
896 my $full_url = $url . ($fullpath eq "" ?
"" : "/$fullpath");
899 print escape_url
($full_url), "\n";
903 my $result = "Path: $path\n";
904 $result .= "Name: " . basename
($path) . "\n" if $file_type ne "dir";
905 $result .= "URL: " . escape_url
($full_url) . "\n";
908 my $repos_root = $gs->repos_root;
909 Git
::SVN
::remove_username
($repos_root);
910 $result .= "Repository Root: " . escape_url
($repos_root) . "\n";
913 $result .= "Repository Root: (offline)\n";
915 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
916 $result .= "Revision: " . ($diff_status eq "A" ?
0 : $rev) . "\n";
918 $result .= "Node Kind: " .
919 ($file_type eq "dir" ?
"directory" : "file") . "\n";
921 my $schedule = $diff_status eq "A"
923 : ($diff_status eq "D" ?
"delete" : "normal");
924 $result .= "Schedule: $schedule\n";
926 if ($diff_status eq "A") {
931 my ($lc_author, $lc_rev, $lc_date_utc);
932 my @args = Git
::SVN
::Log
::git_svn_log_cmd
($rev, $rev, "--", $fullpath);
933 my $log = command_output_pipe
(@args);
934 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
936 if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
938 $lc_date_utc = Git
::SVN
::Log
::parse_git_date
($2, $3);
939 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
940 (undef, $lc_rev, undef) = ::extract_metadata
($1);
945 Git
::SVN
::Log
::set_local_timezone
();
947 $result .= "Last Changed Author: $lc_author\n";
948 $result .= "Last Changed Rev: $lc_rev\n";
949 $result .= "Last Changed Date: " .
950 Git
::SVN
::Log
::format_svn_date
($lc_date_utc) . "\n";
952 if ($file_type ne "dir") {
953 my $text_last_updated_date =
954 ($diff_status eq "D" ?
$lc_date_utc : (stat $path)[9]);
956 "Text Last Updated: " .
957 Git
::SVN
::Log
::format_svn_date
($text_last_updated_date) .
960 if ($diff_status eq "D") {
962 command_output_pipe
(qw(cat-file blob), "HEAD:$path");
963 if ($file_type eq "link") {
964 my $file_name = <$fh>;
965 $checksum = md5sum
("link $file_name");
967 $checksum = md5sum
($fh);
969 command_close_pipe
($fh, $ctx);
970 } elsif ($file_type eq "link") {
972 command
(qw(cat-file blob), "HEAD:$path");
974 md5sum
("link " . $file_name);
976 open FILE
, "<", $path or die $!;
977 $checksum = md5sum
(\
*FILE
);
978 close FILE
or die $!;
980 $result .= "Checksum: " . $checksum . "\n";
986 ########################### utility functions #########################
989 my @cmd = qw
/rebase/;
990 push @cmd, '-v' if $_verbose;
991 push @cmd, qw
/--merge/ if $_merge;
992 push @cmd, "--strategy=$_strategy" if $_strategy;
996 sub post_fetch_checkout
{
997 return if $_no_checkout;
998 my $gs = $Git::SVN
::_head
or return;
999 return if verify_ref
('refs/heads/master^0');
1001 my $valid_head = verify_ref
('HEAD^0');
1002 command_noisy
(qw(update-ref refs/heads/master), $gs->refname);
1003 return if ($valid_head || !verify_ref
('HEAD^0'));
1005 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
1006 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
1007 return if -f
$index;
1009 return if command_oneline
(qw
/rev-parse --is-inside-work-tree/) eq 'false';
1010 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
1011 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
1012 print STDERR
"Checked out HEAD:\n ",
1013 $gs->full_url, " r", $gs->last_rev, "\n";
1016 sub complete_svn_url
{
1017 my ($url, $path) = @_;
1019 if ($path !~ m
#^[a-z\+]+://#) {
1020 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
1021 fatal
("E: '$path' is not a complete URL ",
1022 "and a separate URL is not specified");
1024 return ($url, $path);
1029 sub complete_url_ls_init
{
1030 my ($ra, $repo_path, $switch, $pfx) = @_;
1031 unless ($repo_path) {
1032 print STDERR
"W: $switch not specified\n";
1035 $repo_path =~ s
#/+$##;
1036 if ($repo_path =~ m
#^[a-z\+]+://#) {
1037 $ra = Git
::SVN
::Ra
->new($repo_path);
1040 $repo_path =~ s
#^/+##;
1042 fatal
("E: '$repo_path' is not a complete URL ",
1043 "and a separate URL is not specified");
1046 my $url = $ra->{url
};
1047 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
1048 my $k = "svn-remote.$gs->{repo_id}.url";
1049 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
1050 if ($orig_url && ($orig_url ne $gs->{url
})) {
1051 die "$k already set: $orig_url\n",
1052 "wanted to set to: $gs->{url}\n";
1054 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
1055 my $remote_path = "$ra->{svn_path}/$repo_path";
1056 $remote_path =~ s
#/+#/#g;
1057 $remote_path =~ s
#^/##g;
1058 $remote_path .= "/*" if $remote_path !~ /\
*/;
1059 my ($n) = ($switch =~ /^--(\w+)/);
1060 if (length $pfx && $pfx !~ m
#/$#) {
1061 die "--prefix='$pfx' must have a trailing slash '/'\n";
1063 command_noisy
('config',
1064 "svn-remote.$gs->{repo_id}.$n",
1065 "$remote_path:refs/remotes/$pfx*" .
1066 ('/*' x
(($remote_path =~ tr
/*/*/) - 1)) );
1071 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
1072 { STDERR
=> 0 }); };
1075 sub get_tree_from_treeish
{
1077 # $treeish can be a symbolic ref, too:
1078 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1080 while ($type eq 'tag') {
1081 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
1083 if ($type eq 'commit') {
1084 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
1086 ($expected) = ($expected =~ /^tree ($sha1)$/o);
1087 die "Unable to get tree from $treeish\n" unless $expected;
1088 } elsif ($type eq 'tree') {
1089 $expected = $treeish;
1091 die "$treeish is a $type, expected tree, tag or commit\n";
1096 sub get_commit_entry
{
1097 my ($treeish) = shift;
1098 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
1099 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1100 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1101 open my $log_fh, '>', $commit_editmsg or croak
$!;
1103 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1104 if ($type eq 'commit' || $type eq 'tag') {
1105 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
1113 $in_msg = 1 if (/^\s*$/);
1114 $author = $1 if (/^author (.*>)/);
1115 } elsif (/^git-svn-id: /) {
1116 # skip this for now, we regenerate the
1117 # correct one on re-fetch anyways
1118 # TODO: set *:merge properties or like...
1120 if (/^From:/ || /^Signed-off-by:/) {
1126 $msgbuf =~ s/\s+$//s;
1127 if ($Git::SVN
::_add_author_from
&& defined($author)
1129 $msgbuf .= "\n\nFrom: $author";
1131 print $log_fh $msgbuf or croak
$!;
1132 command_close_pipe
($msg_fh, $ctx);
1134 close $log_fh or croak
$!;
1136 if ($_edit || ($type eq 'tree')) {
1137 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
1138 # TODO: strip out spaces, comments, like git-commit.sh
1139 system($editor, $commit_editmsg);
1141 rename $commit_editmsg, $commit_msg or croak
$!;
1143 # SVN requires messages to be UTF-8 when entering the repo
1145 open $log_fh, '<', $commit_msg or croak
$!;
1147 chomp($log_entry{log} = <$log_fh>);
1149 if (my $enc = Git
::config
('i18n.commitencoding')) {
1151 Encode
::from_to
($log_entry{log}, $enc, 'UTF-8');
1153 close $log_fh or croak
$!;
1160 my ($str, $file, $mode) = @_;
1161 open my $fd,'>',$file or croak
$!;
1162 print $fd $str,"\n" or croak
$!;
1163 close $fd or croak
$!;
1164 chmod ($mode &~ umask, $file) if (defined $mode);
1169 open my $fd,'<',$file or croak
"$!: file: $file\n";
1172 close $fd or croak
$!;
1177 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
1179 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1180 my $log = $cmd eq 'log';
1181 while (<$authors>) {
1183 next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1184 my ($user, $name, $email) = ($1, $2, $3);
1186 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
1188 $users{$user} = [$name, $email];
1191 close $authors or croak
$!;
1194 # convert GetOpt::Long specs for use by git-config
1195 sub read_repo_config
{
1196 return unless -d
$ENV{GIT_DIR
};
1199 foreach my $o (keys %$opts) {
1200 # if we have mixedCase and a long option-only, then
1201 # it's a config-only variable that we don't need for
1203 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
1204 my $v = $opts->{$o};
1205 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
1207 my $arg = 'git config';
1208 $arg .= ' --int' if ($o =~ /[:=]i$/);
1209 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
1210 if (ref $v eq 'ARRAY') {
1211 chomp(my @tmp = `$arg --get-all svn.$key`);
1214 chomp(my $tmp = `$arg --get svn.$key`);
1215 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
1220 delete @
$opts{@config_only} if @config_only;
1223 sub extract_metadata
{
1224 my $id = shift or return (undef, undef, undef);
1225 my ($url, $rev, $uuid) = ($id =~ /^\s
*git
-svn
-id
:\s
+(.*)\@
(\d
+)
1227 if (!defined $rev || !$uuid || !$url) {
1228 # some of the original repositories I made had
1229 # identifiers like this:
1230 ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
1232 return ($url, $rev, $uuid);
1236 return extract_metadata
((grep(/^git-svn-id: /,
1237 command
(qw
/cat-file commit/, shift)))[-1]);
1240 sub working_head_info
{
1241 my ($head, $refs) = @_;
1242 my @args = ('log', '--no-color', '--first-parent', '--pretty=medium');
1243 my ($fh, $ctx) = command_output_pipe
(@args, $head);
1247 if ( m{^commit ($::sha1)$} ) {
1248 unshift @
$refs, $hash if $hash and $refs;
1252 next unless s{^\s*(git-svn-id:)}{$1};
1253 my ($url, $rev, $uuid) = extract_metadata
($_);
1254 if (defined $url && defined $rev) {
1255 next if $max{$url} and $max{$url} < $rev;
1256 if (my $gs = Git
::SVN
->find_by_url($url)) {
1257 my $c = $gs->rev_map_get($rev, $uuid);
1258 if ($c && $c eq $hash) {
1259 close $fh; # break the pipe
1260 return ($url, $rev, $uuid, $gs);
1262 $max{$url} ||= $gs->rev_map_max;
1267 command_close_pipe
($fh, $ctx);
1268 (undef, undef, undef, undef);
1271 sub read_commit_parents
{
1272 my ($parents, $c) = @_;
1273 chomp(my $p = command_oneline
(qw
/rev-list --parents -1/, $c));
1274 $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
1275 @
{$parents->{$c}} = split(/ /, $p);
1278 sub linearize_history
{
1279 my ($gs, $refs) = @_;
1281 foreach my $c (@
$refs) {
1282 read_commit_parents
(\
%parents, $c);
1287 my $last_svn_commit = $gs->last_commit;
1288 foreach my $c (reverse @
$refs) {
1289 next if $c eq $last_svn_commit;
1292 unshift @linear_refs, $c;
1295 # we only want the first parent to diff against for linear
1296 # history, we save the rest to inject when we finalize the
1298 my $fp_a = verify_ref
("$c~1");
1299 my $fp_b = shift @
{$parents{$c}} if $parents{$c};
1300 if (!$fp_a || !$fp_b) {
1302 "has no parent commit, and therefore ",
1303 "nothing to diff against.\n",
1304 "You should be working from a repository ",
1305 "originally created by git-svn\n";
1307 if ($fp_a ne $fp_b) {
1308 die "$c~1 = $fp_a, however parsing commit $c ",
1309 "revealed that:\n$c~1 = $fp_b\nBUG!\n";
1312 foreach my $p (@
{$parents{$c}}) {
1316 (\
@linear_refs, \
%parents);
1319 sub find_file_type_and_diff_status
{
1321 return ('dir', '') if $path eq '';
1324 command_oneline
(qw(diff --cached --name-status --), $path) || "";
1325 my $diff_status = (split(' ', $diff_output))[0] || "";
1327 my $ls_tree = command_oneline
(qw(ls-tree HEAD), $path) || "";
1329 return (undef, undef) if !$diff_status && !$ls_tree;
1331 if ($diff_status eq "A") {
1332 return ("link", $diff_status) if -l
$path;
1333 return ("dir", $diff_status) if -d
$path;
1334 return ("file", $diff_status);
1337 my $mode = (split(' ', $ls_tree))[0] || "";
1339 return ("link", $diff_status) if $mode eq "120000";
1340 return ("dir", $diff_status) if $mode eq "040000";
1341 return ("file", $diff_status);
1347 my $md5 = Digest
::MD5
->new();
1348 if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
1349 $md5->addfile($arg) or croak
$!;
1350 } elsif ($ref eq 'SCALAR') {
1351 $md5->add($$arg) or croak
$!;
1353 $md5->add($arg) or croak
$!;
1355 ::fatal
"Can't provide MD5 hash for unknown ref type: '", $ref, "'";
1357 return $md5->hexdigest();
1363 use Fcntl qw
/:DEFAULT :seek/;
1364 use constant rev_map_fmt
=> 'NH40';
1365 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1366 $_repack $_repack_flags $_use_svm_props $_head
1367 $_use_svnsync_props $no_reuse_existing $_minimize_url
1368 $_use_log_author $_add_author_from $_localtime/;
1370 use File
::Path qw
/mkpath/;
1371 use File
::Copy qw
/copy/;
1374 my ($_gc_nr, $_gc_period);
1376 # properties that we do not log:
1379 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
1380 svn
:special svn
:executable
1381 svn
:entry
:committed
-rev
1382 svn
:entry
:last-author
1384 svn
:entry
:committed
-date
/;
1386 # some options are read globally, but can be overridden locally
1387 # per [svn-remote "..."] section. Command-line options will *NOT*
1388 # override options set in an [svn-remote "..."] section
1390 for my $option (qw
/follow_parent no_metadata use_svm_props
1391 use_svnsync_props
/) {
1394 my $prop = "-$option";
1397 return $self->{$prop} if exists $self->{$prop};
1398 my $k = "svn-remote.$self->{repo_id}.$key";
1399 eval { command_oneline
(qw
/config --get/, $k) };
1401 $self->{$prop} = ${"Git::SVN::_$option"};
1403 my $v = command_oneline
(qw
/config --bool/,$k);
1404 $self->{$prop} = $v eq 'false' ?
0 : 1;
1406 return $self->{$prop};
1412 my (%LOCKFILES, %INDEX_FILES);
1414 unlink keys %LOCKFILES if %LOCKFILES;
1415 unlink keys %INDEX_FILES if %INDEX_FILES;
1418 sub resolve_local_globs
{
1419 my ($url, $fetch, $glob_spec) = @_;
1420 return unless defined $glob_spec;
1421 my $ref = $glob_spec->{ref};
1422 my $path = $glob_spec->{path
};
1423 foreach (command
(qw
#for-each-ref --format=%(refname) refs/remotes#)) {
1424 next unless m
#^refs/remotes/$ref->{regex}$#;
1426 my $pathname = desanitize_refname
($path->full_path($p));
1427 my $refname = desanitize_refname
($ref->full_path($p));
1428 if (my $existing = $fetch->{$pathname}) {
1429 if ($existing ne $refname) {
1430 die "Refspec conflict:\n",
1431 "existing: refs/remotes/$existing\n",
1432 " globbed: refs/remotes/$refname\n";
1434 my $u = (::cmt_metadata
("refs/remotes/$refname"))[0];
1435 $u =~ s!^\Q$url\E(/|$)!! or die
1436 "refs/remotes/$refname: '$url' not found in '$u'\n";
1437 if ($pathname ne $u) {
1438 warn "W: Refspec glob conflict ",
1439 "(ref: refs/remotes/$refname):\n",
1440 "expected path: $pathname\n",
1442 "Continuing ahead with $u\n";
1446 $fetch->{$pathname} = $refname;
1451 sub parse_revision_argument
{
1452 my ($base, $head) = @_;
1453 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
1454 return ($base, $head);
1456 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
1457 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
1458 return ($head, $head) if ($::_revision
eq 'HEAD');
1459 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
1460 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
1461 die "revision argument: $::_revision not understood by git-svn\n";
1465 my ($repo_id, $remotes) = @_;
1469 $repo_id = $gs->{repo_id
};
1471 $remotes ||= read_all_remotes
();
1472 my $remote = $remotes->{$repo_id} or
1473 die "[svn-remote \"$repo_id\"] unknown\n";
1474 my $fetch = $remote->{fetch
};
1475 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
1477 my $ra = Git
::SVN
::Ra
->new($url);
1478 my $uuid = $ra->get_uuid;
1479 my $head = $ra->get_latest_revnum;
1480 my $base = defined $fetch ?
$head : 0;
1482 # read the max revs for wildcard expansion (branches/*, tags/*)
1483 foreach my $t (qw
/branches tags/) {
1484 defined $remote->{$t} or next;
1485 push @globs, $remote->{$t};
1486 my $max_rev = eval { tmp_config
(qw
/--int --get/,
1487 "svn-remote.$repo_id.${t}-maxRev") };
1488 if (defined $max_rev && ($max_rev < $base)) {
1490 } elsif (!defined $max_rev) {
1496 foreach my $p (sort keys %$fetch) {
1497 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
1498 my $lr = $gs->rev_map_max;
1500 $base = $lr if ($lr < $base);
1506 ($base, $head) = parse_revision_argument
($base, $head);
1507 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
1510 sub read_all_remotes
{
1512 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
1513 svn
.useSvmProps
/) };
1514 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
1515 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
1516 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*(.+)\s*$!) {
1517 my ($remote, $local_ref, $_remote_ref) = ($1, $2, $3);
1518 die("svn-remote.$remote: remote ref '$_remote_ref' "
1519 . "must start with 'refs/remotes/'\n")
1520 unless $_remote_ref =~ m{^refs/remotes/(.+)};
1521 my $remote_ref = $1;
1522 $local_ref =~ s{^/}{};
1523 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
1524 $r->{$remote}->{svm
} = {} if $use_svm_props;
1525 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
1526 $r->{$1}->{svm
} = {};
1527 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
1528 $r->{$1}->{url
} = $2;
1529 } elsif (m
!^(.+)\
.(branches
|tags
)=
1530 (.*):refs
/remotes
/(.+)\s
*$/!x
) {
1531 my ($p, $g) = ($3, $4);
1532 my $rs = $r->{$1}->{$2} = {
1535 path
=> Git
::SVN
::GlobSpec
->new($p),
1536 ref => Git
::SVN
::GlobSpec
->new($g) };
1537 if (length($rs->{ref}->{right
}) != 0) {
1538 die "The '*' glob character must be the last ",
1539 "character of '$g'\n";
1545 if (defined $r->{$_}->{svm
}) {
1548 my $section = "svn-remote.$_";
1550 source
=> tmp_config
('--get',
1551 "$section.svm-source"),
1552 replace
=> tmp_config
('--get',
1553 "$section.svm-replace"),
1556 $r->{$_}->{svm
} = $svm;
1564 $_gc_nr = $_gc_period = 1000;
1565 if (defined $_repack || defined $_repack_flags) {
1566 warn "Repack options are obsolete; they have no effect.\n";
1570 sub verify_remotes_sanity
{
1571 return unless -d
$ENV{GIT_DIR
};
1573 foreach (command
(qw
/config -l/)) {
1574 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
1576 die "Remote ref refs/remote/$1 is tracked by",
1577 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
1578 "Please resolve this ambiguity in ",
1579 "your git configuration file before ",
1587 sub find_existing_remote
{
1588 my ($url, $remotes) = @_;
1589 return undef if $no_reuse_existing;
1591 foreach my $repo_id (keys %$remotes) {
1592 my $u = $remotes->{$repo_id}->{url
} or next;
1594 $existing = $repo_id;
1600 sub init_remote_config
{
1601 my ($self, $url, $no_write) = @_;
1602 $url =~ s!/+$!!; # strip trailing slash
1603 my $r = read_all_remotes
();
1604 my $existing = find_existing_remote
($url, $r);
1606 unless ($no_write) {
1607 print STDERR
"Using existing ",
1608 "[svn-remote \"$existing\"]\n";
1610 $self->{repo_id
} = $existing;
1611 } elsif ($_minimize_url) {
1612 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
1613 $existing = find_existing_remote
($min_url, $r);
1615 unless ($no_write) {
1616 print STDERR
"Using existing ",
1617 "[svn-remote \"$existing\"]\n";
1619 $self->{repo_id
} = $existing;
1621 if ($min_url ne $url) {
1622 unless ($no_write) {
1623 print STDERR
"Using higher level of URL: ",
1624 "$url => $min_url\n";
1626 my $old_path = $self->{path
};
1627 $self->{path
} = $url;
1628 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
1629 if (length $old_path) {
1630 $self->{path
} .= "/$old_path";
1637 # verify that we aren't overwriting anything:
1639 command_oneline
('config', '--get',
1640 "svn-remote.$self->{repo_id}.url")
1642 if ($orig_url && ($orig_url ne $url)) {
1643 die "svn-remote.$self->{repo_id}.url already set: ",
1644 "$orig_url\nwanted to set to: $url\n";
1647 my ($xrepo_id, $xpath) = find_ref
($self->refname);
1648 if (defined $xpath) {
1649 die "svn-remote.$xrepo_id.fetch already set to track ",
1650 "$xpath:refs/remotes/", $self->refname, "\n";
1652 unless ($no_write) {
1653 command_noisy
('config',
1654 "svn-remote.$self->{repo_id}.url", $url);
1655 $self->{path
} =~ s{^/}{};
1656 command_noisy
('config', '--add',
1657 "svn-remote.$self->{repo_id}.fetch",
1658 "$self->{path}:".$self->refname);
1660 $self->{url
} = $url;
1663 sub find_by_url
{ # repos_root and, path are optional
1664 my ($class, $full_url, $repos_root, $path) = @_;
1666 return undef unless defined $full_url;
1667 remove_username
($full_url);
1668 remove_username
($repos_root) if defined $repos_root;
1669 my $remotes = read_all_remotes
();
1670 if (defined $full_url && defined $repos_root && !defined $path) {
1672 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
1674 foreach my $repo_id (keys %$remotes) {
1675 my $u = $remotes->{$repo_id}->{url
} or next;
1676 remove_username
($u);
1677 next if defined $repos_root && $repos_root ne $u;
1679 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
1680 foreach (qw
/branches tags/) {
1681 resolve_local_globs
($u, $fetch,
1682 $remotes->{$repo_id}->{$_});
1685 my $rwr = rewrite_root
({repo_id
=> $repo_id});
1686 my $svm = $remotes->{$repo_id}->{svm
}
1687 if defined $remotes->{$repo_id}->{svm
};
1688 unless (defined $p) {
1694 } elsif (defined $svm) {
1695 $z = $svm->{source
};
1696 $prefix = $svm->{replace
};
1697 $prefix =~ s
#^\Q$u\E(?:/|$)##;
1700 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
1702 foreach my $f (keys %$fetch) {
1704 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
1711 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
1712 my $self = _new
($class, $repo_id, $ref_id, $path);
1714 $self->init_remote_config($url, $no_write);
1721 foreach (command
(qw
/config -l/)) {
1722 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
1723 \s
*(.*)\s
*:\s
*refs
/remotes/(.+)\s
*$!x
;
1724 my ($repo_id, $path, $ref) = ($1, $2, $3);
1725 if ($ref eq $ref_id) {
1726 $path = '' if ($path =~ m
#^\./?#);
1727 return ($repo_id, $path);
1730 (undef, undef, undef);
1734 my ($class, $ref_id, $repo_id, $path) = @_;
1735 if (defined $ref_id && !defined $repo_id && !defined $path) {
1736 ($repo_id, $path) = find_ref
($ref_id);
1737 if (!defined $repo_id) {
1738 die "Could not find a \"svn-remote.*.fetch\" key ",
1739 "in the repository configuration matching: ",
1740 "refs/remotes/$ref_id\n";
1743 my $self = _new
($class, $repo_id, $ref_id, $path);
1744 if (!defined $self->{path
} || !length $self->{path
}) {
1745 my $fetch = command_oneline
('config', '--get',
1746 "svn-remote.$repo_id.fetch",
1747 ":refs/remotes/$ref_id\$") or
1748 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
1749 "\":refs/remotes/$ref_id\$\" in config\n";
1750 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
1752 $self->{url
} = command_oneline
('config', '--get',
1753 "svn-remote.$repo_id.url") or
1754 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
1760 my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
1762 # It cannot end with a slash /, we'll throw up on this because
1763 # SVN can't have directories with a slash in their name, either:
1764 if ($refname =~ m{/$}) {
1765 die "ref: '$refname' ends with a trailing slash, this is ",
1766 "not permitted by git nor Subversion\n";
1769 # It cannot have ASCII control character space, tilde ~, caret ^,
1770 # colon :, question-mark ?, asterisk *, space, or open bracket [
1773 # Additionally, % must be escaped because it is used for escaping
1774 # and we want our escaped refname to be reversible
1775 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
1777 # no slash-separated component can begin with a dot .
1779 $refname =~ s{/\.}{/%2E}g;
1781 # It cannot have two consecutive dots .. anywhere
1783 $refname =~ s{\.\.}{%2E%2E}g;
1788 sub desanitize_refname
{
1790 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
1796 return $self->{svm
}->{uuid
} if $self->svm;
1798 unless ($self->{svm
}) {
1799 die "SVM UUID not cached, and reading remotely failed\n";
1801 $self->{svm
}->{uuid
};
1806 return $self->{svm
} if $self->{svm
};
1808 # see if we have it in our config, first:
1810 my $section = "svn-remote.$self->{repo_id}";
1812 source
=> tmp_config
('--get', "$section.svm-source"),
1813 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
1814 replace
=> tmp_config
('--get', "$section.svm-replace"),
1817 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
1818 $self->{svm
} = $svm;
1824 my ($self, $ra) = @_;
1825 return $ra if $self->svm;
1827 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
1828 "(svm:source, svm:uuid) ",
1829 "from the following URLs:\n" );
1830 sub read_svm_props
{
1831 my ($self, $ra, $path, $r) = @_;
1832 my $props = ($ra->get_dir($path, $r))[2];
1833 my $src = $props->{'svm:source'};
1834 my $uuid = $props->{'svm:uuid'};
1835 return undef if (!$src || !$uuid);
1839 $uuid =~ m{^[0-9a-f\-]{30,}$}
1840 or die "doesn't look right - svm:uuid is '$uuid'\n";
1842 # the '!' is used to mark the repos_root!/relative/path
1843 $src =~ s{/?!/?}{/};
1844 $src =~ s{/+$}{}; # no trailing slashes please
1845 # username is of no interest
1846 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
1848 my $replace = $ra->{url
};
1849 $replace .= "/$path" if length $path;
1851 my $section = "svn-remote.$self->{repo_id}";
1852 tmp_config
("$section.svm-source", $src);
1853 tmp_config
("$section.svm-replace", $replace);
1854 tmp_config
("$section.svm-uuid", $uuid);
1862 my $r = $ra->get_latest_revnum;
1863 my $path = $self->{path
};
1865 while (length $path) {
1866 unless ($tried{"$self->{url}/$path"}) {
1867 return $ra if $self->read_svm_props($ra, $path, $r);
1868 $tried{"$self->{url}/$path"} = 1;
1870 $path =~ s
#/?[^/]+$##;
1872 die "Path: '$path' should be ''\n" if $path ne '';
1873 return $ra if $self->read_svm_props($ra, $path, $r);
1874 $tried{"$self->{url}/$path"} = 1;
1876 if ($ra->{repos_root
} eq $self->{url
}) {
1877 die @err, (map { " $_\n" } keys %tried), "\n";
1880 # nope, make sure we're connected to the repository root:
1883 $path = $ra->{svn_path
};
1884 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
1885 while (length $path) {
1886 unless ($tried{"$ra->{url}/$path"}) {
1887 $ok = $self->read_svm_props($ra, $path, $r);
1889 $tried{"$ra->{url}/$path"} = 1;
1891 $path =~ s
#/?[^/]+$##;
1893 die "Path: '$path' should be ''\n" if $path ne '';
1894 $ok ||= $self->read_svm_props($ra, $path, $r);
1895 $tried{"$ra->{url}/$path"} = 1;
1897 die @err, (map { " $_\n" } keys %tried), "\n";
1899 Git
::SVN
::Ra
->new($self->{url
});
1904 return $self->{svnsync
} if $self->{svnsync
};
1906 if ($self->no_metadata) {
1907 die "Can't have both 'noMetadata' and ",
1908 "'useSvnsyncProps' options set!\n";
1910 if ($self->rewrite_root) {
1911 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
1916 # see if we have it in our config, first:
1918 my $section = "svn-remote.$self->{repo_id}";
1920 my $url = tmp_config
('--get', "$section.svnsync-url");
1921 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1922 die "doesn't look right - svn:sync-from-url is '$url'\n";
1924 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
1925 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1926 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1928 $svnsync = { url
=> $url, uuid
=> $uuid }
1930 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
1931 return $self->{svnsync
} = $svnsync;
1934 my $err = "useSvnsyncProps set, but failed to read " .
1935 "svnsync property: svn:sync-from-";
1936 my $rp = $self->ra->rev_proplist(0);
1938 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
1939 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1940 die "doesn't look right - svn:sync-from-url is '$url'\n";
1942 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
1943 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1944 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1946 my $section = "svn-remote.$self->{repo_id}";
1947 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
1948 tmp_config
('--add', "$section.svnsync-url", $url);
1949 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
1952 # this allows us to memoize our SVN::Ra UUID locally and avoid a
1953 # remote lookup (useful for 'git svn log').
1956 unless ($self->{ra_uuid
}) {
1957 my $key = "svn-remote.$self->{repo_id}.uuid";
1958 my $uuid = eval { tmp_config
('--get', $key) };
1959 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/) {
1960 $self->{ra_uuid
} = $uuid;
1962 die "ra_uuid called without URL\n" unless $self->{url
};
1963 $self->{ra_uuid
} = $self->ra->get_uuid;
1964 tmp_config
('--add', $key, $self->{ra_uuid
});
1970 sub _set_repos_root
{
1971 my ($self, $repos_root) = @_;
1972 my $k = "svn-remote.$self->{repo_id}.reposRoot";
1973 $repos_root ||= $self->ra->{repos_root
};
1974 tmp_config
($k, $repos_root);
1980 my $k = "svn-remote.$self->{repo_id}.reposRoot";
1981 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
1986 my $ra = Git
::SVN
::Ra
->new($self->{url
});
1987 $self->_set_repos_root($ra->{repos_root
});
1988 if ($self->use_svm_props && !$self->{svm
}) {
1989 if ($self->no_metadata) {
1990 die "Can't have both 'noMetadata' and ",
1991 "'useSvmProps' options set!\n";
1992 } elsif ($self->use_svnsync_props) {
1993 die "Can't have both 'useSvnsyncProps' and ",
1994 "'useSvmProps' options set!\n";
1996 $ra = $self->_set_svm_vars($ra);
1997 $self->{-want_revprops
} = 1;
2004 my $repos_root = $self->ra->{repos_root
};
2005 return $self->{path
} if ($self->{url
} eq $repos_root);
2006 my $url = $self->{url
} .
2007 (length $self->{path
} ?
"/$self->{path}" : $self->{path
});
2008 $url =~ s!^\Q$repos_root\E(?:/+|$)!!g;
2012 # prop_walk(PATH, REV, SUB)
2013 # -------------------------
2014 # Recursively traverse PATH at revision REV and invoke SUB for each
2015 # directory that contains a SVN property. SUB will be invoked as
2016 # follows: &SUB(gs, path, props); where `gs' is this instance of
2017 # Git::SVN, `path' the path to the directory where the properties
2018 # `props' were found. The `path' will be relative to point of checkout,
2019 # that is, if url://repo/trunk is the current Git branch, and that
2020 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
2021 # as `path' (note the trailing `/').
2023 my ($self, $path, $rev, $sub) = @_;
2026 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
2029 # Strip the irrelevant part of the path.
2030 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
2031 # Ensure the path is terminated by a `/'.
2034 # The properties contain all the internal SVN stuff nobody
2035 # (usually) cares about.
2036 my $interesting_props = 0;
2037 foreach (keys %{$props}) {
2038 # If it doesn't start with `svn:', it must be a
2039 # user-defined property.
2040 ++$interesting_props and next if $_ !~ /^svn:/;
2041 # FIXME: Fragile, if SVN adds new public properties,
2042 # this needs to be updated.
2043 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
2044 |eol
-style
|mime
-type
2045 |externals
|needs
-lock)$/x
;
2047 &$sub($self, $p, $props) if $interesting_props;
2049 foreach (sort keys %$dirent) {
2050 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
2051 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
2055 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
2056 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
2058 # returns the newest SVN revision number and newest commit SHA1
2059 sub last_rev_commit
{
2061 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
2062 return ($self->{last_rev
}, $self->{last_commit
});
2064 my $c = ::verify_ref
($self->refname.'^0');
2065 if ($c && !$self->use_svm_props && !$self->no_metadata) {
2066 my $rev = (::cmt_metadata
($c))[1];
2068 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
2072 my $map_path = $self->map_path;
2073 unless (-e
$map_path) {
2074 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
2075 return (undef, undef);
2077 my ($rev, $commit) = $self->rev_map_max(1);
2078 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
2079 return ($rev, $commit);
2082 sub get_fetch_range
{
2083 my ($self, $min, $max) = @_;
2084 $max ||= $self->ra->get_latest_revnum;
2085 $min ||= $self->rev_map_max;
2091 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
2092 my $config = "$ENV{GIT_DIR}/svn/.metadata";
2093 if (! -f
$config && -f
$old_def_config) {
2094 rename $old_def_config, $config or
2095 die "Failed rename $old_def_config => $config: $!\n";
2097 my $old_config = $ENV{GIT_CONFIG
};
2098 $ENV{GIT_CONFIG
} = $config;
2101 unless (-f
$config) {
2103 open my $fh, '>', $config or
2104 die "Can't open $config: $!\n";
2105 print $fh "; This file is used internally by ",
2107 "Couldn't write to $config: $!\n";
2108 print $fh "; You should not have to edit it\n" or
2109 die "Couldn't write to $config: $!\n";
2110 close $fh or die "Couldn't close $config: $!\n";
2112 command
('config', @args);
2115 if (defined $old_config) {
2116 $ENV{GIT_CONFIG
} = $old_config;
2118 delete $ENV{GIT_CONFIG
};
2121 wantarray ?
@ret : $ret[0];
2125 my ($self, $sub) = @_;
2126 my $old_index = $ENV{GIT_INDEX_FILE
};
2127 $ENV{GIT_INDEX_FILE
} = $self->{index};
2130 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
2131 mkpath
([$dir]) unless -d
$dir;
2135 if (defined $old_index) {
2136 $ENV{GIT_INDEX_FILE
} = $old_index;
2138 delete $ENV{GIT_INDEX_FILE
};
2141 wantarray ?
@ret : $ret[0];
2144 sub assert_index_clean
{
2145 my ($self, $treeish) = @_;
2147 $self->tmp_index_do(sub {
2148 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
2149 my $x = command_oneline
('write-tree');
2150 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
2151 /^tree ($::sha1)/mo);
2154 warn "Index mismatch: $y != $x\nrereading $treeish\n";
2155 unlink $self->{index} or die "unlink $self->{index}: $!\n";
2156 command_noisy
('read-tree', $treeish);
2157 $x = command_oneline
('write-tree');
2159 ::fatal
"trees ($treeish) $y != $x\n",
2160 "Something is seriously wrong...";
2165 sub get_commit_parents
{
2166 my ($self, $log_entry) = @_;
2167 my (%seen, @ret, @tmp);
2168 # legacy support for 'set-tree'; this is only used by set_tree_cb:
2169 if (my $ip = $self->{inject_parents
}) {
2170 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
2174 if (my $cur = ::verify_ref
($self->refname.'^0')) {
2177 if (my $ipd = $self->{inject_parents_dcommit
}) {
2178 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
2179 push @tmp, @
$commit;
2182 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
2183 while (my $p = shift @tmp) {
2187 # MAXPARENT is defined to 16 in commit-tree.c:
2191 die "r$log_entry->{revision}: No room for parents:\n\t",
2192 join("\n\t", @tmp), "\n";
2199 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
2200 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
2201 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
2204 if ($rwr !~ m
#^[a-z\+]+://#) {
2205 die "$rwr is not a valid URL (key: $k)\n";
2208 $self->{-rewrite_root
} = $rwr;
2213 ($self->rewrite_root || $self->{url
}) .
2214 (length $self->{path
} ?
'/' . $self->{path
} : '');
2219 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
2223 sub set_commit_header_env
{
2224 my ($log_entry) = @_;
2226 foreach my $ned (qw
/NAME EMAIL DATE/) {
2227 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2228 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2232 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
2233 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
2234 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
2236 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
2237 ?
$log_entry->{commit_name
}
2238 : $log_entry->{name
};
2239 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
2240 ?
$log_entry->{commit_email
}
2241 : $log_entry->{email
};
2245 sub restore_commit_header_env
{
2247 foreach my $ned (qw
/NAME EMAIL DATE/) {
2248 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2249 my $k = "GIT_${ac}_${ned}";
2250 if (defined $env->{$k}) {
2251 $ENV{$k} = $env->{$k};
2260 command_noisy
('gc', '--auto');
2264 my ($self, $log_entry) = @_;
2265 my $lr = $self->last_rev;
2266 if (defined $lr && $lr >= $log_entry->{revision
}) {
2267 die "Last fetched revision of ", $self->refname,
2268 " was r$lr, but we are about to fetch: ",
2269 "r$log_entry->{revision}!\n";
2271 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
2272 croak
"$log_entry->{revision} = $c already exists! ",
2273 "Why are we refetching it?\n";
2275 my $old_env = set_commit_header_env
($log_entry);
2276 my $tree = $log_entry->{tree
};
2277 if (!defined $tree) {
2278 $tree = $self->tmp_index_do(sub {
2279 command_oneline
('write-tree') });
2281 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
2283 my @exec = ('git', 'commit-tree', $tree);
2284 foreach ($self->get_commit_parents($log_entry)) {
2285 push @exec, '-p', $_;
2287 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
2291 # we always get UTF-8 from SVN, but we may want our commits in
2292 # a different encoding.
2293 if (my $enc = Git
::config
('i18n.commitencoding')) {
2295 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
2297 print $msg_fh $log_entry->{log} or croak
$!;
2298 restore_commit_header_env
($old_env);
2299 unless ($self->no_metadata) {
2300 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
2303 $msg_fh->flush == 0 or croak
$!;
2304 close $msg_fh or croak
$!;
2305 chomp(my $commit = do { local $/; <$out_fh> });
2306 close $out_fh or croak
$!;
2309 if ($commit !~ /^$::sha1$/o) {
2310 die "Failed to commit, invalid sha1: $commit\n";
2313 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
2315 $self->{last_rev
} = $log_entry->{revision
};
2316 $self->{last_commit
} = $commit;
2317 print "r$log_entry->{revision}";
2318 if (defined $log_entry->{svm_revision
}) {
2319 print " (\@$log_entry->{svm_revision})";
2320 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
2321 0, $self->svm_uuid);
2323 print " = $commit ($self->{ref_id})\n";
2324 if (--$_gc_nr == 0) {
2325 $_gc_nr = $_gc_period;
2332 my ($self, $paths, $r) = @_;
2333 return 1 if $self->{path
} eq '';
2334 if (my $path = $paths->{"/$self->{path}"}) {
2335 return ($path->{action
} eq 'D') ?
0 : 1;
2337 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
2338 if (grep /$self->{path_regex}/, keys %$paths) {
2342 foreach (split m
#/#, $self->{path}) {
2344 next unless ($paths->{$c} &&
2345 ($paths->{$c}->{action
} =~ /^[AR]$/));
2346 if ($self->ra->check_path($self->{path
}, $r) ==
2354 sub find_parent_branch
{
2355 my ($self, $paths, $rev) = @_;
2356 return undef unless $self->follow_parent;
2357 unless (defined $paths) {
2358 my $err_handler = $SVN::Error
::handler
;
2359 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
2360 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1, sub {
2362 Git
::SVN
::Ra
::dup_changed_paths
($_[0]) });
2363 $SVN::Error
::handler
= $err_handler;
2365 return undef unless defined $paths;
2367 # look for a parent from another branch:
2368 my @b_path_components = split m
#/#, $self->rel_path;
2369 my @a_path_components;
2371 while (@b_path_components) {
2372 $i = $paths->{'/'.join('/', @b_path_components)};
2373 last if $i && defined $i->{copyfrom_path
};
2374 unshift(@a_path_components, pop(@b_path_components));
2376 return undef unless defined $i && defined $i->{copyfrom_path
};
2377 my $branch_from = $i->{copyfrom_path
};
2378 if (@a_path_components) {
2379 print STDERR
"branch_from: $branch_from => ";
2380 $branch_from .= '/'.join('/', @a_path_components);
2381 print STDERR
$branch_from, "\n";
2383 my $r = $i->{copyfrom_rev
};
2384 my $repos_root = $self->ra->{repos_root
};
2385 my $url = $self->ra->{url
};
2386 my $new_url = $repos_root . $branch_from;
2387 print STDERR
"Found possible branch point: ",
2388 "$new_url => ", $self->full_url, ", $r\n";
2389 $branch_from =~ s
#^/##;
2390 my $gs = Git
::SVN
->find_by_url($new_url, $repos_root, $branch_from);
2392 my $ref_id = $self->{ref_id
};
2393 $ref_id =~ s/\@\d+$//;
2395 # just grow a tail if we're not unique enough :x
2396 $ref_id .= '-' while find_ref
($ref_id);
2397 print STDERR
"Initializing parent: $ref_id\n";
2398 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
2399 if ($u =~ s
#^\Q$url\E(/|$)##) {
2402 $repo_id = $self->{repo_id
};
2404 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
2406 my ($r0, $parent) = $gs->find_rev_before($r, 1);
2409 if (!defined $r0 || !defined $parent) {
2410 ($base, $head) = parse_revision_argument
(0, $r);
2413 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
2414 0, 1, sub { $base = $_[1] - 1 });
2417 if (defined $base && $base <= $r) {
2418 $gs->fetch($base, $r);
2420 ($r0, $parent) = $gs->find_rev_before($r, 1);
2422 if (defined $r0 && defined $parent) {
2423 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n";
2425 if ($self->ra->can_do_switch) {
2426 $self->assert_index_clean($parent);
2427 print STDERR
"Following parent with do_switch\n";
2428 # do_switch works with svn/trunk >= r22312, but that
2429 # is not included with SVN 1.4.3 (the latest version
2430 # at the moment), so we can't rely on it
2431 $self->{last_commit
} = $parent;
2432 $ed = SVN
::Git
::Fetcher
->new($self);
2433 $gs->ra->gs_do_switch($r0, $rev, $gs,
2434 $self->full_url, $ed)
2435 or die "SVN connection failed somewhere...\n";
2436 } elsif ($self->ra->trees_match($new_url, $r0,
2437 $self->full_url, $rev)) {
2438 print STDERR
"Trees match:\n",
2440 " ${\$self->full_url}\@$rev\n",
2441 "Following parent with no changes\n";
2442 $self->tmp_index_do(sub {
2443 command_noisy
('read-tree', $parent);
2445 $self->{last_commit
} = $parent;
2447 print STDERR
"Following parent with do_update\n";
2448 $ed = SVN
::Git
::Fetcher
->new($self);
2449 $self->ra->gs_do_update($rev, $rev, $self, $ed)
2450 or die "SVN connection failed somewhere...\n";
2452 print STDERR
"Successfully followed parent\n";
2453 return $self->make_log_entry($rev, [$parent], $ed);
2459 my ($self, $paths, $rev) = @_;
2461 my ($last_rev, @parents);
2462 if (my $lc = $self->last_commit) {
2463 # we can have a branch that was deleted, then re-added
2464 # under the same name but copied from another path, in
2465 # which case we'll have multiple parents (we don't
2466 # want to break the original ref, nor lose copypath info):
2467 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2468 push @
{$log_entry->{parents
}}, $lc;
2471 $ed = SVN
::Git
::Fetcher
->new($self);
2472 $last_rev = $self->{last_rev
};
2477 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2480 $ed = SVN
::Git
::Fetcher
->new($self);
2482 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
2483 die "SVN connection failed somewhere...\n";
2485 $self->make_log_entry($rev, \
@parents, $ed);
2489 my ($self, $ed) = @_;
2491 my $h = $ed->{empty
};
2492 foreach (sort keys %$h) {
2493 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
2494 push @out, " $act: " . uri_encode
($_);
2495 warn "W: $act: $_\n";
2497 foreach my $t (qw
/dir_prop file_prop/) {
2498 $h = $ed->{$t} or next;
2499 foreach my $path (sort keys %$h) {
2500 my $ppath = $path eq '' ?
'.' : $path;
2501 foreach my $prop (sort keys %{$h->{$path}}) {
2502 next if $SKIP_PROP{$prop};
2503 my $v = $h->{$path}->{$prop};
2504 my $t_ppath_prop = "$t: " .
2505 uri_encode
($ppath) . ' ' .
2508 push @out, " +$t_ppath_prop " .
2511 push @out, " -$t_ppath_prop";
2516 foreach my $t (qw
/absent_file absent_directory/) {
2517 $h = $ed->{$t} or next;
2518 foreach my $parent (sort keys %$h) {
2519 foreach my $path (sort @
{$h->{$parent}}) {
2520 push @out, " $t: " .
2521 uri_encode
("$parent/$path");
2522 warn "W: $t: $parent/$path ",
2523 "Insufficient permissions?\n";
2530 # parse_svn_date(DATE)
2531 # --------------------
2532 # Given a date (in UTC) from Subversion, return a string in the format
2533 # "<TZ Offset> <local date/time>" that Git will use.
2535 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
2536 # is true we'll convert it to the local timezone instead.
2537 sub parse_svn_date
{
2538 my $date = shift || return '+0000 1970-01-01 00:00:00';
2539 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
2540 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
) or
2541 croak
"Unable to parse date: $date\n";
2542 my $parsed_date; # Set next.
2544 if ($Git::SVN
::_localtime
) {
2545 # Translate the Subversion datetime to an epoch time.
2546 # Begin by switching ourselves to $date's timezone, UTC.
2547 my $old_env_TZ = $ENV{TZ
};
2551 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
2553 # Determine our local timezone (including DST) at the
2554 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
2555 # value of TZ, if any, at the time we were run.
2556 if (defined $Git::SVN
::Log
::TZ
) {
2557 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
2563 POSIX
::strftime
('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
2565 # This converts $epoch_in_UTC into our local timezone.
2566 my ($sec, $min, $hour, $mday, $mon, $year,
2567 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
2569 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
2570 $our_TZ, $year + 1900, $mon + 1,
2571 $mday, $hour, $min, $sec);
2573 # Reset us to the timezone in effect when we entered
2575 if (defined $old_env_TZ) {
2576 $ENV{TZ
} = $old_env_TZ;
2581 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
2584 return $parsed_date;
2589 if (!defined $author || length $author == 0) {
2590 $author = '(no author)';
2591 } elsif (defined $::_authors
&& ! defined $::users
{$author}) {
2592 die "Author: $author not defined in $::_authors file\n";
2597 sub make_log_entry
{
2598 my ($self, $rev, $parents, $ed) = @_;
2599 my $untracked = $self->get_untracked($ed);
2601 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
2602 print $un "r$rev\n" or croak
$!;
2603 print $un $_, "\n" foreach @
$untracked;
2604 my %log_entry = ( parents
=> $parents || [], revision
=> $rev,
2608 my $logged = delete $self->{logged_rev_props
};
2609 if (!$logged || $self->{-want_revprops
}) {
2610 my $rp = $self->ra->rev_proplist($rev);
2611 foreach (sort keys %$rp) {
2613 if (/^svn:(author|date|log)$/) {
2614 $log_entry{$1} = $v;
2615 } elsif ($_ eq 'svm:headrev') {
2618 print $un " rev_prop: ", uri_encode
($_), ' ',
2619 uri_encode
($v), "\n";
2623 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
2625 close $un or croak
$!;
2627 $log_entry{date
} = parse_svn_date
($log_entry{date
});
2628 $log_entry{log} .= "\n";
2629 my $author = $log_entry{author
} = check_author
($log_entry{author
});
2630 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
2633 my ($commit_name, $commit_email) = ($name, $email);
2634 if ($_use_log_author) {
2636 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
2638 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
2641 if (!defined $name_field) {
2642 if (!defined $email) {
2645 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
2646 ($name, $email) = ($1, $2);
2647 } elsif ($name_field =~ /(.*)@/) {
2648 ($name, $email) = ($1, $name_field);
2650 ($name, $email) = ($name_field, $name_field);
2653 if (defined $headrev && $self->use_svm_props) {
2654 if ($self->rewrite_root) {
2655 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
2658 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$};
2659 # we don't want "SVM: initializing mirror for junk" ...
2660 return undef if $r == 0;
2661 my $svm = $self->svm;
2662 if ($uuid ne $svm->{uuid
}) {
2663 die "UUID mismatch on SVM path:\n",
2664 "expected: $svm->{uuid}\n",
2667 my $full_url = $self->full_url;
2668 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
2669 die "Failed to replace '$svm->{replace}' with ",
2670 "'$svm->{source}' in $full_url\n";
2671 # throw away username for storing in records
2672 remove_username
($full_url);
2673 $log_entry{metadata
} = "$full_url\@$r $uuid";
2674 $log_entry{svm_revision
} = $r;
2675 $email ||= "$author\@$uuid";
2676 $commit_email ||= "$author\@$uuid";
2677 } elsif ($self->use_svnsync_props) {
2678 my $full_url = $self->svnsync->{url
};
2679 $full_url .= "/$self->{path}" if length $self->{path
};
2680 remove_username
($full_url);
2681 my $uuid = $self->svnsync->{uuid
};
2682 $log_entry{metadata
} = "$full_url\@$rev $uuid";
2683 $email ||= "$author\@$uuid";
2684 $commit_email ||= "$author\@$uuid";
2686 my $url = $self->metadata_url;
2687 remove_username
($url);
2688 $log_entry{metadata
} = "$url\@$rev " .
2689 $self->ra->get_uuid;
2690 $email ||= "$author\@" . $self->ra->get_uuid;
2691 $commit_email ||= "$author\@" . $self->ra->get_uuid;
2693 $log_entry{name
} = $name;
2694 $log_entry{email
} = $email;
2695 $log_entry{commit_name
} = $commit_name;
2696 $log_entry{commit_email
} = $commit_email;
2701 my ($self, $min_rev, $max_rev, @parents) = @_;
2702 my ($last_rev, $last_commit) = $self->last_rev_commit;
2703 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
2704 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
2708 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
2709 $self->{inject_parents
} = { $rev => $tree };
2710 $self->fetch(undef, undef);
2714 my ($self, $tree) = (shift, shift);
2715 my $log_entry = ::get_commit_entry
($tree);
2716 unless ($self->{last_rev
}) {
2717 ::fatal
("Must have an existing revision to commit");
2719 my %ed_opts = ( r
=> $self->{last_rev
},
2720 log => $log_entry->{log},
2722 tree_a
=> $self->{last_commit
},
2725 $self->set_tree_cb($log_entry, $tree, @_) },
2726 svn_path
=> $self->{path
} );
2727 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
2728 print "No changes\nr$self->{last_rev} = $tree\n";
2732 sub rebuild_from_rev_db
{
2733 my ($self, $path) = @_;
2735 open my $fh, '<', $path or croak
"open: $!";
2736 binmode $fh or croak
"binmode: $!";
2738 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
2741 next if $_ eq ('0' x
40);
2742 $self->rev_map_set($r, $_);
2745 close $fh or croak
"close: $!";
2746 unlink $path or croak
"unlink: $!";
2751 my $map_path = $self->map_path;
2752 my $partial = (-e
$map_path && ! -z
$map_path);
2753 return unless ::verify_ref
($self->refname.'^0');
2754 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
2755 my $rev_db = $self->rev_db_path;
2756 $self->rebuild_from_rev_db($rev_db);
2757 if ($self->use_svm_props) {
2758 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
2759 $self->rebuild_from_rev_db($svm_rev_db);
2761 $self->unlink_rev_db_symlink;
2764 print "Rebuilding $map_path ...\n" if (!$partial);
2765 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
2768 command_output_pipe
(qw
/rev-list --pretty=raw --no-color --reverse/,
2769 ($head ?
"$head.." : "") . $self->refname,
2771 my $metadata_url = $self->metadata_url;
2772 remove_username
($metadata_url);
2773 my $svn_uuid = $self->ra_uuid;
2776 if ( m{^commit ($::sha1)$} ) {
2780 next unless s{^\s*(git-svn-id:)}{$1};
2781 my ($url, $rev, $uuid) = ::extract_metadata
($_);
2782 remove_username
($url);
2784 # ignore merges (from set-tree)
2785 next if (!defined $rev || !$uuid);
2787 # if we merged or otherwise started elsewhere, this is
2788 # how we break out of it
2789 if (($uuid ne $svn_uuid) ||
2790 ($metadata_url && $url && ($url ne $metadata_url))) {
2793 if ($partial && $head) {
2794 print "Partial-rebuilding $map_path ...\n";
2795 print "Currently at $base_rev = $head\n";
2799 $self->rev_map_set($rev, $c);
2800 print "r$rev = $c\n";
2802 command_close_pipe
($log, $ctx);
2803 print "Done rebuilding $map_path\n" if (!$partial || !$head);
2804 my $rev_db_path = $self->rev_db_path;
2805 if (-f
$self->rev_db_path) {
2806 unlink $self->rev_db_path or croak
"unlink: $!";
2808 $self->unlink_rev_db_symlink;
2812 # Tie::File seems to be prone to offset errors if revisions get sparse,
2813 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
2814 # one of my favorite modules is out :< Next up would be one of the DBM
2815 # modules, but I'm not sure which is most portable...
2817 # This is the replacement for the rev_db format, which was too big
2818 # and inefficient for large repositories with a lot of sparse history
2821 # The format is this:
2822 # - 24 bytes for every record,
2823 # * 4 bytes for the integer representing an SVN revision number
2824 # * 20 bytes representing the sha1 of a git commit
2825 # - No empty padding records like the old format
2826 # (except the last record, which can be overwritten)
2827 # - new records are written append-only since SVN revision numbers
2828 # increase monotonically
2829 # - lookups on SVN revision number are done via a binary search
2830 # - Piping the file to xxd -c24 is a good way of dumping it for
2831 # viewing or editing (piped back through xxd -r), should the need
2833 # - The last record can be padding revision with an all-zero sha1
2834 # This is used to optimize fetch performance when using multiple
2835 # "fetch" directives in .git/config
2837 # These files are disposable unless noMetadata or useSvmProps is set
2840 my ($fh, $rev, $commit) = @_;
2842 binmode $fh or croak
"binmode: $!";
2843 my $size = (stat($fh))[7];
2844 ($size % 24) == 0 or croak
"inconsistent size: $size";
2848 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2849 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
2850 $read == 24 or croak
"read only $read bytes (!= 24)";
2851 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
2852 if ($last_commit eq ('0' x40
)) {
2854 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2855 $read = sysread($fh, $buf, 24) or
2858 croak
"read only $read bytes (!= 24)";
2859 ($last_rev, $last_commit) =
2860 unpack(rev_map_fmt
, $buf);
2861 if ($last_commit eq ('0' x40
)) {
2862 croak
"inconsistent .rev_map\n";
2865 if ($last_rev >= $rev) {
2866 croak
"last_rev is higher!: $last_rev >= $rev";
2871 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
2872 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
2879 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2880 mkpath
([$dir]) unless -d
$dir;
2881 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
2882 close $fh or die "Couldn't close (create) $path: $!\n";
2887 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
2888 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
2889 my $db = $self->map_path($uuid);
2890 my $db_lock = "$db.lock";
2893 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
2894 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
2898 $LOCKFILES{$db_lock} = 1;
2900 # both of these options make our .rev_db file very, very important
2901 # and we can't afford to lose it because rebuild() won't work
2902 if ($self->use_svm_props || $self->no_metadata) {
2904 copy
($db, $db_lock) or die "rev_map_set(@_): ",
2906 "$db => $db_lock ($!)\n";
2908 rename $db, $db_lock or die "rev_map_set(@_): ",
2909 "Failed to rename: ",
2910 "$db => $db_lock ($!)\n";
2913 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
2914 or croak
"Couldn't open $db_lock: $!\n";
2915 _rev_map_set
($fh, $rev, $commit);
2917 $fh->flush or die "Couldn't flush $db_lock: $!\n";
2918 $fh->sync or die "Couldn't sync $db_lock: $!\n";
2920 close $fh or croak
$!;
2923 command_noisy
('update-ref', '-m', "r$rev",
2924 $self->refname, $commit);
2926 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
2927 "$db_lock => $db ($!)\n";
2928 delete $LOCKFILES{$db_lock};
2930 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
2931 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
2932 kill $sig, $$ if defined $sig;
2936 # If want_commit, this will return an array of (rev, commit) where
2937 # commit _must_ be a valid commit in the archive.
2938 # Otherwise, it'll return the max revision (whether or not the
2939 # commit is valid or just a 0x40 placeholder).
2941 my ($self, $want_commit) = @_;
2943 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
2944 $want_commit ?
($r, $c) : $r;
2947 sub rev_map_max_norebuild
{
2948 my ($self, $want_commit) = @_;
2949 my $map_path = $self->map_path;
2950 stat $map_path or return $want_commit ?
(0, undef) : 0;
2951 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2952 binmode $fh or croak
"binmode: $!";
2953 my $size = (stat($fh))[7];
2954 ($size % 24) == 0 or croak
"inconsistent size: $size";
2957 close $fh or croak
"close: $!";
2958 return $want_commit ?
(0, undef) : 0;
2961 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2962 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2963 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2964 if ($want_commit && $c eq ('0' x40
)) {
2966 return $want_commit ?
(0, undef) : 0;
2968 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2969 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
2970 ($r, $c) = unpack(rev_map_fmt
, $buf);
2971 if ($c eq ('0'x40
)) {
2972 croak
"Penultimate record is all-zeroes in $map_path";
2975 close $fh or croak
"close: $!";
2976 $want_commit ?
($r, $c) : $r;
2980 my ($self, $rev, $uuid) = @_;
2981 my $map_path = $self->map_path($uuid);
2982 return undef unless -e
$map_path;
2984 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2985 binmode $fh or croak
"binmode: $!";
2986 my $size = (stat($fh))[7];
2987 ($size % 24) == 0 or croak
"inconsistent size: $size";
2990 close $fh or croak
"close: $fh";
2994 my ($l, $u) = (0, $size - 24);
2998 my $i = int(($l/24 + $u/24) / 2) * 24;
2999 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
3000 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
3001 my ($r, $c) = unpack('NH40', $buf);
3005 } elsif ($r > $rev) {
3007 } else { # $r == $rev
3008 close($fh) or croak
"close: $!";
3009 return $c eq ('0' x
40) ?
undef : $c;
3012 close($fh) or croak
"close: $!";
3016 # Finds the first svn revision that exists on (if $eq_ok is true) or
3017 # before $rev for the current branch. It will not search any lower
3018 # than $min_rev. Returns the git commit hash and svn revision number
3019 # if found, else (undef, undef).
3020 sub find_rev_before
{
3021 my ($self, $rev, $eq_ok, $min_rev) = @_;
3022 --$rev unless $eq_ok;
3024 while ($rev >= $min_rev) {
3025 if (my $c = $self->rev_map_get($rev)) {
3030 return (undef, undef);
3033 # Finds the first svn revision that exists on (if $eq_ok is true) or
3034 # after $rev for the current branch. It will not search any higher
3035 # than $max_rev. Returns the git commit hash and svn revision number
3036 # if found, else (undef, undef).
3037 sub find_rev_after
{
3038 my ($self, $rev, $eq_ok, $max_rev) = @_;
3039 ++$rev unless $eq_ok;
3040 $max_rev ||= $self->rev_map_max;
3041 while ($rev <= $max_rev) {
3042 if (my $c = $self->rev_map_get($rev)) {
3047 return (undef, undef);
3051 my ($class, $repo_id, $ref_id, $path) = @_;
3052 unless (defined $repo_id && length $repo_id) {
3053 $repo_id = $Git::SVN
::default_repo_id
;
3055 unless (defined $ref_id && length $ref_id) {
3056 $_[2] = $ref_id = $Git::SVN
::default_ref_id
;
3059 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
3060 $_[3] = $path = '' unless (defined $path);
3061 mkpath
(["$ENV{GIT_DIR}/svn"]);
3063 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
3064 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
3065 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
3068 # for read-only access of old .rev_db formats
3069 sub unlink_rev_db_symlink
{
3071 my $link = $self->rev_db_path;
3072 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
3074 unlink $link or croak
"unlink: $link failed!";
3079 my ($self, $uuid) = @_;
3080 my $db_path = $self->map_path($uuid);
3081 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
3082 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
3086 # the new replacement for .rev_db
3088 my ($self, $uuid) = @_;
3089 $uuid ||= $self->ra_uuid;
3090 "$self->{map_root}.$uuid";
3095 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
3099 sub remove_username
{
3100 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};
3103 package Git
::SVN
::Prompt
;
3107 use vars qw
/$_no_auth_cache $_username/;
3110 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
3111 $may_save = undef if $_no_auth_cache;
3112 $default_username = $_username if defined $_username;
3113 if (defined $default_username && length $default_username) {
3114 if (defined $realm && length $realm) {
3115 print STDERR
"Authentication realm: $realm\n";
3118 $cred->username($default_username);
3120 username
($cred, $realm, $may_save, $pool);
3122 $cred->password(_read_password
("Password for '" .
3123 $cred->username . "': ", $realm));
3124 $cred->may_save($may_save);
3125 $SVN::_Core
::SVN_NO_ERROR
;
3128 sub ssl_server_trust
{
3129 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
3130 $may_save = undef if $_no_auth_cache;
3131 print STDERR
"Error validating server certificate for '$realm':\n";
3134 # All variables SVN::Auth::SSL::* are used only once,
3135 # so we're shutting up Perl warnings about this.
3136 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
3137 print STDERR
" - The certificate is not issued ",
3138 "by a trusted authority. Use the\n",
3139 " fingerprint to validate ",
3140 "the certificate manually!\n";
3142 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
3143 print STDERR
" - The certificate hostname ",
3144 "does not match.\n";
3146 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
3147 print STDERR
" - The certificate is not yet valid.\n";
3149 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
3150 print STDERR
" - The certificate has expired.\n";
3152 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
3153 print STDERR
" - The certificate has ",
3154 "an unknown error.\n";
3156 } # no warnings 'once'
3158 "Certificate information:\n".
3159 " - Hostname: %s\n".
3160 " - Valid: from %s until %s\n".
3162 " - Fingerprint: %s\n",
3163 map $cert_info->$_, qw(hostname valid_from valid_until
3164 issuer_dname fingerprint);
3167 print STDERR
$may_save ?
3168 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
3169 "(R)eject or accept (t)emporarily? ";
3171 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
3172 if ($choice =~ /^t$/i) {
3173 $cred->may_save(undef);
3174 } elsif ($choice =~ /^r$/i) {
3176 } elsif ($may_save && $choice =~ /^p$/i) {
3177 $cred->may_save($may_save);
3181 $cred->accepted_failures($failures);
3182 $SVN::_Core
::SVN_NO_ERROR
;
3185 sub ssl_client_cert
{
3186 my ($cred, $realm, $may_save, $pool) = @_;
3187 $may_save = undef if $_no_auth_cache;
3188 print STDERR
"Client certificate filename: ";
3190 chomp(my $filename = <STDIN
>);
3191 $cred->cert_file($filename);
3192 $cred->may_save($may_save);
3193 $SVN::_Core
::SVN_NO_ERROR
;
3196 sub ssl_client_cert_pw
{
3197 my ($cred, $realm, $may_save, $pool) = @_;
3198 $may_save = undef if $_no_auth_cache;
3199 $cred->password(_read_password
("Password: ", $realm));
3200 $cred->may_save($may_save);
3201 $SVN::_Core
::SVN_NO_ERROR
;
3205 my ($cred, $realm, $may_save, $pool) = @_;
3206 $may_save = undef if $_no_auth_cache;
3207 if (defined $realm && length $realm) {
3208 print STDERR
"Authentication realm: $realm\n";
3211 if (defined $_username) {
3212 $username = $_username;
3214 print STDERR
"Username: ";
3216 chomp($username = <STDIN
>);
3218 $cred->username($username);
3219 $cred->may_save($may_save);
3220 $SVN::_Core
::SVN_NO_ERROR
;
3223 sub _read_password
{
3224 my ($prompt, $realm) = @_;
3225 print STDERR
$prompt;
3227 require Term
::ReadKey
;
3228 Term
::ReadKey
::ReadMode
('noecho');
3230 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
3231 last if $key =~ /[\012\015]/; # \n\r
3234 Term
::ReadKey
::ReadMode
('restore');
3240 package SVN
::Git
::Fetcher
;
3245 use File
::Temp qw
/tempfile/;
3248 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
3250 my ($class, $git_svn) = @_;
3251 my $self = SVN
::Delta
::Editor
->new;
3252 bless $self, $class;
3253 if (exists $git_svn->{last_commit
}) {
3254 $self->{c
} = $git_svn->{last_commit
};
3255 $self->{empty_symlinks
} = _mark_empty_symlinks
($git_svn);
3257 $self->{empty
} = {};
3258 $self->{dir_prop
} = {};
3259 $self->{file_prop
} = {};
3260 $self->{absent_dir
} = {};
3261 $self->{absent_file
} = {};
3262 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
3266 # this uses the Ra object, so it must be called before do_{switch,update},
3267 # not inside them (when the Git::SVN::Fetcher object is passed) to
3268 # do_{switch,update}
3269 sub _mark_empty_symlinks
{
3272 my ($rev, $cmt) = $git_svn->last_rev_commit;
3273 return {} unless ($rev && $cmt);
3275 chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
3276 my ($ls, $ctx) = command_output_pipe
(qw
/ls-tree -r -z/, $cmt);
3278 my $pfx = $git_svn->{path
};
3279 $pfx .= '/' if length($pfx);
3282 s/\A100644 blob $empty_blob\t//o or next;
3284 my (undef, $props) =
3285 $git_svn->ra->get_file($pfx.$path, $rev, undef);
3286 if ($props->{'svn:special'}) {
3290 command_close_pipe
($ls, $ctx);
3294 sub set_path_strip
{
3295 my ($self, $path) = @_;
3296 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
3303 sub open_directory
{
3304 my ($self, $path, $pb, $rev) = @_;
3309 my ($self, $path) = @_;
3310 if ($self->{path_strip
}) {
3311 $path =~ s!$self->{path_strip}!! or
3312 die "Failed to strip path '$path' ($self->{path_strip})\n";
3318 my ($self, $path, $rev, $pb) = @_;
3320 my $gpath = $self->git_path($path);
3321 return undef if ($gpath eq '');
3323 # remove entire directories.
3324 if (command
('ls-tree', $self->{c
}, '--', $gpath) =~ /^040000 tree/) {
3325 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3327 $self->{c
}, '--', $gpath);
3331 $self->{gii
}->remove($_);
3332 print "\tD\t$_\n" unless $::_q
;
3334 print "\tD\t$gpath/\n" unless $::_q
;
3335 command_close_pipe
($ls, $ctx);
3336 $self->{empty
}->{$path} = 0
3338 $self->{gii
}->remove($gpath);
3339 print "\tD\t$gpath\n" unless $::_q
;
3345 my ($self, $path, $pb, $rev) = @_;
3346 my $gpath = $self->git_path($path);
3347 my ($mode, $blob) = (command
('ls-tree', $self->{c
}, '--', $gpath)
3348 =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
3349 unless (defined $mode && defined $blob) {
3350 die "$path was not found in commit $self->{c} (r$rev)\n";
3352 if ($mode eq '100644' && $self->{empty_symlinks
}->{$path}) {
3355 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
3356 pool
=> SVN
::Pool
->new, action
=> 'M' };
3360 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
3361 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3362 delete $self->{empty
}->{$dir};
3363 { path
=> $path, mode_a
=> 100644, mode_b
=> 100644,
3364 pool
=> SVN
::Pool
->new, action
=> 'A' };
3368 my ($self, $path, $cp_path, $cp_rev) = @_;
3369 my $gpath = $self->git_path($path);
3371 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3377 $self->{gii
}->remove($_);
3378 print "\tD\t$_\n" unless $::_q
;
3380 command_close_pipe
($ls, $ctx);
3381 $self->{empty
}->{$path} = 0;
3383 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3384 delete $self->{empty
}->{$dir};
3385 $self->{empty
}->{$path} = 1;
3389 sub change_dir_prop
{
3390 my ($self, $db, $prop, $value) = @_;
3391 $self->{dir_prop
}->{$db->{path
}} ||= {};
3392 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
3396 sub absent_directory
{
3397 my ($self, $path, $pb) = @_;
3398 $self->{absent_dir
}->{$pb->{path
}} ||= [];
3399 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
3404 my ($self, $path, $pb) = @_;
3405 $self->{absent_file
}->{$pb->{path
}} ||= [];
3406 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
3410 sub change_file_prop
{
3411 my ($self, $fb, $prop, $value) = @_;
3412 if ($prop eq 'svn:executable') {
3413 if ($fb->{mode_b
} != 120000) {
3414 $fb->{mode_b
} = defined $value ?
100755 : 100644;
3416 } elsif ($prop eq 'svn:special') {
3417 $fb->{mode_b
} = defined $value ?
120000 : 100644;
3419 $self->{file_prop
}->{$fb->{path
}} ||= {};
3420 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
3425 sub apply_textdelta
{
3426 my ($self, $fb, $exp) = @_;
3427 my $fh = $::_repository
->temp_acquire('svn_delta');
3428 # $fh gets auto-closed() by SVN::TxDelta::apply(),
3429 # (but $base does not,) so dup() it for reading in close_file
3430 open my $dup, '<&', $fh or croak
$!;
3431 my $base = $::_repository
->temp_acquire('git_blob');
3433 my ($base_is_link, $size);
3435 if ($fb->{mode_a
} eq '120000' &&
3436 ! $self->{empty_symlinks
}->{$fb->{path
}}) {
3437 print $base 'link ' or die "print $!\n";
3441 $size = $::_repository
->cat_blob($fb->{blob
}, $base);
3442 die "Failed to read object $fb->{blob}" if ($size < 0);
3445 seek $base, 0, 0 or croak
$!;
3446 my $got = ::md5sum
($base);
3448 my $err = "Checksum mismatch: ".
3449 "$fb->{path} $fb->{blob}\n" .
3450 "expected: $exp\n" .
3452 if ($base_is_link) {
3454 "Retrying... (possibly ",
3455 "a bad symlink from SVN)\n";
3456 $::_repository
->temp_reset($base);
3464 seek $base, 0, 0 or croak
$!;
3466 $fb->{base
} = $base;
3467 [ SVN
::TxDelta
::apply
($base, $dup, undef, $fb->{path
}, $fb->{pool
}) ];
3471 my ($self, $fb, $exp) = @_;
3473 my $path = $self->git_path($fb->{path
});
3474 if (my $fh = $fb->{fh
}) {
3476 seek($fh, 0, 0) or croak
$!;
3477 my $got = ::md5sum
($fh);
3479 die "Checksum mismatch: $path\n",
3480 "expected: $exp\n got: $got\n";
3483 if ($fb->{mode_b
} == 120000) {
3484 sysseek($fh, 0, 0) or croak
$!;
3485 my $rd = sysread($fh, my $buf, 5);
3488 croak
"sysread: $!\n";
3489 } elsif ($rd == 0) {
3490 warn "$path has mode 120000",
3491 " but it points to nothing\n",
3492 "converting to an empty file with mode",
3494 $fb->{mode_b
} = '100644';
3495 } elsif ($buf ne 'link ') {
3496 warn "$path has mode 120000",
3497 " but is not a link\n";
3499 my $tmp_fh = $::_repository
->temp_acquire(
3502 while ($res = sysread($fh, my $str, 1024)) {
3503 my $out = syswrite($tmp_fh, $str, $res);
3504 defined($out) && $out == $res
3506 Git
::temp_path
($tmp_fh),
3509 defined $res or croak
$!;
3511 ($fh, $tmp_fh) = ($tmp_fh, $fh);
3512 Git
::temp_release
($tmp_fh, 1);
3516 $hash = $::_repository
->hash_and_insert_object(
3517 Git
::temp_path
($fh));
3518 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
3520 Git
::temp_release
($fb->{base
}, 1);
3521 Git
::temp_release
($fh, 1);
3523 $hash = $fb->{blob
} or die "no blob information\n";
3526 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
3527 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
3533 $self->{nr
} = $self->{gii
}->{nr
};
3534 delete $self->{gii
};
3535 $self->SUPER::abort_edit
(@_);
3540 $self->{git_commit_ok
} = 1;
3541 $self->{nr
} = $self->{gii
}->{nr
};
3542 delete $self->{gii
};
3543 $self->SUPER::close_edit
(@_);
3546 package SVN
::Git
::Editor
;
3547 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
3554 my ($class, $opts) = @_;
3555 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
3556 die "$_ required!\n" unless (defined $opts->{$_});
3559 my $pool = SVN
::Pool
->new;
3560 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
3561 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
3564 # $opts->{ra} functions should not be used after this:
3565 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
3566 $opts->{editor_cb
}, $pool);
3567 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
3568 bless $self, $class;
3569 foreach (qw
/svn_path r tree_a tree_b/) {
3570 $self->{$_} = $opts->{$_};
3572 $self->{url
} = $opts->{ra
}->{url
};
3573 $self->{mods
} = $mods;
3574 $self->{types
} = $types;
3575 $self->{pool
} = $pool;
3576 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
3578 $self->{path_prefix
} = length $self->{svn_path
} ?
3579 "$self->{svn_path}/" : '';
3580 $self->{config
} = $opts->{config
};
3585 my ($tree_a, $tree_b) = @_;
3586 my @diff_tree = qw(diff-tree -z -r);
3587 if ($_cp_similarity) {
3588 push @diff_tree, "-C$_cp_similarity";
3590 push @diff_tree, '-C';
3592 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
3593 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
3594 push @diff_tree, $tree_a, $tree_b;
3595 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
3599 while (<$diff_fh>) {
3600 chomp $_; # this gets rid of the trailing "\0"
3601 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
3602 ($::sha1
)\s
($::sha1
)\s
3603 ([MTCRAD
])\d
*$/xo
) {
3604 push @mods, { mode_a
=> $1, mode_b
=> $2,
3605 sha1_a
=> $3, sha1_b
=> $4,
3607 if ($5 =~ /^(?:C|R)$/) {
3612 } elsif ($state eq 'file_a') {
3613 my $x = $mods[$#mods] or croak
"Empty array\n";
3614 if ($x->{chg
} !~ /^(?:C|R)$/) {
3615 croak
"Error parsing $_, $x->{chg}\n";
3619 } elsif ($state eq 'file_b') {
3620 my $x = $mods[$#mods] or croak
"Empty array\n";
3621 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
3622 croak
"Error parsing $_, $x->{chg}\n";
3624 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
3625 croak
"Error parsing $_, $x->{chg}\n";
3630 croak
"Error parsing $_\n";
3633 command_close_pipe
($diff_fh, $ctx);
3637 sub check_diff_paths
{
3638 my ($ra, $pfx, $rev, $mods) = @_;
3640 $pfx .= '/' if length $pfx;
3642 sub type_diff_paths
{
3643 my ($ra, $types, $path, $rev) = @_;
3644 my @p = split m
#/+#, $path;
3646 unless (defined $types->{$c}) {
3647 $types->{$c} = $ra->check_path($c, $rev);
3650 $c .= '/' . shift @p;
3651 next if defined $types->{$c};
3652 $types->{$c} = $ra->check_path($c, $rev);
3656 foreach my $m (@
$mods) {
3657 foreach my $f (qw
/file_a file_b/) {
3658 next unless defined $m->{$f};
3659 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
3660 if (length $pfx.$dir && ! defined $types{$dir}) {
3661 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
3669 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
3673 my ($self, $path) = @_;
3674 $self->{path_prefix
}.(defined $path ?
$path : '');
3678 my ($self, $path) = @_;
3679 if ($self->{url
} =~ m
#^https?://#) {
3680 $path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
3682 $self->{url
} . '/' . $self->repo_path($path);
3687 my $rm = $self->{rm
};
3688 delete $rm->{''}; # we never delete the url we're tracking
3691 foreach (keys %$rm) {
3692 my @d = split m
#/#, $_;
3696 $c .= '/' . shift @d;
3700 delete $rm->{$self->{svn_path
}};
3701 delete $rm->{''}; # we never delete the url we're tracking
3704 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
3709 my @dn = split m
#/#, $_;
3711 delete $rm->{join '/', @dn};
3718 command_close_pipe
($fh, $ctx);
3720 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
3721 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
3722 $self->close_directory($bat->{$d}, $p);
3723 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
3724 print "\tD+\t$d/\n" unless $::_q
;
3725 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
3730 sub open_or_add_dir
{
3731 my ($self, $full_path, $baton) = @_;
3732 my $t = $self->{types
}->{$full_path};
3734 die "$full_path not known in r$self->{r} or we have a bug!\n";
3738 # SVN::Node::none and SVN::Node::file are used only once,
3739 # so we're shutting up Perl's warnings about them.
3740 if ($t == $SVN::Node
::none
) {
3741 return $self->add_directory($full_path, $baton,
3742 undef, -1, $self->{pool
});
3743 } elsif ($t == $SVN::Node
::dir
) {
3744 return $self->open_directory($full_path, $baton,
3745 $self->{r
}, $self->{pool
});
3746 } # no warnings 'once'
3747 print STDERR
"$full_path already exists in repository at ",
3748 "r$self->{r} and it is not a directory (",
3749 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
3750 } # no warnings 'once'
3755 my ($self, $path) = @_;
3756 my $bat = $self->{bat
};
3757 my $repo_path = $self->repo_path($path);
3758 return $bat->{''} unless (length $repo_path);
3759 my @p = split m
#/+#, $repo_path;
3761 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
3764 $c .= '/' . shift @p;
3765 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
3770 # Subroutine to convert a globbing pattern to a regular expression.
3771 # From perl cookbook.
3773 my $globstr = shift;
3774 my %patmap = ('*' => '.*', '?' => '.', '[' => '[', ']' => ']');
3775 $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
3776 return '^' . $globstr . '$';
3779 sub check_autoprop
{
3780 my ($self, $pattern, $properties, $file, $fbat) = @_;
3781 # Convert the globbing pattern to a regular expression.
3782 my $regex = glob2pat
($pattern);
3783 # Check if the pattern matches the file name.
3784 if($file =~ m/($regex)/) {
3785 # Parse the list of properties to set.
3786 my @props = split(/;/, $properties);
3787 foreach my $prop (@props) {
3788 # Parse 'name=value' syntax and set the property.
3789 if ($prop =~ /([^=]+)=(.*)/) {
3790 my ($n,$v) = ($1,$2);
3794 $self->change_file_prop($fbat, $n, $v);
3800 sub apply_autoprops
{
3801 my ($self, $file, $fbat) = @_;
3802 my $conf_t = ${$self->{config
}}{'config'};
3804 # Check [miscellany]/enable-auto-props in svn configuration.
3805 if (SVN
::_Core
::svn_config_get_bool
(
3807 $SVN::_Core
::SVN_CONFIG_SECTION_MISCELLANY
,
3808 $SVN::_Core
::SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS
,
3810 # Auto-props are enabled. Enumerate them to look for matches.
3811 my $callback = sub {
3812 $self->check_autoprop($_[0], $_[1], $file, $fbat);
3814 SVN
::_Core
::svn_config_enumerate
(
3816 $SVN::_Core
::SVN_CONFIG_SECTION_AUTO_PROPS
,
3822 my ($self, $m) = @_;
3823 my ($dir, $file) = split_path
($m->{file_b
});
3824 my $pbat = $self->ensure_path($dir);
3825 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3827 print "\tA\t$m->{file_b}\n" unless $::_q
;
3828 $self->apply_autoprops($file, $fbat);
3829 $self->chg_file($fbat, $m);
3830 $self->close_file($fbat,undef,$self->{pool
});
3834 my ($self, $m) = @_;
3835 my ($dir, $file) = split_path
($m->{file_b
});
3836 my $pbat = $self->ensure_path($dir);
3837 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3838 $self->url_path($m->{file_a
}), $self->{r
});
3839 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
3840 $self->chg_file($fbat, $m);
3841 $self->close_file($fbat,undef,$self->{pool
});
3845 my ($self, $path, $pbat) = @_;
3846 my $rpath = $self->repo_path($path);
3847 my ($dir, $file) = split_path
($rpath);
3848 $self->{rm
}->{$dir} = 1;
3849 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
3853 my ($self, $m) = @_;
3854 my ($dir, $file) = split_path
($m->{file_b
});
3855 my $pbat = $self->ensure_path($dir);
3856 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3857 $self->url_path($m->{file_a
}), $self->{r
});
3858 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
3859 $self->apply_autoprops($file, $fbat);
3860 $self->chg_file($fbat, $m);
3861 $self->close_file($fbat,undef,$self->{pool
});
3863 ($dir, $file) = split_path
($m->{file_a
});
3864 $pbat = $self->ensure_path($dir);
3865 $self->delete_entry($m->{file_a
}, $pbat);
3869 my ($self, $m) = @_;
3870 my ($dir, $file) = split_path
($m->{file_b
});
3871 my $pbat = $self->ensure_path($dir);
3872 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
3873 $pbat,$self->{r
},$self->{pool
});
3874 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
3875 $self->chg_file($fbat, $m);
3876 $self->close_file($fbat,undef,$self->{pool
});
3879 sub T
{ shift->M(@_) }
3881 sub change_file_prop
{
3882 my ($self, $fbat, $pname, $pval) = @_;
3883 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
3886 sub _chg_file_get_blob
($$$$) {
3887 my ($self, $fbat, $m, $which) = @_;
3888 my $fh = $::_repository
->temp_acquire("git_blob_$which");
3889 if ($m->{"mode_$which"} =~ /^120/) {
3890 print $fh 'link ' or croak
$!;
3891 $self->change_file_prop($fbat,'svn:special','*');
3892 } elsif ($m->{mode_a
} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
3893 $self->change_file_prop($fbat,'svn:special',undef);
3895 my $blob = $m->{"sha1_$which"};
3896 return ($fh,) if ($blob =~ /^0{40}$/);
3897 my $size = $::_repository
->cat_blob($blob, $fh);
3898 croak
"Failed to read object $blob" if ($size < 0);
3899 $fh->flush == 0 or croak
$!;
3900 seek $fh, 0, 0 or croak
$!;
3902 my $exp = ::md5sum
($fh);
3903 seek $fh, 0, 0 or croak
$!;
3908 my ($self, $fbat, $m) = @_;
3909 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
3910 $self->change_file_prop($fbat,'svn:executable','*');
3911 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
3912 $self->change_file_prop($fbat,'svn:executable',undef);
3914 my ($fh_a, $exp_a) = _chg_file_get_blob
$self, $fbat, $m, 'a';
3915 my ($fh_b, $exp_b) = _chg_file_get_blob
$self, $fbat, $m, 'b';
3916 my $pool = SVN
::Pool
->new;
3917 my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
3919 my $txstream = SVN
::TxDelta
::new
($fh_a, $fh_b, $pool);
3920 my $res = SVN
::TxDelta
::send_txstream
($txstream, @
$atd, $pool);
3922 die "Unexpected result from send_txstream: $res\n",
3923 "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
3926 my $got = SVN
::TxDelta
::send_stream
($fh_b, @
$atd, $pool);
3927 die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
3928 if ($got ne $exp_b);
3930 Git
::temp_release
($fh_b, 1);
3931 Git
::temp_release
($fh_a, 1);
3936 my ($self, $m) = @_;
3937 my ($dir, $file) = split_path
($m->{file_b
});
3938 my $pbat = $self->ensure_path($dir);
3939 print "\tD\t$m->{file_b}\n" unless $::_q
;
3940 $self->delete_entry($m->{file_b
}, $pbat);
3945 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
3946 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
3948 $self->close_directory($bat->{$_}, $p);
3950 $self->close_directory($bat->{''}, $p);
3951 $self->SUPER::close_edit
($p);
3957 $self->SUPER::abort_edit
($self->{pool
});
3962 $self->SUPER::DESTROY
(@_);
3963 $self->{pool
}->clear;
3966 # this drives the editor
3969 my $mods = $self->{mods
};
3970 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
3971 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
3973 if (defined $o{$f}) {
3976 fatal
("Invalid change type: $f");
3979 $self->rmdirs if $_rmdir;
3985 return scalar @
$mods;
3988 package Git
::SVN
::Ra
;
3989 use vars qw
/@ISA $config_dir $_log_window_size/;
3992 my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
3995 # enforce temporary pool usage for some simple functions
3997 for my $f (qw
/rev_proplist get_latest_revnum get_uuid get_repos_root/) {
3998 my $SUPER = "SUPER::$f";
4001 my $pool = SVN
::Pool
->new;
4002 my @ret = $self->$SUPER(@_,$pool);
4004 wantarray ?
@ret : $ret[0];
4009 sub _auth_providers
() {
4011 SVN
::Client
::get_simple_provider
(),
4012 SVN
::Client
::get_ssl_server_trust_file_provider
(),
4013 SVN
::Client
::get_simple_prompt_provider
(
4014 \
&Git
::SVN
::Prompt
::simple
, 2),
4015 SVN
::Client
::get_ssl_client_cert_file_provider
(),
4016 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
4017 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
4018 SVN
::Client
::get_ssl_client_cert_pw_file_provider
(),
4019 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
4020 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
4021 SVN
::Client
::get_username_provider
(),
4022 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
4023 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
4024 SVN
::Client
::get_username_prompt_provider
(
4025 \
&Git
::SVN
::Prompt
::username
, 2)
4029 sub escape_uri_only
{
4032 foreach (split m{/}, $uri) {
4033 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
4041 if ($url =~ m
#^(https?)://([^/]+)(.*)$#) {
4042 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
4043 $url = "$scheme://$domain$uri";
4049 my ($class, $url) = @_;
4051 return $RA if ($RA && $RA->{url
} eq $url);
4053 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
4054 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
(_auth_providers
);
4055 my $config = SVN
::Core
::config_get_config
($config_dir);
4057 my $dont_store_passwords = 1;
4058 my $conf_t = ${$config}{'config'};
4061 # The usage of $SVN::_Core::SVN_CONFIG_* variables
4062 # produces warnings that variables are used only once.
4063 # I had not found the better way to shut them up, so
4064 # the warnings of type 'once' are disabled in this block.
4065 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
4066 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
4067 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_PASSWORDS
,
4069 SVN
::_Core
::svn_auth_set_parameter
($baton,
4070 $SVN::_Core
::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS
,
4071 bless (\
$dont_store_passwords, "_p_void"));
4073 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
4074 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
4075 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_AUTH_CREDS
,
4077 $Git::SVN
::Prompt
::_no_auth_cache
= 1;
4079 } # no warnings 'once'
4080 my $self = SVN
::Ra
->new(url
=> escape_url
($url), auth
=> $baton,
4082 pool
=> SVN
::Pool
->new,
4083 auth_provider_callbacks
=> $callbacks);
4084 $self->{url
} = $url;
4085 $self->{svn_path
} = $url;
4086 $self->{repos_root
} = $self->get_repos_root;
4087 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
4088 $self->{cache
} = { check_path
=> { r
=> 0, data
=> {} },
4089 get_dir
=> { r
=> 0, data
=> {} } };
4090 $RA = bless $self, $class;
4094 my ($self, $path, $r) = @_;
4095 my $cache = $self->{cache
}->{check_path
};
4096 if ($r == $cache->{r
} && exists $cache->{data
}->{$path}) {
4097 return $cache->{data
}->{$path};
4099 my $pool = SVN
::Pool
->new;
4100 my $t = $self->SUPER::check_path
($path, $r, $pool);
4102 if ($r != $cache->{r
}) {
4103 %{$cache->{data
}} = ();
4106 $cache->{data
}->{$path} = $t;
4110 my ($self, $dir, $r) = @_;
4111 my $cache = $self->{cache
}->{get_dir
};
4112 if ($r == $cache->{r
}) {
4113 if (my $x = $cache->{data
}->{$dir}) {
4114 return wantarray ? @
$x : $x->[0];
4117 my $pool = SVN
::Pool
->new;
4118 my ($d, undef, $props) = $self->SUPER::get_dir
($dir, $r, $pool);
4119 my %dirents = map { $_ => { kind
=> $d->{$_}->kind } } keys %$d;
4121 if ($r != $cache->{r
}) {
4122 %{$cache->{data
}} = ();
4125 $cache->{data
}->{$dir} = [ \
%dirents, $r, $props ];
4126 wantarray ?
(\
%dirents, $r, $props) : \
%dirents;
4130 # do not call the real DESTROY since we store ourselves in $RA
4133 # get_log(paths, start, end, limit,
4134 # discover_changed_paths, strict_node_history, receiver)
4136 my ($self, @args) = @_;
4137 my $pool = SVN
::Pool
->new;
4139 # the limit parameter was not supported in SVN 1.1.x, so we
4140 # drop it. Therefore, the receiver callback passed to it
4141 # is made aware of this limitation by being wrapped if
4142 # the limit passed to is being wrapped.
4143 if ($SVN::Core
::VERSION
le '1.2.0') {
4144 my $limit = splice(@args, 3, 1);
4146 my $receiver = pop @args;
4147 push(@args, sub { &$receiver(@_) if (--$limit >= 0) });
4150 my $ret = $self->SUPER::get_log
(@args, $pool);
4156 my ($self, $url1, $rev1, $url2, $rev2) = @_;
4157 my $ctx = SVN
::Client
->new(auth
=> _auth_providers
);
4158 my $out = IO
::File
->new_tmpfile;
4160 # older SVN (1.1.x) doesn't take $pool as the last parameter for
4161 # $ctx->diff(), so we'll create a default one
4162 my $pool = SVN
::Pool
->new_default_sub;
4164 $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
4165 $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
4167 my $ret = (($out->stat)[7] == 0);
4168 close $out or croak
$!;
4173 sub get_commit_editor
{
4174 my ($self, $log, $cb, $pool) = @_;
4175 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
4176 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
4180 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
4181 my $new = ($rev_a == $rev_b);
4182 my $path = $gs->{path
};
4184 if ($new && -e
$gs->{index}) {
4185 unlink $gs->{index} or die
4186 "Couldn't unlink index: $gs->{index}: $!\n";
4188 my $pool = SVN
::Pool
->new;
4189 $editor->set_path_strip($path);
4190 my (@pc) = split m
#/#, $path;
4191 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
4193 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4195 # Since we can't rely on svn_ra_reparent being available, we'll
4196 # just have to do some magic with set_path to make it so
4197 # we only want a partial path.
4199 my $final = join('/', @pc);
4201 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
4202 $sp .= '/' if length $sp;
4205 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
4207 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
4209 $reporter->finish_report($pool);
4211 $editor->{git_commit_ok
};
4214 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
4215 # svn_ra_reparent didn't work before 1.4)
4217 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
4218 my $path = $gs->{path
};
4219 my $pool = SVN
::Pool
->new;
4221 my $full_url = $self->{url
};
4222 my $old_url = $full_url;
4223 $full_url .= '/' . escape_uri_only
($path) if length $path;
4224 my ($ra, $reparented);
4226 if ($old_url =~ m
#^svn(\+ssh)?://#) {
4230 $ra = Git
::SVN
::Ra
->new($full_url);
4232 } elsif ($old_url ne $full_url) {
4233 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url, $pool);
4234 $self->{url
} = $full_url;
4239 $url_b = escape_url
($url_b);
4240 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
4241 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4242 $reporter->set_path('', $rev_a, 0, @lock, $pool);
4243 $reporter->finish_report($pool);
4246 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
4247 $self->{url
} = $old_url;
4251 $editor->{git_commit_ok
};
4254 sub longest_common_path
{
4255 my ($gsv, $globs) = @_;
4257 my $common_max = scalar @
$gsv;
4259 foreach my $gs (@
$gsv) {
4260 my @tmp = split m
#/#, $gs->{path};
4263 $p .= length($p) ?
"/$_" : $_;
4269 $common_max += scalar @
$globs;
4270 foreach my $glob (@
$globs) {
4271 my @tmp = split m
#/#, $glob->{path}->{left};
4274 $p .= length($p) ?
"/$_" : $_;
4280 my $longest_path = '';
4281 foreach (sort {length $b <=> length $a} keys %common) {
4282 if ($common{$_} == $common_max) {
4290 sub gs_fetch_loop_common
{
4291 my ($self, $base, $head, $gsv, $globs) = @_;
4292 return if ($base > $head);
4293 my $inc = $_log_window_size;
4294 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
4295 my $longest_path = longest_common_path
($gsv, $globs);
4296 my $ra_url = $self->{url
};
4300 my $err_handler = $SVN::Error
::handler
;
4301 $SVN::Error
::handler
= sub {
4303 skip_unknown_revs
($err);
4306 my ($paths, $r, $author, $date, $log) = @_;
4307 [ dup_changed_paths
($paths),
4308 { author
=> $author, date
=> $date, log => $log } ];
4310 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
4311 sub { $revs{$_[1]} = _cb
(@_) });
4312 if ($err && $max >= $head) {
4313 print STDERR
"Path '$longest_path' ",
4314 "was probably deleted:\n",
4315 $err->expanded_message,
4316 "\nWill attempt to follow ",
4317 "revisions r$min .. r$max ",
4318 "committed before the deletion\n";
4320 while (--$hi >= $min) {
4322 $self->get_log([$longest_path], $min, $hi,
4325 $revs{$_[1]} = _cb
(@_) });
4327 print STDERR
"r$min .. r$ok OK\n";
4332 $SVN::Error
::handler
= $err_handler;
4334 my %exists = map { $_->{path
} => $_ } @
$gsv;
4335 foreach my $r (sort {$a <=> $b} keys %revs) {
4336 my ($paths, $logged) = @
{$revs{$r}};
4338 foreach my $gs ($self->match_globs(\
%exists, $paths,
4340 if ($gs->rev_map_max >= $r) {
4343 next unless $gs->match_paths($paths, $r);
4344 $gs->{logged_rev_props
} = $logged;
4345 if (my $last_commit = $gs->last_commit) {
4346 $gs->assert_index_clean($last_commit);
4348 my $log_entry = $gs->do_fetch($paths, $r);
4350 $gs->do_git_commit($log_entry);
4352 $INDEX_FILES{$gs->{index}} = 1;
4354 foreach my $g (@
$globs) {
4355 my $k = "svn-remote.$g->{remote}." .
4357 Git
::SVN
::tmp_config
($k, $r);
4363 $self = Git
::SVN
::Ra
->new($ra_url);
4364 $ra_invalid = undef;
4367 # pre-fill the .rev_db since it'll eventually get filled in
4368 # with '0' x40 if something new gets committed
4369 foreach my $gs (@
$gsv) {
4370 next if $gs->rev_map_max >= $max;
4371 next if defined $gs->rev_map_get($max);
4372 $gs->rev_map_set($max, 0 x40
);
4374 foreach my $g (@
$globs) {
4375 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
4376 Git
::SVN
::tmp_config
($k, $max);
4378 last if $max >= $head;
4381 $max = $head if ($max > $head);
4386 sub get_dir_globbed
{
4387 my ($self, $left, $depth, $r) = @_;
4389 my @x = eval { $self->get_dir($left, $r) };
4390 return unless scalar @x == 3;
4391 my $dirents = $x[0];
4393 foreach my $de (keys %$dirents) {
4394 next if $dirents->{$de}->{kind
} != $SVN::Node
::dir
;
4396 my @args = ("$left/$de", $depth - 1, $r);
4397 foreach my $dir ($self->get_dir_globbed(@args)) {
4398 push @finalents, "$de/$dir";
4401 push @finalents, $de;
4408 my ($self, $exists, $paths, $globs, $r) = @_;
4411 my ($self, $exists, $g, $r) = @_;
4413 my @dirs = $self->get_dir_globbed($g->{path
}->{left
},
4414 $g->{path
}->{depth
},
4417 foreach my $de (@dirs) {
4418 my $p = $g->{path
}->full_path($de);
4419 next if $exists->{$p};
4420 next if (length $g->{path
}->{right
} &&
4421 ($self->check_path($p, $r) !=
4423 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
4424 $g->{ref}->full_path($de), 1);
4427 foreach my $g (@
$globs) {
4428 if (my $path = $paths->{"/$g->{path}->{left}"}) {
4429 if ($path->{action
} =~ /^[AR]$/) {
4430 get_dir_check
($self, $exists, $g, $r);
4433 foreach (keys %$paths) {
4434 if (/$g->{path}->{left_regex}/ &&
4435 !/$g->{path}->{regex}/) {
4436 next if $paths->{$_}->{action
} !~ /^[AR]$/;
4437 get_dir_check
($self, $exists, $g, $r);
4439 next unless /$g->{path}->{regex}/;
4441 my $pathname = $g->{path
}->full_path($p);
4442 next if $exists->{$pathname};
4443 next if ($self->check_path($pathname, $r) !=
4445 $exists->{$pathname} = Git
::SVN
->init(
4446 $self->{url
}, $pathname, undef,
4447 $g->{ref}->full_path($p), 1);
4450 foreach (split m
#/#, $g->{path}->{left}) {
4452 next unless ($paths->{$c} &&
4453 ($paths->{$c}->{action
} =~ /^[AR]$/));
4454 get_dir_check
($self, $exists, $g, $r);
4462 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
4463 my $url = $self->{repos_root
};
4464 my @components = split(m!/!, $self->{svn_path
});
4467 $url .= "/$c" if length $c;
4468 eval { (ref $self)->new($url)->get_latest_revnum };
4469 } while ($@
&& ($c = shift @components));
4475 unless (defined $can_do_switch) {
4476 my $pool = SVN
::Pool
->new;
4478 $self->do_switch(1, '', 0, $self->{url
},
4479 SVN
::Delta
::Editor
->new, $pool);
4484 $rep->abort_report($pool);
4492 sub skip_unknown_revs
{
4494 my $errno = $err->apr_err();
4495 # Maybe the branch we're tracking didn't
4496 # exist when the repo started, so it's
4497 # not an error if it doesn't, just continue
4499 # Wonderfully consistent library, eh?
4500 # 160013 - svn:// and file://
4501 # 175002 - http(s)://
4502 # 175007 - http(s):// (this repo required authorization, too...)
4503 # More codes may be discovered later...
4504 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
4505 my $err_key = $err->expanded_message;
4506 # revision numbers change every time, filter them out
4507 $err_key =~ s/\d+/\0/g;
4508 $err_key = "$errno\0$err_key";
4509 unless ($ignored_err{$err_key}) {
4510 warn "W: Ignoring error from SVN, path probably ",
4511 "does not exist: ($errno): ",
4512 $err->expanded_message,"\n";
4513 warn "W: Do not be alarmed at the above message ",
4514 "git-svn is just searching aggressively for ",
4516 "This may take a while on large repositories\n";
4517 $ignored_err{$err_key} = 1;
4521 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
4524 # svn_log_changed_path_t objects passed to get_log are likely to be
4525 # overwritten even if only the refs are copied to an external variable,
4526 # so we should dup the structures in their entirety. Using an externally
4527 # passed pool (instead of our temporary and quickly cleared pool in
4528 # Git::SVN::Ra) does not help matters at all...
4529 sub dup_changed_paths
{
4531 return undef unless $paths;
4533 foreach my $p (keys %$paths) {
4534 my $i = $paths->{$p};
4535 my %s = map { $_ => $i->$_ }
4536 qw
/copyfrom_path copyfrom_rev action/;
4542 package Git
::SVN
::Log
;
4545 use POSIX qw
/strftime/;
4546 use constant commit_log_separator
=> ('-' x
72) . "\n";
4547 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
4548 %rusers $show_commit $incremental/;
4553 return 1 if defined $c->{r
};
4555 # big commit message got truncated by the 16k pretty buffer in rev-list
4556 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
4557 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
4559 my @log = command
(qw
/cat-file commit/, $c->{c
});
4561 # shift off the headers
4562 shift @log while ($log[0] ne '');
4565 # TODO: make $c->{l} not have a trailing newline in the future
4566 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
4568 (undef, $c->{r
}, undef) = ::extract_metadata
(
4569 (grep(/^git-svn-id: /, @log))[-1]);
4571 return defined $c->{r
};
4575 return $color || Git
->repository->get_colorbool('color.diff');
4578 sub git_svn_log_cmd
{
4579 my ($r_min, $r_max, @args) = @_;
4581 my (@files, @log_opts);
4582 foreach my $x (@args) {
4583 if ($x eq '--' || @files) {
4586 if (::verify_ref
("$x^0")) {
4594 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
4595 $gs ||= Git
::SVN
->_new;
4596 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
4598 push @cmd, '-r' unless $non_recursive;
4599 push @cmd, qw
/--raw --name-status/ if $verbose;
4600 push @cmd, '--color' if log_use_color
();
4601 push @cmd, @log_opts;
4602 if (defined $r_max && $r_max == $r_min) {
4603 push @cmd, '--max-count=1';
4604 if (my $c = $gs->rev_map_get($r_max)) {
4607 } elsif (defined $r_max) {
4608 if ($r_max < $r_min) {
4609 ($r_min, $r_max) = ($r_max, $r_min);
4611 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
4612 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
4613 # If there are no commits in the range, both $c_max and $c_min
4614 # will be undefined. If there is at least 1 commit in the
4615 # range, both will be defined.
4616 return () if !defined $c_min || !defined $c_max;
4617 if ($c_min eq $c_max) {
4618 push @cmd, '--max-count=1', $c_min;
4620 push @cmd, '--boundary', "$c_min..$c_max";
4623 return (@cmd, @files);
4626 # adapted from pager.c
4628 $pager ||= $ENV{GIT_PAGER
} || $ENV{PAGER
};
4629 if (!defined $pager) {
4631 } elsif (length $pager == 0 || $pager eq 'cat') {
4634 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
4638 return unless -t
*STDOUT
&& defined $pager;
4639 pipe my ($rfd, $wfd) or return;
4640 defined(my $pid = fork) or ::fatal
"Can't fork: $!";
4642 open STDOUT
, '>&', $wfd or
4643 ::fatal
"Can't redirect to stdout: $!";
4646 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!";
4647 $ENV{LESS
} ||= 'FRSX';
4648 exec $pager or ::fatal
"Can't run pager: $! ($pager)";
4651 sub format_svn_date
{
4652 return strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
4655 sub parse_git_date
{
4657 # Date::Parse isn't in the standard Perl distro :(
4658 if ($tz =~ s/^\+//) {
4659 $t += tz_to_s_offset
($tz);
4660 } elsif ($tz =~ s/^\-//) {
4661 $t -= tz_to_s_offset
($tz);
4666 sub set_local_timezone
{
4674 sub tz_to_s_offset
{
4677 return ($1 * 60) + ($tz * 3600);
4680 sub get_author_info
{
4681 my ($dest, $author, $t, $tz) = @_;
4682 $author =~ s/(?:^\s*|\s*$)//g;
4683 $dest->{a_raw
} = $author;
4686 $au = $rusers{$author} || undef;
4689 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
4694 $dest->{t_utc
} = parse_git_date
($t, $tz);
4697 sub process_commit
{
4698 my ($c, $r_min, $r_max, $defer) = @_;
4699 if (defined $r_min && defined $r_max) {
4700 if ($r_min == $c->{r
} && $r_min == $r_max) {
4704 return 1 if $r_min == $r_max;
4705 if ($r_min < $r_max) {
4706 # we need to reverse the print order
4707 return 0 if (defined $limit && --$limit < 0);
4711 if ($r_min != $r_max) {
4712 return 1 if ($r_min < $c->{r
});
4713 return 1 if ($r_max > $c->{r
});
4716 return 0 if (defined $limit && --$limit < 0);
4725 if (my $l = $c->{l
}) {
4726 while ($l->[0] =~ /^\s*$/) { shift @
$l }
4729 $l_fmt ||= 'A' . length($c->{r
});
4730 print 'r',pack($l_fmt, $c->{r
}),' | ';
4731 print "$c->{c} | " if $show_commit;
4734 show_commit_normal
($c);
4738 sub show_commit_changed_paths
{
4740 return unless $c->{changed
};
4741 print "Changed paths:\n", @
{$c->{changed
}};
4744 sub show_commit_normal
{
4746 print commit_log_separator
, "r$c->{r} | ";
4747 print "$c->{c} | " if $show_commit;
4748 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
4751 if (my $l = $c->{l
}) {
4752 while ($l->[$#$l] eq "\n" && $#$l > 0
4753 && $l->[($#$l - 1)] eq "\n") {
4756 $nr_line = scalar @
$l;
4758 print "1 line\n\n\n";
4760 if ($nr_line == 1) {
4761 $nr_line = '1 line';
4763 $nr_line .= ' lines';
4765 print $nr_line, "\n";
4766 show_commit_changed_paths
($c);
4768 print $_ foreach @
$l;
4772 show_commit_changed_paths
($c);
4776 foreach my $x (qw
/raw stat diff/) {
4779 print $_ foreach @
{$c->{$x}}
4786 my ($r_min, $r_max);
4787 my $r_last = -1; # prevent dupes
4788 set_local_timezone
();
4789 if (defined $::_revision
) {
4790 if ($::_revision
=~ /^(\d+):(\d+)$/) {
4791 ($r_min, $r_max) = ($1, $2);
4792 } elsif ($::_revision
=~ /^\d+$/) {
4793 $r_min = $r_max = $::_revision
;
4795 ::fatal
"-r$::_revision is not supported, use ",
4796 "standard 'git log' arguments instead";
4801 @args = git_svn_log_cmd
($r_min, $r_max, @args);
4803 print commit_log_separator
unless $incremental || $oneline;
4806 my $log = command_output_pipe
(@args);
4808 my (@k, $c, $d, $stat);
4809 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
4811 if (/^${esc_color}commit -?($::sha1_short)/o) {
4813 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
4815 process_commit
($c, $r_min, $r_max, \
@k) or
4820 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
4821 get_author_info
($c, $1, $2, $3);
4822 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
4824 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
4825 push @
{$c->{raw
}}, $_;
4826 } elsif (/^${esc_color}[ACRMDT]\t/) {
4827 # we could add $SVN->{svn_path} here, but that requires
4828 # remote access at the moment (repo_path_split)...
4829 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
4830 push @
{$c->{changed
}}, $_;
4831 } elsif (/^${esc_color}diff /o) {
4833 push @
{$c->{diff
}}, $_;
4835 push @
{$c->{diff
}}, $_;
4836 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
4837 $esc_color*[\
+\
-]*$esc_color$/x
) {
4839 push @
{$c->{stat}}, $_;
4840 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
4841 push @
{$c->{stat}}, $_;
4843 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
4844 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
4845 } elsif (s/^${esc_color} //o) {
4846 push @
{$c->{l
}}, $_;
4849 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
4851 process_commit
($c, $r_min, $r_max, \
@k);
4854 ($r_min, $r_max) = ($r_max, $r_min);
4855 process_commit
($_, $r_min, $r_max) foreach reverse @k;
4859 print commit_log_separator
unless $incremental || $oneline;
4868 my ($fh, $ctx, $rev);
4871 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
4872 while (my $line = <$fh>) {
4873 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
4874 # Uncommitted edits show up as a rev ID of
4875 # all zeros, which we can't look up with
4878 (undef, $rev, undef) =
4880 $rev = '0' if (!$rev);
4884 $rev = sprintf('%-10s', $rev);
4885 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
4890 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
4894 while (my $line = <$fh>) {
4895 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
4897 (undef, $rev, undef) = ::cmt_metadata
($1);
4898 $rev = '0' if (!$rev);
4900 elsif ($line =~ /^author (.*)/) {
4901 $authors{$rev} = $1;
4902 $authors{$rev} =~ s/\s/_/g;
4904 elsif ($line =~ /^\t(.*)$/) {
4905 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
4909 command_close_pipe
($fh, $ctx);
4912 package Git
::SVN
::Migration
;
4913 # these version numbers do NOT correspond to actual version numbers
4914 # of git nor git-svn. They are just relative.
4916 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
4918 # v1 layout: .git/$id/info/url, refs/remotes/$id
4920 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
4922 # v3 layout: .git/svn/$id, refs/remotes/$id
4923 # - info/url may remain for backwards compatibility
4924 # - this is what we migrate up to this layout automatically,
4925 # - this will be used by git svn init on single branches
4926 # v3.1 layout (auto migrated):
4927 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
4928 # for backwards compatibility
4930 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
4931 # - this is only created for newly multi-init-ed
4932 # repositories. Similar in spirit to the
4933 # --use-separate-remotes option in git-clone (now default)
4934 # - we do not automatically migrate to this (following
4935 # the example set by core git)
4937 # v5 layout: .rev_db.$UUID => .rev_map.$UUID
4938 # - newer, more-efficient format that uses 24-bytes per record
4939 # with no filler space.
4940 # - use xxd -c24 < .rev_map.$UUID to view and debug
4941 # - This is a one-way migration, repositories updated to the
4942 # new format will not be able to use old git-svn without
4943 # rebuilding the .rev_db. Rebuilding the rev_db is not
4944 # possible if noMetadata or useSvmProps are set; but should
4945 # be no problem for users that use the (sensible) defaults.
4949 use File
::Path qw
/mkpath/;
4950 use File
::Basename qw
/dirname basename/;
4951 use vars qw
/$_minimize/;
4953 sub migrate_from_v0
{
4954 my $git_dir = $ENV{GIT_DIR
};
4955 return undef unless -d
$git_dir;
4956 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
4960 my ($id, $orig_ref) = ($_, $_);
4961 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
4962 next unless -f
"$git_dir/$id/info/url";
4963 my $new_ref = "refs/remotes/$id";
4964 if (::verify_ref
("$new_ref^0")) {
4965 print STDERR
"W: $orig_ref is probably an old ",
4966 "branch used by an ancient version of ",
4968 "However, $new_ref also exists.\n",
4969 "We will not be able ",
4970 "to use this branch until this ",
4971 "ambiguity is resolved.\n";
4974 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
4975 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
4976 command_noisy
('update-ref', $new_ref, $orig_ref);
4977 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
4980 command_close_pipe
($fh, $ctx);
4981 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
4985 sub migrate_from_v1
{
4986 my $git_dir = $ENV{GIT_DIR
};
4988 return $migrated unless -d
$git_dir;
4989 my $svn_dir = "$git_dir/svn";
4991 # just in case somebody used 'svn' as their $id at some point...
4992 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
4994 print STDERR
"Migrating from a git-svn v1 layout...\n";
4996 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
4997 "$svn_dir\n\t(required for this version ",
4998 "($::VERSION) of git-svn) does not exist.\n";
4999 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
5002 next unless $x =~ s
#^refs/remotes/##;
5004 next unless -f
"$git_dir/$x/info/url";
5005 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
5007 my $dn = dirname
("$git_dir/svn/$x");
5008 mkpath
([$dn]) unless -d
$dn;
5009 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
5010 mkpath
(["$git_dir/svn/svn"]);
5011 print STDERR
" - $git_dir/$x/info => ",
5012 "$git_dir/svn/$x/info\n";
5013 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
5015 # don't worry too much about these, they probably
5016 # don't exist with repos this old (save for index,
5017 # and we can easily regenerate that)
5018 foreach my $f (qw
/unhandled.log index .rev_db/) {
5019 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
5022 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
5023 rename "$git_dir/$x", "$git_dir/svn/$x" or
5028 command_close_pipe
($fh, $ctx);
5029 print STDERR
"Done migrating from a git-svn v1 layout\n";
5034 my ($l_map, $pfx, $path) = @_;
5036 foreach (<$path/*>) {
5037 if (-r
"$_/info/url") {
5038 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
5039 my $ref_id = $pfx . basename
$_;
5040 my $url = ::file_to_s
("$_/info/url");
5041 $l_map->{$ref_id} = $url;
5048 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
5049 read_old_urls
($l_map, $x, $_);
5053 sub migrate_from_v2
{
5054 my @cfg = command
(qw
/config -l/);
5055 return if grep /^svn-remote\..+\.url=/, @cfg;
5057 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
5060 foreach my $ref_id (sort keys %l_map) {
5061 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
5063 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
5070 sub minimize_connections
{
5071 my $r = Git
::SVN
::read_all_remotes
();
5073 my $root_repos = {};
5074 foreach my $repo_id (keys %$r) {
5075 my $url = $r->{$repo_id}->{url
} or next;
5076 my $fetch = $r->{$repo_id}->{fetch
} or next;
5077 my $ra = Git
::SVN
::Ra
->new($url);
5079 # skip existing cases where we already connect to the root
5080 if (($ra->{url
} eq $ra->{repos_root
}) ||
5081 ($ra->{repos_root
} eq $repo_id)) {
5082 $root_repos->{$ra->{url
}} = $repo_id;
5086 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
5087 my $root_path = $ra->{url
};
5088 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
5089 foreach my $path (keys %$fetch) {
5090 my $ref_id = $fetch->{$path};
5091 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
5093 # make sure we can read when connecting to
5094 # a higher level of a repository
5095 my ($last_rev, undef) = $gs->last_rev_commit;
5096 if (!defined $last_rev) {
5098 $root_ra->get_latest_revnum;
5102 my $new = $root_path;
5103 $new .= length $path ?
"/$path" : '';
5105 $root_ra->get_log([$new], $last_rev, $last_rev,
5109 $new_urls->{$ra->{repos_root
}}->{$new} =
5110 { ref_id
=> $ref_id,
5111 old_repo_id
=> $repo_id,
5112 old_path
=> $path };
5117 foreach my $url (keys %$new_urls) {
5118 # see if we can re-use an existing [svn-remote "repo_id"]
5119 # instead of creating a(n ugly) new section:
5120 my $repo_id = $root_repos->{$url} || $url;
5122 my $fetch = $new_urls->{$url};
5123 foreach my $path (keys %$fetch) {
5124 my $x = $fetch->{$path};
5125 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
5126 my $pfx = "svn-remote.$x->{old_repo_id}";
5128 my $old_fetch = quotemeta("$x->{old_path}:".
5129 "refs/remotes/$x->{ref_id}");
5130 command_noisy
(qw
/config --unset/,
5131 "$pfx.fetch", '^'. $old_fetch . '$');
5132 delete $r->{$x->{old_repo_id
}}->
5133 {fetch
}->{$x->{old_path
}};
5134 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
5135 command_noisy
(qw
/config --unset/,
5137 push @emptied, $x->{old_repo_id
}
5142 my $file = $ENV{GIT_CONFIG
} || "$ENV{GIT_DIR}/config";
5144 The following [svn-remote] sections in your config file ($file) are empty
5145 and can be safely removed:
5147 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
5151 sub migration_check
{
5155 minimize_connections
() if $_minimize;
5158 package Git
::IndexInfo
;
5161 use Git qw
/command_input_pipe command_close_pipe/;
5165 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
5166 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
5170 my ($self, $path) = @_;
5171 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
5172 return ++$self->{nr
};
5178 my ($self, $mode, $hash, $path) = @_;
5179 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
5180 return ++$self->{nr
};
5187 command_close_pipe
($self->{gui
}, $self->{ctx
});
5190 package Git
::SVN
::GlobSpec
;
5195 my ($class, $glob) = @_;
5197 $re =~ s!/+$!!g; # no need for trailing slashes
5198 $re =~ m!^([^*]*)(\*(?:/\*)*)([^*]*)$!;
5200 my ($left, $right) = ($1, $3);
5202 my $depth = $re =~ tr/*/*/;
5203 if ($depth != $temp =~ tr/*/*/) {
5204 die "Only one set of wildcard directories " .
5205 "(e.g. '*' or '*/*/*') is supported: '$glob'\n";
5208 die "One '*' is needed for glob: '$glob'\n";
5210 $re =~ s!\*!\[^/\]*!g;
5211 $re = quotemeta($left) . "($re)" . quotemeta($right);
5212 if (length $left && !($left =~ s!/+$!!g)) {
5213 die "Missing trailing '/' on left side of: '$glob' ($left)\n";
5215 if (length $right && !($right =~ s!^/+!!g)) {
5216 die "Missing leading '/' on right side of: '$glob' ($right)\n";
5218 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
5219 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
5220 regex
=> qr/$re/, glob => $glob, depth
=> $depth }, $class;
5224 my ($self, $path) = @_;
5225 return (length $self->{left
} ?
"$self->{left}/" : '') .
5226 $path . (length $self->{right
} ?
"/$self->{right}" : '');
5234 $remotes = { # returned by read_all_remotes()
5236 # svn-remote.svn.url=https://svn.musicpd.org
5237 url
=> 'https://svn.musicpd.org',
5238 # svn-remote.svn.fetch=mpd/trunk:trunk
5240 'mpd/trunk' => 'trunk',
5242 # svn-remote.svn.tags=mpd/tags/*:tags/*
5247 regex
=> qr!mpd/tags/([^/]+)$!,
5253 regex
=> qr!tags/([^/]+)$!,
5260 $log_entry hashref as returned by libsvn_log_entry
()
5262 log => 'whitespace-formatted log entry
5263 ', # trailing newline is preserved
5264 revision
=> '8', # integer
5265 date
=> '2004-02-24T17:01:44.108345Z', # commit date
5266 author
=> 'committer name'
5270 # this is generated by generate_diff();
5271 @mods = array of diff
-index line hashes
, each element represents one line
5272 of diff
-index output
5274 diff
-index line
($m hash
)
5276 mode_a
=> first column of diff
-index output
, no leading
':',
5277 mode_b
=> second column of diff
-index output
,
5278 sha1_b
=> sha1sum of the final blob
,
5279 chg
=> change type
[MCRADT
],
5280 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
5281 file_b
=> new
/current file name of a file
(any chg
)
5285 # retval of read_url_paths{,_all}();
5287 # repository root url
5288 'https://svn.musicpd.org' => {
5289 # repository path # GIT_SVN_ID
5290 'mpd/trunk' => 'trunk',
5291 'mpd/tags/0.11.5' => 'tags/0.11.5',
5296 I don
't trust the each() function on unless I created %hash myself
5297 because the internal iterator may not have started at base.